Skip to content

Commit

Permalink
upgrade to debug@2.6.8; closes #2859 (#2860)
Browse files Browse the repository at this point in the history
* upgrade to debug@2.6.8; closes #2859

- ensure we can run the test suite with `DEBUG=mocha*` by removing it
  when spawning `mocha`
- remove some cruft in the test helpers

* downgrade should to ^v9.0.2

* increase timeout on file-utils tests

* use cross-spawn to spawn mocha in integration tests

* integration tests will now fail with less useless information

* lint
  • Loading branch information
boneskull committed Jun 17, 2017
1 parent 50fc47d commit 27c7496
Show file tree
Hide file tree
Showing 13 changed files with 195 additions and 94 deletions.
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -309,7 +309,7 @@
"dependencies": {
"browser-stdout": "1.3.0",
"commander": "2.9.0",
"debug": "2.6.0",
"debug": "2.6.8",
"diff": "3.2.0",
"escape-string-regexp": "1.0.5",
"glob": "7.1.1",
Expand All @@ -325,6 +325,7 @@
"browserify": "^13.0.0",
"coffee-script": "^1.10.0",
"coveralls": "^2.11.15",
"cross-spawn": "^5.1.0",
"eslint": "^3.11.1",
"eslint-config-semistandard": "^7.0.0",
"eslint-config-standard": "^6.2.1",
Expand All @@ -343,7 +344,7 @@
"os-name": "^2.0.1",
"phantomjs": "1.9.8",
"rimraf": "^2.5.2",
"should": "^11.1.1",
"should": "^9.0.2",
"through2": "^2.0.1",
"watchify": "^3.7.0"
},
Expand Down
48 changes: 3 additions & 45 deletions test/integration/helpers.js
@@ -1,8 +1,7 @@
'use strict';

var spawn = require('child_process').spawn;
var spawn = require('cross-spawn').spawn;
var path = require('path');
var fs = require('fs');
var baseReporter = require('../../lib/reporters/base');

