Skip to content

Commit 6007c91

Browse files
committed
added deep dependency uninstall test case
1 parent c1818cc commit 6007c91

File tree

8 files changed

+81
-0
lines changed

8 files changed

+81
-0
lines changed

src/package-request.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ export default class PackageRequest {
262262
// while we're fetching the package we have some idle time to warm the cache with
263263
// registry responses for known dependencies
264264
for (let name in info.dependencies) {
265+
// TODO not needed for offline installation
265266
this.warmCacheIfRegistry(`${name}@${info.dependencies[name]}`);
266267
}
267268

test/commands/install.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,3 +419,62 @@ test("uninstall should remove dependency from package.json, fbkpm.lock and node_
419419
await fs.unlink(path.join(config.cwd, "package.json.orig"));
420420
});
421421
});
422+
423+
test.only("uninstall should remove subdependencies", () => {
424+
// A@1 -> B@1
425+
// C@1
426+
427+
// remove A
428+
429+
// C@1
430+
431+
let mirrorPath = "mirror-for-offline";
432+
433+
return run({}, [], "uninstall-should-remove-subdependencies", async (config, reporter) => {
434+
assert.equal(
435+
JSON.parse(await fs.readFile(path.join(config.cwd, "node_modules/dep-a/package.json"))).version,
436+
"1.0.0"
437+
);
438+
assert.equal(
439+
JSON.parse(await fs.readFile(path.join(config.cwd, "node_modules/dep-b/package.json"))).version,
440+
"1.0.0"
441+
);
442+
assert.equal(
443+
JSON.parse(await fs.readFile(path.join(config.cwd, "node_modules/dep-c/package.json"))).version,
444+
"1.0.0"
445+
);
446+
447+
await fs.copy(path.join(config.cwd, "fbkpm.lock"), path.join(config.cwd, "fbkpm.lock.orig"));
448+
await fs.copy(path.join(config.cwd, "package.json"), path.join(config.cwd, "package.json.orig"));
449+
450+
await uninstall(config, reporter, {}, ["dep-a"]);
451+
452+
assert(!await fs.exists(path.join(config.cwd, "node_modules/dep-a")));
453+
// TODO dep-b did not get removed
454+
assert(!await fs.exists(path.join(config.cwd, "node_modules/dep-b")));
455+
assert(await fs.exists(path.join(config.cwd, "node_modules/dep-c")));
456+
457+
assert(await fs.exists(path.join(config.cwd, `${mirrorPath}/dep-a-1.0.0.tgz`)));
458+
assert(await fs.exists(path.join(config.cwd, `${mirrorPath}/dep-b-1.0.0.tgz`)));
459+
assert(await fs.exists(path.join(config.cwd, `${mirrorPath}/dep-c-1.0.0.tgz`)));
460+
461+
assert.deepEqual(
462+
JSON.parse(await fs.readFile(path.join(config.cwd, "package.json"))).dependencies,
463+
{"dep-c": "^1.0.0"}
464+
);
465+
466+
let lockFileContent = await fs.readFile(path.join(config.cwd, "fbkpm.lock"));
467+
let lockFileLines = lockFileContent.split("\n").filter((line) => !!line);
468+
assert.equal(lockFileLines.length, 4);
469+
assert.equal(lockFileLines[0], "dep-c@^1.0.0:");
470+
471+
await fs.unlink(path.join(config.cwd, "fbkpm.lock"));
472+
await fs.unlink(path.join(config.cwd, "package.json"));
473+
await fs.copy(path.join(config.cwd, "fbkpm.lock.orig"), path.join(config.cwd, "fbkpm.lock"));
474+
await fs.copy(path.join(config.cwd, "package.json.orig"), path.join(config.cwd, "package.json"));
475+
await fs.unlink(path.join(config.cwd, "fbkpm.lock.orig"));
476+
await fs.unlink(path.join(config.cwd, "package.json.orig"));
477+
});
478+
});
479+
480+
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: 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-c@^1.0.0:
12+
name dep-c
13+
version "1.0.0"
14+
resolved dep-c-1.0.0.tgz#87be3f12250ea4b3a060a80663fe376670710775
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"dependencies": {
3+
"dep-a": "^1.0.0",
4+
"dep-c": "^1.0.0"
5+
}
6+
}

0 commit comments

Comments
 (0)