Skip to content

Commit fce6d07

Browse files
committed
fixup! fixup! fixup! fixup! Add integration tests for reporters
1 parent 8c7681c commit fce6d07

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

test/helper/report.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,30 @@ const globby = require('globby');
66
const proxyquire = require('proxyquire');
77
const replaceString = require('replace-string');
88

9-
const Api = proxyquire('../../api', {
10-
'./lib/fork': proxyquire('../../lib/fork', {
11-
child_process: Object.assign({}, childProcess, { // eslint-disable-line camelcase
12-
fork(filename, argv, options) {
13-
return childProcess.fork(path.join(__dirname, 'report-worker.js'), argv, options);
14-
}
15-
})
16-
})
17-
});
9+
let _Api = null;
10+
const createApi = options => {
11+
if (!_Api) {
12+
_Api = proxyquire('../../api', {
13+
'./lib/fork': proxyquire('../../lib/fork', {
14+
child_process: Object.assign({}, childProcess, { // eslint-disable-line camelcase
15+
fork(filename, argv, options) {
16+
return childProcess.fork(path.join(__dirname, 'report-worker.js'), argv, options);
17+
}
18+
})
19+
})
20+
});
21+
}
22+
23+
return new _Api(options);
24+
};
25+
26+
// At least in Appveyor with Node.js 6, IPC can overtake stdout/stderr
27+
let hasReliableStdIO = true;
28+
exports.captureStdIOReliability = () => {
29+
if (process.platform === 'win32' && parseInt(process.versions.node, 10) < 8) {
30+
hasReliableStdIO = false;
31+
}
32+
};
1833

1934
exports.assert = (t, logFile, buffer, stripStdIO) => {
2035
let existing = null;
@@ -30,7 +45,7 @@ exports.assert = (t, logFile, buffer, stripStdIO) => {
3045
// At least in Appveyor with Node.js 6, IPC can overtake stdout/stderr. This
3146
// causes the reporter to emit in a different order, resulting in a test
3247
// failure. "Fix" by not asserting on the stdout/stderr reporting at all.
33-
if (stripStdIO && process.platform === 'win32' && parseInt(process.versions.node, 10) < 8) {
48+
if (stripStdIO && !hasReliableStdIO) {
3449
expected = expected.replace(/---tty-stream-chunk-separator\n(stderr|stdout)\n/g, '');
3550
}
3651
t.is(buffer.toString('utf8'), expected);
@@ -46,18 +61,14 @@ exports.sanitizers = {
4661
// causes the reporter to emit in a different order, resulting in a test
4762
// failure. "Fix" by not asserting on the stdout/stderr reporting at all.
4863
unreliableProcessIO(str) {
49-
if (process.platform !== 'win32' || parseInt(process.versions.node, 10) >= 8) {
50-
return str;
51-
}
52-
53-
return str === 'stdout\n' || str === 'stderr\n' ? '' : str;
64+
return !hasReliableStdIO && (str === 'stdout\n' || str === 'stderr\n') ? '' : str;
5465
}
5566
};
5667

5768
const run = (type, reporter) => {
5869
const projectDir = path.join(__dirname, '../fixture/report', type.toLowerCase());
5970

60-
const api = new Api({
71+
const api = createApi({
6172
failFast: type === 'failFast' || type === 'failFast2',
6273
failWithoutAssertions: false,
6374
serial: type === 'failFast' || type === 'failFast2',

test/reporters/mini.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
require('../helper/report').captureStdIOReliability();
23
require('../helper/fix-reporter-env')();
34

45
const path = require('path');

test/reporters/tap.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
require('../helper/report').captureStdIOReliability();
23
require('../helper/fix-reporter-env')();
34

45
const path = require('path');

test/reporters/verbose.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
require('../helper/report').captureStdIOReliability();
23
require('../helper/fix-reporter-env')();
34

45
const path = require('path');

0 commit comments

Comments
 (0)