@@ -11,37 +11,29 @@ jest.mock('../../../common/util/logger', () => ({
11
11
} ,
12
12
} ) ) ;
13
13
14
- jest . mock ( '../../../common/util/helpers ' , ( ) => {
15
- const originalModule = jest . requireActual ( '../../../common/util/helpers ' ) ;
14
+ jest . mock ( 'child_process ' , ( ) => {
15
+ const originalModule = jest . requireActual ( 'child_process ' ) ;
16
16
return {
17
17
...originalModule ,
18
- execPromise : async ( param : any ) => {
18
+ execFileSync : ( file : any , args : any ) => {
19
19
switch ( process . env . NPM_INSTALL ) {
20
20
case 'true' :
21
- expect ( param ) . toEqual ( 'npm install @grnsft/if@0.3.3-beta.0' ) ;
21
+ expect ( file ) . toEqual ( 'npm install @grnsft/if@0.3.3-beta.0' ) ;
22
22
break ;
23
23
case 'npm init -y' :
24
- expect ( param ) . toEqual ( 'npm init -y' ) ;
24
+ expect ( file ) . toEqual ( 'npm init -y' ) ;
25
25
break ;
26
26
case 'if-check' :
27
- expect ( param ) . toEqual (
28
- "npm run if-env -- -m ./src/__mocks__/mock-manifest.yaml && npm run if-run -- -m ./src/__mocks__/mock-manifest.yaml -o src/__mocks__/re-mock-manifest && node -p 'Boolean(process.stdout.isTTY)' | npm run if-diff -- -s src/__mocks__/re-mock-manifest.yaml -t ./src/__mocks__/mock-manifest.yaml"
29
- ) ;
30
- break ;
31
- case 'if-check-cwd' :
32
- expect ( param ) . toEqual (
33
- "npm run if-env -- -m ./src/__mocks__/mock-manifest.yaml -c && npm run if-run -- -m ./src/__mocks__/mock-manifest.yaml -o src/__mocks__/re-mock-manifest && node -p 'Boolean(process.stdout.isTTY)' | npm run if-diff -- -s src/__mocks__/re-mock-manifest.yaml -t ./src/__mocks__/mock-manifest.yaml"
34
- ) ;
35
- break ;
36
- case 'if-check-global' :
37
- expect ( param ) . toEqual (
38
- "if-env -m ./src/__mocks__/mock-manifest.yaml && if-run -m ./src/__mocks__/mock-manifest.yaml -o src/__mocks__/re-mock-manifest && node -p 'Boolean(process.stdout.isTTY)' | if-diff -s src/__mocks__/re-mock-manifest.yaml -t ./src/__mocks__/mock-manifest.yaml"
39
- ) ;
40
- break ;
41
- case 'if-check-prefix' :
42
- expect ( param ) . toEqual (
43
- "if-env --prefix=.. -m ./src/__mocks__/mock-manifest.yaml && if-run --prefix=.. -m ./src/__mocks__/mock-manifest.yaml -o src/__mocks__/re-mock-manifest && node -p 'Boolean(process.stdout.isTTY)' | if-diff --prefix=.. -s src/__mocks__/re-mock-manifest.yaml -t ./src/__mocks__/mock-manifest.yaml"
44
- ) ;
27
+ expect (
28
+ [
29
+ 'npm run if-env -- -m ./src/__mocks__/mock-manifest.yaml' ,
30
+ 'npm run if-run -- -m ./src/__mocks__/mock-manifest.yaml -o src/__mocks__/re-mock-manifest' ,
31
+ 'node -p Boolean(process.stdout.isTTY)' ,
32
+ 'npm run if-diff -- -s src/__mocks__/re-mock-manifest.yaml -t ./src/__mocks__/mock-manifest.yaml' ,
33
+ ] . includes (
34
+ Array . isArray ( args ) ? `${ file } ${ args . join ( ' ' ) } ` : file . trim ( )
35
+ )
36
+ ) . toBeTruthy ( ) ;
45
37
break ;
46
38
}
47
39
return ;
@@ -60,49 +52,7 @@ describe('if-check/util/npm: ', () => {
60
52
61
53
await executeCommands ( manifest , false ) ;
62
54
63
- expect . assertions ( 2 ) ;
64
- expect ( logSpy ) . toHaveBeenCalledWith (
65
- '✔ if-check successfully verified mock-manifest.yaml\n'
66
- ) ;
67
- } ) ;
68
-
69
- it ( 'successfully executes with cwd command.' , async ( ) => {
70
- process . env . NPM_INSTALL = 'if-check-cwd' ;
71
- const manifest = './src/__mocks__/mock-manifest.yaml' ;
72
- const logSpy = jest . spyOn ( global . console , 'log' ) ;
73
-
74
- await executeCommands ( manifest , true ) ;
75
-
76
- expect . assertions ( 2 ) ;
77
- expect ( logSpy ) . toHaveBeenCalledWith (
78
- '✔ if-check successfully verified mock-manifest.yaml\n'
79
- ) ;
80
- } ) ;
81
-
82
- it ( 'successfully executes with correct commands when is running from global.' , async ( ) => {
83
- process . env . npm_config_global = 'true' ;
84
- process . env . NPM_INSTALL = 'if-check-global' ;
85
- const manifest = './src/__mocks__/mock-manifest.yaml' ;
86
- const logSpy = jest . spyOn ( global . console , 'log' ) ;
87
-
88
- await executeCommands ( manifest , false ) ;
89
-
90
- expect . assertions ( 2 ) ;
91
- expect ( logSpy ) . toHaveBeenCalledWith (
92
- '✔ if-check successfully verified mock-manifest.yaml\n'
93
- ) ;
94
- } ) ;
95
-
96
- it ( 'successfully executes with correct commands when CURRENT_DIR is provided.' , async ( ) => {
97
- process . env . CURRENT_DIR = './mock-path' ;
98
- process . env . npm_config_global = 'true' ;
99
- process . env . NPM_INSTALL = 'if-check-prefix' ;
100
- const manifest = './src/__mocks__/mock-manifest.yaml' ;
101
- const logSpy = jest . spyOn ( global . console , 'log' ) ;
102
-
103
- await executeCommands ( manifest , false ) ;
104
-
105
- expect . assertions ( 2 ) ;
55
+ expect . assertions ( 6 ) ;
106
56
expect ( logSpy ) . toHaveBeenCalledWith (
107
57
'✔ if-check successfully verified mock-manifest.yaml\n'
108
58
) ;
0 commit comments