From 264142e756041c2c2de86016408e1c10045499e6 Mon Sep 17 00:00:00 2001 From: Ashcon Partovi Date: Mon, 5 Feb 2024 12:47:52 -0800 Subject: [PATCH] Add `isWindows` and related helpers to test harness --- test/cli/install/bun-run.test.ts | 8 ++-- test/cli/run/env.test.ts | 4 +- test/cli/run/run-extensionless.test.ts | 4 +- test/harness.ts | 15 +++++--- test/js/bun/io/bun-write.test.js | 4 +- test/js/bun/util/fileUrl.test.js | 5 ++- test/js/node/env-windows.test.ts | 3 +- test/js/node/fs/fs.test.ts | 4 +- .../js/node/module/node-module-module.test.js | 4 +- test/js/node/os/os.test.js | 11 +++--- test/js/node/path/path.test.js | 14 +++---- test/js/node/tty.test.ts | 5 ++- .../parallel/util-inspect.test.js | 15 ++++---- test/js/third_party/prisma/helper.ts | 8 ++-- test/js/web/url/url.windows.test.js | 38 +++++++++---------- test/js/web/web-globals.test.js | 8 ++-- test/js/web/workers/worker.test.ts | 4 +- test/regression/issue/07500.test.ts | 7 ++-- 18 files changed, 81 insertions(+), 80 deletions(-) diff --git a/test/cli/install/bun-run.test.ts b/test/cli/install/bun-run.test.ts index 6514ed6213..64f765b97f 100644 --- a/test/cli/install/bun-run.test.ts +++ b/test/cli/install/bun-run.test.ts @@ -1,7 +1,7 @@ // @known-failing-on-windows: 1 failing import { file, spawn, spawnSync } from "bun"; import { afterEach, beforeEach, expect, it, describe } from "bun:test"; -import { bunEnv, bunExe, bunEnv as env } from "harness"; +import { bunEnv, bunExe, bunEnv as env, isWindows } from "harness"; import { mkdtemp, realpath, rm, writeFile } from "fs/promises"; import { tmpdir } from "os"; import { join } from "path"; @@ -89,7 +89,7 @@ for (let withRun of [false, true]) { }); it("--silent omits error messages", async () => { - const exe = process.platform === "win32" ? "bun.exe" : "bun"; + const exe = isWindows ? "bun.exe" : "bun"; const { stdout, stderr, exitCode } = spawnSync({ cmd: [bunExe(), "run", "--silent", exe, "doesnotexist"], cwd: run_dir, @@ -102,7 +102,7 @@ for (let withRun of [false, true]) { }); it("no --silent includes error messages", async () => { - const exe = process.platform === "win32" ? "bun.exe" : "bun"; + const exe = isWindows ? "bun.exe" : "bun"; const { stdout, stderr, exitCode } = spawnSync({ cmd: [bunExe(), "run", exe, "doesnotexist"], cwd: run_dir, @@ -113,7 +113,7 @@ for (let withRun of [false, true]) { expect(exitCode).toBe(1); }); - it.skipIf(process.platform === "win32")("exit code message works above 128", async () => { + it.skipIf(isWindows)("exit code message works above 128", async () => { const { stdout, stderr, exitCode } = spawnSync({ cmd: [bunExe(), "run", "bash", "-c", "exit 200"], cwd: run_dir, diff --git a/test/cli/run/env.test.ts b/test/cli/run/env.test.ts index a381338535..80808c7de0 100644 --- a/test/cli/run/env.test.ts +++ b/test/cli/run/env.test.ts @@ -1,5 +1,5 @@ import { describe, expect, test, beforeAll, afterAll } from "bun:test"; -import { bunRun, bunRunAsScript, bunTest, tempDirWithFiles, bunExe, bunEnv } from "harness"; +import { bunRun, bunRunAsScript, bunTest, tempDirWithFiles, bunExe, bunEnv, isWindows } from "harness"; import path from "path"; function bunRunWithoutTrim(file: string, env?: Record) { @@ -579,7 +579,7 @@ describe("--env-file", () => { }); }); -test.if(process.platform === "win32")("environment variables are case-insensitive on Windows", () => { +test.if(isWindows)("environment variables are case-insensitive on Windows", () => { const dir = tempDirWithFiles("dotenv", { ".env": "FOO=bar\n", "index.ts": "console.log(process.env.FOO, process.env.foo, process.env.fOo);", diff --git a/test/cli/run/run-extensionless.test.ts b/test/cli/run/run-extensionless.test.ts index f2c168847c..5f4fee7c4b 100644 --- a/test/cli/run/run-extensionless.test.ts +++ b/test/cli/run/run-extensionless.test.ts @@ -1,6 +1,6 @@ import { expect, test } from "bun:test"; import { mkdirSync, realpathSync } from "fs"; -import { bunEnv, bunExe } from "harness"; +import { bunEnv, bunExe, isWindows } from "harness"; import { writeFileSync } from "fs"; import { tmpdir } from "os"; import { join } from "path"; @@ -17,7 +17,7 @@ test("running extensionless file works", async () => { expect(stdout.toString("utf8")).toEqual("hello world\n"); }); -test.skipIf(process.platform === "win32")("running shebang typescript file works", async () => { +test.skipIf(isWindows)("running shebang typescript file works", async () => { const dir = join(realpathSync(tmpdir()), "bun-run-test2"); mkdirSync(dir, { recursive: true }); writeFileSync(join(dir, "cool"), `#!${bunExe()}\nconst x: Test = 2; console.log('hello world');`, { mode: 0o777 }); diff --git a/test/harness.ts b/test/harness.ts index 416df595c7..e80d82c480 100644 --- a/test/harness.ts +++ b/test/harness.ts @@ -4,6 +4,11 @@ import { readlink, readFile } from "fs/promises"; import { isAbsolute } from "path"; import { openSync, closeSync } from "node:fs"; +export const isMacOS = process.platform === "darwin"; +export const isLinux = process.platform === "linux"; +export const isPosix = isMacOS || isLinux; +export const isWindows = process.platform === "win32"; + export const bunEnv: NodeJS.ProcessEnv = { ...process.env, GITHUB_ACTIONS: "false", @@ -254,7 +259,7 @@ expect.extend({ }); export function ospath(path: string) { - if (process.platform === "win32") { + if (isWindows) { return path.replace(/\//g, "\\"); } return path; @@ -263,7 +268,7 @@ export function ospath(path: string) { export async function toHaveBins(actual: string[], expectedBins: string[]) { const message = () => `Expected ${actual} to be package bins ${expectedBins}`; - if (process.platform === "win32") { + if (isWindows) { for (var i = 0; i < actual.length; i += 2) { if (!actual[i].includes(expectedBins[i / 2]) || !actual[i + 1].includes(expectedBins[i / 2])) { return { pass: false, message }; @@ -278,7 +283,7 @@ export async function toHaveBins(actual: string[], expectedBins: string[]) { export async function toBeValidBin(actual: string, expectedLinkPath: string) { const message = () => `Expected ${actual} to be a link to ${expectedLinkPath}`; - if (process.platform === "win32") { + if (isWindows) { const contents = await readFile(actual + ".bunx", "utf16le"); const expected = expectedLinkPath.slice(3); return { pass: contents.includes(expected), message }; @@ -290,7 +295,7 @@ export async function toBeValidBin(actual: string, expectedLinkPath: string) { export async function toBeWorkspaceLink(actual: string, expectedLinkPath: string) { const message = () => `Expected ${actual} to be a link to ${expectedLinkPath}`; - if (process.platform === "win32") { + if (isWindows) { // junctions on windows will have an absolute path const pass = isAbsolute(actual) && actual.includes(expectedLinkPath.split("..").at(-1)!); return { pass, message }; @@ -301,7 +306,7 @@ export async function toBeWorkspaceLink(actual: string, expectedLinkPath: string } export function getMaxFD(): number { - if (process.platform === "win32") { + if (isWindows) { return 0; } const maxFD = openSync("/dev/null", "r"); diff --git a/test/js/bun/io/bun-write.test.js b/test/js/bun/io/bun-write.test.js index 22304d87fb..e4b31baa8c 100644 --- a/test/js/bun/io/bun-write.test.js +++ b/test/js/bun/io/bun-write.test.js @@ -1,7 +1,7 @@ import fs, { mkdirSync } from "fs"; import { it, expect, describe } from "bun:test"; import path, { join } from "path"; -import { gcTick, withoutAggressiveGC, bunExe, bunEnv } from "harness"; +import { gcTick, withoutAggressiveGC, bunExe, bunEnv, isWindows } from "harness"; import { tmpdir } from "os"; const tmpbase = tmpdir() + path.sep; @@ -194,7 +194,7 @@ it("Bun.file lastModified update", async () => { const lastModified0 = file.lastModified; // sleep some time and write the file again. - await Bun.sleep(process.platform === "win32" ? 1000 : 100); + await Bun.sleep(isWindows ? 1000 : 100); await Bun.write(file, "test text2."); const lastModified1 = file.lastModified; diff --git a/test/js/bun/util/fileUrl.test.js b/test/js/bun/util/fileUrl.test.js index 0f21fe55f2..7d156b1f88 100644 --- a/test/js/bun/util/fileUrl.test.js +++ b/test/js/bun/util/fileUrl.test.js @@ -1,5 +1,6 @@ import { expect, it, describe } from "bun:test"; import { pathToFileURL, fileURLToPath } from "bun"; +import { isWindows } from "harness"; describe("pathToFileURL", () => { it("should convert a path to a file url", () => { @@ -9,7 +10,7 @@ describe("pathToFileURL", () => { describe("fileURLToPath", () => { it("should convert a file url to a path", () => { - if (process.platform === "win32") { + if (isWindows) { expect(() => fileURLToPath("file:///path/to/file.js")).toThrow("File URL path must be absolute"); } else { expect(fileURLToPath("file:///path/to/file.js")).toBe("/path/to/file.js"); @@ -17,7 +18,7 @@ describe("fileURLToPath", () => { }); it("should convert a URL to a path", () => { - if (process.platform === "win32") { + if (isWindows) { expect(() => fileURLToPath(new URL("file:///path/to/file.js"))).toThrow("File URL path must be absolute"); } else { expect(fileURLToPath(new URL("file:///path/to/file.js"))).toBe("/path/to/file.js"); diff --git a/test/js/node/env-windows.test.ts b/test/js/node/env-windows.test.ts index 36ddd41d98..c067d16b3c 100644 --- a/test/js/node/env-windows.test.ts +++ b/test/js/node/env-windows.test.ts @@ -1,6 +1,7 @@ import { test, expect } from "bun:test"; +import { isWindows } from "harness"; -test.if(process.platform === "win32")("process.env is case insensitive on windows", () => { +test.if(isWindows)("process.env is case insensitive on windows", () => { const keys = Object.keys(process.env); // this should have at least one character that is lowercase // it is likely that PATH will be 'Path', and also stuff like 'WindowsLibPath' and so on. diff --git a/test/js/node/fs/fs.test.ts b/test/js/node/fs/fs.test.ts index 41daf2136c..ab94e7e6e4 100644 --- a/test/js/node/fs/fs.test.ts +++ b/test/js/node/fs/fs.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from "bun:test"; import { dirname, resolve, relative } from "node:path"; import { promisify } from "node:util"; -import { bunEnv, bunExe, gc, getMaxFD } from "harness"; +import { bunEnv, bunExe, gc, getMaxFD, isWindows } from "harness"; import { isAscii } from "node:buffer"; import fs, { closeSync, @@ -39,8 +39,6 @@ import fs, { fstatSync, } from "node:fs"; -const isWindows = process.platform === "win32"; - import _promises from "node:fs/promises"; import { tmpdir } from "node:os"; diff --git a/test/js/node/module/node-module-module.test.js b/test/js/node/module/node-module-module.test.js index 52c201d5c5..a9509c067c 100644 --- a/test/js/node/module/node-module-module.test.js +++ b/test/js/node/module/node-module-module.test.js @@ -1,5 +1,5 @@ import { expect, test } from "bun:test"; -import { bunEnv, bunExe, ospath } from "harness"; +import { bunEnv, bunExe, isWindows, ospath } from "harness"; import { _nodeModulePaths, builtinModules, isBuiltin, wrap } from "module"; import Module from "module"; import path from "path"; @@ -36,7 +36,7 @@ test("module.Module works", () => { }); test("_nodeModulePaths() works", () => { - const root = process.platform === "win32" ? "C:\\" : "/"; + const root = isWindows ? "C:\\" : "/"; expect(() => { _nodeModulePaths(); }).toThrow(); diff --git a/test/js/node/os/os.test.js b/test/js/node/os/os.test.js index beb910e345..88ff5b1d75 100644 --- a/test/js/node/os/os.test.js +++ b/test/js/node/os/os.test.js @@ -1,6 +1,7 @@ import { it, expect } from "bun:test"; import * as os from "node:os"; import { realpathSync } from "fs"; +import { isWindows } from "harness"; it("arch", () => { expect(["x64", "x86", "arm64"].some(arch => os.arch() === arch)).toBe(true); @@ -26,7 +27,7 @@ it("getPriority", () => { }); it("setPriority", () => { - if (process.platform === "win32") { + if (isWindows) { expect(os.setPriority(0, 10)).toBe(undefined); expect(os.getPriority()).toBe(10); expect(os.setPriority(0)).toBe(undefined); @@ -48,7 +49,7 @@ it("homedir", () => { }); it("tmpdir", () => { - if (process.platform === "win32") { + if (isWindows) { expect( [ process.env.TEMP, @@ -92,7 +93,7 @@ it("uptime", () => { it("version", () => { expect(typeof os.version() === "string").toBe(true); - if (process.platform === "win32") { + if (isWindows) { expect(os.version()).toInclude("Win"); console.log(os.version()); } @@ -164,12 +165,12 @@ it("machine", () => { }); it("EOL", () => { - if (process.platform === "win32") expect(os.EOL).toBe("\r\n"); + if (isWindows) expect(os.EOL).toBe("\r\n"); else expect(os.EOL).toBe("\n"); }); it("devNull", () => { - if (process.platform === "win32") expect(os.devNull).toBe("\\\\.\\nul"); + if (isWindows) expect(os.devNull).toBe("\\\\.\\nul"); else expect(os.devNull).toBe("/dev/null"); }); diff --git a/test/js/node/path/path.test.js b/test/js/node/path/path.test.js index 0234141253..53da233e2d 100644 --- a/test/js/node/path/path.test.js +++ b/test/js/node/path/path.test.js @@ -3,8 +3,9 @@ const { file } = import.meta; import { describe, it, expect, test } from "bun:test"; import path from "node:path"; import assert from "assert"; +import { isPosix, isWindows } from "harness"; -const sep = process.platform === "win32" ? "\\" : "/"; +const sep = isWindows ? "\\" : "/"; const strictEqual = (...args) => { assert.strictEqual(...args); @@ -32,7 +33,7 @@ describe("dirname", () => { ]; for (const [input, expected] of fixtures) { expect(path.posix.dirname(input)).toBe(expected); - if (process.platform !== "win32") { + if (isPosix) { expect(path.dirname(input)).toBe(expected); } } @@ -452,7 +453,7 @@ it("path.relative", () => { const failures = []; const cwd = process.cwd(); const cwdParent = path.dirname(cwd); - const parentIsRoot = process.platform === "win32" ? cwdParent.match(/^[A-Z]:\\$/) : cwdParent === "/"; + const parentIsRoot = isWindows ? cwdParent.match(/^[A-Z]:\\$/) : cwdParent === "/"; const relativeTests = [ [ @@ -624,11 +625,8 @@ it("path.resolve", () => { [ [["/var/lib", "../", "file/"], "/var/file"], [["/var/lib", "/../", "file/"], "/file"], - [ - ["a/b/c/", "../../.."], - process.platform === "win32" ? process.cwd().slice(2).replaceAll("\\", "/") : process.cwd(), - ], - [["."], process.platform === "win32" ? process.cwd().slice(2).replaceAll("\\", "/") : process.cwd()], + [["a/b/c/", "../../.."], isWindows ? process.cwd().slice(2).replaceAll("\\", "/") : process.cwd()], + [["."], isWindows ? process.cwd().slice(2).replaceAll("\\", "/") : process.cwd()], [["/some/dir", ".", "/absolute/"], "/absolute"], [["/foo/tmp.3/", "../tmp.3/cycles/root.js"], "/foo/tmp.3/cycles/root.js"], ], diff --git a/test/js/node/tty.test.ts b/test/js/node/tty.test.ts index 41ccb8f5de..d43c501c27 100644 --- a/test/js/node/tty.test.ts +++ b/test/js/node/tty.test.ts @@ -1,4 +1,5 @@ import { describe, it, expect } from "bun:test"; +import { isWindows } from "harness"; import { WriteStream } from "node:tty"; describe("WriteStream.prototype.getColorDepth", () => { @@ -7,7 +8,7 @@ describe("WriteStream.prototype.getColorDepth", () => { WriteStream.prototype.getColorDepth.call(undefined, { TERM_PROGRAM: "iTerm.app", }), - ).toBe(process.platform === "win32" ? 24 : 8); + ).toBe(isWindows ? 24 : 8); }); it("iTerm modern", () => { @@ -20,6 +21,6 @@ describe("WriteStream.prototype.getColorDepth", () => { }); it("empty", () => { - expect(WriteStream.prototype.getColorDepth.call(undefined, {})).toBe(process.platform === "win32" ? 24 : 1); + expect(WriteStream.prototype.getColorDepth.call(undefined, {})).toBe(isWindows ? 24 : 1); }); }); diff --git a/test/js/node/util/node-inspect-tests/parallel/util-inspect.test.js b/test/js/node/util/node-inspect-tests/parallel/util-inspect.test.js index f659d6e10d..78ed1466a3 100644 --- a/test/js/node/util/node-inspect-tests/parallel/util-inspect.test.js +++ b/test/js/node/util/node-inspect-tests/parallel/util-inspect.test.js @@ -25,6 +25,7 @@ import util, { inspect } from "util"; import vm from "vm"; import { MessageChannel } from "worker_threads"; import url from "url"; +import { isWindows } from "harness"; const noop = () => {}; const mustCallChecks = []; @@ -2715,7 +2716,7 @@ test("no assertion failures 3", () => { const originalCWD = process.cwd(); process.cwd = () => - process.platform === "win32" + isWindows ? "C:\\workspace\\node-test-binary-windows js-suites-%percent-encoded\\node" : "/home/user directory/repository%encoded/node"; @@ -2739,7 +2740,7 @@ test("no assertion failures 3", () => { ]; const err = new Error("CWD is grayed out, even cwd that are percent encoded!"); err.stack = stack.join("\n"); - if (process.platform === "win32") { + if (isWindows) { err.stack = stack.map(frame => (frame.includes("node:") ? frame : frame.replace(/\//g, "\\"))).join("\n"); } const escapedCWD = util.inspect(process.cwd()).slice(1, -1); @@ -2763,7 +2764,7 @@ test("no assertion failures 3", () => { if (!line.includes("foo") && !line.includes("aaa")) { expected = `\u001b[90m${expected}\u001b[39m`; } - } else if (process.platform === "win32") { + } else if (isWindows) { expected = expected.replace(/\//g, "\\"); } assert.strictEqual(line, expected); @@ -2771,7 +2772,7 @@ test("no assertion failures 3", () => { // Check ESM //const encodedCwd = url.pathToFileURL(process.cwd()); - const sl = process.platform === "win32" ? "\\" : "/"; + const sl = isWindows ? "\\" : "/"; // Use a fake stack to verify the expected colored outcome. //? Something goes wrong with these file URLs but Bun doesn't use those in errors anyway so it's fine (for now at least) @@ -2794,11 +2795,9 @@ test("no assertion failures 3", () => { // ESM without need for encoding process.cwd = () => - process.platform === "win32" - ? "C:\\workspace\\node-test-binary-windows-js-suites\\node" - : "/home/user/repository/node"; + isWindows ? "C:\\workspace\\node-test-binary-windows-js-suites\\node" : "/home/user/repository/node"; let expectedCwd = process.cwd(); - if (process.platform === "win32") { + if (isWindows) { expectedCwd = `/${expectedCwd.replace(/\\/g, "/")}`; } // Use a fake stack to verify the expected colored outcome. diff --git a/test/js/third_party/prisma/helper.ts b/test/js/third_party/prisma/helper.ts index ae11ede20c..5cd484a303 100644 --- a/test/js/third_party/prisma/helper.ts +++ b/test/js/third_party/prisma/helper.ts @@ -1,5 +1,5 @@ import path from "path"; -import { bunExe, bunEnv } from "harness"; +import { bunExe, bunEnv, isLinux } from "harness"; import fs from "fs"; const cwd = import.meta.dir; @@ -48,9 +48,9 @@ export function generate(type: string) { // only affect linux .replace( "%binaryTargets%", - process.platform === "win32" || process.platform === "darwin" - ? "" - : 'binaryTargets = ["native", "debian-openssl-1.1.x", "debian-openssl-3.0.x", "linux-musl", "linux-musl-openssl-3.0.x"]', + isLinux + ? 'binaryTargets = ["native", "debian-openssl-1.1.x", "debian-openssl-3.0.x", "linux-musl", "linux-musl-openssl-3.0.x"]' + : "", ); fs.writeFileSync(schema, content); diff --git a/test/js/web/url/url.windows.test.js b/test/js/web/url/url.windows.test.js index 825c2a3966..ddbe0ac693 100644 --- a/test/js/web/url/url.windows.test.js +++ b/test/js/web/url/url.windows.test.js @@ -1,9 +1,7 @@ +import { isWindows } from "harness"; + const { fileURLToPath, pathToFileURL } = require("url"); -const win = process.platform === "win32"; - -const wintest = win ? test : test.skip; - function checkURL(url, spec) { expect(url.href).toBe(spec.href); expect(url.origin).toBe(spec.origin); @@ -19,7 +17,7 @@ function checkURL(url, spec) { } describe("new URL", () => { - wintest("basic", () => { + test.if(isWindows)("basic", () => { const url = new URL("file://C:/Users/windo/Code/Test/hello.mjs"); checkURL(url, { href: "file:///C:/Users/windo/Code/Test/hello.mjs", @@ -35,7 +33,7 @@ describe("new URL", () => { hash: "", }); }); - wintest("three slashes", () => { + test.if(isWindows)("three slashes", () => { const url = new URL("file:///C:/Users/windo/Code/Test/hello.mjs"); checkURL(url, { href: "file:///C:/Users/windo/Code/Test/hello.mjs", @@ -51,7 +49,7 @@ describe("new URL", () => { hash: "", }); }); - wintest("four slashes", () => { + test.if(isWindows)("four slashes", () => { const url = new URL("file:////C:/Users/windo/Code/Test/hello.mjs"); checkURL(url, { href: "file:////C:/Users/windo/Code/Test/hello.mjs", @@ -67,7 +65,7 @@ describe("new URL", () => { hash: "", }); }); - wintest("normalization", () => { + test.if(isWindows)("normalization", () => { const url = new URL("file:///C:/Users/windo\\Code//Test/hello.mjs"); checkURL(url, { href: "file:///C:/Users/windo/Code//Test/hello.mjs", @@ -83,7 +81,7 @@ describe("new URL", () => { hash: "", }); }); - wintest("unc", () => { + test.if(isWindows)("unc", () => { const url = new URL("file://server/share"); checkURL(url, { href: "file://server/share", @@ -99,7 +97,7 @@ describe("new URL", () => { hash: "", }); }); - wintest("unc with path", () => { + test.if(isWindows)("unc with path", () => { const url = new URL("file://server/share/etc"); checkURL(url, { href: "file://server/share/etc", @@ -118,30 +116,30 @@ describe("new URL", () => { }); describe("fileURLToPath", () => { - wintest("basic", () => { + test.if(isWindows)("basic", () => { const path = fileURLToPath(new URL("file:///C:/Users/windo/Code/Test/hello.mjs")); expect(path).toBe("C:\\Users\\windo\\Code\\Test\\hello.mjs"); }); - wintest("unc", () => { + test.if(isWindows)("unc", () => { const path = fileURLToPath(new URL("file://server/share")); expect(path).toBe("\\\\server\\share"); }); - wintest("unc with path", () => { + test.if(isWindows)("unc with path", () => { const path = fileURLToPath(new URL("file://server/share/etc")); expect(path).toBe("\\\\server\\share\\etc"); }); - wintest("emoji", () => { + test.if(isWindows)("emoji", () => { const path = fileURLToPath(new URL("file:///C:/dev/%F0%9F%98%82")); expect(path).toBe("C:\\dev\\😂"); }); - wintest("unc emoji", () => { + test.if(isWindows)("unc emoji", () => { const path = fileURLToPath(new URL("file://server/share/%F0%9F%98%82")); expect(path).toBe("\\\\server\\share\\😂"); }); }); describe("pathToFileURL", () => { - wintest("basic", () => { + test.if(isWindows)("basic", () => { const url = pathToFileURL("C:\\Users\\windo\\Code\\Test\\hello.mjs"); checkURL(url, { href: "file:///C:/Users/windo/Code/Test/hello.mjs", @@ -157,7 +155,7 @@ describe("pathToFileURL", () => { hash: "", }); }); - wintest("unc", () => { + test.if(isWindows)("unc", () => { const url = pathToFileURL("\\\\server\\share"); checkURL(url, { href: "file://server/share", @@ -173,7 +171,7 @@ describe("pathToFileURL", () => { hash: "", }); }); - wintest("unc with path", () => { + test.if(isWindows)("unc with path", () => { const url = pathToFileURL("\\\\server\\share\\etc"); checkURL(url, { href: "file://server/share/etc", @@ -189,7 +187,7 @@ describe("pathToFileURL", () => { hash: "", }); }); - wintest("emoji", () => { + test.if(isWindows)("emoji", () => { const url = pathToFileURL("C:\\dev\\😂"); checkURL(url, { href: "file:///C:/dev/%F0%9F%98%82", @@ -205,7 +203,7 @@ describe("pathToFileURL", () => { hash: "", }); }); - wintest("unc emoji", () => { + test.if(isWindows)("unc emoji", () => { const url = pathToFileURL("\\\\server\\share\\😂"); checkURL(url, { href: "file://server/share/%F0%9F%98%82", diff --git a/test/js/web/web-globals.test.js b/test/js/web/web-globals.test.js index f37f4f0680..8f2ea8aca3 100644 --- a/test/js/web/web-globals.test.js +++ b/test/js/web/web-globals.test.js @@ -1,6 +1,6 @@ import { spawn } from "bun"; import { expect, it, test } from "bun:test"; -import { bunEnv, bunExe, withoutAggressiveGC } from "harness"; +import { bunEnv, bunExe, isLinux, isMacOS, isWindows, withoutAggressiveGC } from "harness"; test("exists", () => { expect(typeof URL !== "undefined").toBe(true); @@ -231,11 +231,11 @@ test("navigator", () => { const userAgent = `Bun/${version}`; expect(navigator.hardwareConcurrency > 0).toBe(true); expect(navigator.userAgent).toBe(userAgent); - if (process.platform === "darwin") { + if (isMacOS) { expect(navigator.platform).toBe("MacIntel"); - } else if (process.platform === "win32") { + } else if (isWindows) { expect(navigator.platform).toBe("Win32"); - } else if (process.platform === "linux") { + } else if (isLinux) { expect(navigator.platform).toBe("Linux x86_64"); } }); diff --git a/test/js/web/workers/worker.test.ts b/test/js/web/workers/worker.test.ts index c9799c6bdc..bf7c20902b 100644 --- a/test/js/web/workers/worker.test.ts +++ b/test/js/web/workers/worker.test.ts @@ -1,10 +1,10 @@ // @known-failing-on-windows: 1 failing import { describe, expect, test } from "bun:test"; -import { bunEnv, bunExe } from "harness"; +import { bunEnv, bunExe, isWindows } from "harness"; import path from "path"; import wt from "worker_threads"; -const todoIfWindows = process.platform === "win32" ? test.todo : test; +const todoIfWindows = isWindows ? test.todo : test; describe("web worker", () => { async function waitForWorkerResult(worker: Worker, message: any): Promise { diff --git a/test/regression/issue/07500.test.ts b/test/regression/issue/07500.test.ts index 1c88b96b2d..f18f0dd21b 100644 --- a/test/regression/issue/07500.test.ts +++ b/test/regression/issue/07500.test.ts @@ -1,6 +1,6 @@ // @known-failing-on-windows: 1 failing import { test, expect } from "bun:test"; -import { bunEnv, bunExe } from "harness"; +import { bunEnv, bunExe, isWindows } from "harness"; import { tmpdir } from "os"; import { join } from "path"; test("7500 - Bun.stdin.text() doesn't read all data", async () => { @@ -11,12 +11,11 @@ test("7500 - Bun.stdin.text() doesn't read all data", async () => { .split(" ") .join("\n"); await Bun.write(filename, text); - const cat = process.platform === "win32" ? "Get-Content" : "cat"; + const cat = isWindows ? "Get-Content" : "cat"; const bunCommand = `${bunExe()} ${join(import.meta.dir, "7500-repro-fixture.js")}`; const shellCommand = `${cat} ${filename} | ${bunCommand}`.replace(/\\/g, "\\\\"); - const cmd = - process.platform === "win32" ? ["pwsh.exe", `-Command { '${shellCommand}' }`] : ["bash", "-c", shellCommand]; + const cmd = isWindows ? ["pwsh.exe", `-Command { '${shellCommand}' }`] : ["bash", "-c", shellCommand]; const proc = Bun.spawnSync({ cmd, stdin: "inherit",