Skip to content

Commit 3f1a03a

Browse files
committed
added change branch scenario where a change in packages causes dedupe to kick in
1 parent 6007c91 commit 3f1a03a

File tree

11 files changed

+81
-1
lines changed

11 files changed

+81
-1
lines changed

test/commands/install.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,50 @@ test("downgrade scenario", () => {
385385
});
386386
});
387387

388+
test.only("install have a clean node_modules after lockfile update (branch switch scenario)", async () => {
389+
// A@1 -> B@1
390+
// B@2
391+
392+
// after package.json/lock file update
393+
394+
// A@1.2 -> B@1.2
395+
396+
// (deduped)
397+
398+
// A@1.2
399+
// B@1.2
400+
401+
let cwd = path.join(fixturesLoc, "install-should-cleanup-when-package-json-changed");
402+
403+
await fs.copy(path.join(cwd, "fbkpm.lock.before"), path.join(cwd, "fbkpm.lock"));
404+
await fs.copy(path.join(cwd, "package.json.before"), path.join(cwd, "package.json"));
405+
406+
return run({}, [], "install-should-cleanup-when-package-json-changed", async (config) => {
407+
assert.equal(JSON.parse(await fs.readFile(path.join(config.cwd,
408+
"node_modules/dep-a/package.json"))).version, "1.0.0");
409+
assert.equal(JSON.parse(await fs.readFile(path.join(config.cwd,
410+
"node_modules/dep-b/package.json"))).version, "2.0.0");
411+
assert.equal(JSON.parse(await fs.readFile(path.join(config.cwd,
412+
"node_modules/dep-a/node_modules/dep-b/package.json"))).version, "1.0.0");
413+
414+
await fs.unlink(path.join(config.cwd, "fbkpm.lock"));
415+
await fs.unlink(path.join(config.cwd, "package.json"));
416+
417+
await fs.copy(path.join(cwd, "fbkpm.lock.after"), path.join(cwd, "fbkpm.lock"));
418+
await fs.copy(path.join(cwd, "package.json.after"), path.join(cwd, "package.json"));
419+
420+
return run({}, [], "install-should-cleanup-when-package-json-changed", async (config) => {
421+
assert.equal(JSON.parse(await fs.readFile(path.join(config.cwd,
422+
"node_modules/dep-a/package.json"))).version, "1.2.0");
423+
assert.equal(JSON.parse(await fs.readFile(path.join(config.cwd,
424+
"node_modules/dep-b/package.json"))).version, "1.2.0");
425+
426+
await fs.unlink(path.join(config.cwd, "fbkpm.lock"));
427+
await fs.unlink(path.join(config.cwd, "package.json"));
428+
});
429+
});
430+
});
431+
388432
test("uninstall should remove dependency from package.json, fbkpm.lock and node_modules", () => {
389433
let mirrorPath = "mirror-for-offline";
390434

@@ -420,7 +464,7 @@ test("uninstall should remove dependency from package.json, fbkpm.lock and node_
420464
});
421465
});
422466

423-
test.only("uninstall should remove subdependencies", () => {
467+
test("uninstall should remove subdependencies", () => {
424468
// A@1 -> B@1
425469
// C@1
426470

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+
dep-a@^1.2.0:
2+
name dep-a
3+
version "1.2.0"
4+
resolved dep-a-1.2.0.tgz#1e0d57d4c2055944ab042b617a064dc2ce1308fb
5+
dependencies:
6+
dep-b "1.2.0"
7+
dep-b@^1.2.0:
8+
name dep-b
9+
version "1.2.0"
10+
resolved dep-b-1.2.0.tgz#d82ed4984566c1aea13d3d369b231bf52b672de3
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
dep-a@^1.0.0:
2+
name dep-a
3+
version "1.0.0"
4+
resolved dep-a-1.0.0.tgz#d170a960654001b74bdee4747e71f744ecf0a24f
5+
dependencies:
6+
dep-b "1.0.0"
7+
dep-b@1.0.0:
8+
name dep-b
9+
version "1.0.0"
10+
resolved dep-b-1.0.0.tgz#fa3fab4e36d8eb93ac74790748a30547e9cb0f3f
11+
dep-b@^2.0.0:
12+
name dep-b
13+
version "2.0.0"
14+
resolved dep-b-2.0.0.tgz#7d2e5fefe8bfaf5f162dc9e07883966e84c264cd
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"dep-a": "^1.2.0"
4+
}
5+
}

0 commit comments

Comments
 (0)