Files
bun.sh/test/cli/install/bun-install-pathname-trailing-slash.test.ts
2025-11-07 05:28:33 -08:00

57 lines
1.4 KiB
TypeScript

import { beforeEach, expect, test } from "bun:test";
import { bunEnv, bunExe, tmpdirSync } from "harness";
import { join } from "path";
let package_dir: string;
beforeEach(() => {
package_dir = tmpdirSync();
});
// https://github.com/oven-sh/bun/issues/2462
test("custom registry doesn't have multiple trailing slashes in pathname", async () => {
const urls: string[] = [];
using server = Bun.serve({
port: 0,
async fetch(req) {
urls.push(req.url);
return Response.json({ broken: true, message: "This is a test response" });
},
});
const { port, hostname } = server;
await Bun.write(
join(package_dir, "bunfig.toml"),
`
[install]
cache = false
registry = "http://${hostname}:${port}/prefixed-route/"
`,
);
await Bun.write(
join(package_dir, "package.json"),
JSON.stringify({
name: "test",
version: "0.0.0",
dependencies: {
"react": "my-custom-tag",
},
}),
);
await using proc = Bun.spawn({
cmd: [bunExe(), "install", "--force"],
env: bunEnv,
cwd: package_dir,
stdout: "ignore",
stderr: "ignore",
stdin: "ignore",
});
// The install should fail, but we're just testing the request goes to the right route.
expect(await proc.exited).toBe(1);
expect(urls.length).toBe(1);
expect(urls).toEqual([`http://${hostname}:${port}/prefixed-route/react`]);
});