forked from sindresorhus/fkill-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
39 lines (34 loc) · 1.07 KB
/
test.js
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
38
39
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('main', 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 => {
await t.throwsAsync(
execa('./cli.js', ['--force', 'notFoundProcess']),
/Killing process notFoundProcess failed: Process doesn't exist/
);
});