forked from sindresorhus/fkill-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
37 lines (32 loc) · 1.09 KB
/
test.js
File metadata and controls
37 lines (32 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import childProcess from 'child_process';
import test from 'ava';
import execa from 'execa';
import delay from 'delay';
import noopProcess from 'noop-process';
import processExists from 'process-exists';
import getPort from 'get-port';
const noopProcessKilled = async (t, pid) => {
// Ensure the noop process has time to exit
await delay(100);
t.false(await processExists(pid));
};
test(async t => {
const {stdout} = await execa('./cli.js', ['--version']);
t.true(stdout.length > 0);
});
test('pid', async t => {
const pid = await noopProcess();
await execa('./cli.js', ['--force', pid]);
await noopProcessKilled(t, pid);
});
test('kill from port', async t => {
const port = await getPort();
const {pid} = childProcess.spawn('node', ['fixture.js', port]);
await execa('./cli.js', ['--force', pid]);
await noopProcessKilled(t, pid);
t.is(await getPort({port}), port);
});
test('error when process is not found', async t => {
const error = await t.throws(execa('./cli.js', ['--force', 'notFoundProcess']));
t.regex(error.message, /Killing process notFoundProcess failed: Process doesn't exist/);
});