aboutsummaryrefslogtreecommitdiff
path: root/test/cli/install/migration/migrate.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'test/cli/install/migration/migrate.test.ts')
-rw-r--r--test/cli/install/migration/migrate.test.ts54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/cli/install/migration/migrate.test.ts b/test/cli/install/migration/migrate.test.ts
new file mode 100644
index 000000000..28ccac2a0
--- /dev/null
+++ b/test/cli/install/migration/migrate.test.ts
@@ -0,0 +1,54 @@
+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");
+});