Skip to content

Commit 2c0f98f

Browse files
committed
Added another branch switch scenario test
1 parent 3f1a03a commit 2c0f98f

File tree

9 files changed

+68
-4
lines changed

9 files changed

+68
-4
lines changed

test/commands/install.js

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ test("downgrade scenario", () => {
385385
});
386386
});
387387

388-
test.only("install have a clean node_modules after lockfile update (branch switch scenario)", async () => {
388+
test("install have a clean node_modules after lockfile update (branch switch scenario)", async () => {
389389
// A@1 -> B@1
390390
// B@2
391391

@@ -398,12 +398,13 @@ test.only("install have a clean node_modules after lockfile update (branch switc
398398
// A@1.2
399399
// B@1.2
400400

401-
let cwd = path.join(fixturesLoc, "install-should-cleanup-when-package-json-changed");
401+
let fixture = "install-should-cleanup-when-package-json-changed";
402+
let cwd = path.join(fixturesLoc, fixture);
402403

403404
await fs.copy(path.join(cwd, "fbkpm.lock.before"), path.join(cwd, "fbkpm.lock"));
404405
await fs.copy(path.join(cwd, "package.json.before"), path.join(cwd, "package.json"));
405406

406-
return run({}, [], "install-should-cleanup-when-package-json-changed", async (config) => {
407+
return run({}, [], fixture, async (config) => {
407408
assert.equal(JSON.parse(await fs.readFile(path.join(config.cwd,
408409
"node_modules/dep-a/package.json"))).version, "1.0.0");
409410
assert.equal(JSON.parse(await fs.readFile(path.join(config.cwd,
@@ -417,7 +418,7 @@ test.only("install have a clean node_modules after lockfile update (branch switc
417418
await fs.copy(path.join(cwd, "fbkpm.lock.after"), path.join(cwd, "fbkpm.lock"));
418419
await fs.copy(path.join(cwd, "package.json.after"), path.join(cwd, "package.json"));
419420

420-
return run({}, [], "install-should-cleanup-when-package-json-changed", async (config) => {
421+
return run({}, [], fixture, async (config) => {
421422
assert.equal(JSON.parse(await fs.readFile(path.join(config.cwd,
422423
"node_modules/dep-a/package.json"))).version, "1.2.0");
423424
assert.equal(JSON.parse(await fs.readFile(path.join(config.cwd,
@@ -429,6 +430,44 @@ test.only("install have a clean node_modules after lockfile update (branch switc
429430
});
430431
});
431432

433+
434+
test("install have a clean node_modules after lockfile update (branch switch scenario 2)", async () => {
435+
// A@1 -> B@1
436+
437+
// after package.json/lock file update
438+
439+
// A@1.2
440+
441+
let fixture = "install-should-cleanup-when-package-json-changed-2";
442+
let cwd = path.join(fixturesLoc, fixture);
443+
444+
await fs.copy(path.join(cwd, "fbkpm.lock.before"), path.join(cwd, "fbkpm.lock"));
445+
await fs.copy(path.join(cwd, "package.json.before"), path.join(cwd, "package.json"));
446+
447+
return run({}, [], fixture, async (config) => {
448+
assert.equal(JSON.parse(await fs.readFile(path.join(config.cwd,
449+
"node_modules/dep-a/package.json"))).version, "1.0.0");
450+
assert.equal(JSON.parse(await fs.readFile(path.join(config.cwd,
451+
"node_modules/dep-b/package.json"))).version, "1.0.0");
452+
453+
await fs.unlink(path.join(config.cwd, "fbkpm.lock"));
454+
await fs.unlink(path.join(config.cwd, "package.json"));
455+
456+
await fs.copy(path.join(cwd, "fbkpm.lock.after"), path.join(cwd, "fbkpm.lock"));
457+
await fs.copy(path.join(cwd, "package.json.after"), path.join(cwd, "package.json"));
458+
459+
return run({}, [], fixture, async (config) => {
460+
assert.equal(JSON.parse(await fs.readFile(path.join(config.cwd,
461+
"node_modules/dep-a/package.json"))).version, "1.2.0");
462+
463+
assert(!await fs.exists(path.join(config.cwd, "node_modules/dep-b")));
464+
465+
await fs.unlink(path.join(config.cwd, "fbkpm.lock"));
466+
await fs.unlink(path.join(config.cwd, "package.json"));
467+
});
468+
});
469+
});
470+
432471
test("uninstall should remove dependency from package.json, fbkpm.lock and node_modules", () => {
433472
let mirrorPath = "mirror-for-offline";
434473

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dep-a@^1.2.0:
2+
name dep-a
3+
version "1.2.0"
4+
resolved dep-a-1.2.0.tgz#24fbe8e7aafea09dbfc4837058848a05eec95bf2
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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
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+
}
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.0.0"
4+
}
5+
}

0 commit comments

Comments
 (0)