UNPKG

2 kBJavaScriptView Raw
1/**
2 * Tests windowslib's process module.
3 *
4 * @copyright
5 * Copyright (c) 2014-2016 by Appcelerator, Inc. All Rights Reserved.
6 *
7 * @license
8 * Licensed under the terms of the Apache Public License.
9 * Please see the LICENSE included with this distribution for details.
10 */
11
12const windowslib = require('..');
13
14describe('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 // FIXME let's hope there's no process using this pid?
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 // use bad pid value
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 // find our own process
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});