From 1bf28e0d77a8b2261befbdb708cefd03e0126960 Mon Sep 17 00:00:00 2001 From: dave caruso Date: Wed, 11 Oct 2023 02:27:07 -0700 Subject: feat(install): automatically migrate package-lock.json to bun.lockb (#6352) * work so far * stuff * a * basics work * stuff * yoo * build lockfile * correct * f * a * install fixture havent tested * i made it worse * lol * be more reasonable * make the test easier to pass because bun install doesn't handle obscure lockfile edge cases :/ * a * works now * ok * a * a * cool * nah * fix stuff * l * a * idfk * LAME * prettier errors * does this fix tests? * Add more safety checks to Integrity * Add another check * More careful lifetime handling * Fix linux debugger issue * a * tmp dir and snapshot test --------- Co-authored-by: Jarred SUmner --- test/cli/install/bun-pm.test.ts | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'test/cli/install/bun-pm.test.ts') diff --git a/test/cli/install/bun-pm.test.ts b/test/cli/install/bun-pm.test.ts index 9729ada7b..06ffb4c45 100644 --- a/test/cli/install/bun-pm.test.ts +++ b/test/cli/install/bun-pm.test.ts @@ -1,6 +1,6 @@ -import { spawn } from "bun"; +import { hash, spawn } from "bun"; import { afterAll, afterEach, beforeAll, beforeEach, expect, it } from "bun:test"; -import { bunExe, bunEnv as env } from "harness"; +import { bunEnv, bunExe, bunEnv as env } from "harness"; import { mkdir, writeFile, exists } from "fs/promises"; import { join } from "path"; import { @@ -15,6 +15,7 @@ import { root_url, setHandler, } from "./dummy.registry"; +import { cpSync, rmSync } from "js/node/fs/export-star-from"; beforeAll(dummyBeforeAll); afterAll(dummyAfterAll); @@ -332,3 +333,39 @@ it("should remove all cache", async () => { expect(await exited2).toBe(0); expect(await exists(cache_dir)).toBeFalse(); }); + +import { tmpdir } from "os"; +it("bun pm migrate", async () => { + const test_dir = join(tmpdir(), "contoso-test" + Math.random().toString(36).slice(2)); + + cpSync(join(import.meta.dir, "migration/contoso-test"), test_dir, { recursive: true }); + + const { stdout, stderr, exitCode } = Bun.spawnSync({ + cmd: [bunExe(), "pm", "migrate", "--force"], + cwd: test_dir, + stdout: "pipe", + stdin: "pipe", + stderr: "pipe", + env: bunEnv, + }); + expect(exitCode).toBe(0); + + expect(stderr).toBeDefined(); + expect(stdout).toBeDefined(); + + expect(stdout.toString("utf-8")).toBe(""); + expect(stderr.toString("utf-8")).toEndWith("migrated lockfile from package-lock.json\n"); + + const hashExec = Bun.spawnSync({ + cmd: [bunExe(), "pm", "hash"], + cwd: test_dir, + stdout: "pipe", + stdin: "pipe", + stderr: "pipe", + env: bunEnv, + }); + expect(hashExec.exitCode).toBe(0); + const hash = hashExec.stdout.toString("utf-8").trim(); + + expect(hash).toMatchSnapshot(); +}); -- cgit v1.2.3