Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watcher integration test #3379

Merged
merged 23 commits into from
Jun 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 28 additions & 5 deletions test/integration/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ module.exports = {
fn(null, result);
});
},
runMochaJSONRaw: function(fixturePath, args, fn) {
var path;

path = resolveFixturePath(fixturePath);
args = args || [];

return invokeSubMocha(args.concat(['--reporter', 'json', path]), function(
err,
resRaw
) {
if (err) return fn(err);

fn(null, resRaw);
});
},

/**
* regular expression used for splitting lines based on new line / dot symbol.
Expand Down Expand Up @@ -102,13 +117,21 @@ module.exports = {
};

function invokeMocha(args, fn, cwd) {
var output, mocha, listener;

output = '';
args = [path.join(__dirname, '..', '..', 'bin', 'mocha')].concat(args);
mocha = spawn(process.execPath, args, {cwd: cwd});

listener = function(data) {
return _spawnMochaWithListeners(args, fn, cwd);
}

function invokeSubMocha(args, fn, cwd) {
args = [path.join(__dirname, '..', '..', 'bin', '_mocha')].concat(args);

return _spawnMochaWithListeners(args, fn, cwd);
}

function _spawnMochaWithListeners(args, fn, cwd) {
var output = '';
var mocha = spawn(process.execPath, args, {cwd: cwd});
var listener = function(data) {
output += data;
};

Expand Down
35 changes: 35 additions & 0 deletions test/integration/options.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var path = require('path');
var helpers = require('./helpers');
var run = helpers.runMochaJSON;
var runRaw = helpers.runMochaJSONRaw;
var directInvoke = helpers.invokeMocha;
var resolvePath = helpers.resolveFixturePath;
var args = [];
Expand Down Expand Up @@ -503,4 +504,38 @@ describe('options', function() {
);
});
});

if (process.platform !== 'win32') {
// Windows: Feature works but SIMULATING the signal (ctr+c), via child process, does not work
// due to lack of *nix signal compliance.
describe('--watch', function() {
describe('with watch enabled', function() {
it('should show the cursor and signal correct exit code, when watch process is terminated', function(done) {
this.timeout(0);
this.slow(3000);
// executes Mocha in a subprocess
var mocha = runRaw('exit.fixture.js', ['--watch'], function(
err,
data
) {
// After the process ends, this callback is ran
clearTimeout(t);
if (err) {
done(err);
return;
}

var expectedCloseCursor = '\u001b[?25h';
expect(data.output, 'to contain', expectedCloseCursor);
expect(data.code, 'to be', 130);
done();
});
var t = setTimeout(function() {
// kill the child process
mocha.kill('SIGINT');
}, 500);
});
});
});
}
});