@@ -6,15 +6,30 @@ const globby = require('globby');
6
6
const proxyquire = require ( 'proxyquire' ) ;
7
7
const replaceString = require ( 'replace-string' ) ;
8
8
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
+ } ;
18
33
19
34
exports . assert = ( t , logFile , buffer , stripStdIO ) => {
20
35
let existing = null ;
@@ -30,7 +45,7 @@ exports.assert = (t, logFile, buffer, stripStdIO) => {
30
45
// At least in Appveyor with Node.js 6, IPC can overtake stdout/stderr. This
31
46
// causes the reporter to emit in a different order, resulting in a test
32
47
// 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 ) {
34
49
expected = expected . replace ( / - - - t t y - s t r e a m - c h u n k - s e p a r a t o r \n ( s t d e r r | s t d o u t ) \n / g, '' ) ;
35
50
}
36
51
t . is ( buffer . toString ( 'utf8' ) , expected ) ;
@@ -46,18 +61,14 @@ exports.sanitizers = {
46
61
// causes the reporter to emit in a different order, resulting in a test
47
62
// failure. "Fix" by not asserting on the stdout/stderr reporting at all.
48
63
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 ;
54
65
}
55
66
} ;
56
67
57
68
const run = ( type , reporter ) => {
58
69
const projectDir = path . join ( __dirname , '../fixture/report' , type . toLowerCase ( ) ) ;
59
70
60
- const api = new Api ( {
71
+ const api = createApi ( {
61
72
failFast : type === 'failFast' || type === 'failFast2' ,
62
73
failWithoutAssertions : false ,
63
74
serial : type === 'failFast' || type === 'failFast2' ,
0 commit comments