|
1 | | -var os = require('os'); |
2 | | - |
3 | 1 | var ava = require('ava'); |
4 | 2 | var test = ava.test; |
5 | 3 |
|
6 | 4 | 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 | +}); |
7 | 26 |
|
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 | +}); |
11 | 36 |
|
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.'); |
14 | 44 | t.pass(); |
15 | 45 | }); |
| 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 | + |
0 commit comments