Skip to content

Commit

Permalink
Merge pull request #3 from rjz/fix/test-exceptions
Browse files Browse the repository at this point in the history
Handles child-process exceptions in tests (#2)
  • Loading branch information
rjz committed Jun 10, 2016
2 parents 1cb9efe + 4fa9450 commit ef958f0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"main": "index.js",
"scripts": {
"pretest": "npm run lint",
"test": "jasmine-node test/",
"test": "jasmine-node --captureExceptions test/",
"lint": "jshint .",
"cover": "istanbul cover jasmine-node test/",
"cover": "istanbul cover jasmine-node --captureExceptions test/",
"docs": "node -e 'require(\"./tasks\").docs([\"index.js\"])'",
"pages": "bash tasks/pages.sh"
},
Expand Down
5 changes: 4 additions & 1 deletion test/app.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ var config = featureGates([
}
});

process.stdout.write(JSON.stringify(config));
process.send({
name: 'FEATURES',
data: config.features
});
20 changes: 7 additions & 13 deletions test/index_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var assert = require('assert');
var assign = require('object-assign');
var exec = require('child_process').exec;
var fork = require('child_process').fork;
var featureGates = require('../index');
var path = require('path');

Expand Down Expand Up @@ -89,20 +89,14 @@ describe('confab-feature-gates', function () {
function execTestAppWithEnv (env, callback) {
var testAppPath = path.resolve(__dirname, 'app.js');
var opts = { env: assign({}, process.env, env) };
exec('node ' + testAppPath, opts, function (err, stdout) {
var config;

if (err) return callback(err);

try {
config = JSON.parse(stdout);
}
catch (e) {
console.error('Failed parsing stdout:', stdout);
return callback(e);
var child = fork(testAppPath, [], opts);
child.on('error', callback);
child.on('message', function (message) {
if (message.name !== 'FEATURES') {
return callback(new Error('Unexpected message' + JSON.stringify(message)));
}

callback(null, config.features);
callback(null, message.data);
});
}

Expand Down

0 comments on commit ef958f0

Please sign in to comment.