Skip to content

Commit 968eab6

Browse files
committed
added test for dedupe when installing top level dependency
1 parent 6d92dd5 commit 968eab6

File tree

11 files changed

+141
-0
lines changed

11 files changed

+141
-0
lines changed

test/commands/install.js

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,3 +736,112 @@ test("install --initMirror should add init mirror deps from package.json", async
736736
});
737737
});
738738

739+
test("install --save with new dependency should be deterministic", async () => {
740+
// mime-types@2.0.0->mime-db@1.0.3 is saved in local mirror and is deduped
741+
// install mime-db@1.23.0 should move mime-db@1.0.3 deep into mime-types
742+
743+
let mirrorPath = "mirror-for-offline";
744+
let fixture = "install-deterministic";
745+
let cwd = path.join(fixturesLoc, fixture);
746+
await fs.copy(path.join(cwd, "fbkpm.lock.before"), path.join(cwd, "fbkpm.lock"));
747+
await fs.copy(path.join(cwd, "package.json.before"), path.join(cwd, "package.json"));
748+
749+
return run({}, [], fixture, async (config) => {
750+
assert(semver.satisfies(
751+
JSON.parse(await fs.readFile(path.join(config.cwd, "node_modules/mime-db/package.json"))).version,
752+
"~1.0.1")
753+
);
754+
assert.equal(
755+
JSON.parse(await fs.readFile(path.join(config.cwd, "node_modules/mime-types/package.json"))).version,
756+
"2.0.0"
757+
);
758+
759+
return run({save: true}, ["mime-db@1.23.0"], fixture, async (config) => {
760+
assert(semver.satisfies(
761+
JSON.parse(await fs.readFile(path.join(config.cwd, "node_modules/mime-db/package.json"))).version,
762+
"~1.23.0"
763+
));
764+
assert.equal(
765+
JSON.parse(await fs.readFile(path.join(config.cwd, "node_modules/mime-types/package.json"))).version,
766+
"2.0.0"
767+
);
768+
assert.equal(
769+
JSON.parse(await fs.readFile(path.join(config.cwd,
770+
"node_modules/mime-types/node_modules/mime-db/package.json"))).version,
771+
"1.0.3"
772+
);
773+
assert.deepEqual(
774+
JSON.parse(await fs.readFile(path.join(config.cwd, "package.json"))).dependencies, {
775+
"mime-types": "2.0.0",
776+
"mime-db": "1.23.0"
777+
}
778+
);
779+
780+
let lockFileWritten = await fs.readFile(path.join(config.cwd, "fbkpm.lock"));
781+
let lockFileLines = lockFileWritten.split("\n").filter((line) => !!line);
782+
assert.equal(lockFileLines.length, 14);
783+
784+
785+
let mirror = await fs.walk(path.join(config.cwd, mirrorPath));
786+
assert.equal(mirror.length, 3);
787+
assert.equal(mirror[1].relative, "mime-db-1.23.0.tgz");
788+
789+
await fs.unlink(mirror[1].absolute);
790+
await fs.unlink(path.join(config.cwd, "fbkpm.lock"));
791+
await fs.unlink(path.join(config.cwd, "package.json"));
792+
});
793+
});
794+
});
795+
796+
test.only("install --save with new dependency should be deterministic 2", async () => {
797+
// mime-types@2.0.0->mime-db@1.0.1 is saved in local mirror and is deduped
798+
// install mime-db@1.0.3 should replace mime-db@1.0.1 in root
799+
800+
let mirrorPath = "mirror-for-offline";
801+
let fixture = "install-deterministic-2";
802+
let cwd = path.join(fixturesLoc, fixture);
803+
await fs.copy(path.join(cwd, "fbkpm.lock.before"), path.join(cwd, "fbkpm.lock"));
804+
await fs.copy(path.join(cwd, "package.json.before"), path.join(cwd, "package.json"));
805+
806+
return run({}, [], fixture, async (config) => {
807+
assert.equal(
808+
JSON.parse(await fs.readFile(path.join(config.cwd, "node_modules/mime-db/package.json"))).version,
809+
"1.0.1"
810+
);
811+
assert.equal(
812+
JSON.parse(await fs.readFile(path.join(config.cwd, "node_modules/mime-types/package.json"))).version,
813+
"2.0.0"
814+
);
815+
816+
return run({save: true}, ["mime-db@1.0.3"], fixture, async (config) => {
817+
assert.equal(
818+
JSON.parse(await fs.readFile(path.join(config.cwd, "node_modules/mime-db/package.json"))).version,
819+
"1.0.3"
820+
);
821+
assert.equal(
822+
JSON.parse(await fs.readFile(path.join(config.cwd, "node_modules/mime-types/package.json"))).version,
823+
"2.0.0"
824+
);
825+
assert(!await fs.exists(path.join(config.cwd, "node_modules/mime-types/node-modules/mime-db")));
826+
assert.deepEqual(
827+
JSON.parse(await fs.readFile(path.join(config.cwd, "package.json"))).dependencies, {
828+
"mime-types": "2.0.0",
829+
"mime-db": "1.0.3"
830+
}
831+
);
832+
833+
let lockFileWritten = await fs.readFile(path.join(config.cwd, "fbkpm.lock"));
834+
let lockFileLines = lockFileWritten.split("\n").filter((line) => !!line);
835+
assert.equal(lockFileLines.length, 10);
836+
837+
838+
let mirror = await fs.walk(path.join(config.cwd, mirrorPath));
839+
assert.equal(mirror.length, 3);
840+
assert.equal(mirror[1].relative, "mime-db-1.0.3.tgz");
841+
842+
await fs.unlink(mirror[1].absolute);
843+
await fs.unlink(path.join(config.cwd, "fbkpm.lock"));
844+
await fs.unlink(path.join(config.cwd, "package.json"));
845+
});
846+
});
847+
});
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.1"
4+
resolved mime-db-1.0.1.tgz#35d99b0965967253bb30633a7d07a8de9975a952
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"
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+
}
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.

0 commit comments

Comments
 (0)