@@ -66,7 +66,7 @@ async function run(flags, args, name, checkInstalled, beforeInstall) {
66
66
await install . init ( ) ;
67
67
68
68
if ( checkInstalled ) {
69
- await checkInstalled ( cwd ) ;
69
+ await checkInstalled ( config , reporter ) ;
70
70
}
71
71
72
72
// clean up
@@ -95,50 +95,50 @@ test("install with arg that has binaries", () => {
95
95
96
96
test ( "install with --save and offline mirror" , ( ) => {
97
97
let mirrorPath = "mirror-for-offline" ;
98
- return run ( { save : true } , [ "is-array@1.0.1" ] , "install-with-save-offline-mirror" , async ( cwd ) => {
98
+ return run ( { save : true } , [ "is-array@1.0.1" ] , "install-with-save-offline-mirror" , async ( config ) => {
99
99
100
- let allFiles = await fs . walk ( cwd ) ;
100
+ let allFiles = await fs . walk ( config . cwd ) ;
101
101
102
102
assert ( allFiles . findIndex ( ( file ) => {
103
103
return file . relative === `${ mirrorPath } /is-array-1.0.1.tgz` ;
104
104
} ) !== - 1 ) ;
105
105
106
- let rawLockfile = await fs . readFile ( path . join ( cwd , constants . LOCKFILE_FILENAME ) ) ;
106
+ let rawLockfile = await fs . readFile ( path . join ( config . cwd , constants . LOCKFILE_FILENAME ) ) ;
107
107
let lockfile = parse ( rawLockfile ) ;
108
108
assert . equal ( lockfile [ "is-array@1.0.1" ] [ "resolved" ] ,
109
109
"is-array-1.0.1.tgz#e9850cc2cc860c3bc0977e84ccf0dd464584279a" ) ;
110
110
111
- await fs . unlink ( path . join ( cwd , mirrorPath ) ) ;
112
- await fs . unlink ( path . join ( cwd , "package.json" ) ) ;
111
+ await fs . unlink ( path . join ( config . cwd , mirrorPath ) ) ;
112
+ await fs . unlink ( path . join ( config . cwd , "package.json" ) ) ;
113
113
return allFiles ;
114
114
} ) ;
115
115
} ) ;
116
116
117
117
test ( "install with --save and without offline mirror" , ( ) => {
118
118
let mirrorPath = "mirror-for-offline" ;
119
- return run ( { save : true } , [ "is-array@1.0.1" ] , "install-with-save-no-offline-mirror" , async ( cwd ) => {
119
+ return run ( { save : true } , [ "is-array@1.0.1" ] , "install-with-save-no-offline-mirror" , async ( config ) => {
120
120
121
- let allFiles = await fs . walk ( cwd ) ;
121
+ let allFiles = await fs . walk ( config . cwd ) ;
122
122
123
123
assert ( allFiles . findIndex ( ( file ) => {
124
124
return file . relative === `${ mirrorPath } /is-array-1.0.1.tgz` ;
125
125
} ) === - 1 ) ;
126
126
127
- let rawLockfile = await fs . readFile ( path . join ( cwd , constants . LOCKFILE_FILENAME ) ) ;
127
+ let rawLockfile = await fs . readFile ( path . join ( config . cwd , constants . LOCKFILE_FILENAME ) ) ;
128
128
let lockfile = parse ( rawLockfile ) ;
129
129
assert . equal ( lockfile [ "is-array@1.0.1" ] [ "resolved" ] ,
130
130
"https://registry.npmjs.org/is-array/-/is-array-1.0.1.tgz#e9850cc2cc860c3bc0977e84ccf0dd464584279a" ) ;
131
131
132
- await fs . unlink ( path . join ( cwd , mirrorPath ) ) ;
133
- await fs . unlink ( path . join ( cwd , "package.json" ) ) ;
132
+ await fs . unlink ( path . join ( config . cwd , mirrorPath ) ) ;
133
+ await fs . unlink ( path . join ( config . cwd , "package.json" ) ) ;
134
134
return allFiles ;
135
135
} ) ;
136
136
} ) ;
137
137
138
138
test ( "install from offline mirror" , ( ) => {
139
- return run ( { } , [ ] , "install-from-offline-mirror" , async ( cwd ) => {
139
+ return run ( { } , [ ] , "install-from-offline-mirror" , async ( config ) => {
140
140
141
- let allFiles = await fs . walk ( cwd ) ;
141
+ let allFiles = await fs . walk ( config . cwd ) ;
142
142
143
143
assert ( allFiles . findIndex ( ( file ) => {
144
144
return file . relative === "node_modules/fake-fbkpm-dependency/package.json" ;
@@ -152,23 +152,23 @@ test("install should dedupe dependencies avoiding conflicts 0", () => {
152
152
// A@2.0.1 -> B@2.0.0
153
153
// B@1.0.0
154
154
// should result in B@2.0.0 not flattened
155
- return run ( { } , [ ] , "install-should-dedupe-avoiding-conflicts-0" , async ( cwd ) => {
156
- let rawDepBPackage = await fs . readFile ( path . join ( cwd , "node_modules/dep-b/package.json" ) ) ;
155
+ return run ( { } , [ ] , "install-should-dedupe-avoiding-conflicts-0" , async ( config ) => {
156
+ let rawDepBPackage = await fs . readFile ( path . join ( config . cwd , "node_modules/dep-b/package.json" ) ) ;
157
157
assert . equal ( JSON . parse ( rawDepBPackage ) . version , "1.0.0" ) ;
158
158
159
- rawDepBPackage = await fs . readFile ( path . join ( cwd , "node_modules/dep-a/node_modules/dep-b/package.json" ) ) ;
159
+ rawDepBPackage = await fs . readFile ( path . join ( config . cwd , "node_modules/dep-a/node_modules/dep-b/package.json" ) ) ;
160
160
assert . equal ( JSON . parse ( rawDepBPackage ) . version , "2.0.0" ) ;
161
161
} ) ;
162
162
} ) ;
163
163
164
164
test ( "install should dedupe dependencies avoiding conflicts 1" , ( ) => {
165
165
// A@2.0.1 -> B@2.0.0
166
166
// should result in B@2.0.0 flattened
167
- return run ( { } , [ ] , "install-should-dedupe-avoiding-conflicts-1" , async ( cwd ) => {
168
- let rawDepBPackage = await fs . readFile ( path . join ( cwd , "node_modules/dep-b/package.json" ) ) ;
167
+ return run ( { } , [ ] , "install-should-dedupe-avoiding-conflicts-1" , async ( config ) => {
168
+ let rawDepBPackage = await fs . readFile ( path . join ( config . cwd , "node_modules/dep-b/package.json" ) ) ;
169
169
assert . equal ( JSON . parse ( rawDepBPackage ) . version , "2.0.0" ) ;
170
170
171
- rawDepBPackage = await fs . readFile ( path . join ( cwd , "node_modules/dep-a/package.json" ) ) ;
171
+ rawDepBPackage = await fs . readFile ( path . join ( config . cwd , "node_modules/dep-a/package.json" ) ) ;
172
172
assert . equal ( JSON . parse ( rawDepBPackage ) . version , "2.0.1" ) ;
173
173
} ) ;
174
174
} ) ;
@@ -183,18 +183,18 @@ test("install should dedupe dependencies avoiding conflicts 2", () => {
183
183
// B@1 -> C@1
184
184
// C@2
185
185
186
- return run ( { } , [ ] , "install-should-dedupe-avoiding-conflicts-2" , async ( cwd ) => {
187
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
186
+ return run ( { } , [ ] , "install-should-dedupe-avoiding-conflicts-2" , async ( config ) => {
187
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
188
188
"node_modules/dep-a/package.json" ) ) ) . version , "2.0.0" ) ;
189
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
189
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
190
190
"node_modules/dep-a/node_modules/dep-b/package.json" ) ) ) . version , "2.0.0" ) ;
191
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
191
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
192
192
"node_modules/dep-c/package.json" ) ) ) . version , "2.0.0" ) ;
193
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
193
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
194
194
"node_modules/dep-d/package.json" ) ) ) . version , "1.0.0" ) ;
195
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
195
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
196
196
"node_modules/dep-b/package.json" ) ) ) . version , "1.0.0" ) ;
197
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
197
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
198
198
"node_modules/dep-b/node_modules/dep-c/package.json" ) ) ) . version , "1.0.0" ) ;
199
199
} ) ;
200
200
} ) ;
@@ -208,16 +208,16 @@ test("install should dedupe dependencies avoiding conflicts 3", () => {
208
208
// B@2
209
209
// C@2
210
210
// D@1
211
- return run ( { } , [ ] , "install-should-dedupe-avoiding-conflicts-3" , async ( cwd ) => {
212
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
211
+ return run ( { } , [ ] , "install-should-dedupe-avoiding-conflicts-3" , async ( config ) => {
212
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
213
213
"node_modules/dep-a/package.json" ) ) ) . version , "2.0.0" ) ;
214
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
214
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
215
215
"node_modules/dep-c/package.json" ) ) ) . version , "2.0.0" ) ;
216
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
216
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
217
217
"node_modules/dep-d/package.json" ) ) ) . version , "1.0.0" ) ;
218
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
218
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
219
219
"node_modules/dep-b/package.json" ) ) ) . version , "2.0.0" ) ;
220
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
220
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
221
221
"node_modules/dep-a/node_modules/dep-c/package.json" ) ) ) . version , "1.0.0" ) ;
222
222
} ) ;
223
223
} ) ;
@@ -233,16 +233,16 @@ test("install should dedupe dependencies avoiding conflicts 4", () => {
233
233
// C@2
234
234
// B@2
235
235
// D@1
236
- return run ( { } , [ ] , "install-should-dedupe-avoiding-conflicts-4" , async ( cwd ) => {
237
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
236
+ return run ( { } , [ ] , "install-should-dedupe-avoiding-conflicts-4" , async ( config ) => {
237
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
238
238
"node_modules/dep-a/package.json" ) ) ) . version , "2.0.0" ) ;
239
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
239
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
240
240
"node_modules/dep-c/package.json" ) ) ) . version , "2.0.0" ) ;
241
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
241
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
242
242
"node_modules/dep-d/package.json" ) ) ) . version , "1.0.0" ) ;
243
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
243
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
244
244
"node_modules/dep-b/package.json" ) ) ) . version , "2.0.0" ) ;
245
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
245
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
246
246
"node_modules/dep-a/node_modules/dep-c/package.json" ) ) ) . version , "1.0.0" ) ;
247
247
} ) ;
248
248
} ) ;
@@ -259,18 +259,18 @@ test("install should dedupe dependencies avoiding conflicts 5", () => {
259
259
// D@1 -> A@2
260
260
// -> B@2
261
261
262
- return run ( { } , [ ] , "install-should-dedupe-avoiding-conflicts-5" , async ( cwd ) => {
263
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
262
+ return run ( { } , [ ] , "install-should-dedupe-avoiding-conflicts-5" , async ( config ) => {
263
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
264
264
"node_modules/dep-a/package.json" ) ) ) . version , "1.0.0" ) ;
265
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
265
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
266
266
"node_modules/dep-b/package.json" ) ) ) . version , "1.0.0" ) ;
267
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
267
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
268
268
"node_modules/dep-c/package.json" ) ) ) . version , "1.0.0" ) ;
269
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
269
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
270
270
"node_modules/dep-d/package.json" ) ) ) . version , "1.0.0" ) ;
271
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
271
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
272
272
"node_modules/dep-d/node_modules/dep-a/package.json" ) ) ) . version , "2.0.0" ) ;
273
- assert . equal ( JSON . parse ( await fs . readFile ( path . join ( cwd ,
273
+ assert . equal ( JSON . parse ( await fs . readFile ( path . join ( config . cwd ,
274
274
"node_modules/dep-d/node_modules/dep-b/package.json" ) ) ) . version , "2.0.0" ) ;
275
275
276
276
} ) ;
@@ -288,47 +288,47 @@ test("upgrade scenario", () => {
288
288
await fs . unlink ( path . join ( cwd , "package.json" ) ) ;
289
289
}
290
290
291
- return run ( { save : true } , [ "left-pad@0.0.9" ] , "install-upgrade-scenario" , async ( cwd ) => {
291
+ return run ( { save : true } , [ "left-pad@0.0.9" ] , "install-upgrade-scenario" , async ( config ) => {
292
292
assert . equal (
293
- JSON . parse ( await fs . readFile ( path . join ( cwd , "node_modules/left-pad/package.json" ) ) ) . version ,
293
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "node_modules/left-pad/package.json" ) ) ) . version ,
294
294
"0.0.9"
295
295
) ;
296
296
assert . deepEqual (
297
- JSON . parse ( await fs . readFile ( path . join ( cwd , "package.json" ) ) ) . dependencies ,
297
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "package.json" ) ) ) . dependencies ,
298
298
{ "left-pad" : "0.0.9" }
299
299
) ;
300
300
301
- let lockFileWritten = await fs . readFile ( path . join ( cwd , "fbkpm.lock" ) ) ;
301
+ let lockFileWritten = await fs . readFile ( path . join ( config . cwd , "fbkpm.lock" ) ) ;
302
302
let lockFileLines = lockFileWritten . split ( "\n" ) . filter ( ( line ) => ! ! line ) ;
303
303
assert . equal ( lockFileLines [ 0 ] , "left-pad@0.0.9:" ) ;
304
304
assert . equal ( lockFileLines . length , 4 ) ;
305
305
assert . notEqual ( lockFileLines [ 3 ] . indexOf ( "resolved left-pad-0.0.9.tgz" ) , - 1 ) ;
306
306
307
- let mirror = await fs . walk ( path . join ( cwd , mirrorPath ) ) ;
307
+ let mirror = await fs . walk ( path . join ( config . cwd , mirrorPath ) ) ;
308
308
assert . equal ( mirror . length , 1 ) ;
309
309
assert . equal ( mirror [ 0 ] . relative , "left-pad-0.0.9.tgz" ) ;
310
310
311
- return run ( { save : true } , [ "left-pad@1.1.0" ] , "install-upgrade-scenario" , async ( cwd ) => {
311
+ return run ( { save : true } , [ "left-pad@1.1.0" ] , "install-upgrade-scenario" , async ( config ) => {
312
312
assert . equal (
313
- JSON . parse ( await fs . readFile ( path . join ( cwd , "node_modules/left-pad/package.json" ) ) ) . version ,
313
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "node_modules/left-pad/package.json" ) ) ) . version ,
314
314
"1.1.0"
315
315
) ;
316
316
assert . deepEqual (
317
- JSON . parse ( await fs . readFile ( path . join ( cwd , "package.json" ) ) ) . dependencies ,
317
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "package.json" ) ) ) . dependencies ,
318
318
{ "left-pad" : "1.1.0" }
319
319
) ;
320
320
321
- let lockFileWritten = await fs . readFile ( path . join ( cwd , "fbkpm.lock" ) ) ;
321
+ let lockFileWritten = await fs . readFile ( path . join ( config . cwd , "fbkpm.lock" ) ) ;
322
322
let lockFileLines = lockFileWritten . split ( "\n" ) . filter ( ( line ) => ! ! line ) ;
323
323
assert . equal ( lockFileLines [ 0 ] , "left-pad@1.1.0:" ) ;
324
324
assert . equal ( lockFileLines . length , 4 ) ;
325
325
assert . notEqual ( lockFileLines [ 3 ] . indexOf ( "resolved left-pad-1.1.0.tgz" ) , - 1 ) ;
326
326
327
- let mirror = await fs . walk ( path . join ( cwd , mirrorPath ) ) ;
327
+ let mirror = await fs . walk ( path . join ( config . cwd , mirrorPath ) ) ;
328
328
assert . equal ( mirror . length , 2 ) ;
329
329
assert . equal ( mirror [ 1 ] . relative , "left-pad-1.1.0.tgz" ) ;
330
330
331
- await clean ( cwd ) ;
331
+ await clean ( config . cwd ) ;
332
332
} ) ;
333
333
} , clean ) ;
334
334
} ) ;
@@ -337,65 +337,85 @@ test("downgrade scenario", () => {
337
337
// left-pad first installed 1.1.0 then downgraded to 0.0.9
338
338
// files in mirror, fbkpm.lock, package.json and node_modules should reflect that
339
339
340
- return run ( { save : true } , [ "left-pad@1.1.0" ] , "install-downgrade-scenario" , async ( cwd ) => {
340
+ return run ( { save : true } , [ "left-pad@1.1.0" ] , "install-downgrade-scenario" , async ( config ) => {
341
341
assert . equal (
342
- JSON . parse ( await fs . readFile ( path . join ( cwd , "node_modules/left-pad/package.json" ) ) ) . version ,
342
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "node_modules/left-pad/package.json" ) ) ) . version ,
343
343
"1.1.0"
344
344
) ;
345
345
assert . deepEqual (
346
- JSON . parse ( await fs . readFile ( path . join ( cwd , "package.json" ) ) ) . dependencies ,
346
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "package.json" ) ) ) . dependencies ,
347
347
{ "left-pad" : "1.1.0" }
348
348
) ;
349
349
350
350
let mirrorPath = "mirror-for-offline" ;
351
- let lockFileWritten = await fs . readFile ( path . join ( cwd , "fbkpm.lock" ) ) ;
351
+ let lockFileWritten = await fs . readFile ( path . join ( config . cwd , "fbkpm.lock" ) ) ;
352
352
let lockFileLines = lockFileWritten . split ( "\n" ) . filter ( ( line ) => ! ! line ) ;
353
353
assert . equal ( lockFileLines [ 0 ] , "left-pad@1.1.0:" ) ;
354
354
assert . equal ( lockFileLines . length , 4 ) ;
355
355
assert . notEqual ( lockFileLines [ 3 ] . indexOf ( "resolved left-pad-1.1.0.tgz" ) , - 1 ) ;
356
356
357
- let mirror = await fs . walk ( path . join ( cwd , mirrorPath ) ) ;
357
+ let mirror = await fs . walk ( path . join ( config . cwd , mirrorPath ) ) ;
358
358
assert . equal ( mirror . length , 1 ) ;
359
359
assert . equal ( mirror [ 0 ] . relative , "left-pad-1.1.0.tgz" ) ;
360
360
361
- return run ( { save : true } , [ "left-pad@0.0.9" ] , "install-downgrade-scenario" , async ( cwd ) => {
361
+ return run ( { save : true } , [ "left-pad@0.0.9" ] , "install-downgrade-scenario" , async ( config ) => {
362
362
assert . equal (
363
- JSON . parse ( await fs . readFile ( path . join ( cwd , "node_modules/left-pad/package.json" ) ) ) . version ,
363
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "node_modules/left-pad/package.json" ) ) ) . version ,
364
364
"0.0.9"
365
365
) ;
366
366
assert . deepEqual (
367
- JSON . parse ( await fs . readFile ( path . join ( cwd , "package.json" ) ) ) . dependencies ,
367
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "package.json" ) ) ) . dependencies ,
368
368
{ "left-pad" : "0.0.9" }
369
369
) ;
370
370
371
- let lockFileWritten = await fs . readFile ( path . join ( cwd , "fbkpm.lock" ) ) ;
371
+ let lockFileWritten = await fs . readFile ( path . join ( config . cwd , "fbkpm.lock" ) ) ;
372
372
let lockFileLines = lockFileWritten . split ( "\n" ) . filter ( ( line ) => ! ! line ) ;
373
373
assert . equal ( lockFileLines [ 0 ] , "left-pad@0.0.9:" ) ;
374
374
assert . equal ( lockFileLines . length , 4 ) ;
375
375
assert . notEqual ( lockFileLines [ 3 ] . indexOf ( "resolved left-pad-0.0.9.tgz" ) , - 1 ) ;
376
376
377
- let mirror = await fs . walk ( path . join ( cwd , mirrorPath ) ) ;
377
+ let mirror = await fs . walk ( path . join ( config . cwd , mirrorPath ) ) ;
378
378
assert . equal ( mirror . length , 2 ) ;
379
379
assert . equal ( mirror [ 0 ] . relative , "left-pad-0.0.9.tgz" ) ;
380
380
381
- await fs . unlink ( path . join ( cwd , mirrorPath ) ) ;
382
- await fs . unlink ( path . join ( cwd , "fbkpm.lock" ) ) ;
383
- await fs . unlink ( path . join ( cwd , "package.json" ) ) ;
381
+ await fs . unlink ( path . join ( config . cwd , mirrorPath ) ) ;
382
+ await fs . unlink ( path . join ( config . cwd , "fbkpm.lock" ) ) ;
383
+ await fs . unlink ( path . join ( config . cwd , "package.json" ) ) ;
384
384
} ) ;
385
385
} ) ;
386
386
} ) ;
387
387
388
- test . skip ( "uninstall should remove dependency from package.json, fbkpm.lock and node_modules" , ( ) => {
389
- return run ( { } , [ ] , "uninstall-should-clean" , async ( cwd ) => {
388
+ test ( "uninstall should remove dependency from package.json, fbkpm.lock and node_modules" , ( ) => {
389
+ let mirrorPath = "mirror-for-offline" ;
390
+
391
+ return run ( { } , [ ] , "uninstall-should-clean" , async ( config , reporter ) => {
390
392
assert . equal (
391
- JSON . parse ( await fs . readFile ( path . join ( cwd , "node_modules/dep-a/package.json" ) ) ) . version ,
393
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "node_modules/dep-a/package.json" ) ) ) . version ,
392
394
"1.0.0"
393
395
) ;
394
396
395
- let reporter = new reporters . NoopReporter ;
396
- let config = new Config ( reporter , { cwd } ) ;
397
- await config . init ( ) ;
397
+ await fs . copy ( path . join ( config . cwd , "fbkpm.lock" ) , path . join ( config . cwd , "fbkpm.lock.orig" ) ) ;
398
+ await fs . copy ( path . join ( config . cwd , "package.json" ) , path . join ( config . cwd , "package.json.orig" ) ) ;
398
399
399
400
await uninstall ( config , reporter , { } , [ "dep-a" ] ) ;
401
+
402
+ assert ( ! await fs . exists ( path . join ( config . cwd , "node_modules/dep-a" ) ) ) ;
403
+ assert ( await fs . exists ( path . join ( config . cwd , `${ mirrorPath } /dep-a-1.0.0.tgz` ) ) ) ;
404
+
405
+ assert . deepEqual (
406
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "package.json" ) ) ) . dependencies ,
407
+ { }
408
+ ) ;
409
+
410
+ let lockFileContent = await fs . readFile ( path . join ( config . cwd , "fbkpm.lock" ) ) ;
411
+ let lockFileLines = lockFileContent . split ( "\n" ) . filter ( ( line ) => ! ! line ) ;
412
+ assert . equal ( lockFileLines . length , 0 ) ;
413
+
414
+ await fs . unlink ( path . join ( config . cwd , "fbkpm.lock" ) ) ;
415
+ await fs . unlink ( path . join ( config . cwd , "package.json" ) ) ;
416
+ await fs . copy ( path . join ( config . cwd , "fbkpm.lock.orig" ) , path . join ( config . cwd , "fbkpm.lock" ) ) ;
417
+ await fs . copy ( path . join ( config . cwd , "package.json.orig" ) , path . join ( config . cwd , "package.json" ) ) ;
418
+ await fs . unlink ( path . join ( config . cwd , "fbkpm.lock.orig" ) ) ;
419
+ await fs . unlink ( path . join ( config . cwd , "package.json.orig" ) ) ;
400
420
} ) ;
401
421
} ) ;
0 commit comments