Files
bun.sh/test/cli/install/migration/migrate.test.ts
Dylan Conway 46955e95ef migration without resolved properties (#7123)
* packages without `resolved` properties

* test

* free more

* find registry scope
2023-11-14 23:17:59 -08:00

70 lines
2.5 KiB
TypeScript

import fs from "fs";
import { test, expect } from "bun:test";
import { bunEnv, bunExe } from "harness";
import { join } from "path";
import { mkdtempSync } from "js/node/fs/export-star-from";
import { tmpdir } from "os";
test("migrate from npm during `bun add`", async () => {
const testDir = mkdtempSync(join(tmpdir(), "migrate-"));
fs.writeFileSync(
join(testDir, "package.json"),
JSON.stringify({
name: "test3",
dependencies: {
"svelte": "*",
},
}),
);
fs.cpSync(join(import.meta.dir, "add-while-migrate-fixture.json"), join(testDir, "package-lock.json"));
Bun.spawnSync([bunExe(), "add", "lodash@4.17.21"], {
env: bunEnv,
cwd: testDir,
});
expect(fs.existsSync(join(testDir, "node_modules/lodash"))).toBeTrue();
const svelte_version = JSON.parse(fs.readFileSync(join(testDir, "node_modules/svelte/package.json"), "utf8")).version;
expect(svelte_version).toBe("4.0.0");
const lodash_version = JSON.parse(fs.readFileSync(join(testDir, "node_modules/lodash/package.json"), "utf8")).version;
expect(lodash_version).toBe("4.17.21");
});
// Currently this upgrades svelte :(
test.todo("migrate workspace from npm during `bun add`", async () => {
const testDir = join(tmpdir(), "migrate-" + Math.random().toString(36).slice(2));
fs.cpSync(join(import.meta.dir, "add-while-migrate-workspace"), testDir, { recursive: true });
Bun.spawnSync([bunExe(), "add", "lodash@4.17.21"], {
env: bunEnv,
cwd: join(testDir, "packages", "a"),
});
expect(fs.existsSync(join(testDir, "node_modules/lodash"))).toBeTrue();
const lodash_version = JSON.parse(fs.readFileSync(join(testDir, "node_modules/lodash/package.json"), "utf8")).version;
expect(lodash_version).toBe("4.17.21");
const svelte_version = JSON.parse(fs.readFileSync(join(testDir, "node_modules/svelte/package.json"), "utf8")).version;
expect(svelte_version).toBe("3.0.0");
});
test("migrate from npm lockfile that is missing `resolved` properties", async () => {
const testDir = join(tmpdir(), "migrate-" + Math.random().toString(36).slice(2));
fs.cpSync(join(import.meta.dir, "missing-resolved-properties"), testDir, { recursive: true });
const { exitCode } = Bun.spawnSync([bunExe(), "install"], {
env: bunEnv,
cwd: testDir,
});
expect(fs.existsSync(join(testDir, "node_modules/lodash"))).toBeTrue();
expect(await Bun.file(join(testDir, "node_modules/lodash/package.json")).json()).toHaveProperty("version", "4.17.21");
expect(exitCode).toBe(0);
});