Skip to content

Commit 41c7dc1

Browse files
committed
Refactor tests
1 parent c0f01ad commit 41c7dc1

30 files changed

Lines changed: 466 additions & 254 deletions

test/_option-warmup-true-helper.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var WindowsKillClass = require('../lib/windows-kill-class');
2+
3+
var noop = function () { };
4+
5+
var defaultApplyOptions = WindowsKillClass.prototype._applyOptions;
6+
WindowsKillClass.prototype._applyOptions = noop;
7+
8+
var windowsKill = new WindowsKillClass({
9+
warmUp: true
10+
});
11+
12+
windowsKill._native.warmUp = noop;
13+
WindowsKillClass.prototype._applyOptions = defaultApplyOptions;
14+
15+
windowsKill._applyOptions();
16+
17+
module.exports = windowsKill;

test/functionality-general.test.js

Lines changed: 0 additions & 67 deletions
This file was deleted.

test/functionality-options-1.non-windows.test.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

test/functionality-options-1.test.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

test/functionality-options-2.non-windows.test.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

test/functionality-options-2.test.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

test/functionality-options-default.non-windows.test.js

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,86 @@
1-
var os = require('os');
2-
31
var ava = require('ava');
42
var test = ava.test;
53

64
var WindowsKill = require('..')
5+
var windowsKill = WindowsKill();
6+
7+
test('should throw exception when sending SIGBREAK with invalid pid using returned function', function (t) {
8+
var error = t.throws(function () { windowsKill('INVALID', 'SIGBREAK'); }, TypeError, 'Exception error is instance of TypeError for pid="INVALID"');
9+
t.is(error.message, 'invalid pid.');
10+
error = t.throws(function () { windowsKill('10.2', 'SIGBREAK'); }, TypeError, 'Exception error is instance of TypeError for pid="10.2"');
11+
t.is(error.message, 'invalid pid.');
12+
error = t.throws(function () { windowsKill(10.2, 'SIGBREAK'); }, TypeError, 'Exception error is instance of TypeError for pid=10.2');
13+
t.is(error.message, 'invalid pid.');
14+
t.pass();
15+
});
16+
17+
test('should throw exception when sending SIGINT with invalid pid using returned function', function (t) {
18+
var error = t.throws(function () { windowsKill('INVALID', 'SIGINT'); }, TypeError, 'Exception error is instance of TypeError for pid="INVALID"');
19+
t.is(error.message, 'invalid pid.');
20+
error = t.throws(function () { windowsKill('10.2', 'SIGINT'); }, TypeError, 'Exception error is instance of TypeError for pid="10.2"');
21+
t.is(error.message, 'invalid pid.');
22+
error = t.throws(function () { windowsKill(10.2, 'SIGINT'); }, TypeError, 'Exception error is instance of TypeError for pid=10.2');
23+
t.is(error.message, 'invalid pid.');
24+
t.pass();
25+
});
726

