Skip to content

Commit 3c5348a

Browse files
committed
upgrade scenario with deeper dependencies
1 parent 6d50320 commit 3c5348a

File tree

6 files changed

+72
-0
lines changed

6 files changed

+72
-0
lines changed

test/commands/install.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { run as uninstall } from "../../src/cli/commands/uninstall.js";
1515
import Config from "../../src/config.js";
1616
import * as fs from "../../src/util/fs.js";
1717
import assert from "assert";
18+
import semver from "semver";
19+
1820

1921
let test = require("ava");
2022
let path = require("path");
@@ -335,6 +337,60 @@ test("upgrade scenario", () => {
335337
}, clean);
336338
});
337339

340+
test.only("upgrade scenario 2 (with sub dependencies)", async () => {
341+
// mime-types@2.0.0 is saved in local mirror and gets updated to mime-types@2.1.11
342+
// files in mirror, fbkpm.lock, package.json and node_modules should reflect that
343+
344+
let mirrorPath = "mirror-for-offline";
345+
let fixture = "install-upgrade-scenario-2";
346+
let cwd = path.join(fixturesLoc, fixture);
347+
await fs.copy(path.join(cwd, "fbkpm.lock.before"), path.join(cwd, "fbkpm.lock"));
348+
await fs.copy(path.join(cwd, "package.json.before"), path.join(cwd, "package.json"));
349+
350+
return run({}, [], fixture, async (config) => {
351+
assert(semver.satisfies(
352+
JSON.parse(await fs.readFile(path.join(config.cwd, "node_modules/mime-db/package.json"))).version,
353+
"~1.0.1")
354+
);
355+
assert.equal(
356+
JSON.parse(await fs.readFile(path.join(config.cwd, "node_modules/mime-types/package.json"))).version,
357+
"2.0.0"
358+
);
359+
360+
return run({save: true}, ["mime-types@2.1.11"], fixture, async (config) => {
361+
assert(semver.satisfies(
362+
JSON.parse(await fs.readFile(path.join(config.cwd, "node_modules/mime-db/package.json"))).version,
363+
"~1.23.0"
364+
));
365+
assert.equal(
366+
JSON.parse(await fs.readFile(path.join(config.cwd, "node_modules/mime-types/package.json"))).version,
367+
"2.1.11"
368+
);
369+
370+
let lockFileWritten = await fs.readFile(path.join(config.cwd, "fbkpm.lock"));
371+
let lockFileLines = lockFileWritten.split("\n").filter((line) => !!line);
372+
assert.equal(lockFileLines[0], "mime-db@~1.23.0:");
373+
assert.notEqual(lockFileLines[3].indexOf("resolved mime-db-"), -1);
374+
assert.equal(lockFileLines[4], "mime-types@2.1.11:");
375+
assert.notEqual(lockFileLines[7].indexOf("resolved mime-types-2.1.11.tgz"), -1);
376+
377+
let mirror = await fs.walk(path.join(config.cwd, mirrorPath));
378+
assert.equal(mirror.length, 4);
379+
let newFilesInMirror = mirror.filter((elem) => {
380+
return elem.relative !== "mime-db-1.0.3.tgz" && elem.relative !== "mime-types-2.0.0.tgz";
381+
});
382+
383+
assert.equal(newFilesInMirror.length, 2);
384+
385+
await fs.unlink(newFilesInMirror[0].absolute);
386+
await fs.unlink(newFilesInMirror[1].absolute);
387+
388+
await fs.unlink(path.join(config.cwd, "fbkpm.lock"));
389+
await fs.unlink(path.join(config.cwd, "package.json"));
390+
});
391+
});
392+
});
393+
338394
test("downgrade scenario", () => {
339395
// left-pad first installed 1.1.0 then downgraded to 0.0.9
340396
// files in mirror, fbkpm.lock, package.json and node_modules should reflect that
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"
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+
}

0 commit comments

Comments
 (0)