-
Notifications
You must be signed in to change notification settings - Fork 12
/
ps.js
136 lines (111 loc) 路 2.92 KB
/
ps.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import test from 'ava';
import mockery from 'mockery';
import pify from 'pify';
import mocks from './helpers/mocks';
test.before(() => {
mockery.enable({
warnOnReplace: false,
warnOnUnregistered: false,
useCleanCache: true,
});
});
test.beforeEach(() => {
mockery.resetCache();
});
test.after(() => {
mockery.disable();
});
test('should parse ps output on Darwin', async t => {
const stdout =
'PPID PID\n' +
' 1 430\n' +
' 430 432\n' +
' 1 727\n' +
' 1 7166\n';
mockery.registerMock('child_process', {
spawn: () => mocks.spawn(stdout, '', null, 0, null),
});
mockery.registerMock('os', {
EOL: '\n',
platform: () => 'darwin',
type: () => 'type',
release: () => 'release',
});
const ps = require('../lib/ps');
const result = await pify(ps)();
t.deepEqual(result, [[1, 430], [430, 432], [1, 727], [1, 7166]]);
mockery.deregisterMock('child_process');
mockery.deregisterMock('os');
});
test('should parse ps output on *nix', async t => {
const stdout =
'PPID PID\n' +
' 1 430\n' +
' 430 432\n' +
' 1 727\n' +
' 1 7166\n';
mockery.registerMock('child_process', {
spawn: () => mocks.spawn(stdout, '', null, 0, null),
});
mockery.registerMock('os', {
EOL: '\n',
platform: () => 'linux',
type: () => 'type',
release: () => 'release',
});
const ps = require('../lib/ps');
const result = await pify(ps)();
t.deepEqual(result, [[1, 430], [430, 432], [1, 727], [1, 7166]]);
mockery.deregisterMock('child_process');
mockery.deregisterMock('os');
});
test('should throw if stderr contains an error', async t => {
const stdout =
'PPID PID\n' +
' 1 430\n' +
' 430 432\n' +
' 1 727\n' +
' 1 7166\n';
mockery.registerMock('child_process', {
spawn: () => mocks.spawn(stdout, 'Some error', null, 0, null),
});
mockery.registerMock('os', {
EOL: '\n',
platform: () => 'linux',
type: () => 'type',
release: () => 'release',
});
const ps = require('../lib/ps');
await t.throws(pify(ps)());
mockery.deregisterMock('child_process');
mockery.deregisterMock('os');
});
test('should not throw if stderr contains the "bogus" error message from vscode', async t => {
const stdout =
'PPID PID\n' +
' 1 430\n' +
' 430 432\n' +
' 1 727\n' +
' 1 7166\n';
mockery.registerMock('child_process', {
spawn: () =>
mocks.spawn(
stdout,
'your 131072x1 screen size is bogus. expect trouble',
null,
0,
null
),
});
mockery.registerMock('os', {
EOL: '\n',
platform: () => 'linux',
type: () => 'type',
release: () => 'release',
});
const ps = require('../lib/ps');
const result = await pify(ps)();
t.deepEqual(result, [[1, 430], [430, 432], [1, 727], [1, 7166]]);
mockery.deregisterMock('child_process');
mockery.deregisterMock('os');
});