@@ -12,25 +12,28 @@ cases(
12
12
'test' ,
13
13
( {
14
14
args = [ ] ,
15
- utils = require ( '../../utils' ) ,
16
- pkgHasJestProp = false ,
15
+ ci = false ,
16
+ env = { } ,
17
17
hasJestConfigFile = false ,
18
+ pkgHasJestProp = false ,
18
19
setup = ( ) => ( ) => { } ,
19
- ci = false ,
20
- preCommit = 'false' ,
20
+ utils = require ( '../../utils' ) ,
21
21
} ) => {
22
22
// beforeEach
23
- // eslint-disable-next -line jest/no-jest-import
24
- const { run : jestRunMock } = require ( 'jest' )
23
+ const { run : jestRunMock } = require ( 'jest' ) // eslint-disable-line jest/no-jest-import
24
+
25
25
const originalArgv = process . argv
26
26
const prevCI = mockIsCI
27
- const prevPreCommit = process . env [ 'SCRIPTS_PRE-COMMIT' ]
27
+ const originalEnv = process . env
28
+
28
29
mockIsCI = ci
29
- process . env [ 'SCRIPTS_PRE-COMMIT' ] = preCommit
30
+ process . env = env
31
+
30
32
Object . assign ( utils , {
31
33
hasPkgProp : ( ) => pkgHasJestProp ,
32
34
hasFile : ( ) => hasJestConfigFile ,
33
35
} )
36
+
34
37
process . exit = jest . fn ( )
35
38
const teardown = setup ( )
36
39
@@ -39,9 +42,12 @@ cases(
39
42
try {
40
43
// tests
41
44
require ( '../test' )
45
+
42
46
expect ( jestRunMock ) . toHaveBeenCalledTimes ( 1 )
47
+
43
48
const [ firstCall ] = jestRunMock . mock . calls
44
49
const [ jestArgs ] = firstCall
50
+
45
51
expect ( jestArgs . join ( ' ' ) ) . toMatchSnapshot ( )
46
52
} catch ( error ) {
47
53
throw error
50
56
// afterEach
51
57
process . argv = originalArgv
52
58
mockIsCI = prevCI
53
- process . env [ 'SCRIPTS_PRE-COMMIT' ] = prevPreCommit
59
+ process . env = originalEnv
60
+
54
61
jest . resetModules ( )
55
62
}
56
63
} ,
60
67
ci : true ,
61
68
} ,
62
69
'does not watch on SCRIPTS_PRE-COMMIT' : {
63
- preCommit : 'true' ,
70
+ env : { 'SCRIPTS_PRE-COMMIT' : true } ,
64
71
} ,
65
72
'does not watch with --no-watch' : {
66
73
args : [ '--no-watch' ] ,
0 commit comments