@@ -650,6 +650,65 @@ test("install --save should add missing deps to fbkpm and mirror (PR import scen
650
650
} ) ;
651
651
} ) ;
652
652
653
+
654
+ test ( "install --save should update a dependency to fbkpm and mirror (PR import scenario 2)" , async ( ) => {
655
+ // mime-types@2.0.0 is saved in local mirror and gets updated to mime-types@2.1.11 via
656
+ // a change in package.json,
657
+ // files in mirror, fbkpm.lock, package.json and node_modules should reflect that
658
+
659
+ let mirrorPath = "mirror-for-offline" ;
660
+ let fixture = "install-import-pr-2" ;
661
+ let cwd = path . join ( fixturesLoc , fixture ) ;
662
+ await fs . copy ( path . join ( cwd , "fbkpm.lock.before" ) , path . join ( cwd , "fbkpm.lock" ) ) ;
663
+ await fs . copy ( path . join ( cwd , "package.json.before" ) , path . join ( cwd , "package.json" ) ) ;
664
+
665
+ return run ( { } , [ ] , fixture , async ( config ) => {
666
+ assert ( semver . satisfies (
667
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "node_modules/mime-db/package.json" ) ) ) . version ,
668
+ "~1.0.1" )
669
+ ) ;
670
+ assert . equal (
671
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "node_modules/mime-types/package.json" ) ) ) . version ,
672
+ "2.0.0"
673
+ ) ;
674
+
675
+ await fs . unlink ( path . join ( config . cwd , "package.json" ) ) ;
676
+ await fs . copy ( path . join ( cwd , "package.json.after" ) , path . join ( cwd , "package.json" ) ) ;
677
+
678
+ return run ( { save : true } , [ ] , fixture , async ( config ) => {
679
+ assert ( semver . satisfies (
680
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "node_modules/mime-db/package.json" ) ) ) . version ,
681
+ "~1.23.0"
682
+ ) ) ;
683
+ assert . equal (
684
+ JSON . parse ( await fs . readFile ( path . join ( config . cwd , "node_modules/mime-types/package.json" ) ) ) . version ,
685
+ "2.1.11"
686
+ ) ;
687
+
688
+ let lockFileWritten = await fs . readFile ( path . join ( config . cwd , "fbkpm.lock" ) ) ;
689
+ let lockFileLines = lockFileWritten . split ( "\n" ) . filter ( ( line ) => ! ! line ) ;
690
+ assert . equal ( lockFileLines [ 0 ] , "mime-db@~1.23.0:" ) ;
691
+ assert . notEqual ( lockFileLines [ 3 ] . indexOf ( "resolved mime-db-" ) , - 1 ) ;
692
+ assert . equal ( lockFileLines [ 4 ] , "mime-types@2.1.11:" ) ;
693
+ assert . notEqual ( lockFileLines [ 7 ] . indexOf ( "resolved mime-types-2.1.11.tgz" ) , - 1 ) ;
694
+
695
+ let mirror = await fs . walk ( path . join ( config . cwd , mirrorPath ) ) ;
696
+ assert . equal ( mirror . length , 4 ) ;
697
+ let newFilesInMirror = mirror . filter ( ( elem ) => {
698
+ return elem . relative !== "mime-db-1.0.3.tgz" && elem . relative !== "mime-types-2.0.0.tgz" ;
699
+ } ) ;
700
+
701
+ assert . equal ( newFilesInMirror . length , 2 ) ;
702
+
703
+ await fs . unlink ( newFilesInMirror [ 0 ] . absolute ) ;
704
+ await fs . unlink ( newFilesInMirror [ 1 ] . absolute ) ;
705
+
706
+ await fs . unlink ( path . join ( config . cwd , "fbkpm.lock" ) ) ;
707
+ await fs . unlink ( path . join ( config . cwd , "package.json" ) ) ;
708
+ } ) ;
709
+ } ) ;
710
+ } ) ;
711
+
653
712
test ( "install --initMirror should add init mirror deps from package.json" , async ( ) => {
654
713
let mirrorPath = "mirror-for-offline" ;
655
714
let fixture = "install-init-mirror" ;
0 commit comments