source: node_modules/pstree.remy/tests/index.test.js@ 62b2964

finki-main main
Last change on this file since 62b2964 was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago

Initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1const tap = require('tap');
2const test = tap.test;
3const readFile = require('fs').readFileSync;
4const spawn = require('child_process').spawn;
5const pstree = require('../');
6const { tree, pidsForTree, getStat } = require('../lib/utils');
7
8if (process.platform !== 'darwin') {
9 test('reads from /proc', async (t) => {
10 const ps = await getStat();
11 t.ok(ps.split('\n').length > 1);
12 });
13}
14
15test('tree for live env', async (t) => {
16 const pid = 4079;
17 const fixture = readFile(__dirname + '/fixtures/out2', 'utf8');
18 const ps = await tree(fixture);
19 t.deepEqual(
20 pidsForTree(ps, pid).map((_) => _.PID),
21 ['4080']
22 );
23});
24
25function testTree(t, runCallCount) {
26 const sub = spawn('node', [`${__dirname}/fixtures/index.js`, runCallCount], {
27 stdio: 'pipe',
28 });
29 setTimeout(() => {
30 const pid = sub.pid;
31
32 pstree(pid, (error, pids) => {
33 pids.concat([pid]).forEach((p) => {
34 spawn('kill', ['-s', 'SIGTERM', p]);
35 });
36
37 // the fixture launches `sh` which launches node which is why we
38 // are looking for two processes.
39 // Important: IDKW but MacOS seems to skip the `sh` process. no idea.
40 t.equal(pids.length, runCallCount * 2);
41 t.end();
42 });
43 }, 1000);
44}
45
46test('can read full process tree', (t) => {
47 testTree(t, 1);
48});
49test('can read full process tree with multiple processes', (t) => {
50 testTree(t, 2);
51});
Note: See TracBrowser for help on using the repository browser.