-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
35 lines (32 loc) · 675 Bytes
/
test.js
File metadata and controls
35 lines (32 loc) · 675 Bytes
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
/* eslint-env jest */
const nproc = require('.');
it('when nproc works', () => {
const childProcess = {
spawnSync: () => ({
stdout: Buffer.from('5\n'),
}),
};
expect(nproc(childProcess)).toBe(5);
});
it('when nproc throws', () => {
const childProcess = {
spawnSync: () => {
throw new Error('fail');
},
};
const os = {
cpus: () => [1, 2, 3],
};
expect(nproc(childProcess, os)).toBe(3);
});
it('when nproc has error', () => {
const childProcess = {
spawnSync: () => ({
error: new Error('fail'),
}),
};
const os = {
cpus: () => [1, 2, 3, 4, 5, 6, 7],
};
expect(nproc(childProcess, os)).toBe(7);
});