1+ import { overridePlatform , resetPlatform } from '../utils' ;
2+
13jest . mock ( 'child_process' ) ;
24
35const mockShellEnv = jest . fn ( ) ;
46jest . mock ( 'shell-env' , ( ) => mockShellEnv ) ;
57
68describe ( 'exec' , ( ) => {
7- const oldPlatform = process . platform ;
8-
99 // Allow us to reset the module between each run
1010 let execModule = require ( '../../src/utils/exec' ) ;
1111
@@ -16,9 +16,7 @@ describe('exec', () => {
1616 } ) ;
1717
1818 afterEach ( ( ) => {
19- Object . defineProperty ( process , 'platform' , {
20- value : oldPlatform ,
21- } ) ;
19+ resetPlatform ( ) ;
2220 } ) ;
2321
2422 describe ( 'exec()' , ( ) => {
@@ -76,29 +74,23 @@ describe('exec', () => {
7674
7775 describe ( 'maybeFixPath()' , ( ) => {
7876 it ( 'does not do anything on Windows' , async ( ) => {
79- Object . defineProperty ( process , 'platform' , {
80- value : 'win32' ,
81- } ) ;
77+ overridePlatform ( 'win32' ) ;
8278
8379 await execModule . maybeFixPath ( ) ;
8480
8581 expect ( mockShellEnv ) . toHaveBeenCalledTimes ( 0 ) ;
8682 } ) ;
8783
8884 it ( 'calls shell-env on macOS' , async ( ) => {
89- Object . defineProperty ( process , 'platform' , {
90- value : 'darwin' ,
91- } ) ;
85+ overridePlatform ( 'darwin' ) ;
9286
9387 await execModule . maybeFixPath ( ) ;
9488
9589 expect ( mockShellEnv ) . toHaveBeenCalledTimes ( 1 ) ;
9690 } ) ;
9791
9892 it ( 'calls shell-env on Linux' , async ( ) => {
99- Object . defineProperty ( process , 'platform' , {
100- value : 'linux' ,
101- } ) ;
93+ overridePlatform ( 'linux' ) ;
10294
10395 await execModule . maybeFixPath ( ) ;
10496
0 commit comments