forked from sindresorhus/tasklist
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.js
More file actions
51 lines (42 loc) · 1.28 KB
/
test.js
File metadata and controls
51 lines (42 loc) · 1.28 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import test from 'ava';
import tasklist from '.';
const hasDefaultTaskProps = (t, task) => {
t.is(typeof task.imageName, 'string');
t.is(typeof task.pid, 'number');
t.is(typeof task.sessionName, 'string');
t.is(typeof task.sessionNumber, 'number');
t.is(typeof task.memUsage, 'number');
};
const hasNonVerboseTaskProps = (t, task) => {
t.is(task.status, undefined);
t.is(task.username, undefined);
t.is(task.cpuTime, undefined);
t.is(task.windowTitle, undefined);
};
const hasVerboseTaskProps = (t, task) => {
t.is(typeof task.status, 'string');
t.is(typeof task.username, 'string');
t.is(typeof task.cpuTime, 'number');
t.is(typeof task.windowTitle, 'string');
};
const macro = async (t, options) => {
const tasks = await tasklist(options);
t.true(tasks.length > 0);
for (const task of tasks) {
hasDefaultTaskProps(t, task);
if (options.verbose) {
hasVerboseTaskProps(t, task);
} else {
hasNonVerboseTaskProps(t, task);
}
}
};
test('default', macro, {});
test('verbose option', macro, {verbose: true});
test('filter option', macro, {filter: ['sessionname eq console', 'username ne F4k3U53RN4M3']});
test('test handle no matching tasks gracefully', async t => {
const tasks = await tasklist({
filter: ['imagename eq does-not-exist']
});
t.is(tasks.length, 0);
});