UNPKG

1.9 kBJavaScriptView Raw
1var logger = console.log;
2var logs = "";
3console.log = function(msg){
4// logger(msg);
5 logs += msg;
6};
7
8var testScript = "test/fixture.js"
9var testCase = require('nodeunit').testCase;
10var supervisor = require('../lib/supervisor.js');
11
12var assertValueExists = function(assertion, test){
13 test.ok(assertion);
14 test.done();
15 setTimeout(function(){
16 logs = "";
17 process.kill();
18 }, 20)
19};
20
21var tests = {
22 tearDown:function testGroupOneTearDown(cb){
23 logs = "";
24 console.log = logger;
25 cb();
26 },
27 "should exist when supervisor is imported": function (test) {
28 test.ok(!!supervisor);
29 test.done();
30 },
31 "should accept a debug port when passed through": function(test){
32 var EXPECTED = '--debug=1234';
33 supervisor.run([ EXPECTED, "--no-restart-on", "exit", "--", testScript]);
34 assertValueExists(logs.indexOf(EXPECTED) > -1, test);
35 },
36 "should use debug alone when no port number passed through": function(test){
37 var EXPECTED = '--debug';
38 supervisor.run([ EXPECTED, "--no-restart-on", "exit", "--", testScript]);
39 assertValueExists(logs.indexOf(EXPECTED) > -1, test);
40 },
41 "should not overwrite with debug-brk value if debug-brk also passed through": function(test){
42 var EXPECTED = '--debug=1236';
43 supervisor.run([ EXPECTED, "--debug-brk", "--no-restart-on", "exit", "--", testScript]);
44 assertValueExists(logs.indexOf(EXPECTED) > -1, test);
45 },
46 "should pass the debug-brk flag through": function(test){
47 var EXPECTED = '--debug-brk';
48 supervisor.run([ EXPECTED, "--no-restart-on", "exit", "--", testScript]);
49 assertValueExists(logs.indexOf(EXPECTED) > -1, test);
50 },
51 "should pass the debug-brk port number arg through with debug-brk flag": function(test){
52 var EXPECTED = '--debug-brk=5859';
53 supervisor.run([ EXPECTED, "--no-restart-on", "exit", "--", testScript]);
54 assertValueExists(logs.indexOf(EXPECTED) > -1, test);
55 }
56};
57
58module.exports.testGroupOne = testCase(tests);