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

Rework hook error tests to actually assert #1781

Merged
merged 2 commits into from
Jul 5, 2015
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
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()';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's pretty damn (beautifully) hacky ;)

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