diff --git a/test/cli/install/registry/bun-install-registry.test.ts b/test/cli/install/registry/bun-install-registry.test.ts index 7bbe29152c..48952f9362 100644 --- a/test/cli/install/registry/bun-install-registry.test.ts +++ b/test/cli/install/registry/bun-install-registry.test.ts @@ -123,7 +123,9 @@ describe("optionalDependencies", () => { savesLockfile: !rootOptional, }); - expect(err).toContain("warn: GET http://localhost:4873/this-package-does-not-exist-in-the-registry - "); + expect(err).toMatch( + `warn: GET http://localhost:${port}/this-package-does-not-exist-in-the-registry/-/this-package-does-not-exist-in-the-registry-1.0.0.tgz - `, + ); }); } }); @@ -455,7 +457,7 @@ registry = "http://localhost:${port}" const lockfile = await parseLockfile(packageDir); for (const pkg of Object.values(lockfile.packages) as any) { if (pkg.tag === "npm") { - expect(pkg.resolution.resolved).toContain("http://localhost:4873"); + expect(pkg.resolution.resolved).toContain(`http://localhost:${port}`); } } @@ -476,7 +478,7 @@ cache = "${cacheDir}" const npmLockfile = await parseLockfile(packageDir); for (const pkg of Object.values(npmLockfile.packages) as any) { if (pkg.tag === "npm") { - expect(pkg.resolution.resolved).not.toContain("http://localhost:4873"); + expect(pkg.resolution.resolved).not.toContain(`http://localhost:${port}`); } } }); diff --git a/test/harness.ts b/test/harness.ts index ab539d183b..f470711bd2 100644 --- a/test/harness.ts +++ b/test/harness.ts @@ -57,30 +57,8 @@ export function nodeExe(): string | null { return which("node") || null; } -export function bashExe(): string { - const bash = which("bash"); - if (!bash) { - throw new Error("Failed to find 'bash'"); - } - return bash; -} - -export function pwshExe(): string { - if (!isWindows) { - throw new Error("Powershell is only supported on Windows"); - } - const pwsh = which("pwsh") || which("powershell"); - if (!pwsh) { - throw new Error("Failed to find 'pwsh' or 'powershell'"); - } - return pwsh; -} - export function shellExe(): string { - if (isWindows) { - return bashExe() || pwshExe(); - } - return bashExe(); + return isWindows ? "pwsh" : "bash"; } export function gc(force = true) { diff --git a/test/js/bun/test/expect.test.js b/test/js/bun/test/expect.test.js index e1161ff7ed..692e5d2ee8 100644 --- a/test/js/bun/test/expect.test.js +++ b/test/js/bun/test/expect.test.js @@ -2231,12 +2231,19 @@ describe("expect()", () => { expect(thisFile).toHaveLength(thisFileSize); expect(thisFile).toHaveLength(Bun.file(__filename).size); + const { join } = require("path"); + const { tmpdir } = require("os"); + const { mkdtempSync, writeFileSync } = require("fs"); + const tmpDir = mkdtempSync(join(tmpdir(), "jest-extended-")); + const tmpFile = join(tmpDir, "empty.txt"); + writeFileSync(tmpFile, ""); + // empty file should have length 0 - require("fs").writeFileSync("/tmp/empty.txt", ""); expect(Bun.file("/tmp/empty.txt")).toHaveLength(0); // if a file doesn't exist, it should throw (not return 0 size) - expect(() => expect(Bun.file("/does-not-exist/file.txt")).toHaveLength(0)).toThrow(); + const emptyFile = join(tmpDir, "does-not-exist.txt"); + expect(() => expect(Bun.file(emptyFile)).toHaveLength(0)).toThrow(); // Blob expect(new Blob(ANY([1, 2, 3]))).toHaveLength(3); diff --git a/test/js/bun/test/jest-extended.test.js b/test/js/bun/test/jest-extended.test.js index 0cc9c42aac..be0b6465d7 100644 --- a/test/js/bun/test/jest-extended.test.js +++ b/test/js/bun/test/jest-extended.test.js @@ -45,18 +45,22 @@ describe("jest-extended", () => { new Uint8Array(), new Object(), Buffer.from(""), - ...(isBun ? [Bun.file("/tmp/empty.txt")] : []), new Headers(), new URLSearchParams(), new FormData(), (function* () {})(), ]; + if (isBun) { + const { join } = require("path"); + const { tmpdir } = require("os"); + const { mkdtempSync, writeFileSync } = require("fs"); + const tmpDir = mkdtempSync(join(tmpdir(), "jest-extended-")); + const tmpFile = join(tmpDir, "empty.txt"); + values.push(Bun.file(tmpFile)); + writeFileSync(tmpFile, ""); + } for (const value of values) { test(label(value), () => { - if (value && typeof value === "object" && value instanceof Blob) { - require("fs").writeFileSync("/tmp/empty.txt", ""); - } - expect(value).toBeEmpty(); }); } diff --git a/test/js/third_party/st.test.ts b/test/js/third_party/st.test.ts index 418a126c74..5ea9a11d89 100644 --- a/test/js/third_party/st.test.ts +++ b/test/js/third_party/st.test.ts @@ -1,22 +1,22 @@ -import { bunExe } from "bun:harness"; -import { bunEnv } from "harness"; +import { bunExe, bunEnv } from "harness"; import { expect, it } from "bun:test"; -import * as path from "node:path"; +import { join, dirname } from "node:path"; it("works", async () => { - const fixture_path = path.join(import.meta.dirname, "_fixtures", "st.ts"); + const fixture_path = join(import.meta.dirname, "_fixtures", "st.ts"); const fixture_data = await Bun.file(fixture_path).text(); let { stdout, stderr, exited } = Bun.spawn({ cmd: [bunExe(), "run", fixture_path], - cwd: path.dirname(fixture_path), + cwd: dirname(fixture_path), stdout: "pipe", stdin: "ignore", stderr: "pipe", env: bunEnv, }); - // err = await new Response(stderr).text(); - // expect(err).toBeEmpty(); - let out = await new Response(stdout).text(); + let [code, err, out] = await Promise.all([exited, new Response(stderr).text(), new Response(stdout).text()]); + if (code !== 0) { + expect(err).toBeEmpty(); + } expect(out).toEqual(fixture_data + "\n"); - expect(await exited).toBe(0); + expect(code).toBe(0); });