Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

add blocking mocha and test

Craig Tauba5b5efca9dc9
diff --git a/test/integration/fixtures/mocha-process-blocked.js b/test/integration/fixtures/mocha-process-blocked.js
new file mode 100644
index 00000000..118f977f
--- /dev/null
+++ b/test/integration/fixtures/mocha-process-blocked.js
@@ -0,0 +1,4 @@
+'use strict';
+
+require('../../../bin/_mocha');
+process.stdout.on('data', function(data) {});
diff --git a/test/integration/helpers.js b/test/integration/helpers.js
index 23722ea4..bbecb8fc 100644
--- a/test/integration/helpers.js
+++ b/test/integration/helpers.js
@@ -95,6 +95,11 @@ module.exports = {
*/
invokeMocha: invokeMocha,
+ /**
+ * Same as above except mocha child process spawned is blocked on stdout stream
+ */
+ invokeBlockingMocha: invokeBlockingMocha,
+
/**
* Resolves the path to a fixture to the full path.
*/
@@ -102,13 +107,28 @@ 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 invokeBlockingMocha(args, fn, cwd) {
+ args = [
+ path.join(
+ __dirname,
+ '../..',
+ 'test/integration/fixtures',
+ 'mocha-process-blocked'
+ )
+ ].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;
};
diff --git a/test/integration/options.spec.js b/test/integration/options.spec.js
index 25775de6..4e7f1238 100644
--- a/test/integration/options.spec.js
+++ b/test/integration/options.spec.js
@@ -4,6 +4,7 @@ var path = require('path');
var helpers = require('./helpers');
var run = helpers.runMochaJSON;
var directInvoke = helpers.invokeMocha;
+var directInvokeBlocking = helpers.invokeBlockingMocha;
var resolvePath = helpers.resolveFixturePath;
var args = [];
@@ -503,4 +504,35 @@ describe('options', function() {
);
});
});
+
+ describe('--watch', function() {
+ describe('with watch enabled', function() {
+ it('should return correct output when watch process is terminated', function(done) {
+ // After the process ends, this callback is ran
+ var assertionCallback = function(err, data) {
+ clearTimeout(t);
+ if (err) {
+ done(err);
+ return;
+ }
+
+ var expectedCloseCursor = '\u001b[?25h';
+ assert(
+ data.output.indexOf(expectedCloseCursor) !== -1,
+ 'No assert found'
+ );
+ done();
+ };
+
+ this.timeout(0);
+ this.slow(3000);
+ // executes Mocha in a subprocess
+ var mocha = directInvokeBlocking(['--watch'], assertionCallback);
+ var t = setTimeout(function() {
+ // kill the child process
+ mocha.kill('SIGINT');
+ }, 500);
+ });
+ });
+ });
});