aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Ai Hoshino <ambiguous404@gmail.com> 2023-09-24 11:09:45 +0800
committerGravatar GitHub <noreply@github.com> 2023-09-23 20:09:45 -0700
commita5908e9f2704f801587115007c2bec5788bd718a (patch)
tree5ef841abad46365ac826135291b011d43694b1dd /test
parent72f9017b21cbb6de83d054a0b985e9fe9a7708f3 (diff)
downloadbun-a5908e9f2704f801587115007c2bec5788bd718a.tar.gz
bun-a5908e9f2704f801587115007c2bec5788bd718a.tar.zst
bun-a5908e9f2704f801587115007c2bec5788bd718a.zip
fix(lockfile): ensure all bytes of union are initialized before serialization. (#5957)
Diffstat (limited to 'test')
-rw-r--r--test/cli/install/bun-update.test.ts65
1 files changed, 64 insertions, 1 deletions
diff --git a/test/cli/install/bun-update.test.ts b/test/cli/install/bun-update.test.ts
index ff8e22c37..8434ca470 100644
--- a/test/cli/install/bun-update.test.ts
+++ b/test/cli/install/bun-update.test.ts
@@ -1,7 +1,7 @@
import { file, listen, Socket, spawn } from "bun";
import { afterAll, afterEach, beforeAll, beforeEach, expect, it } from "bun:test";
import { bunExe, bunEnv as env } from "harness";
-import { access, mkdir, readlink, realpath, rm, writeFile } from "fs/promises";
+import { readFile, access, mkdir, readlink, realpath, rm, writeFile } from "fs/promises";
import { join } from "path";
import {
dummyAfterAll,
@@ -257,3 +257,66 @@ it("should update to latest versions of dependencies", async () => {
});
await access(join(package_dir, "bun.lockb"));
});
+
+it("lockfile should not be modified when there are no version changes, issue#5888", async () => {
+ // Install packages
+ const urls: string[] = [];
+ const registry = {
+ "0.0.3": {
+ bin: {
+ "baz-run": "index.js",
+ },
+ },
+ latest: "0.0.3",
+ };
+ setHandler(dummyRegistry(urls, registry));
+ await writeFile(
+ join(package_dir, "package.json"),
+ JSON.stringify({
+ name: "foo",
+ dependencies: {
+ baz: "0.0.3",
+ },
+ }),
+ );
+ const { stdout, stderr, exited } = spawn({
+ cmd: [bunExe(), "install"],
+ cwd: package_dir,
+ stdout: null,
+ stdin: "pipe",
+ stderr: "pipe",
+ env,
+ });
+ expect(await exited).toBe(0);
+ const err1 = await new Response(stderr).text();
+ expect(err1).not.toContain("error:");
+ expect(err1).toContain("Saved lockfile");
+ expect(stdout).toBeDefined();
+ const out1 = await new Response(stdout).text();
+ expect(out1.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([
+ " + baz@0.0.3",
+ "",
+ " 1 packages installed",
+ ]);
+
+ // Test if the lockb has been modified by `bun update`.
+ const getLockbContent = async () => {
+ const { exited } = spawn({
+ cmd: [bunExe(), "update"],
+ cwd: package_dir, // package.json is not changed
+ stdout: null,
+ stdin: "pipe",
+ stderr: "pipe",
+ env,
+ });
+ expect(await exited).toBe(0);
+ return await readFile(join(package_dir, "bun.lockb"));
+ };
+
+ let prev = await getLockbContent();
+ for (let i = 0; i < 5; i++) {
+ const content = await getLockbContent();
+ expect(prev).toStrictEqual(content);
+ prev = content;
+ }
+});