@@ -28,58 +28,54 @@ describe('npmAdapter', () => {
28
28
} ) ;
29
29
30
30
describe ( '#setup' , ( ) => {
31
- it ( 'backs up the package.json file and node_modules' , ( ) => {
31
+ it ( 'backs up the package.json file and node_modules' , async ( ) => {
32
32
fs . mkdirSync ( 'node_modules' ) ;
33
33
writeJSONFile ( 'node_modules/prove-it.json' , { originalNodeModules : true } ) ;
34
34
writeJSONFile ( 'package.json' , { originalPackageJSON : true } ) ;
35
- return new NpmAdapter ( {
36
- cwd : tmpdir ,
37
- } )
38
- . setup ( )
39
- . then ( ( ) => {
40
- assertFileContainsJSON ( path . join ( tmpdir , 'package.json.ember-try' ) , {
41
- originalPackageJSON : true ,
42
- } ) ;
43
- assertFileContainsJSON ( path . join ( tmpdir , '.node_modules.ember-try/prove-it.json' ) , {
44
- originalNodeModules : true ,
45
- } ) ;
46
- } ) ;
35
+
36
+ let adapter = new NpmAdapter ( { cwd : tmpdir } ) ;
37
+ await adapter . setup ( ) ;
38
+
39
+ assertFileContainsJSON ( path . join ( tmpdir , 'package.json.ember-try' ) , {
40
+ originalPackageJSON : true ,
41
+ } ) ;
42
+ assertFileContainsJSON ( path . join ( tmpdir , '.node_modules.ember-try/prove-it.json' ) , {
43
+ originalNodeModules : true ,
44
+ } ) ;
47
45
} ) ;
48
46
49
- it ( 'backs up the yarn.lock file, npm-shrinkwrap.json and package-lock.json if they exist' , ( ) => {
47
+ it ( 'backs up the yarn.lock file, npm-shrinkwrap.json and package-lock.json if they exist' , async ( ) => {
50
48
fs . mkdirSync ( 'node_modules' ) ;
51
49
writeJSONFile ( 'node_modules/prove-it.json' , { originalNodeModules : true } ) ;
52
50
writeJSONFile ( 'package.json' , { originalPackageJSON : true } ) ;
53
51
writeJSONFile ( 'yarn.lock' , { originalYarnLock : true } ) ;
54
52
writeJSONFile ( 'npm-shrinkwrap.json' , { originalNpmShrinkWrap : true } ) ;
55
53
writeJSONFile ( 'package-lock.json' , { originalPackageLock : true } ) ;
56
- return new NpmAdapter ( {
57
- cwd : tmpdir ,
58
- } )
59
- . setup ( )
60
- . then ( ( ) => {
61
- assertFileContainsJSON ( path . join ( tmpdir , 'package.json.ember-try' ) , {
62
- originalPackageJSON : true ,
63
- } ) ;
64
- assertFileContainsJSON ( path . join ( tmpdir , '.node_modules.ember-try/prove-it.json' ) , {
65
- originalNodeModules : true ,
66
- } ) ;
67
- assertFileContainsJSON ( path . join ( tmpdir , 'yarn.lock.ember-try' ) , {
68
- originalYarnLock : true ,
69
- } ) ;
70
- assertFileContainsJSON ( path . join ( tmpdir , 'npm-shrinkwrap.json.ember-try' ) , {
71
- originalNpmShrinkWrap : true ,
72
- } ) ;
73
- assertFileContainsJSON ( path . join ( tmpdir , 'package-lock.json.ember-try' ) , {
74
- originalPackageLock : true ,
75
- } ) ;
76
- } ) ;
54
+
55
+ let adapter = new NpmAdapter ( { cwd : tmpdir } ) ;
56
+ await adapter . setup ( ) ;
57
+
58
+ assertFileContainsJSON ( path . join ( tmpdir , 'package.json.ember-try' ) , {
59
+ originalPackageJSON : true ,
60
+ } ) ;
61
+ assertFileContainsJSON ( path . join ( tmpdir , '.node_modules.ember-try/prove-it.json' ) , {
62
+ originalNodeModules : true ,
63
+ } ) ;
64
+ assertFileContainsJSON ( path . join ( tmpdir , 'yarn.lock.ember-try' ) , {
65
+ originalYarnLock : true ,
66
+ } ) ;
67
+ assertFileContainsJSON ( path . join ( tmpdir , 'npm-shrinkwrap.json.ember-try' ) , {
68
+ originalNpmShrinkWrap : true ,
69
+ } ) ;
70
+ assertFileContainsJSON ( path . join ( tmpdir , 'package-lock.json.ember-try' ) , {
71
+ originalPackageLock : true ,
72
+ } ) ;
77
73
} ) ;
78
74
} ) ;
79
75
80
76
describe ( '#_install' , ( ) => {
81
77
describe ( 'without yarn' , ( ) => {
82
- it ( 'only runs npm install with npm 5' , ( ) => {
78
+ it ( 'only runs npm install with npm 5' , async ( ) => {
83
79
writeJSONFile ( 'package.json' , fixturePackage ) ;
84
80
let runCount = 0 ;
85
81
let stubbedRun = generateMockRun (
@@ -103,17 +99,16 @@ describe('npmAdapter', () => {
103
99
{ allowPassthrough : false }
104
100
) ;
105
101
106
- return new NpmAdapter ( {
102
+ let adapter = new NpmAdapter ( {
107
103
cwd : tmpdir ,
108
104
run : stubbedRun ,
109
- } )
110
- . _install ( )
111
- . then ( ( ) => {
112
- expect ( runCount ) . to . equal ( 2 ) ;
113
- } ) ;
105
+ } ) ;
106
+
107
+ await adapter . _install ( ) ;
108
+ expect ( runCount ) . to . equal ( 2 ) ;
114
109
} ) ;
115
110
116
- it ( 'runs npm prune and npm install with npm 4' , ( ) => {
111
+ it ( 'runs npm prune and npm install with npm 4' , async ( ) => {
117
112
writeJSONFile ( 'package.json' , fixturePackage ) ;
118
113
let runCount = 0 ;
119
114
let stubbedRun = generateMockRun (
@@ -145,17 +140,16 @@ describe('npmAdapter', () => {
145
140
{ allowPassthrough : false }
146
141
) ;
147
142
148
- return new NpmAdapter ( {
143
+ let adapter = new NpmAdapter ( {
149
144
cwd : tmpdir ,
150
145
run : stubbedRun ,
151
- } )
152
- . _install ( )
153
- . then ( ( ) => {
154
- expect ( runCount ) . to . equal ( 3 , 'All three commands should run' ) ;
155
- } ) ;
146
+ } ) ;
147
+
148
+ await adapter . _install ( ) ;
149
+ expect ( runCount ) . to . equal ( 3 , 'All three commands should run' ) ;
156
150
} ) ;
157
151
158
- it ( 'uses managerOptions for npm commands' , ( ) => {
152
+ it ( 'uses managerOptions for npm commands' , async ( ) => {
159
153
writeJSONFile ( 'package.json' , fixturePackage ) ;
160
154
let runCount = 0 ;
161
155
let stubbedRun = generateMockRun (
@@ -178,18 +172,17 @@ describe('npmAdapter', () => {
178
172
{ allowPassthrough : false }
179
173
) ;
180
174
181
- return new NpmAdapter ( {
175
+ let adapter = new NpmAdapter ( {
182
176
cwd : tmpdir ,
183
177
run : stubbedRun ,
184
178
managerOptions : [ '--no-optional' ] ,
185
- } )
186
- . _install ( )
187
- . then ( ( ) => {
188
- expect ( runCount ) . to . equal ( 2 ) ;
189
- } ) ;
179
+ } ) ;
180
+
181
+ await adapter . _install ( ) ;
182
+ expect ( runCount ) . to . equal ( 2 ) ;
190
183
} ) ;
191
184
192
- it ( 'uses buildManagerOptions for npm commands' , ( ) => {
185
+ it ( 'uses buildManagerOptions for npm commands' , async ( ) => {
193
186
writeJSONFile ( 'package.json' , fixturePackage ) ;
194
187
let runCount = 0 ;
195
188
let stubbedRun = generateMockRun (
@@ -212,17 +205,16 @@ describe('npmAdapter', () => {
212
205
{ allowPassthrough : false }
213
206
) ;
214
207
215
- return new NpmAdapter ( {
208
+ let adapter = new NpmAdapter ( {
216
209
cwd : tmpdir ,
217
210
run : stubbedRun ,
218
211
buildManagerOptions : function ( ) {
219
212
return [ '--flat' ] ;
220
213
} ,
221
- } )
222
- . _install ( )
223
- . then ( ( ) => {
224
- expect ( runCount ) . to . equal ( 2 , 'npm install should run with buildManagerOptions' ) ;
225
- } ) ;
214
+ } ) ;
215
+
216
+ await adapter . _install ( ) ;
217
+ expect ( runCount ) . to . equal ( 2 , 'npm install should run with buildManagerOptions' ) ;
226
218
} ) ;
227
219
228
220
it ( 'throws an error if buildManagerOptions does not return an array' , async ( ) => {
@@ -246,7 +238,7 @@ describe('npmAdapter', () => {
246
238
} ) ;
247
239
248
240
describe ( 'with yarn' , ( ) => {
249
- it ( 'runs yarn install' , ( ) => {
241
+ it ( 'runs yarn install' , async ( ) => {
250
242
writeJSONFile ( 'package.json' , fixturePackage ) ;
251
243
let runCount = 0 ;
252
244
let stubbedRun = generateMockRun (
@@ -263,18 +255,17 @@ describe('npmAdapter', () => {
263
255
{ allowPassthrough : false }
264
256
) ;
265
257
266
- return new NpmAdapter ( {
258
+ let adapter = new NpmAdapter ( {
267
259
cwd : tmpdir ,
268
260
run : stubbedRun ,
269
261
useYarnCommand : true ,
270
- } )
271
- . _install ( )
272
- . then ( ( ) => {
273
- expect ( runCount ) . to . equal ( 1 , 'Only yarn install should run' ) ;
274
- } ) ;
262
+ } ) ;
263
+
264
+ await adapter . _install ( ) ;
265
+ expect ( runCount ) . to . equal ( 1 , 'Only yarn install should run' ) ;
275
266
} ) ;
276
267
277
- it ( 'uses managerOptions for yarn commands' , ( ) => {
268
+ it ( 'uses managerOptions for yarn commands' , async ( ) => {
278
269
writeJSONFile ( 'package.json' , fixturePackage ) ;
279
270
let runCount = 0 ;
280
271
let stubbedRun = generateMockRun (
@@ -290,19 +281,18 @@ describe('npmAdapter', () => {
290
281
{ allowPassthrough : false }
291
282
) ;
292
283
293
- return new NpmAdapter ( {
284
+ let adapter = new NpmAdapter ( {
294
285
cwd : tmpdir ,
295
286
run : stubbedRun ,
296
287
useYarnCommand : true ,
297
288
managerOptions : [ '--flat' ] ,
298
- } )
299
- . _install ( )
300
- . then ( ( ) => {
301
- expect ( runCount ) . to . equal ( 1 , 'Only yarn install should run with manager options' ) ;
302
- } ) ;
289
+ } ) ;
290
+
291
+ await adapter . _install ( ) ;
292
+ expect ( runCount ) . to . equal ( 1 , 'Only yarn install should run with manager options' ) ;
303
293
} ) ;
304
294
305
- it ( 'uses buildManagerOptions for yarn commands' , ( ) => {
295
+ it ( 'uses buildManagerOptions for yarn commands' , async ( ) => {
306
296
writeJSONFile ( 'package.json' , fixturePackage ) ;
307
297
let runCount = 0 ;
308
298
let stubbedRun = generateMockRun (
@@ -318,18 +308,17 @@ describe('npmAdapter', () => {
318
308
{ allowPassthrough : false }
319
309
) ;
320
310
321
- return new NpmAdapter ( {
311
+ let adapter = new NpmAdapter ( {
322
312
cwd : tmpdir ,
323
313
run : stubbedRun ,
324
314
useYarnCommand : true ,
325
315
buildManagerOptions : function ( ) {
326
316
return [ '--flat' ] ;
327
317
} ,
328
- } )
329
- . _install ( )
330
- . then ( ( ) => {
331
- expect ( runCount ) . to . equal ( 1 , 'Only yarn install should run with buildManagerOptions' ) ;
332
- } ) ;
318
+ } ) ;
319
+
320
+ await adapter . _install ( ) ;
321
+ expect ( runCount ) . to . equal ( 1 , 'Only yarn install should run with buildManagerOptions' ) ;
333
322
} ) ;
334
323
335
324
it ( 'throws an error if buildManagerOptions does not return an array' , async ( ) => {
@@ -355,20 +344,22 @@ describe('npmAdapter', () => {
355
344
} ) ;
356
345
357
346
describe ( '#_restoreOriginalDependencies' , ( ) => {
358
- it ( 'replaces the package.json with the backed up version' , ( ) => {
347
+ it ( 'replaces the package.json with the backed up version' , async ( ) => {
359
348
writeJSONFile ( 'package.json.ember-try' , { originalPackageJSON : true } ) ;
360
349
writeJSONFile ( 'package.json' , { originalPackageJSON : false } ) ;
361
350
fs . mkdirSync ( '.node_modules.ember-try' ) ;
362
351
writeJSONFile ( '.node_modules.ember-try/prove-it.json' , { originalNodeModules : true } ) ;
363
- return new NpmAdapter ( { cwd : tmpdir } ) . _restoreOriginalDependencies ( ) . then ( ( ) => {
364
- assertFileContainsJSON ( path . join ( tmpdir , 'package.json' ) , { originalPackageJSON : true } ) ;
365
- assertFileContainsJSON ( path . join ( tmpdir , 'node_modules/prove-it.json' ) , {
366
- originalNodeModules : true ,
367
- } ) ;
352
+
353
+ let adapter = new NpmAdapter ( { cwd : tmpdir } ) ;
354
+ await adapter . _restoreOriginalDependencies ( ) ;
355
+
356
+ assertFileContainsJSON ( path . join ( tmpdir , 'package.json' ) , { originalPackageJSON : true } ) ;
357
+ assertFileContainsJSON ( path . join ( tmpdir , 'node_modules/prove-it.json' ) , {
358
+ originalNodeModules : true ,
368
359
} ) ;
369
360
} ) ;
370
361
371
- it ( 'replaces the yarn.lock, npm-shrinkwrap.json and package-lock.json with the backed up version if they exist' , ( ) => {
362
+ it ( 'replaces the yarn.lock, npm-shrinkwrap.json and package-lock.json with the backed up version if they exist' , async ( ) => {
372
363
writeJSONFile ( 'package.json.ember-try' , { originalPackageJSON : true } ) ;
373
364
writeJSONFile ( 'package.json' , { originalPackageJSON : false } ) ;
374
365
fs . mkdirSync ( '.node_modules.ember-try' ) ;
@@ -379,18 +370,20 @@ describe('npmAdapter', () => {
379
370
writeJSONFile ( 'npm-shrinkwrap.json' , { originalNpmShrinkWrap : false } ) ;
380
371
writeJSONFile ( 'package-lock.json.ember-try' , { originalPackageLock : true } ) ;
381
372
writeJSONFile ( 'package-lock.json' , { originalPackageLock : false } ) ;
382
- return new NpmAdapter ( { cwd : tmpdir } ) . _restoreOriginalDependencies ( ) . then ( ( ) => {
383
- assertFileContainsJSON ( path . join ( tmpdir , 'package.json' ) , { originalPackageJSON : true } ) ;
384
- assertFileContainsJSON ( path . join ( tmpdir , 'node_modules/prove-it.json' ) , {
385
- originalNodeModules : true ,
386
- } ) ;
387
- assertFileContainsJSON ( path . join ( tmpdir , 'yarn.lock' ) , { originalYarnLock : true } ) ;
388
- assertFileContainsJSON ( path . join ( tmpdir , 'npm-shrinkwrap.json' ) , {
389
- originalNpmShrinkWrap : true ,
390
- } ) ;
391
- assertFileContainsJSON ( path . join ( tmpdir , 'package-lock.json' ) , {
392
- originalPackageLock : true ,
393
- } ) ;
373
+
374
+ let adapter = new NpmAdapter ( { cwd : tmpdir } ) ;
375
+ await adapter . _restoreOriginalDependencies ( ) ;
376
+
377
+ assertFileContainsJSON ( path . join ( tmpdir , 'package.json' ) , { originalPackageJSON : true } ) ;
378
+ assertFileContainsJSON ( path . join ( tmpdir , 'node_modules/prove-it.json' ) , {
379
+ originalNodeModules : true ,
380
+ } ) ;
381
+ assertFileContainsJSON ( path . join ( tmpdir , 'yarn.lock' ) , { originalYarnLock : true } ) ;
382
+ assertFileContainsJSON ( path . join ( tmpdir , 'npm-shrinkwrap.json' ) , {
383
+ originalNpmShrinkWrap : true ,
384
+ } ) ;
385
+ assertFileContainsJSON ( path . join ( tmpdir , 'package-lock.json' ) , {
386
+ originalPackageLock : true ,
394
387
} ) ;
395
388
} ) ;
396
389
} ) ;
0 commit comments