module.exports = {
Expand Down Expand Up @@ -41,47 +40,6 @@ 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 Expand Up @@ -157,10 +115,10 @@ module.exports = {

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

// ensure DEBUG doesn't kill tests
output = '';
args = [path.join('bin', 'mocha')].concat(args);
mocha = spawn(process.execPath, args);
mocha = spawn(process.execPath, args, {env: {}});

listener = function (data) {
output += data;
Expand Down
5 changes: 4 additions & 1 deletion test/integration/hooks.spec.js
Expand Up @@ -10,7 +10,10 @@ describe('hooks', function () {
runMocha('cascade.fixture.js', args, function (err, res) {
var lines, expected;

assert(!err);
if (err) {
done(err);
return;
}

lines = res.output.split(splitRegExp).map(function (line) {
return line.trim();
Expand Down
15 changes: 12 additions & 3 deletions test/integration/only.spec.js
Expand Up @@ -7,7 +7,10 @@ describe('.only()', function () {
describe('bdd', function () {
it('should run only tests that marked as `only`', function (done) {
run('options/only/bdd.fixture.js', ['--ui', 'bdd'], function (err, res) {
assert(!err);
if (err) {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 11);
assert.equal(res.stats.failures, 0);
Expand All @@ -20,7 +23,10 @@ describe('.only()', function () {
describe('tdd', function () {
it('should run only tests that marked as `only`', function (done) {
run('options/only/tdd.fixture.js', ['--ui', 'tdd'], function (err, res) {
assert(!err);
if (err) {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 8);
assert.equal(res.stats.failures, 0);
Expand All @@ -33,7 +39,10 @@ describe('.only()', function () {
describe('qunit', function () {
it('should run only tests that marked as `only`', function (done) {
run('options/only/qunit.fixture.js', ['--ui', 'qunit'], function (err, res) {
assert(!err);
if (err) {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 5);
assert.equal(res.stats.failures, 0);
Expand Down
80 changes: 64 additions & 16 deletions test/integration/options.spec.js
Expand Up @@ -12,7 +12,10 @@ describe('options', function () {

it('should fail synchronous specs', function (done) {
run('options/async-only-sync.fixture.js', args, function (err, res) {
assert(!err);
if (err) {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 0);
assert.equal(res.stats.failures, 1);
Expand All @@ -25,7 +28,10 @@ describe('options', function () {

it('should allow asynchronous specs', function (done) {
run('options/async-only-async.fixture.js', args, function (err, res) {
assert(!err);
if (err) {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 1);
assert.equal(res.stats.failures, 0);
Expand All @@ -44,7 +50,10 @@ describe('options', function () {

it('should stop after the first error', function (done) {
run('options/bail.fixture.js', args, function (err, res) {
assert(!err);
if (err) {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 1);
assert.equal(res.stats.failures, 1);
Expand All @@ -64,7 +73,10 @@ describe('options', function () {

it('should sort tests in alphabetical order', function (done) {
run('options/sort*', args, function (err, res) {
assert(!err);
if (err) {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 2);
assert.equal(res.stats.failures, 0);
Expand All @@ -84,7 +96,10 @@ describe('options', function () {

it('should run the generated test suite', function (done) {
run('options/delay.fixture.js', args, function (err, res) {
assert(!err);
if (err) {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 1);
assert.equal(res.stats.failures, 0);
Expand All @@ -98,7 +113,10 @@ describe('options', function () {

it('should throw an error if the test suite failed to run', function (done) {
run('options/delay-fail.fixture.js', args, function (err, res) {
assert(!err);
if (err) {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 0);
assert.equal(res.stats.failures, 1);
Expand All @@ -115,7 +133,10 @@ describe('options', function () {
it('runs specs matching a string', function (done) {
args = ['--grep', 'match'];
run('options/grep.fixture.js', args, function (err, res) {
assert(!err);
if (err) {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 2);
assert.equal(res.stats.failures, 0);
Expand All @@ -128,7 +149,10 @@ describe('options', function () {
it('with RegExp like strings(pattern follow by flag)', function (done) {
args = ['--grep', '/match/i'];
run('options/grep.fixture.js', args, function (err, res) {
assert(!err);
if (err) {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 4);
assert.equal(res.stats.failures, 0);
Expand All @@ -140,7 +164,10 @@ describe('options', function () {
it('string as pattern', function (done) {
args = ['--grep', '.*'];
run('options/grep.fixture.js', args, function (err, res) {
assert(!err);
if (err) {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 4);
assert.equal(res.stats.failures, 1);
Expand All @@ -154,7 +181,10 @@ describe('options', function () {
it('runs specs that do not match the pattern', function (done) {
args = ['--grep', 'fail', '--invert'];
run('options/grep.fixture.js', args, function (err, res) {
assert(!err);
if (err) {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 4);
assert.equal(res.stats.failures, 0);
Expand All @@ -169,7 +199,10 @@ describe('options', function () {
it('retries after a certain threshold', function (done) {
args = ['--retries', '3'];
run('options/retries.fixture.js', args, function (err, res) {
assert(!err);
if (err) {
done(err);
return;
}
assert.equal(res.stats.pending, 0);
assert.equal(res.stats.passes, 0);
assert.equal(res.stats.tests, 1);
Expand All @@ -188,15 +221,21 @@ describe('options', function () {

it('succeeds if there are only passed tests', function (done) {
run('options/forbid-only/passed.js', args, function (err, res) {
assert(!err);
if (err) {
done(err);
return;
}
assert.equal(res.code, 0);
done();
});
});

it('fails if there are tests marked only', function (done) {
run('options/forbid-only/only.js', args, function (err, res) {
assert(!err);
if (err) {
done(err);
return;
}
assert.equal(res.code, 1);
done();
});
Expand All @@ -210,23 +249,32 @@ describe('options', function () {

it('succeeds if there are only passed tests', function (done) {
run('options/forbid-pending/passed.js', args, function (err, res) {
assert(!err);
if (err) {
done(err);
return;
}
assert.equal(res.code, 0);
done();
});
});

it('fails if there are tests marked skip', function (done) {
run('options/forbid-pending/skip.js', args, function (err, res) {
assert(!err);
if (err) {
done(err);
return;
}
assert.equal(res.code, 1);
done();
});
});

it('fails if there are pending tests', function (done) {
run('options/forbid-pending/pending.js', args, function (err, res) {
assert(!err);
if (err) {
done(err);
return;
}
assert.equal(res.code, 1);
done();
});
Expand Down

0 comments on commit 27c7496

Please sign in to comment.