@@ -12,25 +12,28 @@ cases(
1212 'test' ,
1313 ( {
1414 args = [ ] ,
15- utils = require ( '../../utils' ) ,
16- pkgHasJestProp = false ,
15+ ci = false ,
16+ env = { } ,
1717 hasJestConfigFile = false ,
18+ pkgHasJestProp = false ,
1819 setup = ( ) => ( ) => { } ,
19- ci = false ,
20- preCommit = 'false' ,
20+ utils = require ( '../../utils' ) ,
2121 } ) => {
2222 // 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+
2525 const originalArgv = process . argv
2626 const prevCI = mockIsCI
27- const prevPreCommit = process . env [ 'SCRIPTS_PRE-COMMIT' ]
27+ const originalEnv = process . env
28+
2829 mockIsCI = ci
29- process . env [ 'SCRIPTS_PRE-COMMIT' ] = preCommit
30+ process . env = env
31+
3032 Object . assign ( utils , {
3133 hasPkgProp : ( ) => pkgHasJestProp ,
3234 hasFile : ( ) => hasJestConfigFile ,
3335 } )
36+
3437 process . exit = jest . fn ( )
3538 const teardown = setup ( )
3639
@@ -39,9 +42,12 @@ cases(
3942 try {
4043 // tests
4144 require ( '../test' )
45+
4246 expect ( jestRunMock ) . toHaveBeenCalledTimes ( 1 )
47+
4348 const [ firstCall ] = jestRunMock . mock . calls
4449 const [ jestArgs ] = firstCall
50+
4551 expect ( jestArgs . join ( ' ' ) ) . toMatchSnapshot ( )
4652 } catch ( error ) {
4753 throw error
5056 // afterEach
5157 process . argv = originalArgv
5258 mockIsCI = prevCI
53- process . env [ 'SCRIPTS_PRE-COMMIT' ] = prevPreCommit
59+ process . env = originalEnv
60+
5461 jest . resetModules ( )
5562 }
5663 } ,
6067 ci : true ,
6168 } ,
6269 'does not watch on SCRIPTS_PRE-COMMIT' : {
63- preCommit : 'true' ,
70+ env : { 'SCRIPTS_PRE-COMMIT' : true } ,
6471 } ,
6572 'does not watch with --no-watch' : {
6673 args : [ '--no-watch' ] ,
0 commit comments