8-
test('instance with default options should replace node.kill', t => {
9-
var nodeKill = process.kill;
10-
var windowsKill = WindowsKill();
27+
test('should throw exception when sending SIGBREAK with invalid pid using process.kill function', function (t) {
28+
var error = t.throws(function () { process.kill('INVALID', 'SIGBREAK'); }, TypeError, 'Exception error is instance of TypeError for pid="INVALID"');
29+
t.is(error.message, 'invalid pid.');
30+
error = t.throws(function () { process.kill('10.2', 'SIGBREAK'); }, TypeError, 'Exception error is instance of TypeError for pid="10.2"');
31+
t.is(error.message, 'invalid pid.');
32+
error = t.throws(function () { process.kill(10.2, 'SIGBREAK'); }, TypeError, 'Exception error is instance of TypeError for pid=10.2');
33+
t.is(error.message, 'invalid pid.');
34+
t.pass();
35+
});
1136

12-
t.is(typeof windowsKill, 'function', 'typeof must be function.');
13-
t.not(nodeKill, process.kill, 'node\'s process.kill must be changed.');
37+
test('should throw exception when sending SIGINT with invalid pid using process.kill function', function (t) {
38+
var error = t.throws(function () { process.kill('INVALID', 'SIGINT'); }, TypeError, 'Exception error is instance of TypeError for pid="INVALID"');
39+
t.is(error.message, 'invalid pid.');
40+
error = t.throws(function () { process.kill('10.2', 'SIGINT'); }, TypeError, 'Exception error is instance of TypeError for pid="10.2"');
41+
t.is(error.message, 'invalid pid.');
42+
error = t.throws(function () { process.kill(10.2, 'SIGINT'); }, TypeError, 'Exception error is instance of TypeError for pid=10.2');
43+
t.is(error.message, 'invalid pid.');
1444
t.pass();
1545
});
46+
47+
test('should throw exception when sending SIGBREAK signal to not existing pid', function (t) {
48+
var error = t.throws(function () { windowsKill(-1, 'SIGBREAK'); }, Error, 'Exception error is instance of Error');
49+
t.is(error.message, 'windows-kill ESRCH');
50+
t.pass();
51+
});
52+
53+
test('should throw exception when sending SIGINT signal to not existing pid', function (t) {
54+
var error = t.throws(function () { windowsKill(-1, 'SIGINT'); }, Error, 'Exception error is instance of Error');
55+
t.is(error.message, 'windows-kill ESRCH');
56+
t.pass();
57+
});
58+
59+
test('should pass to node\'s process.kill if signal type not supported', function (t) {
60+
var error = t.throws(function () { windowsKill(-1, 0); }, Error, 'Exception error is instance of Error');
61+
t.is(error.message, 'kill ESRCH');
62+
var error = t.throws(function () { windowsKill(-1, 'SIGTERM'); }, Error, 'Exception error is instance of Error');
63+
t.is(error.message, 'kill ESRCH');
64+
var error = t.throws(function () { windowsKill(-1, 'SIGHUP'); }, Error, 'Exception error is instance of Error');
65+
t.is(error.message, 'kill ESRCH');
66+
var error = t.throws(function () { windowsKill(-1, 'SIGWINCH'); }, Error, 'Exception error is instance of Error');
67+
t.is(error.message, 'kill ESRCH');
68+
var error = t.throws(function () { windowsKill(-1, 'SIGKILL'); }, Error, 'Exception error is instance of Error');
69+
t.is(error.message, 'kill ESRCH');
70+
var error = t.throws(function () { windowsKill(-1, 'SIGFPE'); }, Error, 'Exception error is instance of Error');
71+
t.is(error.message, 'kill ESRCH');
72+
var error = t.throws(function () { windowsKill(-1, 'SIGSEGV'); }, Error, 'Exception error is instance of Error');
73+
t.is(error.message, 'kill ESRCH');
74+
var error = t.throws(function () { windowsKill(-1, 'SIGILL'); }, Error, 'Exception error is instance of Error');
75+
t.is(error.message, 'kill ESRCH');
76+
var error = t.throws(function () { windowsKill(-1, 'SIGUSR1'); }, Error, 'Exception error is instance of Error');
77+
t.is(error.message, 'Unknown signal: SIGUSR1');
78+
var error = t.throws(function () { windowsKill(-1, 'SIGPIPE'); }, Error, 'Exception error is instance of Error');
79+
t.is(error.message, 'Unknown signal: SIGPIPE');
80+
var error = t.throws(function () { windowsKill(-1, 'SIGSTOP'); }, Error, 'Exception error is instance of Error');
81+
t.is(error.message, 'Unknown signal: SIGSTOP');
82+
var error = t.throws(function () { windowsKill(-1, 'SIGBUS'); }, Error, 'Exception error is instance of Error');
83+
t.is(error.message, 'Unknown signal: SIGBUS');
84+
t.pass();
85+
});
86+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
var ava = require('ava');
2+
var test = ava.test;
3+
4+
var Options = require('../lib/options');
5+
6+
var defaultOptions = {
7+
replaceNodeKill: true,
8+
warmUp: false
9+
};
10+
11+
var customOptions = {
12+
replaceNodeKill: false,
13+
warmUp: true
14+
};
15+
16+
var options = new Options(customOptions);
17+
18+
test('should have default options', t => {
19+
t.truthy(options.hasOwnProperty('_defaultOptions'), '_defaultOptions property should exists.');
20+
t.deepEqual(options._defaultOptions, defaultOptions, '_defaultOptions should be equal to defaultOptions.');
21+
t.pass();
22+
});
23+
24+
test('should return null when getting missing id', t => {
25+
t.is(options.get('UNKNOWN'), null, 'should return null for UNKNOWN id which is missing.');
26+
t.pass();
27+
});
28+
29+
test('instance _options and _defaultOptions should not be equal', t => {
30+
t.truthy(options.hasOwnProperty('_options'), '_options property should exists.');
31+
t.notDeepEqual(options._options, options._defaultOptions, '_options should not be equal to _defaultOptions.');
32+
t.deepEqual(options._options, customOptions, '_options should be equal to customOptions.');
33+
t.pass();
34+
});
35+
36+
test('get method should return correct values', t => {
37+
t.truthy(typeof options.get('replaceNodeKill'), 'boolean', 'replaceNodeKill should be boolean.');
38+
t.is(options.get('replaceNodeKill'), false, 'replaceNodeKill should be true.');
39+
t.is(options.get('replaceNodeKill'), customOptions.replaceNodeKill, 'replaceNodeKill should be equal.');
40+
t.truthy(typeof options.get('warmUp'), 'boolean', 'warmUp should be boolean.');
41+
t.is(options.get('warmUp'), true, 'warmUp should be false.');
42+
t.is(options.get('warmUp'), customOptions.warmUp, 'warmUp should be equal.');
43+
t.pass();
44+
});
45+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var ava = require('ava');
2+
var test = ava.test;
3+
4+
var Options = require('../lib/options');
5+
6+
var defaultOptions = {
7+
replaceNodeKill: true,
8+
warmUp: false
9+
};
10+
11+
var options = new Options();
12+
13+
test('should have _defaultOptions property', t => {
14+
t.truthy(options.hasOwnProperty('_defaultOptions'), '_defaultOptions property should exists.');
15+
t.deepEqual(options._defaultOptions, defaultOptions, '_defaultOptions should be equal to defaultOptions.');
16+
t.pass();
17+
});
18+
19+
test('should return null when getting missing id', t => {
20+
t.is(options.get('UNKNOWN'), null, 'should return null for UNKNOWN id which is missing.');
21+
t.pass();
22+
});
23+
24+
test('_options and _defaultOptions should be equal', t => {
25+
t.truthy(options.hasOwnProperty('_options'), '_options property should exists.');
26+
t.deepEqual(options._options, options._defaultOptions, '_options should be equal to _defaultOptions.');
27+
t.pass();
28+
});
29+
30+
test('get method should return correct values', t => {
31+
t.truthy(typeof options.get('replaceNodeKill'), 'boolean', 'replaceNodeKill should be boolean.');
32+
t.is(options.get('replaceNodeKill'), true, 'replaceNodeKill should be true.');
33+
t.is(options.get('replaceNodeKill'), defaultOptions.replaceNodeKill, 'replaceNodeKill should be equal.');
34+
t.truthy(typeof options.get('warmUp'), 'boolean', 'warmUp should be boolean.');
35+
t.is(options.get('warmUp'), false, 'warmUp should be false.');
36+
t.is(options.get('warmUp'), defaultOptions.warmUp, 'warmUp should be equal.');
37+
t.pass();
38+
});

0 commit comments

Comments
 (0)