aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/cli/install/bun-install.test.ts100
1 files changed, 100 insertions, 0 deletions
diff --git a/test/cli/install/bun-install.test.ts b/test/cli/install/bun-install.test.ts
index 09c5fa770..a530cac38 100644
--- a/test/cli/install/bun-install.test.ts
+++ b/test/cli/install/bun-install.test.ts
@@ -775,6 +775,7 @@ it("should handle life-cycle scripts during re-installation", async () => {
});
expect(stderr1).toBeDefined();
const err1 = await new Response(stderr1).text();
+ expect(err1).not.toContain("error:");
expect(err1).toContain("Saved lockfile");
expect(stdout1).toBeDefined();
const out1 = await new Response(stdout1).text();
@@ -856,6 +857,105 @@ it("should handle life-cycle scripts during re-installation", async () => {
await access(join(package_dir, "bun.lockb"));
});
+it("should use updated life-cycle scripts during re-installation", async () => {
+ await writeFile(
+ join(package_dir, "package.json"),
+ JSON.stringify({
+ name: "Foo",
+ scripts: {
+ install: [bunExe(), "foo.js"].join(" "),
+ },
+ workspaces: ["bar"],
+ }),
+ );
+ await writeFile(join(package_dir, "foo.js"), 'console.log("[scripts:run] Foo");');
+ await mkdir(join(package_dir, "bar"));
+ await writeFile(
+ join(package_dir, "bar", "package.json"),
+ JSON.stringify({
+ name: "Bar",
+ scripts: {
+ preinstall: [bunExe(), "bar.js"].join(" "),
+ },
+ }),
+ );
+ await writeFile(join(package_dir, "bar", "bar.js"), 'console.log("[scripts:run] Bar");');
+ const {
+ stdout: stdout1,
+ stderr: stderr1,
+ exited: exited1,
+ } = spawn({
+ cmd: [bunExe(), "install"],
+ cwd: package_dir,
+ stdout: null,
+ stdin: "pipe",
+ stderr: "pipe",
+ env,
+ });
+ expect(stderr1).toBeDefined();
+ const err1 = await new Response(stderr1).text();
+ expect(err1).not.toContain("error:");
+ expect(err1).toContain("Saved lockfile");
+ expect(stdout1).toBeDefined();
+ const out1 = await new Response(stdout1).text();
+ expect(out1.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([
+ "[scripts:run] Bar",
+ " + Bar@workspace:bar",
+ "[scripts:run] Foo",
+ "",
+ " 1 packages installed",
+ ]);
+ expect(await exited1).toBe(0);
+ expect(requested).toBe(0);
+ expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "Bar"]);
+ expect(await readlink(join(package_dir, "node_modules", "Bar"))).toBe(join("..", "bar"));
+ await access(join(package_dir, "bun.lockb"));
+ // Perform `bun install` with outdated lockfile
+ await rm(join(package_dir, "node_modules"), { force: true, recursive: true });
+ await writeFile(
+ join(package_dir, "bar", "package.json"),
+ JSON.stringify({
+ name: "Bar",
+ scripts: {
+ preinstall: [bunExe(), "baz.js"].join(" "),
+ postinstall: [bunExe(), "bar.js"].join(" "),
+ },
+ }),
+ );
+ await writeFile(join(package_dir, "bar", "baz.js"), 'console.log("[scripts:run] Baz");');
+ const {
+ stdout: stdout2,
+ stderr: stderr2,
+ exited: exited2,
+ } = spawn({
+ cmd: [bunExe(), "install"],
+ cwd: package_dir,
+ stdout: null,
+ stdin: "pipe",
+ stderr: "pipe",
+ env,
+ });
+ expect(stderr2).toBeDefined();
+ const err2 = await new Response(stderr2).text();
+ expect(err2).not.toContain("error:");
+ expect(err2).toContain("Saved lockfile");
+ expect(stdout2).toBeDefined();
+ const out2 = await new Response(stdout2).text();
+ expect(out2.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([
+ "[scripts:run] Baz",
+ " + Bar@workspace:bar",
+ "[scripts:run] Foo",
+ "[scripts:run] Bar",
+ "",
+ " 1 packages installed",
+ ]);
+ expect(await exited2).toBe(0);
+ expect(requested).toBe(0);
+ expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "Bar"]);
+ expect(await readlink(join(package_dir, "node_modules", "Bar"))).toBe(join("..", "bar"));
+ await access(join(package_dir, "bun.lockb"));
+});
+
it("should ignore workspaces within workspaces", async () => {
await writeFile(
join(package_dir, "package.json"),