1
+ const proc = typeof process === 'object' && process ? process : null
2
+
1
3
const chokidar = require ( 'chokidar' )
2
4
const EE = require ( 'events' )
3
5
const Minipass = require ( 'minipass' )
@@ -12,25 +14,27 @@ class Watch extends Minipass {
12
14
constructor ( options ) {
13
15
if ( ! options . coverage )
14
16
throw new Error ( '--watch requires coverage to be enabled' )
17
+ if ( ! proc )
18
+ throw new Error ( '--watch requires working node.js process object' )
15
19
super ( )
16
20
this . args = [ bin , ...options . _ . parsed , '--no-watch' ]
17
21
this . positionals = [ ...options . _ ]
18
22
this . log ( 'initial test run' , this . args )
19
- this . proc = spawn ( process . execPath , this . args , {
23
+ this . proc = spawn ( proc . execPath , this . args , {
20
24
stdio : 'inherit'
21
25
} )
22
26
this . proc . on ( 'close' , ( ) => this . main ( ) )
23
27
const saveFolder = 'node_modules/.cache/tap'
24
28
require ( '../settings.js' ) . mkdirRecursiveSync ( saveFolder )
25
- this . saveFile = saveFolder + '/watch-' + process . pid
29
+ this . saveFile = saveFolder + '/watch-' + proc . pid
26
30
/* istanbul ignore next */
27
31
onExit ( ( ) => require ( '../settings.js' ) . rmdirRecursiveSync ( this . saveFile ) )
28
32
this . index = null
29
33
this . indexFile = '.nyc_output/processinfo/index.json'
30
34
this . fileList = [ ]
31
35
this . queue = [ ]
32
36
this . watcher = null
33
- this . env = { ...process . env }
37
+ this . env = { ...proc . env }
34
38
}
35
39
36
40
readIndex ( ) {
@@ -51,7 +55,7 @@ class Watch extends Minipass {
51
55
// Since a covered test was definitely included in its own
52
56
// test run, don't add it a second time, so we don't get
53
57
// two chokidar events for the same file change.
54
- const cwd = process . cwd ( )
58
+ const cwd = proc . cwd ( )
55
59
const fileSet = new Set ( Object . keys ( this . index . files ) )
56
60
Object . keys ( this . index . externalIds )
57
61
. filter ( f => ! fileSet . has ( resolve ( f ) ) )
@@ -109,7 +113,7 @@ class Watch extends Minipass {
109
113
writeFileSync ( this . saveFile , set . join ( '\n' ) + '\n' )
110
114
this . queue . length = 0
111
115
112
- this . proc = spawn ( process . execPath , [
116
+ this . proc = spawn ( proc . execPath , [
113
117
...this . args , '--save=' + this . saveFile , '--nyc-arg=--no-clean'
114
118
] , {
115
119
stdio : 'inherit' ,
0 commit comments