Skip to content

Commit 27c7496

Browse files
authored
upgrade to [email protected]; closes #2859 (#2860)
* upgrade to [email protected]; 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
1 parent 50fc47d commit 27c7496

File tree

13 files changed

+195
-94
lines changed

13 files changed

+195
-94
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@
309309
"dependencies": {
310310
"browser-stdout": "1.3.0",
311311
"commander": "2.9.0",
312-
"debug": "2.6.0",
312+
"debug": "2.6.8",
313313
"diff": "3.2.0",
314314
"escape-string-regexp": "1.0.5",
315315
"glob": "7.1.1",
@@ -325,6 +325,7 @@
325325
"browserify": "^13.0.0",
326326
"coffee-script": "^1.10.0",
327327
"coveralls": "^2.11.15",
328+
"cross-spawn": "^5.1.0",
328329
"eslint": "^3.11.1",
329330
"eslint-config-semistandard": "^7.0.0",
330331
"eslint-config-standard": "^6.2.1",
@@ -343,7 +344,7 @@
343344
"os-name": "^2.0.1",
344345
"phantomjs": "1.9.8",
345346
"rimraf": "^2.5.2",
346-
"should": "^11.1.1",
347+
"should": "^9.0.2",
347348
"through2": "^2.0.1",
348349
"watchify": "^3.7.0"
349350
},

test/integration/helpers.js

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict';
22

3-
var spawn = require('child_process').spawn;
3+
var spawn = require('cross-spawn').spawn;
44
var path = require('path');
5-
var fs = require('fs');
65
var baseReporter = require('../../lib/reporters/base');
76

87
module.exports = {
@@ -41,47 +40,6 @@ module.exports = {
4140
});
4241
},
4342

