Skip to content

Commit 6d92dd5

Browse files
committed
pr with package.json change scenario
1 parent 76aeba5 commit 6d92dd5

File tree

7 files changed

+80
-0
lines changed

7 files changed

+80
-0
lines changed

test/commands/install.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,65 @@ test("install --save should add missing deps to fbkpm and mirror (PR import scen
650650
});
651651
});
652652

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+
653712
test("install --initMirror should add init mirror deps from package.json", async () => {
654713
let mirrorPath = "mirror-for-offline";
655714
let fixture = "install-init-mirror";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kpm-offline-mirror=./mirror-for-offline
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
mime-db@~1.0.1:
2+
name mime-db
3+
version "1.0.3"
4+
resolved mime-db-1.0.3.tgz#5680b12300b3cecea5620f20f269ee80f2632d81
5+
mime-types@2.0.0:
6+
name mime-types
7+
version "2.0.0"
8+
resolved mime-types-2.0.0.tgz#4a85688446a4d94a03909e0ae292766744a3c313
9+
dependencies:
10+
mime-db "~1.0.1"
Binary file not shown.
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"mime-types": "2.1.11"
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"mime-types": "2.0.0"
4+
}
5+
}

0 commit comments

Comments
 (0)