-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest.js
34 lines (28 loc) · 793 Bytes
/
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
import childProcess from 'node:child_process';
import process from 'node:process';
import test from 'ava';
import {taskkill, taskkillSync} from './index.js';
test('async - kills a process', async t => {
const {pid} = childProcess.spawn(process.execPath);
await taskkill(pid, {force: true});
// Check if the process exists
t.throws(() => {
process.kill(pid);
});
});
test('async - throws on not found', async t => {
await t.throwsAsync(taskkill('not-running.exe'));
});
test('sync - kills a process', t => {
const {pid} = childProcess.spawn(process.execPath);
taskkillSync(pid, {force: true});
// Check if the process exists
t.throws(() => {
process.kill(pid);
});
});
test('sync - throws on not found', t => {
t.throws(() => {
taskkillSync('not-running.exe');
});
});