1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | const windowslib = require('..');
|
13 |
|
14 | describe('process', function () {
|
15 | it('namespace should be an object', function () {
|
16 | should(windowslib.process).be.an.Object;
|
17 | });
|
18 |
|
19 | (process.platform === 'win32' ? it : it.skip)('list all processes', function (done) {
|
20 | this.timeout(5000);
|
21 | this.slow(4000);
|
22 |
|
23 | windowslib.process.list(function (err, results) {
|
24 | if (err) {
|
25 | return done(err);
|
26 | }
|
27 |
|
28 | should(results).be.an.Array;
|
29 |
|
30 | results.forEach(function (proc) {
|
31 | should(proc).have.keys('name', 'pid', 'title');
|
32 | });
|
33 |
|
34 | done();
|
35 | });
|
36 | });
|
37 |
|
38 | (process.platform === 'win32' ? it : it.skip)('find process by pid returns null for process not running', function (done) {
|
39 | this.timeout(500);
|
40 | this.slow(200);
|
41 |
|
42 | windowslib.process.find('12345', function (err, p) {
|
43 | if (err) {
|
44 | return done(err);
|
45 | }
|
46 |
|
47 | should(p).be.null;
|
48 |
|
49 | done();
|
50 | });
|
51 | });
|
52 |
|
53 | (process.platform === 'win32' ? it : it.skip)('find process by pid returns error if pid is not integer', function (done) {
|
54 | this.timeout(500);
|
55 | this.slow(200);
|
56 |
|
57 | windowslib.process.find('abc', function (err, p) {
|
58 | if (!err) {
|
59 | return done('tasklist should have failed due to invalid pid type');
|
60 | }
|
61 |
|
62 | should(p).be.null;
|
63 |
|
64 | done();
|
65 | });
|
66 | });
|
67 |
|
68 | (process.platform === 'win32' ? it : it.skip)('find process by pid', function (done) {
|
69 | this.timeout(500);
|
70 | this.slow(200);
|
71 |
|
72 | windowslib.process.find(process.pid, function (err, p) {
|
73 | if (err) {
|
74 | return done(err);
|
75 | }
|
76 |
|
77 | should(p).be.an.Object;
|
78 | should(p).have.keys('name', 'pid', 'title');
|
79 |
|
80 | done();
|
81 | });
|
82 | });
|
83 | });
|