Files
bun.sh/test/cli/install/bun-install-retry.test.ts
Dylan Conway aad4d800ff add "configVersion" to bun.lock(b) (#24236)
### What does this PR do?

Adds `"configVersion"` to bun.lock(b). The version will be used to keep
default settings the same if they would be breaking across bun versions.

fixes ENG-21389
fixes ENG-21388
### How did you verify your code works?
TODO:
- [ ] new project
- [ ] existing project without configVersion
- [ ] existing project with configVersion
- [ ] same as above but with bun.lockb
- [ ] configVersion@0 defaults to hoisted linker
- [ ] new projects use isolated linker

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2025-11-03 22:20:07 -08:00

112 lines
2.9 KiB
TypeScript

import { file, spawn } from "bun";
import { afterAll, afterEach, beforeAll, beforeEach, expect, it, setDefaultTimeout } from "bun:test";
import { access, writeFile } from "fs/promises";
import { bunExe, bunEnv as env, readdirSorted, tmpdirSync, toBeValidBin, toBeWorkspaceLink, toHaveBins } from "harness";
import { join } from "path";
import {
dummyAfterAll,
dummyAfterEach,
dummyBeforeAll,
dummyBeforeEach,
dummyRegistry,
package_dir,
requested,
root_url,
setHandler,
} from "./dummy.registry";
beforeAll(dummyBeforeAll);
afterAll(dummyAfterAll);
expect.extend({
toHaveBins,
toBeValidBin,
toBeWorkspaceLink,
});
let port: string;
let add_dir: string;
beforeAll(() => {
setDefaultTimeout(1000 * 60 * 5);
port = new URL(root_url).port;
});
beforeEach(async () => {
add_dir = tmpdirSync();
await dummyBeforeEach();
});
afterEach(async () => {
await dummyAfterEach();
});
it("retries on 500", async () => {
const urls: string[] = [];
setHandler(dummyRegistry(urls, undefined, 4));
await writeFile(
join(package_dir, "package.json"),
JSON.stringify({
name: "foo",
version: "0.0.1",
}),
);
const { stdout, stderr, exited } = spawn({
cmd: [bunExe(), "add", "BaR", "--linker=hoisted"],
cwd: package_dir,
stdout: "pipe",
stdin: "pipe",
stderr: "pipe",
env,
});
const err = await stderr.text();
expect(err).not.toContain("error:");
expect(err).toContain("Saved lockfile");
const out = await stdout.text();
expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([
expect.stringContaining("bun add v1."),
"",
"installed BaR@0.0.2",
"",
"1 package installed",
]);
expect(await exited).toBe(0);
expect(urls.sort()).toEqual([
`${root_url}/BaR`,
`${root_url}/BaR`,
`${root_url}/BaR`,
`${root_url}/BaR`,
`${root_url}/BaR`,
`${root_url}/BaR`,
`${root_url}/BaR-0.0.2.tgz`,
`${root_url}/BaR-0.0.2.tgz`,
`${root_url}/BaR-0.0.2.tgz`,
`${root_url}/BaR-0.0.2.tgz`,
`${root_url}/BaR-0.0.2.tgz`,
`${root_url}/BaR-0.0.2.tgz`,
]);
expect(requested).toBe(12);
await Promise.all([
(async () => expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "BaR"]))(),
(async () => expect(await readdirSorted(join(package_dir, "node_modules", "BaR"))).toEqual(["package.json"]))(),
(async () =>
expect(await file(join(package_dir, "node_modules", "BaR", "package.json")).json()).toEqual({
name: "bar",
version: "0.0.2",
}))(),
(async () =>
expect(await file(join(package_dir, "package.json")).text()).toEqual(
JSON.stringify(
{
name: "foo",
version: "0.0.1",
dependencies: {
BaR: "^0.0.2",
},
},
null,
2,
),
))(),
async () => await access(join(package_dir, "bun.lockb")),
]);
});