-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
732c5e7
commit feba0d6
Showing
2 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
test/cli/install/bun-install-pathname-trailing-slash.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { sleep } from "bun"; | ||
import { expect, test } from "bun:test"; | ||
import { mkdirSync, mkdtempSync, rmSync } from "fs"; | ||
import { bunEnv, bunExe } from "harness"; | ||
import { tmpdir } from "os"; | ||
import { join } from "path"; | ||
|
||
// https://github.com/oven-sh/bun/issues/2462 | ||
test("custom registry doesn't have multiple trailing slashes in pathname", async () => { | ||
var urls: string[] = []; | ||
|
||
var server = Bun.serve({ | ||
port: 0, | ||
async fetch(req) { | ||
urls.push(req.url); | ||
return new Response("ok"); | ||
}, | ||
}); | ||
const { port, hostname } = server; | ||
const package_dir = join(tmpdir(), mkdtempSync("bun-install-path")); | ||
try { | ||
mkdirSync(package_dir, { recursive: true }); | ||
} catch {} | ||
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", | ||
}, | ||
}), | ||
); | ||
|
||
Bun.spawnSync({ | ||
cmd: [bunExe(), "install", "--force"], | ||
env: bunEnv, | ||
cwd: package_dir, | ||
stdout: "ignore", | ||
stderr: "ignore", | ||
stdin: "ignore", | ||
}); | ||
|
||
await sleep(10); | ||
|
||
server.stop(true); | ||
expect(urls.length).toBeGreaterThan(0); | ||
expect(urls[0]).toBe(`http://${hostname}:${port}/prefixed-route/react`); | ||
rmSync(package_dir, { recursive: true, force: true }); | ||
}); |