Skip to content

Commit

Permalink
add integration tests for --exit/--no-exit
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Sep 30, 2017
1 parent 3a7f8dc commit c5d69e0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/integration/fixtures/exit.fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

var net = require('net');

it('should hang when --no-exit used', function (done) {
var server = net.createServer();
server.listen(55555, done);
});
53 changes: 53 additions & 0 deletions test/integration/options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,57 @@ describe('options', function () {
});
});
});

describe('--exit', function () {
var behaviors = {
enabled: '--exit',
disabled: '--no-exit'
};

/**
* Returns a test that executes Mocha in a subprocess with either
* `--exit`, `--no-exit`, or default behavior.
* @param {boolean} shouldExit - Expected result; `true` if Mocha should have force-killed the process.
* @param {string} [behavior] - 'enabled' or 'disabled'
* @returns {Function}
*/
var runExit = function (shouldExit, behavior) {
return function (done) {
this.timeout(0);
var didExit = true;
var t;
var args = behaviors[behavior] ? [behaviors[behavior]] : [];

var mocha = run('exit.fixture.js', args, function (err) {
clearTimeout(t);
if (err) {
done(err);
return;
}
expect(didExit).to.equal(shouldExit);
done();
});

// if this callback happens, then Mocha didn't automatically exit.
t = setTimeout(function () {
didExit = false;
// this is the only way to kill the child, afaik.
// after the process ends, the callback to `run()` above is handled.
mocha.kill('SIGINT');
}, 2000);
};
};

describe('default behavior', function () {
it('should force exit after root suite completion', runExit(true));
});

describe('with exit enabled', function () {
it('should force exit after root suite completion', runExit(true, 'enabled'));
});

describe('with exit disabled', function () {
it('should not force exit after root suite completion', runExit(false, 'disabled'));
});
});
});

0 comments on commit c5d69e0

Please sign in to comment.