44-
/**
45-
* Invokes the mocha binary on the code of the body of the function.
46-
* Accepts an array of additional command line args to pass. The callback is
47-
* invoked with a summary of the run, in addition to its output. The summary
48-
* includes the number of passing, pending, and failing tests, as well as the
49-
* exit code. Useful for testing different reporters.
50-
*
51-
* Example response:
52-
* {
53-
* pending: 0,
54-
* passing: 0,
55-
* failing: 1,
56-
* code: 1,
57-
* output: '...'
58-
* }
59-
*
60-
* @param {function} fixture
61-
* @param {array} args
62-
* @param {function} fn
63-
*/
64-
runMochaFunction: function (fixture, args, fn) {
65-
var path = resolveFixturePath(fixture.name + '.js' || 'tempfile.js');
66-
args = args || [];
67-
68-
var fixtureContent = 'var fn = ' + fixture.toString() + '; fn()';
69-
fs.writeFileSync(path, fixtureContent, 'utf8');
70-
71-
function cleanup () {
72-
fs.unlink(path);
73-
fn.apply(this, arguments);
74-
}
75-
76-
invokeMocha(args.concat(['-C', path]), function (err, res) {
77-
if (err) {
78-
return cleanup(err);
79-
}
80-
81-
cleanup(null, getSummary(res));
82-
});
83-
},
84-
8543
/**
8644
* Invokes the mocha binary for the given fixture using the JSON reporter,
8745
* returning the parsed output, as well as exit code.
@@ -157,10 +115,10 @@ module.exports = {
157115

158116
function invokeMocha (args, fn) {
159117
var output, mocha, listener;
160-
118+
// ensure DEBUG doesn't kill tests
161119
output = '';
162120
args = [path.join('bin', 'mocha')].concat(args);
163-
mocha = spawn(process.execPath, args);
121+
mocha = spawn(process.execPath, args, {env: {}});
164122

165123
listener = function (data) {
166124
output += data;

test/integration/hooks.spec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ describe('hooks', function () {
1010
runMocha('cascade.fixture.js', args, function (err, res) {
1111
var lines, expected;
1212

13-
assert(!err);
13+
if (err) {
14+
done(err);
15+
return;
16+
}
1417

1518
lines = res.output.split(splitRegExp).map(function (line) {
1619
return line.trim();

test/integration/only.spec.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ describe('.only()', function () {
77
describe('bdd', function () {
88
it('should run only tests that marked as `only`', function (done) {
99
run('options/only/bdd.fixture.js', ['--ui', 'bdd'], function (err, res) {
10-
assert(!err);
10+
if (err) {
11+
done(err);
12+
return;
13+
}
1114
assert.equal(res.stats.pending, 0);
1215
assert.equal(res.stats.passes, 11);
1316
assert.equal(res.stats.failures, 0);
@@ -20,7 +23,10 @@ describe('.only()', function () {
2023
describe('tdd', function () {
2124
it('should run only tests that marked as `only`', function (done) {
2225
run('options/only/tdd.fixture.js', ['--ui', 'tdd'], function (err, res) {
23-
assert(!err);
26+
if (err) {
27+
done(err);
28+
return;
29+
}
2430
assert.equal(res.stats.pending, 0);
2531
assert.equal(res.stats.passes, 8);
2632
assert.equal(res.stats.failures, 0);
@@ -33,7 +39,10 @@ describe('.only()', function () {
3339
describe('qunit', function () {
3440
it('should run only tests that marked as `only`', function (done) {
3541
run('options/only/qunit.fixture.js', ['--ui', 'qunit'], function (err, res) {
36-
assert(!err);
42+
if (err) {
43+
done(err);
44+
return;
45+
}
3746
assert.equal(res.stats.pending, 0);
3847
assert.equal(res.stats.passes, 5);
3948
assert.equal(res.stats.failures, 0);

test/integration/options.spec.js

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ describe('options', function () {
1212

1313
it('should fail synchronous specs', function (done) {
1414
run('options/async-only-sync.fixture.js', args, function (err, res) {
15-
assert(!err);
15+
if (err) {
16+
done(err);
17+
return;
18+
}
1619
assert.equal(res.stats.pending, 0);
1720
assert.equal(res.stats.passes, 0);
1821
assert.equal(res.stats.failures, 1);
@@ -25,7 +28,10 @@ describe('options', function () {
2528

2629
it('should allow asynchronous specs', function (done) {
2730
run('options/async-only-async.fixture.js', args, function (err, res) {
28-
assert(!err);
31+
if (err) {
32+
done(err);
33+
return;
34+
}
2935
assert.equal(res.stats.pending, 0);
3036
assert.equal(res.stats.passes, 1);
3137
assert.equal(res.stats.failures, 0);
@@ -44,7 +50,10 @@ describe('options', function () {
4450

4551
it('should stop after the first error', function (done) {
4652
run('options/bail.fixture.js', args, function (err, res) {
47-
assert(!err);
53+
if (err) {
54+
done(err);
55+
return;
56+
}
4857
assert.equal(res.stats.pending, 0);
4958
assert.equal(res.stats.passes, 1);
5059
assert.equal(res.stats.failures, 1);
@@ -64,7 +73,10 @@ describe('options', function () {
6473

6574
it('should sort tests in alphabetical order', function (done) {
6675
run('options/sort*', args, function (err, res) {
67-
assert(!err);
76+
if (err) {
77+
done(err);
78+
return;
79+
}
6880
assert.equal(res.stats.pending, 0);
6981
assert.equal(res.stats.passes, 2);
7082
assert.equal(res.stats.failures, 0);
@@ -84,7 +96,10 @@ describe('options', function () {
8496

8597
it('should run the generated test suite', function (done) {
8698
run('options/delay.fixture.js', args, function (err, res) {
87-
assert(!err);
99+
if (err) {
100+
done(err);
101+
return;
102+
}
88103
assert.equal(res.stats.pending, 0);
89104
assert.equal(res.stats.passes, 1);
90105
assert.equal(res.stats.failures, 0);
@@ -98,7 +113,10 @@ describe('options', function () {
98113

99114
it('should throw an error if the test suite failed to run', function (done) {
100115
run('options/delay-fail.fixture.js', args, function (err, res) {
101-
assert(!err);
116+
if (err) {
117+
done(err);
118+
return;
119+
}
102120
assert.equal(res.stats.pending, 0);
103121
assert.equal(res.stats.passes, 0);
104122
assert.equal(res.stats.failures, 1);
@@ -115,7 +133,10 @@ describe('options', function () {
115133
it('runs specs matching a string', function (done) {
116134
args = ['--grep', 'match'];
117135
run('options/grep.fixture.js', args, function (err, res) {
118-
assert(!err);
136+
if (err) {
137+
done(err);
138+
return;
139+
}
119140
assert.equal(res.stats.pending, 0);
120141
assert.equal(res.stats.passes, 2);
121142
assert.equal(res.stats.failures, 0);
@@ -128,7 +149,10 @@ describe('options', function () {
128149
it('with RegExp like strings(pattern follow by flag)', function (done) {
129150
args = ['--grep', '/match/i'];
130151
run('options/grep.fixture.js', args, function (err, res) {
131-
assert(!err);
152+
if (err) {
153+
done(err);
154+
return;
155+
}
132156
assert.equal(res.stats.pending, 0);
133157
assert.equal(res.stats.passes, 4);
134158
assert.equal(res.stats.failures, 0);
@@ -140,7 +164,10 @@ describe('options', function () {
140164
it('string as pattern', function (done) {
141165
args = ['--grep', '.*'];
142166
run('options/grep.fixture.js', args, function (err, res) {
143-
assert(!err);
167+
if (err) {
168+
done(err);
169+
return;
170+
}
144171
assert.equal(res.stats.pending, 0);
145172
assert.equal(res.stats.passes, 4);
146173
assert.equal(res.stats.failures, 1);
@@ -154,7 +181,10 @@ describe('options', function () {
154181
it('runs specs that do not match the pattern', function (done) {
155182
args = ['--grep', 'fail', '--invert'];
156183
run('options/grep.fixture.js', args, function (err, res) {
157-
assert(!err);
184+
if (err) {
185+
done(err);
186+
return;
187+
}
158188
assert.equal(res.stats.pending, 0);
159189
assert.equal(res.stats.passes, 4);
160190
assert.equal(res.stats.failures, 0);
@@ -169,7 +199,10 @@ describe('options', function () {
169199
it('retries after a certain threshold', function (done) {
170200
args = ['--retries', '3'];
171201
run('options/retries.fixture.js', args, function (err, res) {
172-
assert(!err);
202+
if (err) {
203+
done(err);
204+
return;
205+
}
173206
assert.equal(res.stats.pending, 0);
174207
assert.equal(res.stats.passes, 0);
175208
assert.equal(res.stats.tests, 1);
@@ -188,15 +221,21 @@ describe('options', function () {
188221

189222
it('succeeds if there are only passed tests', function (done) {
190223
run('options/forbid-only/passed.js', args, function (err, res) {
191-
assert(!err);
224+
if (err) {
225+
done(err);
226+
return;
227+
}
192228
assert.equal(res.code, 0);
193229
done();
194230
});
195231
});
196232

197233
it('fails if there are tests marked only', function (done) {
198234
run('options/forbid-only/only.js', args, function (err, res) {
199-
assert(!err);
235+
if (err) {
236+
done(err);
237+
return;
238+
}
200239
assert.equal(res.code, 1);
201240
done();
202241
});
@@ -210,23 +249,32 @@ describe('options', function () {
210249

211250
it('succeeds if there are only passed tests', function (done) {
212251
run('options/forbid-pending/passed.js', args, function (err, res) {
213-
assert(!err);
252+
if (err) {
253+
done(err);
254+
return;
255+
}
214256
assert.equal(res.code, 0);
215257
done();
216258
});
217259
});
218260

219261
it('fails if there are tests marked skip', function (done) {
220262
run('options/forbid-pending/skip.js', args, function (err, res) {
221-
assert(!err);
263+
if (err) {
264+
done(err);
265+
return;
266+
}
222267
assert.equal(res.code, 1);
223268
done();
224269
});
225270
});
226271

227272
it('fails if there are pending tests', function (done) {
228273
run('options/forbid-pending/pending.js', args, function (err, res) {
229-
assert(!err);
274+
if (err) {
275+
done(err);
276+
return;
277+
}
230278
assert.equal(res.code, 1);
231279
done();
232280
});

0 commit comments

Comments
 (0)