@@ -15,6 +15,8 @@ import { run as uninstall } from "../../src/cli/commands/uninstall.js";
15
15
import Config from "../../src/config.js" ;
16
16
import * as fs from "../../src/util/fs.js" ;
17
17
import assert from "assert" ;
18
+ import semver from "semver" ;
19
+
18
20
19
21
let test = require ( "ava" ) ;
20
22
let path = require ( "path" ) ;
@@ -335,6 +337,60 @@ test("upgrade scenario", () => {
335
337
} , clean ) ;
336
338
} ) ;
337
339
340
+ test . only ( "upgrade scenario 2 (with sub dependencies)" , async ( ) => {
341
+ // mime-types@2.0.0 is saved in local mirror and gets updated to mime-types@2.1.11
342
+ // files in mirror, fbkpm.lock, package.json and node_modules should reflect that
343
+
344
+ let mirrorPath = "mirror-for-offline" ;
345
+ let fixture = "install-upgrade-scenario-2" ;
346
+ let cwd = path . join ( fixturesLoc , fixture ) ;
347
+ await fs . copy ( path . join ( cwd , "fbkpm.lock.before" ) , path . join ( cwd , "fbkpm.lock" ) ) ;
348
+ await fs . copy ( path . join ( cwd , "package.json.before" ) , path . join ( cwd , "package.json" ) ) ;
349
+
350
+ return run ( { } , [ ] , fixture , async ( config ) => {
351
+ assert ( semver . satisfies (
352
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "node_modules/mime-db/package.json" ) ) ) . version ,
353
+ "~1.0.1" )
354
+ ) ;
355
+ assert . equal (
356
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "node_modules/mime-types/package.json" ) ) ) . version ,
357
+ "2.0.0"
358
+ ) ;
359
+
360
+ return run ( { save : true } , [ "mime-types@2.1.11" ] , fixture , async ( config ) => {
361
+ assert ( semver . satisfies (
362
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "node_modules/mime-db/package.json" ) ) ) . version ,
363
+ "~1.23.0"
364
+ ) ) ;
365
+ assert . equal (
366
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "node_modules/mime-types/package.json" ) ) ) . version ,
367
+ "2.1.11"
368
+ ) ;
369
+
370
+ let lockFileWritten = await fs . readFile ( path . join ( config . cwd , "fbkpm.lock" ) ) ;
371
+ let lockFileLines = lockFileWritten . split ( "\n" ) . filter ( ( line ) => ! ! line ) ;
372
+ assert . equal ( lockFileLines [ 0 ] , "mime-db@~1.23.0:" ) ;
373
+ assert . notEqual ( lockFileLines [ 3 ] . indexOf ( "resolved mime-db-" ) , - 1 ) ;
374
+ assert . equal ( lockFileLines [ 4 ] , "mime-types@2.1.11:" ) ;
375
+ assert . notEqual ( lockFileLines [ 7 ] . indexOf ( "resolved mime-types-2.1.11.tgz" ) , - 1 ) ;
376
+
377
+ let mirror = await fs . walk ( path . join ( config . cwd , mirrorPath ) ) ;
378
+ assert . equal ( mirror . length , 4 ) ;
379
+ let newFilesInMirror = mirror . filter ( ( elem ) => {
380
+ return elem . relative !== "mime-db-1.0.3.tgz" && elem . relative !== "mime-types-2.0.0.tgz" ;
381
+ } ) ;
382
+
383
+ assert . equal ( newFilesInMirror . length , 2 ) ;
384
+
385
+ await fs . unlink ( newFilesInMirror [ 0 ] . absolute ) ;
386
+ await fs . unlink ( newFilesInMirror [ 1 ] . absolute ) ;
387
+
388
+ await fs . unlink ( path . join ( config . cwd , "fbkpm.lock" ) ) ;
389
+ await fs . unlink ( path . join ( config . cwd , "package.json" ) ) ;
390
+ } ) ;
391
+ } ) ;
392
+ } ) ;
393
+
338
394
test ( "downgrade scenario" , ( ) => {
339
395
// left-pad first installed 1.1.0 then downgraded to 0.0.9
340
396
// files in mirror, fbkpm.lock, package.json and node_modules should reflect that
0 commit comments