Skip to content

Commit 6357a1f

Browse files
committed
added test case for PR import scenario
1 parent 3c5348a commit 6357a1f

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

test/commands/install.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ test("upgrade scenario", () => {
337337
}, clean);
338338
});
339339

340-
test.only("upgrade scenario 2 (with sub dependencies)", async () => {
340+
test("upgrade scenario 2 (with sub dependencies)", async () => {
341341
// mime-types@2.0.0 is saved in local mirror and gets updated to mime-types@2.1.11
342342
// files in mirror, fbkpm.lock, package.json and node_modules should reflect that
343343

@@ -591,7 +591,6 @@ test("uninstall should remove subdependencies", () => {
591591
await uninstall(config, reporter, {}, ["dep-a"]);
592592

593593
assert(!await fs.exists(path.join(config.cwd, "node_modules/dep-a")));
594-
// TODO dep-b did not get removed
595594
assert(!await fs.exists(path.join(config.cwd, "node_modules/dep-b")));
596595
assert(await fs.exists(path.join(config.cwd, "node_modules/dep-c")));
597596

@@ -618,4 +617,36 @@ test("uninstall should remove subdependencies", () => {
618617
});
619618
});
620619

620+
test("install --save should add missing deps to fbkpm and mirror (PR import scenario)", async () => {
621+
let mirrorPath = "mirror-for-offline";
622+
let fixture = "install-init-mirror";
623+
let cwd = path.join(fixturesLoc, fixture);
624+
await fs.copy(path.join(cwd, "fbkpm.lock.before"), path.join(cwd, "fbkpm.lock"));
625+
626+
return run({save: true}, [], fixture, async (config, reporter) => {
627+
assert.equal(JSON.parse(await fs.readFile(path.join(config.cwd,
628+
"node_modules/mime-types/package.json"))).version, "2.0.0");
629+
assert(semver.satisfies(JSON.parse(await fs.readFile(path.join(config.cwd,
630+
"node_modules/mime-db/package.json"))).version, "~1.0.1"));
631+
assert.equal(JSON.parse(await fs.readFile(path.join(config.cwd,
632+
"node_modules/fake-fbkpm-dependency/package.json"))).version, "1.0.1");
633+
634+
let mirror = await fs.walk(path.join(config.cwd, mirrorPath));
635+
assert.equal(mirror.length, 3);
636+
assert.equal(mirror[0].relative, "fake-fbkpm-dependency-1.0.1.tgz");
637+
assert.equal(mirror[1].relative.indexOf("mime-db-1.0."), 0);
638+
assert.equal(mirror[2].relative, "mime-types-2.0.0.tgz");
639+
640+
let lockFileContent = await fs.readFile(path.join(config.cwd, "fbkpm.lock"));
641+
let lockFileLines = lockFileContent.split("\n").filter((line) => !!line);
642+
assert.equal(lockFileLines.length, 14);
643+
assert.equal(lockFileLines[4].indexOf("mime-db@"), 0);
644+
assert.equal(lockFileLines[8].indexOf("mime-types@2.0.0"), 0);
645+
646+
await fs.unlink(path.join(mirror[1].absolute));
647+
await fs.unlink(path.join(mirror[2].absolute));
648+
await fs.unlink(path.join(config.cwd, "fbkpm.lock"));
649+
650+
});
651+
});
621652

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+
fake-fbkpm-dependency@1.0.1:
2+
name fake-fbkpm-dependency
3+
version "1.0.1"
4+
resolved fake-fbkpm-dependency-1.0.1.tgz#ef965c2c237a58e3d4c3f09569d303a1dc9c0d72
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"dependencies": {
3+
"fake-fbkpm-dependency": "1.0.1",
4+
"mime-types": "2.0.0"
5+
}
6+
}

0 commit comments

Comments
 (0)