mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 10:58:56 +00:00
* fix regression tests * fix fs.test.ts bigintstats * enable transpiler cache lol * remove failing * fix filesystem router * update * fix run-unicode test * update comment * add updated snapshot * fix remaining node-module-module tests * fixup * [autofix.ci] apply automated fixes * fix tty tests --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
93 lines
2.9 KiB
TypeScript
93 lines
2.9 KiB
TypeScript
import fs from "fs";
|
|
import { test, expect, beforeAll, afterAll } from "bun:test";
|
|
import { bunEnv, bunExe } from "harness";
|
|
import { join, sep } from "path";
|
|
import { mkdtempSync } from "js/node/fs/export-star-from";
|
|
import { tmpdir } from "os";
|
|
|
|
const ROOT_TEMP_DIR = join(tmpdir(), "migrate", sep);
|
|
|
|
beforeAll(() => {
|
|
// if the test was stopped early
|
|
fs.rmSync(ROOT_TEMP_DIR, { recursive: true, force: true });
|
|
fs.mkdirSync(ROOT_TEMP_DIR);
|
|
});
|
|
|
|
afterAll(() => {
|
|
fs.rmSync(ROOT_TEMP_DIR, {
|
|
recursive: true,
|
|
force: true,
|
|
});
|
|
});
|
|
|
|
function testMigration(lockfile: string) {
|
|
const testDir = mkdtempSync(ROOT_TEMP_DIR);
|
|
|
|
fs.writeFileSync(
|
|
join(testDir, "package.json"),
|
|
JSON.stringify({
|
|
name: "test3",
|
|
dependencies: {
|
|
"svelte": "*",
|
|
},
|
|
}),
|
|
);
|
|
fs.cpSync(join(import.meta.dir, lockfile), 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");
|
|
}
|
|
|
|
test("migrate from npm during `bun add`", () => {
|
|
testMigration("add-while-migrate-fixture.json");
|
|
});
|
|
|
|
test("migrate from npm lockfile v2 during `bun add`", () => {
|
|
testMigration("migrate-from-lockfilev2-fixture.json");
|
|
});
|
|
|
|
// Currently this upgrades svelte :(
|
|
test.todo("migrate workspace from npm during `bun add`", async () => {
|
|
const testDir = mkdtempSync(ROOT_TEMP_DIR);
|
|
|
|
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 = mkdtempSync(ROOT_TEMP_DIR);
|
|
|
|
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);
|
|
});
|