Skip to content

Commit

Permalink
Merge pull request #1781 from glenjamin/test-hook-errors
Browse files Browse the repository at this point in the history
Rework hook error tests to actually assert
  • Loading branch information
Joshua Appelman committed Jul 5, 2015
2 parents 9676fc9 + 092ea46 commit 93d5a3a
Show file tree
Hide file tree
Showing 3 changed files with 402 additions and 296 deletions.
296 changes: 0 additions & 296 deletions test/hook.err.js

This file was deleted.

42 changes: 42 additions & 0 deletions test/integration/helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var spawn = require('child_process').spawn;
var path = require('path');
var fs = require('fs');

module.exports = {
/**
Expand Down Expand Up @@ -35,6 +36,47 @@ module.exports = {
});
},

/**
* Invokes the mocha binary on the code of the body of the function.
* Accepts an array of additional command line args to pass. The callback is
* invoked with a summary of the run, in addition to its output. The summary
* includes the number of passing, pending, and failing tests, as well as the
* exit code. Useful for testing different reporters.
*
* Example response:
* {
* pending: 0,
* passing: 0,
* failing: 1,
* code: 1,
* output: '...'
* }
*
* @param {function} fixture
* @param {array} args
* @param {function} fn
*/
runMochaFunction: function(fixture, args, fn) {
var path = resolveFixturePath(fixture.name + '.js' || 'tempfile.js');
args = args || [];

var fixtureContent = 'var fn = ' + fixture.toString() + '; fn()';
fs.writeFileSync(path, fixtureContent, 'utf8');

function cleanup() {
fs.unlink(path);
fn.apply(this, arguments);
}

invokeMocha(args.concat(['-C', path]), function(err, res) {
if (err) {
return cleanup(err);
}

cleanup(null, getSummary(res));
});
},

/**
* Invokes the mocha binary for the given fixture using the JSON reporter,
* returning the parsed output, as well as exit code.
Expand Down

0 comments on commit 93d5a3a

Please sign in to comment.