diff options
-rw-r--r-- | test/cli/install/bad-workspace.test.ts | 20 | ||||
-rw-r--r-- | test/cli/install/bun-install-pathname-trailing-slash.test.ts | 30 | ||||
-rw-r--r-- | test/cli/install/dummy.registry.ts | 6 |
3 files changed, 33 insertions, 23 deletions
diff --git a/test/cli/install/bad-workspace.test.ts b/test/cli/install/bad-workspace.test.ts index bd8f0b24d..0c72c2fd2 100644 --- a/test/cli/install/bad-workspace.test.ts +++ b/test/cli/install/bad-workspace.test.ts @@ -1,12 +1,21 @@ import { spawnSync } from "bun"; -import { test, describe, expect } from "bun:test"; +import { afterEach, beforeEach, expect, test } from "bun:test"; +import { mkdtempSync, realpathSync, rmSync, writeFileSync } from "fs"; import { bunExe, bunEnv } from "harness"; -import { mkdirSync, rmSync, writeFileSync } from "fs"; +import { join } from "path"; +import { tmpdir } from "os"; -test("bad workspace path", () => { - const cwd = "/tmp/bun-bad-workspace"; +let cwd: string; + +beforeEach(() => { + cwd = mkdtempSync(join(realpathSync(tmpdir()), "bad-workspace.test")); +}); + +afterEach(() => { rmSync(cwd, { recursive: true, force: true }); - mkdirSync(cwd); +}); + +test("bad workspace path", () => { writeFileSync( `${cwd}/package.json`, JSON.stringify( @@ -32,5 +41,4 @@ test("bad workspace path", () => { expect(text).toContain("glob star * in the middle of a path"); expect(exitCode).toBe(1); - rmSync(cwd, { recursive: true, force: true }); }); diff --git a/test/cli/install/bun-install-pathname-trailing-slash.test.ts b/test/cli/install/bun-install-pathname-trailing-slash.test.ts index 8cc34fe59..dc01a4690 100644 --- a/test/cli/install/bun-install-pathname-trailing-slash.test.ts +++ b/test/cli/install/bun-install-pathname-trailing-slash.test.ts @@ -1,15 +1,24 @@ -import { sleep } from "bun"; -import { expect, test } from "bun:test"; -import { mkdirSync, mkdtempSync, rmSync } from "fs"; +import { afterEach, beforeEach, expect, test } from "bun:test"; +import { mkdtempSync, realpathSync, rmSync } from "fs"; import { bunEnv, bunExe } from "harness"; import { tmpdir } from "os"; import { join } from "path"; +let package_dir: string; + +beforeEach(() => { + package_dir = mkdtempSync(join(realpathSync(tmpdir()), "bun-install-path")); +}); + +afterEach(() => { + rmSync(package_dir, { recursive: true, force: true }); +}); + // https://github.com/oven-sh/bun/issues/2462 test("custom registry doesn't have multiple trailing slashes in pathname", async () => { - var urls: string[] = []; + const urls: string[] = []; - var server = Bun.serve({ + const server = Bun.serve({ port: 0, async fetch(req) { urls.push(req.url); @@ -17,10 +26,6 @@ test("custom registry doesn't have multiple trailing slashes in pathname", async }, }); 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"), ` @@ -49,10 +54,7 @@ registry = "http://${hostname}:${port}/prefixed-route/" 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 }); + expect(urls.length).toBe(1); + expect(urls).toEqual([`http://${hostname}:${port}/prefixed-route/react`]); }); diff --git a/test/cli/install/dummy.registry.ts b/test/cli/install/dummy.registry.ts index d9496b0e7..a54fdb812 100644 --- a/test/cli/install/dummy.registry.ts +++ b/test/cli/install/dummy.registry.ts @@ -5,7 +5,7 @@ */ import { file, Server } from "bun"; -var expect: typeof import("bun:test")["expect"]; +let expect: typeof import("bun:test")["expect"]; import { mkdtemp, readdir, realpath, rm, writeFile } from "fs/promises"; import { tmpdir } from "os"; @@ -94,8 +94,8 @@ export function dummyAfterAll() { server.stop(); } -var packageDirGetter: () => Promise<string> = async () => { - return await realpath(await mkdtemp(join(await realpath(tmpdir()), "bun-install-test-" + testCounter++ + "--"))); +let packageDirGetter: () => Promise<string> = async () => { + return await mkdtemp(join(await realpath(tmpdir()), "bun-install-test-" + testCounter++ + "--")); }; export async function dummyBeforeEach() { resetHandler(); |