@@ -10,7 +10,7 @@ const map = require(`lodash/map`);
10
10
const TEST_SUITE = `npm-pack-all: ${ __filename } ` ;
11
11
const TMP_DIR = path . join ( process . cwd ( ) , ".npm-pack-all-tmp" ) ;
12
12
13
- beforeAll ( ( ) => {
13
+ beforeAll ( ( ) => {
14
14
console . error = jest . fn ( ) ;
15
15
} ) ;
16
16
@@ -29,7 +29,6 @@ afterAll(() => {
29
29
30
30
describe ( TEST_SUITE , ( ) => {
31
31
test ( "Can run proper shell commands, npm, no flags" , ( ) => {
32
-
33
32
let mockArgs = `` ;
34
33
mockArgs = minimist ( mockArgs . split ( ` ` ) ) ;
35
34
@@ -38,13 +37,13 @@ describe(TEST_SUITE, () => {
38
37
return jest . fn ( ( ) => mockArgs ) ; // supply mock arguments to the script
39
38
} ) ;
40
39
41
- jest . mock ( `fs` , ( ) => {
42
- return {
43
- existsSync : jest . fn ( arg => {
44
- return arg . includes ( `package-lock.json` )
45
- } ) ,
46
- writeFileSync : jest . fn ( )
47
- }
40
+ jest . mock ( `fs` , ( ) => {
41
+ return {
42
+ existsSync : jest . fn ( arg => {
43
+ return arg . includes ( `package-lock.json` ) ;
44
+ } ) ,
45
+ writeFileSync : jest . fn ( )
46
+ } ;
48
47
} ) ;
49
48
50
49
// mock shell commands
@@ -66,28 +65,26 @@ describe(TEST_SUITE, () => {
66
65
// call script
67
66
require ( `../index` ) ;
68
67
69
- let { orderedArgs } = sortModuleMockFnsByCallOrder ( mockShell ) ;
68
+ const { orderedArgs } = sortModuleMockFnsByCallOrder ( mockShell ) ;
70
69
71
70
// these commands should be run in the following order by default
72
71
expect ( orderedArgs ) . toEqual ( [
73
72
`rm("-Rf","${ TMP_DIR } ")` ,
74
73
`mkdir("-p","${ TMP_DIR } ")` ,
75
- `cp("-Rf","${ path . join ( process . cwd ( ) , ' package.json' ) } ","${ TMP_DIR } /package.json")` ,
76
- `cp("-Rf","${ path . join ( process . cwd ( ) , ' package-lock.json' ) } ","${ TMP_DIR } /package-lock.json")` ,
77
- `cp("-Rf","${ path . join ( process . cwd ( ) , ' yarn.lock' ) } ","${ TMP_DIR } /yarn.lock")` ,
74
+ `cp("-Rf","${ path . join ( process . cwd ( ) , " package.json" ) } ","${ TMP_DIR } /package.json")` ,
75
+ `cp("-Rf","${ path . join ( process . cwd ( ) , " package-lock.json" ) } ","${ TMP_DIR } /package-lock.json")` ,
76
+ `cp("-Rf","${ path . join ( process . cwd ( ) , " yarn.lock" ) } ","${ TMP_DIR } /yarn.lock")` ,
78
77
`exec("npm prune --production && npm install --production")` ,
79
78
`exec("npm -dd pack",{"silent":false,"timeout":180000})` ,
80
- `mv("-f","${ TMP_DIR } /package.json","${ path . join ( process . cwd ( ) , ' package.json' ) } ")` ,
81
- `mv("-f","${ TMP_DIR } /package-lock.json","${ path . join ( process . cwd ( ) , ' package-lock.json' ) } ")` ,
82
- `mv("-f","${ TMP_DIR } /yarn.lock","${ path . join ( process . cwd ( ) , ' yarn.lock' ) } ")` ,
79
+ `mv("-f","${ TMP_DIR } /package.json","${ path . join ( process . cwd ( ) , " package.json" ) } ")` ,
80
+ `mv("-f","${ TMP_DIR } /package-lock.json","${ path . join ( process . cwd ( ) , " package-lock.json" ) } ")` ,
81
+ `mv("-f","${ TMP_DIR } /yarn.lock","${ path . join ( process . cwd ( ) , " yarn.lock" ) } ")` ,
83
82
`rm("-Rf","${ TMP_DIR } ")` ,
84
83
`exec("npm install --force")`
85
84
] ) ;
86
85
} ) ;
87
86
88
-
89
87
test ( "Can run proper shell commands, yarn, no flags" , ( ) => {
90
-
91
88
let mockArgs = `` ;
92
89
mockArgs = minimist ( mockArgs . split ( ` ` ) ) ;
93
90
@@ -96,13 +93,13 @@ describe(TEST_SUITE, () => {
96
93
return jest . fn ( ( ) => mockArgs ) ; // supply mock arguments to the script
97
94
} ) ;
98
95
99
- jest . mock ( `fs` , ( ) => {
100
- return {
101
- existsSync : jest . fn ( arg => {
102
- return arg . includes ( `yarn.lock` )
103
- } ) ,
104
- writeFileSync : jest . fn ( )
105
- }
96
+ jest . mock ( `fs` , ( ) => {
97
+ return {
98
+ existsSync : jest . fn ( arg => {
99
+ return arg . includes ( `yarn.lock` ) ;
100
+ } ) ,
101
+ writeFileSync : jest . fn ( )
102
+ } ;
106
103
} ) ;
107
104
108
105
// mock shell commands
@@ -124,27 +121,26 @@ describe(TEST_SUITE, () => {
124
121
// call script
125
122
require ( `../index` ) ;
126
123
127
- let { orderedArgs } = sortModuleMockFnsByCallOrder ( mockShell ) ;
124
+ const { orderedArgs } = sortModuleMockFnsByCallOrder ( mockShell ) ;
128
125
129
126
// these commands should be run in the following order for a yarn-only config
130
127
expect ( orderedArgs ) . toEqual ( [
131
128
`rm("-Rf","${ TMP_DIR } ")` ,
132
129
`mkdir("-p","${ TMP_DIR } ")` ,
133
- `cp("-Rf","${ path . join ( process . cwd ( ) , ' package.json' ) } ","${ TMP_DIR } /package.json")` ,
134
- `cp("-Rf","${ path . join ( process . cwd ( ) , ' package-lock.json' ) } ","${ TMP_DIR } /package-lock.json")` ,
135
- `cp("-Rf","${ path . join ( process . cwd ( ) , ' yarn.lock' ) } ","${ TMP_DIR } /yarn.lock")` ,
130
+ `cp("-Rf","${ path . join ( process . cwd ( ) , " package.json" ) } ","${ TMP_DIR } /package.json")` ,
131
+ `cp("-Rf","${ path . join ( process . cwd ( ) , " package-lock.json" ) } ","${ TMP_DIR } /package-lock.json")` ,
132
+ `cp("-Rf","${ path . join ( process . cwd ( ) , " yarn.lock" ) } ","${ TMP_DIR } /yarn.lock")` ,
136
133
`exec("yarn install --production")` ,
137
134
`exec("npm -dd pack",{"silent":false,"timeout":180000})` ,
138
- `mv("-f","${ TMP_DIR } /package.json","${ path . join ( process . cwd ( ) , ' package.json' ) } ")` ,
139
- `mv("-f","${ TMP_DIR } /package-lock.json","${ path . join ( process . cwd ( ) , ' package-lock.json' ) } ")` ,
140
- `mv("-f","${ TMP_DIR } /yarn.lock","${ path . join ( process . cwd ( ) , ' yarn.lock' ) } ")` ,
135
+ `mv("-f","${ TMP_DIR } /package.json","${ path . join ( process . cwd ( ) , " package.json" ) } ")` ,
136
+ `mv("-f","${ TMP_DIR } /package-lock.json","${ path . join ( process . cwd ( ) , " package-lock.json" ) } ")` ,
137
+ `mv("-f","${ TMP_DIR } /yarn.lock","${ path . join ( process . cwd ( ) , " yarn.lock" ) } ")` ,
141
138
`rm("-Rf","${ TMP_DIR } ")` ,
142
139
`exec("yarn install --force")`
143
140
] ) ;
144
141
} ) ;
145
142
146
143
test ( "Does inject bundledDependencies, npm, --dev-deps" , ( ) => {
147
-
148
144
let mockArgs = `--dev-deps` ;
149
145
mockArgs = minimist ( mockArgs . split ( ` ` ) ) ;
150
146
@@ -153,13 +149,13 @@ describe(TEST_SUITE, () => {
153
149
return jest . fn ( ( ) => mockArgs ) ; // supply mock arguments to the script
154
150
} ) ;
155
151
156
- jest . mock ( `fs` , ( ) => {
157
- return {
158
- existsSync : jest . fn ( arg => {
159
- return arg . includes ( `package-lock.json` )
160
- } ) ,
161
- writeFileSync : jest . fn ( )
162
- }
152
+ jest . mock ( `fs` , ( ) => {
153
+ return {
154
+ existsSync : jest . fn ( arg => {
155
+ return arg . includes ( `package-lock.json` ) ;
156
+ } ) ,
157
+ writeFileSync : jest . fn ( )
158
+ } ;
163
159
} ) ;
164
160
165
161
// mock shell commands
@@ -181,26 +177,21 @@ describe(TEST_SUITE, () => {
181
177
// call script
182
178
require ( `../index` ) ;
183
179
184
- let { orderedArgs } = sortModuleMockFnsByCallOrder ( mockShell ) ;
180
+ const { orderedArgs } = sortModuleMockFnsByCallOrder ( mockShell ) ;
185
181
186
- expect ( orderedArgs ) . toEqual ( expect . arrayContaining ( [
187
- `exec("npm install --force")`
188
- ] ) ) ;
182
+ expect ( orderedArgs ) . toEqual ( expect . arrayContaining ( [ `exec("npm install --force")` ] ) ) ;
189
183
} ) ;
190
184
} ) ;
191
185
192
-
193
186
function sortModuleMockFnsByCallOrder ( mocks ) {
194
-
195
- let mockFnsInOrder = [ ] ;
187
+ const mockFnsInOrder = [ ] ;
196
188
197
189
const mockFns = pickBy ( mocks , mock => {
198
190
return mock . _isMockFunction ;
199
191
} ) ;
200
192
201
193
// iterate each mocked fn in module
202
194
keys ( mockFns ) . forEach ( fnName => {
203
-
204
195
// combine calls, instances, results, etc
205
196
for ( let i = 0 ; i < mockFns [ fnName ] . mock . calls . length ; i ++ ) {
206
197
mockFnsInOrder . push ( {
@@ -213,9 +204,9 @@ function sortModuleMockFnsByCallOrder(mocks) {
213
204
}
214
205
} ) ;
215
206
216
- const orderedFns = sortBy ( mockFnsInOrder , [ ' invocationCallOrder' ] ) ;
207
+ const orderedFns = sortBy ( mockFnsInOrder , [ " invocationCallOrder" ] ) ;
217
208
const orderedArgs = map ( orderedFns , fn => {
218
- return `${ fn . fnName } (${ JSON . stringify ( fn . calls ) . replace ( / [ \[ \] ' ] + / g, '' ) } )` ;
209
+ return `${ fn . fnName } (${ JSON . stringify ( fn . calls ) . replace ( / [ \[ \] ' ] + / g, "" ) } )` ;
219
210
} ) ;
220
211
221
212
return { orderedFns, orderedArgs } ;
0 commit comments