diff --git a/test/cli/run/commonjs-invalid.test.ts b/test/cli/run/commonjs-invalid.test.ts index b0461dcd62..b8910b2a62 100644 --- a/test/cli/run/commonjs-invalid.test.ts +++ b/test/cli/run/commonjs-invalid.test.ts @@ -1,16 +1,20 @@ -import { expect, test } from "bun:test"; +import { describe, expect, test } from "bun:test"; import { bunEnv, bunExe } from "harness"; import { join } from "path"; -test("Loading an invalid commonjs module", () => { - const { stderr, exitCode } = Bun.spawnSync({ - cmd: [bunExe(), "run", join(import.meta.dir, "cjs-fixture-bad.cjs")], - env: bunEnv, - stdout: "inherit", - stderr: "pipe", - stdin: "inherit", - }); +describe.concurrent("commonjs-invalid", () => { + test("Loading an invalid commonjs module", async () => { + await using proc = Bun.spawn({ + cmd: [bunExe(), "run", join(import.meta.dir, "cjs-fixture-bad.cjs")], + env: bunEnv, + stdout: "inherit", + stderr: "pipe", + stdin: "inherit", + }); - expect(stderr.toString().trim()).toContain("Expected CommonJS module to have a function wrapper"); - expect(exitCode).toBe(1); + const [stderr, exitCode] = await Promise.all([proc.stderr.text(), proc.exited]); + + expect(stderr.trim()).toContain("Expected CommonJS module to have a function wrapper"); + expect(exitCode).toBe(1); + }); }); diff --git a/test/cli/run/commonjs-no-export.test.ts b/test/cli/run/commonjs-no-export.test.ts index 39b7e82781..a9a6fc5c92 100644 --- a/test/cli/run/commonjs-no-export.test.ts +++ b/test/cli/run/commonjs-no-export.test.ts @@ -1,14 +1,19 @@ -import { expect, test } from "bun:test"; +import { describe, expect, test } from "bun:test"; import { bunEnv, bunExe } from "harness"; import { join } from "path"; -test("CommonJS entry point with no exports", () => { - const { stdout, exitCode } = Bun.spawnSync({ - cmd: [bunExe(), "run", "--bun", join(import.meta.dir, "commonjs-no-exports-fixture.js")], - env: bunEnv, - stderr: "inherit", - }); +describe.concurrent("commonjs-no-export", () => { + test("CommonJS entry point with no exports", async () => { + await using proc = Bun.spawn({ + cmd: [bunExe(), "run", "--bun", join(import.meta.dir, "commonjs-no-exports-fixture.js")], + env: bunEnv, + stderr: "inherit", + stdout: "pipe", + }); - expect(stdout.toString().trim().endsWith("--pass--")).toBe(true); - expect(exitCode).toBe(0); + const [stdout, exitCode] = await Promise.all([proc.stdout.text(), proc.exited]); + + expect(stdout.trim().endsWith("--pass--")).toBe(true); + expect(exitCode).toBe(0); + }); }); diff --git a/test/cli/run/empty-file.test.ts b/test/cli/run/empty-file.test.ts index e9f2975752..bd2af23582 100644 --- a/test/cli/run/empty-file.test.ts +++ b/test/cli/run/empty-file.test.ts @@ -1,15 +1,18 @@ -import { expect, it } from "bun:test"; +import { describe, expect, it } from "bun:test"; import { bunEnv, bunExe } from "harness"; import { join } from "path"; -it("should execute empty scripts", () => { - const { stdout, stderr, exitCode } = Bun.spawnSync({ - cmd: [bunExe(), "run", "--bun", join(import.meta.dir, "empty-file.js")], - env: bunEnv, - stdout: "pipe", - stderr: "pipe", +describe.concurrent("empty-file", () => { + it("should execute empty scripts", async () => { + await using proc = Bun.spawn({ + cmd: [bunExe(), "run", "--bun", join(import.meta.dir, "empty-file.js")], + env: bunEnv, + stdout: "pipe", + stderr: "pipe", + }); + const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); + expect(stdout).toBeEmpty(); + expect(stderr).toBeEmpty(); + expect(exitCode).toBe(0); }); - expect(stdout.toString()).toBeEmpty(); - expect(stderr.toString()).toBeEmpty(); - expect(exitCode).toBe(0); }); diff --git a/test/cli/run/jsx-symbol-collision.test.ts b/test/cli/run/jsx-symbol-collision.test.ts index 572396b387..f05eb740bb 100644 --- a/test/cli/run/jsx-symbol-collision.test.ts +++ b/test/cli/run/jsx-symbol-collision.test.ts @@ -1,15 +1,18 @@ -import { expect, it } from "bun:test"; +import { describe, expect, it } from "bun:test"; import { bunEnv, bunExe } from "harness"; import { join } from "path"; -it("should not have a symbol collision with jsx imports", () => { - const { stdout, stderr, exitCode } = Bun.spawnSync({ - cmd: [bunExe(), "run", "--bun", join(import.meta.dir, "jsx-collision.tsx")], - env: bunEnv, - stdout: "pipe", - stderr: "pipe", +describe.concurrent("jsx-symbol-collision", () => { + it("should not have a symbol collision with jsx imports", async () => { + await using proc = Bun.spawn({ + cmd: [bunExe(), "run", "--bun", join(import.meta.dir, "jsx-collision.tsx")], + env: bunEnv, + stdout: "pipe", + stderr: "pipe", + }); + const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); + expect(stdout).toBe("[Function: Fragment]\n"); + expect(stderr).toBeEmpty(); + expect(exitCode).toBe(0); }); - expect(stdout.toString()).toBe("[Function: Fragment]\n"); - expect(stderr.toString()).toBeEmpty(); - expect(exitCode).toBe(0); }); diff --git a/test/cli/run/run-cjs.test.ts b/test/cli/run/run-cjs.test.ts index 73584616a4..ebf49dba3f 100644 --- a/test/cli/run/run-cjs.test.ts +++ b/test/cli/run/run-cjs.test.ts @@ -1,16 +1,20 @@ -import { expect, test } from "bun:test"; +import { describe, expect, test } from "bun:test"; import { mkdirSync } from "fs"; import { bunEnv, bunExe, tmpdirSync } from "harness"; import { join } from "path"; -test("running a commonjs module works", async () => { - const dir = tmpdirSync(); - mkdirSync(dir, { recursive: true }); - await Bun.write(join(dir, "index1.js"), "module.exports = 1; console.log('hello world');"); - let { stdout } = Bun.spawnSync({ - cmd: [bunExe(), join(dir, "index1.js")], - cwd: dir, - env: bunEnv, +describe.concurrent("run-cjs", () => { + test("running a commonjs module works", async () => { + const dir = tmpdirSync(); + mkdirSync(dir, { recursive: true }); + await Bun.write(join(dir, "index1.js"), "module.exports = 1; console.log('hello world');"); + await using proc = Bun.spawn({ + cmd: [bunExe(), join(dir, "index1.js")], + cwd: dir, + env: bunEnv, + stdout: "pipe", + }); + const stdout = await proc.stdout.text(); + expect(stdout).toEqual("hello world\n"); }); - expect(stdout.toString("utf8")).toEqual("hello world\n"); }); diff --git a/test/cli/run/run-extensionless.test.ts b/test/cli/run/run-extensionless.test.ts index 3163c258e4..9541b6cc49 100644 --- a/test/cli/run/run-extensionless.test.ts +++ b/test/cli/run/run-extensionless.test.ts @@ -1,29 +1,35 @@ -import { expect, test } from "bun:test"; +import { describe, expect, test } from "bun:test"; import { mkdirSync, writeFileSync } from "fs"; import { bunEnv, bunExe, isWindows, tmpdirSync } from "harness"; import { join } from "path"; -test("running extensionless file works", async () => { - const dir = tmpdirSync(); - mkdirSync(dir, { recursive: true }); - await Bun.write(join(dir, "cool"), "const x: Test = 2; console.log('hello world');"); - let { stdout } = Bun.spawnSync({ - cmd: [bunExe(), join(dir, "./cool")], - cwd: dir, - env: bunEnv, +describe.concurrent("run-extensionless", () => { + test("running extensionless file works", async () => { + const dir = tmpdirSync(); + mkdirSync(dir, { recursive: true }); + await Bun.write(join(dir, "cool"), "const x: Test = 2; console.log('hello world');"); + await using proc = Bun.spawn({ + cmd: [bunExe(), join(dir, "./cool")], + cwd: dir, + env: bunEnv, + stdout: "pipe", + }); + const stdout = await proc.stdout.text(); + expect(stdout).toEqual("hello world\n"); }); - expect(stdout.toString("utf8")).toEqual("hello world\n"); -}); -test.skipIf(isWindows)("running shebang typescript file works", async () => { - const dir = tmpdirSync(); - mkdirSync(dir, { recursive: true }); - writeFileSync(join(dir, "cool"), `#!${bunExe()}\nconst x: Test = 2; console.log('hello world');`, { mode: 0o777 }); + test.skipIf(isWindows)("running shebang typescript file works", async () => { + const dir = tmpdirSync(); + mkdirSync(dir, { recursive: true }); + writeFileSync(join(dir, "cool"), `#!${bunExe()}\nconst x: Test = 2; console.log('hello world');`, { mode: 0o777 }); - let { stdout } = Bun.spawnSync({ - cmd: [join(dir, "./cool")], - cwd: dir, - env: bunEnv, + await using proc = Bun.spawn({ + cmd: [join(dir, "./cool")], + cwd: dir, + env: bunEnv, + stdout: "pipe", + }); + const stdout = await proc.stdout.text(); + expect(stdout).toEqual("hello world\n"); }); - expect(stdout.toString("utf8")).toEqual("hello world\n"); }); diff --git a/test/cli/run/run-shell.test.ts b/test/cli/run/run-shell.test.ts index a2c7ef0c44..eb9da98d70 100644 --- a/test/cli/run/run-shell.test.ts +++ b/test/cli/run/run-shell.test.ts @@ -1,33 +1,40 @@ -import { expect, test } from "bun:test"; +import { describe, expect, test } from "bun:test"; import { mkdirSync } from "fs"; import { bunEnv, bunExe, tmpdirSync } from "harness"; import { join } from "path"; -test("running a shell script works", async () => { - const dir = tmpdirSync(); - mkdirSync(dir, { recursive: true }); - await Bun.write(join(dir, "something.sh"), "echo wah"); - let { stdout, stderr } = Bun.spawnSync({ - cmd: [bunExe(), join(dir, "something.sh")], - cwd: dir, - env: bunEnv, - stderr: "pipe", +describe.concurrent("run-shell", () => { + test("running a shell script works", async () => { + const dir = tmpdirSync(); + mkdirSync(dir, { recursive: true }); + await Bun.write(join(dir, "something.sh"), "echo wah"); + await using proc = Bun.spawn({ + cmd: [bunExe(), join(dir, "something.sh")], + cwd: dir, + env: bunEnv, + stderr: "pipe", + stdout: "pipe", + }); + const stdout = await proc.stdout.text(); + const stderr = await proc.stderr.text(); + console.log(stderr); + expect(stdout).toEqual("wah\n"); }); - console.log(stderr.toString("utf8")); - expect(stdout.toString("utf8")).toEqual("wah\n"); -}); -test("invalid syntax reports the error correctly", async () => { - const dir = tmpdirSync("bun-shell-test-error"); - mkdirSync(dir, { recursive: true }); - const shellScript = `-h) + test("invalid syntax reports the error correctly", async () => { + const dir = tmpdirSync("bun-shell-test-error"); + mkdirSync(dir, { recursive: true }); + const shellScript = `-h) echo "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"`; - await Bun.write(join(dir, "scripts", "script.sh"), shellScript); - let { stderr } = Bun.spawnSync({ - cmd: [bunExe(), join(dir, "scripts", "script.sh")], - cwd: dir, - env: bunEnv, - stderr: "pipe", + await Bun.write(join(dir, "scripts", "script.sh"), shellScript); + await using proc = Bun.spawn({ + cmd: [bunExe(), join(dir, "scripts", "script.sh")], + cwd: dir, + env: bunEnv, + stderr: "pipe", + stdout: "pipe", + }); + const stderr = await proc.stderr.text(); + expect(stderr).toBe("error: Failed to run script.sh due to error Unexpected ')'\n"); }); - expect(stderr.toString("utf8")).toBe("error: Failed to run script.sh due to error Unexpected ')'\n"); }); diff --git a/test/cli/run/run-unicode.test.ts b/test/cli/run/run-unicode.test.ts index 3e459a5dd7..7c9e4c364f 100644 --- a/test/cli/run/run-unicode.test.ts +++ b/test/cli/run/run-unicode.test.ts @@ -1,28 +1,32 @@ -import { expect, test } from "bun:test"; +import { describe, expect, test } from "bun:test"; import { mkdirSync, realpathSync } from "fs"; import { bunEnv, bunExe, bunRun } from "harness"; import { tmpdir } from "os"; import { join } from "path"; -test("running a weird filename works", async () => { - const troll = process.platform == "win32" ? "💥'​\\" : "💥'\"​\n"; - const dir = join(realpathSync(tmpdir()), "bun-run-test" + troll); - mkdirSync(dir, { recursive: true }); - console.log("dir", dir); - // i this it's possible that the filesystem rejects the path - await Bun.write(join(dir, troll + ".js"), "console.log('hello world');"); - let { stdout } = Bun.spawnSync({ - cmd: [bunExe(), join(dir, troll + ".js")], - cwd: dir, - env: bunEnv, - stdio: ["ignore", "pipe", "inherit"], +describe.concurrent("run-unicode", () => { + test("running a weird filename works", async () => { + const troll = process.platform == "win32" ? "💥'​\\" : "💥'\"​\n"; + const dir = join(realpathSync(tmpdir()), "bun-run-test" + troll); + mkdirSync(dir, { recursive: true }); + console.log("dir", dir); + // i this it's possible that the filesystem rejects the path + await Bun.write(join(dir, troll + ".js"), "console.log('hello world');"); + await using proc = Bun.spawn({ + cmd: [bunExe(), join(dir, troll + ".js")], + cwd: dir, + env: bunEnv, + stdin: "ignore", + stdout: "pipe", + stderr: "inherit", + }); + const stdout = await proc.stdout.text(); + expect(stdout).toEqual("hello world\n"); }); - expect(stdout.toString("utf8")).toEqual("hello world\n"); -}); -test("ts enum with utf16 works", () => { - const result = bunRun(join(import.meta.dir, "ts-enum-fixture.ts")); - expect(result.stdout).toBe(`{ + test("ts enum with utf16 works", () => { + const result = bunRun(join(import.meta.dir, "ts-enum-fixture.ts")); + expect(result.stdout).toBe(`{ "1": "aaaa\u5FEB\u00E9\u00E9", "123": "bbb", "\u5B89\u5168\u4E32\u884C": "\u5B89\u5168\u4E32\u884C", @@ -35,4 +39,5 @@ test("ts enum with utf16 works", () => { "Fran\u00E7ais": 123, bbb: 123, }`); + }); }); diff --git a/test/js/bun/resolve/non-english-import.test.js b/test/js/bun/resolve/non-english-import.test.js index cbe01da23a..77a6cd5667 100644 --- a/test/js/bun/resolve/non-english-import.test.js +++ b/test/js/bun/resolve/non-english-import.test.js @@ -1,94 +1,102 @@ // We do not make these files imports in the codebase because non-ascii file paths can cause issues with git // Instead, we put them into a temporary directory and run them from there -import { expect, test } from "bun:test"; +import { describe, expect, test } from "bun:test"; import { bunEnv, bunExe } from "harness"; import { mkdirSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; -test("latin1 entry point", async () => { - const latin1Char = String.fromCharCode(0xc7); - const latin1Chars = latin1Char + latin1Char + latin1Char + latin1Char; - const prefix = join(tmpdir(), "bun-test-non-english-import-latin1"); +describe.concurrent("non-english-import", () => { + test("latin1 entry point", async () => { + const latin1Char = String.fromCharCode(0xc7); + const latin1Chars = latin1Char + latin1Char + latin1Char + latin1Char; + const prefix = join(tmpdir(), "bun-test-non-english-import-latin1"); - for (let variation of [latin1Chars + "-latin1-prefix.js", "latin1-suffix-" + latin1Chars + ".js"]) { - const inputPath = join(prefix, variation); - try { - mkdirSync(prefix, { recursive: true }); - } catch (e) {} - await Bun.write(inputPath, `console.log(42);`); + for (let variation of [latin1Chars + "-latin1-prefix.js", "latin1-suffix-" + latin1Chars + ".js"]) { + const inputPath = join(prefix, variation); + try { + mkdirSync(prefix, { recursive: true }); + } catch (e) {} + await Bun.write(inputPath, `console.log(42);`); - const { stdout, exitCode } = Bun.spawnSync({ - cmd: [bunExe(), "run", inputPath], - stderr: "inherit", - env: bunEnv, - cwd: prefix, - }); + await using proc = Bun.spawn({ + cmd: [bunExe(), "run", inputPath], + stderr: "inherit", + stdout: "pipe", + env: bunEnv, + cwd: prefix, + }); - expect(exitCode).toBe(0); - expect(stdout.toString()).toBe("42\n"); - } -}); - -test("utf16 entry point", async () => { - const utf16Char = "\u{1F600}"; - const utf16Chars = utf16Char + utf16Char + utf16Char + utf16Char; - const prefix = join(tmpdir(), "bun-test-non-english-import-u16"); - - for (let variation of [utf16Chars + "-utf16-prefix.js", "utf16-suffix-" + utf16Chars + ".js"]) { - const inputPath = join(prefix, variation); - try { - mkdirSync(prefix, { recursive: true }); - } catch (e) {} - await Bun.write(inputPath, `console.log(42);`); - - const { stdout, exitCode } = Bun.spawnSync({ - cmd: [bunExe(), "run", inputPath], - stderr: "inherit", - env: bunEnv, - cwd: prefix, - }); - - expect(exitCode).toBe(0); - expect(stdout.toString()).toBe("42\n"); - } -}); - -test("latin1 & utf16 imports", async () => { - const prefix = join(tmpdir(), "bun-test-non-english-import-imports"); - const utf16Char = "\u{1F600}"; - const utf16Chars = utf16Char + utf16Char + utf16Char + utf16Char; - const latin1Char = String.fromCharCode(0xc7); - const latin1Chars = latin1Char + latin1Char + latin1Char + latin1Char; - - const imports = []; - for (let variation of [utf16Chars + "-utf16-prefix.js", "utf16-suffix-" + utf16Chars + ".js"]) { - imports.push(join(prefix, variation)); - } - - for (let variation of [latin1Chars + "-latin1-prefix.js", "latin1-suffix-" + latin1Chars + ".js"]) { - imports.push(join(prefix, variation)); - } - - const inputPath = join(prefix, "entry.js"); - try { - mkdirSync(prefix, { recursive: true }); - } catch (e) {} - - let entryCode = imports.map(i => `import ${JSON.stringify(i)};`).join("\n"); - await Bun.write(inputPath, entryCode); - - for (let importPath of imports) { - await Bun.write(importPath, "console.log(42);"); - } - - const { stdout, exitCode } = Bun.spawnSync({ - cmd: [bunExe(), "run", inputPath], - stderr: "inherit", - env: bunEnv, - cwd: prefix, + const stdout = await proc.stdout.text(); + expect(stdout).toBe("42\n"); + expect(await proc.exited).toBe(0); + } }); - expect(exitCode).toBe(0); - expect(stdout.toString()).toBe("42\n".repeat(imports.length)); + test("utf16 entry point", async () => { + const utf16Char = "\u{1F600}"; + const utf16Chars = utf16Char + utf16Char + utf16Char + utf16Char; + const prefix = join(tmpdir(), "bun-test-non-english-import-u16"); + + for (let variation of [utf16Chars + "-utf16-prefix.js", "utf16-suffix-" + utf16Chars + ".js"]) { + const inputPath = join(prefix, variation); + try { + mkdirSync(prefix, { recursive: true }); + } catch (e) {} + await Bun.write(inputPath, `console.log(42);`); + + await using proc = Bun.spawn({ + cmd: [bunExe(), "run", inputPath], + stderr: "inherit", + stdout: "pipe", + env: bunEnv, + cwd: prefix, + }); + + const stdout = await proc.stdout.text(); + expect(stdout).toBe("42\n"); + expect(await proc.exited).toBe(0); + } + }); + + test("latin1 & utf16 imports", async () => { + const prefix = join(tmpdir(), "bun-test-non-english-import-imports"); + const utf16Char = "\u{1F600}"; + const utf16Chars = utf16Char + utf16Char + utf16Char + utf16Char; + const latin1Char = String.fromCharCode(0xc7); + const latin1Chars = latin1Char + latin1Char + latin1Char + latin1Char; + + const imports = []; + for (let variation of [utf16Chars + "-utf16-prefix.js", "utf16-suffix-" + utf16Chars + ".js"]) { + imports.push(join(prefix, variation)); + } + + for (let variation of [latin1Chars + "-latin1-prefix.js", "latin1-suffix-" + latin1Chars + ".js"]) { + imports.push(join(prefix, variation)); + } + + const inputPath = join(prefix, "entry.js"); + try { + mkdirSync(prefix, { recursive: true }); + } catch (e) {} + + let entryCode = imports.map(i => `import ${JSON.stringify(i)};`).join("\n"); + await Bun.write(inputPath, entryCode); + + for (let importPath of imports) { + await Bun.write(importPath, "console.log(42);"); + } + + await using proc = Bun.spawn({ + cmd: [bunExe(), "run", inputPath], + stderr: "inherit", + stdout: "pipe", + env: bunEnv, + cwd: prefix, + }); + + const stdout = await proc.stdout.text(); + expect(stdout).toBe("42\n".repeat(imports.length)); + expect(await proc.exited).toBe(0); + }); }); diff --git a/test/js/node/module/node-module-module.test.js b/test/js/node/module/node-module-module.test.js index 558510b2d1..f179e71a74 100644 --- a/test/js/node/module/node-module-module.test.js +++ b/test/js/node/module/node-module-module.test.js @@ -1,221 +1,233 @@ -import { expect, test } from "bun:test"; +import { describe, expect, test } from "bun:test"; import { bunEnv, bunExe, ospath } from "harness"; import Module, { _nodeModulePaths, builtinModules, createRequire, isBuiltin, wrap } from "module"; import path from "path"; -test("builtinModules exists", () => { - expect(Array.isArray(builtinModules)).toBe(true); - expect(builtinModules).toHaveLength(76); -}); - -test("isBuiltin() works", () => { - expect(isBuiltin("fs")).toBe(true); - expect(isBuiltin("path")).toBe(true); - expect(isBuiltin("crypto")).toBe(true); - expect(isBuiltin("assert")).toBe(true); - expect(isBuiltin("util")).toBe(true); - expect(isBuiltin("events")).toBe(true); - expect(isBuiltin("node:events")).toBe(true); - expect(isBuiltin("node:bacon")).toBe(false); - expect(isBuiltin("node:test")).toBe(true); - expect(isBuiltin("test")).toBe(false); // "test" does not alias to "node:test" -}); - -test("module.globalPaths exists", () => { - expect(Array.isArray(require("module").globalPaths)).toBe(true); -}); - -test("createRequire trailing slash", () => { - const req = createRequire(import.meta.dir + "/"); - expect(req.resolve("./node-module-module.test.js")).toBe( - ospath(path.resolve(import.meta.dir, "./node-module-module.test.js")), - ); -}); - -test("createRequire trailing slash file url", () => { - const req = createRequire(Bun.pathToFileURL(import.meta.dir + "/")); - expect(req.resolve("./node-module-module.test.js")).toBe( - ospath(path.resolve(import.meta.dir, "./node-module-module.test.js")), - ); -}); - -test("Module exists", () => { - expect(Module).toBeDefined(); -}); - -test("module.Module works", () => { - expect(Module.Module === Module).toBeTrue(); - - const m = new Module("asdf"); - expect(m.exports).toEqual({}); -}); - -test("_nodeModulePaths() works", () => { - const root = path.resolve("/"); - expect(() => { - _nodeModulePaths(); - }).toThrow(); - expect(_nodeModulePaths(".").length).toBeGreaterThan(0); - expect(_nodeModulePaths(".").pop()).toBe(root + "node_modules"); - expect(_nodeModulePaths("")).toEqual(_nodeModulePaths(".")); - expect(_nodeModulePaths("/")).toEqual([root + "node_modules"]); - expect(_nodeModulePaths("/a/b/c/d")).toEqual([ - ospath(root + "a/b/c/d/node_modules"), - ospath(root + "a/b/c/node_modules"), - ospath(root + "a/b/node_modules"), - ospath(root + "a/node_modules"), - ospath(root + "node_modules"), - ]); - expect(_nodeModulePaths("/a/b/../d")).toEqual([ - ospath(root + "a/d/node_modules"), - ospath(root + "a/node_modules"), - ospath(root + "node_modules"), - ]); -}); - -test("Module.wrap", () => { - var mod = { exports: {} }; - expect(eval(wrap("exports.foo = 1; return 42"))(mod.exports, mod)).toBe(42); - expect(mod.exports.foo).toBe(1); - expect(wrap()).toBe("(function (exports, require, module, __filename, __dirname) { undefined\n});"); -}); - -test("Overwriting _resolveFilename", () => { - const { stdout, exitCode } = Bun.spawnSync({ - cmd: [bunExe(), "run", path.join(import.meta.dir, "resolveFilenameOverwrite.cjs")], - env: bunEnv, - stderr: "inherit", +describe.concurrent("node-module-module", () => { + test("builtinModules exists", () => { + expect(Array.isArray(builtinModules)).toBe(true); + expect(builtinModules).toHaveLength(76); }); - expect(stdout.toString().trim().endsWith("--pass--")).toBe(true); - expect(exitCode).toBe(0); -}); - -test("Overwriting Module.prototype.require", () => { - const { stdout, exitCode } = Bun.spawnSync({ - cmd: [bunExe(), "run", path.join(import.meta.dir, "modulePrototypeOverwrite.cjs")], - env: bunEnv, - stderr: "inherit", + test("isBuiltin() works", () => { + expect(isBuiltin("fs")).toBe(true); + expect(isBuiltin("path")).toBe(true); + expect(isBuiltin("crypto")).toBe(true); + expect(isBuiltin("assert")).toBe(true); + expect(isBuiltin("util")).toBe(true); + expect(isBuiltin("events")).toBe(true); + expect(isBuiltin("node:events")).toBe(true); + expect(isBuiltin("node:bacon")).toBe(false); + expect(isBuiltin("node:test")).toBe(true); + expect(isBuiltin("test")).toBe(false); // "test" does not alias to "node:test" }); - expect(stdout.toString().trim().endsWith("--pass--")).toBe(true); - expect(exitCode).toBe(0); -}); - -test.each([ - "/file/name/goes/here.js", - "file/here.js", - "file\\here.js", - "/file\\here.js", - "\\file\\here.js", - "\\file/here.js", -])("Module.prototype._compile", filename => { - const module = new Module("module id goes here"); - const starting_exports = module.exports; - const r = module._compile("module.exports = { module, exports, require, __filename, __dirname }", filename); - expect(r).toBe(undefined); - expect(module.exports).not.toBe(starting_exports); - const { module: m, exports: e, require: req, __filename: fn, __dirname: dn } = module.exports; - expect(m).toBe(module); - expect(e).toBe(starting_exports); - expect(req).toBe(module.require); - expect(fn).toBe(filename); - expect(dn).toBe(path.dirname(filename)); -}); - -test("Module._extensions", () => { - expect(".js" in Module._extensions).toBeTrue(); - expect(".json" in Module._extensions).toBeTrue(); - expect(".node" in Module._extensions).toBeTrue(); - expect(require.extensions).toBe(Module._extensions); -}); - -test("Module._resolveLookupPaths", () => { - expect(Module._resolveLookupPaths("foo")).toEqual([]); - expect(Module._resolveLookupPaths("./bar", { id: "1", filename: "/baz/abc" })).toEqual(["/baz"]); - expect(Module._resolveLookupPaths("./bar", {})).toEqual(["."]); - expect(Module._resolveLookupPaths("./bar", { paths: ["a"] })).toEqual(["."]); - expect(Module._resolveLookupPaths("bar", { paths: ["a"] })).toEqual(["a"]); -}); - -test("Module.findSourceMap doesn't throw", () => { - expect(Module.findSourceMap("foo")).toEqual(undefined); -}); - -test("require cache relative specifier", () => { - require.cache["./bar.cjs"] = { exports: { default: "bar" } }; - expect(() => require("./bar.cjs")).toThrow("Cannot find module"); -}); -test("builtin resolution", () => { - expect(require.resolve("fs")).toBe("fs"); - expect(require.resolve("node:fs")).toBe("node:fs"); -}); -test("require cache node builtins specifier", () => { - // as js builtin - try { - const fake = { default: "bar" }; - const real = require("fs"); - expect(require.cache["fs"]).toBe(undefined); - require.cache["fs"] = { exports: fake }; - expect(require("fs")).toBe(fake); - expect(require("node:fs")).toBe(real); - } finally { - delete require.cache["fs"]; - } - - // as native module - try { - const fake = { default: "bar" }; - const real = require("util/types"); - expect(require.cache["util/types"]).toBe(undefined); - require.cache["util/types"] = { exports: fake }; - expect(require("util/types")).toBe(fake); - expect(require("node:util/types")).toBe(real); - } finally { - delete require.cache["util/types"]; - } -}); -test("require a cjs file uses the 'module.exports' export", () => { - expect(require("./esm_to_cjs_interop.mjs")).toEqual(Symbol.for("meow")); -}); - -test("Module.runMain", () => { - const { stdout, exitCode } = Bun.spawnSync({ - cmd: [ - bunExe(), - "--require", - path.join(import.meta.dir, "overwrite-module-run-main-1.cjs"), - path.join(import.meta.dir, "overwrite-module-run-main-2.cjs"), - ], - env: bunEnv, - stderr: "inherit", + test("module.globalPaths exists", () => { + expect(Array.isArray(require("module").globalPaths)).toBe(true); }); - expect(stdout.toString().trim()).toBe("pass"); - expect(exitCode).toBe(0); -}); -test("Module.runMain 2", () => { - const { stdout, exitCode } = Bun.spawnSync({ - cmd: [ - bunExe(), - "--require", - path.join(import.meta.dir, "overwrite-module-run-main-3.cjs"), - path.join(import.meta.dir, "overwrite-module-run-main-2.cjs"), - ], - env: bunEnv, - stderr: "inherit", + test("createRequire trailing slash", () => { + const req = createRequire(import.meta.dir + "/"); + expect(req.resolve("./node-module-module.test.js")).toBe( + ospath(path.resolve(import.meta.dir, "./node-module-module.test.js")), + ); }); - expect(stdout.toString().trim()).toBe("pass"); - expect(exitCode).toBe(0); -}); -test.each(["no args", "--access-early"])("children, %s", arg => { - const { stdout, exitCode } = Bun.spawnSync({ - cmd: [bunExe(), path.join(import.meta.dir, "children-fixture/a.cjs"), arg], - env: bunEnv, - stderr: "inherit", + test("createRequire trailing slash file url", () => { + const req = createRequire(Bun.pathToFileURL(import.meta.dir + "/")); + expect(req.resolve("./node-module-module.test.js")).toBe( + ospath(path.resolve(import.meta.dir, "./node-module-module.test.js")), + ); }); - expect(stdout.toString().trim()).toBe(`. (./a.cjs) + + test("Module exists", () => { + expect(Module).toBeDefined(); + }); + + test("module.Module works", () => { + expect(Module.Module === Module).toBeTrue(); + + const m = new Module("asdf"); + expect(m.exports).toEqual({}); + }); + + test("_nodeModulePaths() works", () => { + const root = path.resolve("/"); + expect(() => { + _nodeModulePaths(); + }).toThrow(); + expect(_nodeModulePaths(".").length).toBeGreaterThan(0); + expect(_nodeModulePaths(".").pop()).toBe(root + "node_modules"); + expect(_nodeModulePaths("")).toEqual(_nodeModulePaths(".")); + expect(_nodeModulePaths("/")).toEqual([root + "node_modules"]); + expect(_nodeModulePaths("/a/b/c/d")).toEqual([ + ospath(root + "a/b/c/d/node_modules"), + ospath(root + "a/b/c/node_modules"), + ospath(root + "a/b/node_modules"), + ospath(root + "a/node_modules"), + ospath(root + "node_modules"), + ]); + expect(_nodeModulePaths("/a/b/../d")).toEqual([ + ospath(root + "a/d/node_modules"), + ospath(root + "a/node_modules"), + ospath(root + "node_modules"), + ]); + }); + + test("Module.wrap", () => { + var mod = { exports: {} }; + expect(eval(wrap("exports.foo = 1; return 42"))(mod.exports, mod)).toBe(42); + expect(mod.exports.foo).toBe(1); + expect(wrap()).toBe("(function (exports, require, module, __filename, __dirname) { undefined\n});"); + }); + + test("Overwriting _resolveFilename", async () => { + await using proc = Bun.spawn({ + cmd: [bunExe(), "run", path.join(import.meta.dir, "resolveFilenameOverwrite.cjs")], + env: bunEnv, + stderr: "inherit", + stdout: "pipe", + }); + + const stdout = await proc.stdout.text(); + expect(stdout.trim().endsWith("--pass--")).toBe(true); + expect(await proc.exited).toBe(0); + }); + + test("Overwriting Module.prototype.require", async () => { + await using proc = Bun.spawn({ + cmd: [bunExe(), "run", path.join(import.meta.dir, "modulePrototypeOverwrite.cjs")], + env: bunEnv, + stderr: "inherit", + stdout: "pipe", + }); + + const stdout = await proc.stdout.text(); + expect(stdout.trim().endsWith("--pass--")).toBe(true); + expect(await proc.exited).toBe(0); + }); + + test.each([ + "/file/name/goes/here.js", + "file/here.js", + "file\\here.js", + "/file\\here.js", + "\\file\\here.js", + "\\file/here.js", + ])("Module.prototype._compile", filename => { + const module = new Module("module id goes here"); + const starting_exports = module.exports; + const r = module._compile("module.exports = { module, exports, require, __filename, __dirname }", filename); + expect(r).toBe(undefined); + expect(module.exports).not.toBe(starting_exports); + const { module: m, exports: e, require: req, __filename: fn, __dirname: dn } = module.exports; + expect(m).toBe(module); + expect(e).toBe(starting_exports); + expect(req).toBe(module.require); + expect(fn).toBe(filename); + expect(dn).toBe(path.dirname(filename)); + }); + + test("Module._extensions", () => { + expect(".js" in Module._extensions).toBeTrue(); + expect(".json" in Module._extensions).toBeTrue(); + expect(".node" in Module._extensions).toBeTrue(); + expect(require.extensions).toBe(Module._extensions); + }); + + test("Module._resolveLookupPaths", () => { + expect(Module._resolveLookupPaths("foo")).toEqual([]); + expect(Module._resolveLookupPaths("./bar", { id: "1", filename: "/baz/abc" })).toEqual(["/baz"]); + expect(Module._resolveLookupPaths("./bar", {})).toEqual(["."]); + expect(Module._resolveLookupPaths("./bar", { paths: ["a"] })).toEqual(["."]); + expect(Module._resolveLookupPaths("bar", { paths: ["a"] })).toEqual(["a"]); + }); + + test("Module.findSourceMap doesn't throw", () => { + expect(Module.findSourceMap("foo")).toEqual(undefined); + }); + + test("require cache relative specifier", () => { + require.cache["./bar.cjs"] = { exports: { default: "bar" } }; + expect(() => require("./bar.cjs")).toThrow("Cannot find module"); + }); + test("builtin resolution", () => { + expect(require.resolve("fs")).toBe("fs"); + expect(require.resolve("node:fs")).toBe("node:fs"); + }); + test("require cache node builtins specifier", () => { + // as js builtin + try { + const fake = { default: "bar" }; + const real = require("fs"); + expect(require.cache["fs"]).toBe(undefined); + require.cache["fs"] = { exports: fake }; + expect(require("fs")).toBe(fake); + expect(require("node:fs")).toBe(real); + } finally { + delete require.cache["fs"]; + } + + // as native module + try { + const fake = { default: "bar" }; + const real = require("util/types"); + expect(require.cache["util/types"]).toBe(undefined); + require.cache["util/types"] = { exports: fake }; + expect(require("util/types")).toBe(fake); + expect(require("node:util/types")).toBe(real); + } finally { + delete require.cache["util/types"]; + } + }); + test("require a cjs file uses the 'module.exports' export", () => { + expect(require("./esm_to_cjs_interop.mjs")).toEqual(Symbol.for("meow")); + }); + + test("Module.runMain", async () => { + await using proc = Bun.spawn({ + cmd: [ + bunExe(), + "--require", + path.join(import.meta.dir, "overwrite-module-run-main-1.cjs"), + path.join(import.meta.dir, "overwrite-module-run-main-2.cjs"), + ], + env: bunEnv, + stderr: "inherit", + stdout: "pipe", + }); + + const stdout = await proc.stdout.text(); + expect(stdout.trim()).toBe("pass"); + expect(await proc.exited).toBe(0); + }); + test("Module.runMain 2", async () => { + await using proc = Bun.spawn({ + cmd: [ + bunExe(), + "--require", + path.join(import.meta.dir, "overwrite-module-run-main-3.cjs"), + path.join(import.meta.dir, "overwrite-module-run-main-2.cjs"), + ], + env: bunEnv, + stderr: "inherit", + stdout: "pipe", + }); + + const stdout = await proc.stdout.text(); + expect(stdout.trim()).toBe("pass"); + expect(await proc.exited).toBe(0); + }); + test.each(["no args", "--access-early"])("children, %s", async arg => { + await using proc = Bun.spawn({ + cmd: [bunExe(), path.join(import.meta.dir, "children-fixture/a.cjs"), arg], + env: bunEnv, + stderr: "inherit", + stdout: "pipe", + }); + + const stdout = await proc.stdout.text(); + expect(stdout.trim()).toBe(`. (./a.cjs) ./b.cjs . (./a.cjs) (seen) ./b.cjs (seen) @@ -237,4 +249,6 @@ test.each(["no args", "--access-early"])("children, %s", arg => { ./j.cjs (seen) ./j.cjs (seen) ./k.cjs (seen)`); + expect(await proc.exited).toBe(0); + }); }); diff --git a/test/regression/issue/00631.test.ts b/test/regression/issue/00631.test.ts index f9311059f2..912c7a4af0 100644 --- a/test/regression/issue/00631.test.ts +++ b/test/regression/issue/00631.test.ts @@ -1,39 +1,44 @@ -import { expect, it } from "bun:test"; +import { describe, expect, it } from "bun:test"; import { mkdirSync, readFileSync, rmSync, writeFileSync } from "fs"; import { join } from "path"; import { bunEnv, bunExe, tmpdirSync } from "../../harness.js"; -it("JSON strings escaped properly", async () => { - const testDir = tmpdirSync(); +describe.concurrent("issue/00631", () => { + it("JSON strings escaped properly", async () => { + const testDir = tmpdirSync(); - // Clean up from prior runs if necessary - rmSync(testDir, { recursive: true, force: true }); + // Clean up from prior runs if necessary + rmSync(testDir, { recursive: true, force: true }); - // Create a directory with our test package file - mkdirSync(testDir, { recursive: true }); - writeFileSync(join(testDir, "package.json"), String.raw`{"testRegex":"\\a\n\\b\\"}`); + // Create a directory with our test package file + mkdirSync(testDir, { recursive: true }); + writeFileSync(join(testDir, "package.json"), String.raw`{"testRegex":"\\a\n\\b\\"}`); - // Attempt to add a package, causing the package file to be parsed, modified, - // written, and reparsed. This verifies that escaped backslashes in JSON - // survive the roundtrip - const { exitCode, stderr } = Bun.spawnSync({ - cmd: [bunExe(), "add", "left-pad"], - env: bunEnv, - cwd: testDir, - }); - if (exitCode !== 0) { - console.log(stderr.toString("utf8")); - } - expect(exitCode).toBe(0); + // Attempt to add a package, causing the package file to be parsed, modified, + // written, and reparsed. This verifies that escaped backslashes in JSON + // survive the roundtrip + await using proc = Bun.spawn({ + cmd: [bunExe(), "add", "left-pad"], + env: bunEnv, + cwd: testDir, + stdout: "pipe", + stderr: "pipe", + }); + const [stderr, exitCode] = await Promise.all([proc.stderr.text(), proc.exited]); + if (exitCode !== 0) { + console.log(stderr); + } + expect(exitCode).toBe(0); - const packageContents = readFileSync(join(testDir, "package.json"), { encoding: "utf8" }); - expect(packageContents).toBe(String.raw`{ + const packageContents = readFileSync(join(testDir, "package.json"), { encoding: "utf8" }); + expect(packageContents).toBe(String.raw`{ "testRegex": "\\a\n\\b\\", "dependencies": { "left-pad": "^1.3.0" } }`); - //// If successful clean up test artifacts - rmSync(testDir, { recursive: true }); + //// If successful clean up test artifacts + rmSync(testDir, { recursive: true }); + }); }); diff --git a/test/regression/issue/03216.test.ts b/test/regression/issue/03216.test.ts index 84505b620a..2218da3277 100644 --- a/test/regression/issue/03216.test.ts +++ b/test/regression/issue/03216.test.ts @@ -1,14 +1,15 @@ // https://github.com/oven-sh/bun/issues/3216 -import { expect, test } from "bun:test"; +import { describe, expect, test } from "bun:test"; import { writeFileSync } from "fs"; import { bunEnv, bunExe, tmpdirSync } from "harness"; import { join } from "path"; -test("runtime directory caching gets invalidated", () => { - const tmp = tmpdirSync(); - writeFileSync( - join(tmp, "index.ts"), - `const file = \`\${import.meta.dir}/temp.mjs\`; +describe.concurrent("issue/03216", () => { + test("runtime directory caching gets invalidated", async () => { + const tmp = tmpdirSync(); + writeFileSync( + join(tmp, "index.ts"), + `const file = \`\${import.meta.dir}/temp.mjs\`; const file2 = \`\${import.meta.dir}/second.mjs\`; import { existsSync, unlinkSync, writeFileSync } from "fs"; @@ -38,18 +39,23 @@ try { unlinkSync(file2); } `, - ); + ); - const result = Bun.spawnSync({ - cmd: [bunExe(), "run", join(tmp, "index.ts")], - cwd: tmp, - env: bunEnv, + await using proc = Bun.spawn({ + cmd: [bunExe(), "run", join(tmp, "index.ts")], + cwd: tmp, + env: bunEnv, + stdout: "pipe", + stderr: "pipe", + }); + + const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); + + if (exitCode !== 0) { + console.log(stderr); + } + + expect(stdout).toBe("1\n2\n"); + expect(exitCode).toBe(0); }); - - if (result.exitCode !== 0) { - console.log(result.stderr.toString("utf-8")); - } - - expect(result.exitCode).toBe(0); - expect(result.stdout.toString("utf-8")).toBe("1\n2\n"); }); diff --git a/test/regression/issue/03830.test.ts b/test/regression/issue/03830.test.ts index e55856d950..6b8a1fe159 100644 --- a/test/regression/issue/03830.test.ts +++ b/test/regression/issue/03830.test.ts @@ -1,32 +1,37 @@ -import { expect, it } from "bun:test"; +import { describe, expect, it } from "bun:test"; import { mkdirSync, realpathSync, rmSync, writeFileSync } from "fs"; import { bunEnv, bunExe, tmpdirSync } from "harness"; import { join } from "path"; -it("macros should not lead to seg faults under any given input", async () => { - // this test code follows the same structure as and - // is based on the code for testing issue 4893 +describe.concurrent("issue/03830", () => { + it("macros should not lead to seg faults under any given input", async () => { + // this test code follows the same structure as and + // is based on the code for testing issue 4893 - let testDir = tmpdirSync(); + let testDir = tmpdirSync(); - // Clean up from prior runs if necessary - rmSync(testDir, { recursive: true, force: true }); + // Clean up from prior runs if necessary + rmSync(testDir, { recursive: true, force: true }); - // Create a directory with our test file - mkdirSync(testDir, { recursive: true }); - writeFileSync(join(testDir, "macro.ts"), "export function fn(str) { return str; }"); - writeFileSync( - join(testDir, "index.ts"), - "import { fn } from './macro' assert { type: 'macro' };\nfn(`©${Number(0)}`);", - ); - testDir = realpathSync(testDir); + // Create a directory with our test file + mkdirSync(testDir, { recursive: true }); + writeFileSync(join(testDir, "macro.ts"), "export function fn(str) { return str; }"); + writeFileSync( + join(testDir, "index.ts"), + "import { fn } from './macro' assert { type: 'macro' };\nfn(`©${Number(0)}`);", + ); + testDir = realpathSync(testDir); - const { stderr, exitCode } = Bun.spawnSync({ - cmd: [bunExe(), "build", "--minify", join(testDir, "index.ts")], - env: bunEnv, - stderr: "pipe", + await using proc = Bun.spawn({ + cmd: [bunExe(), "build", "--minify", join(testDir, "index.ts")], + env: bunEnv, + stderr: "pipe", + stdout: "pipe", + }); + + const [stderr, exitCode] = await Promise.all([proc.stderr.text(), proc.exited]); + + expect(stderr.trim().replaceAll(testDir, "[dir]").replaceAll("\\", "/")).toMatchSnapshot(); + expect(exitCode).toBe(1); }); - - expect(stderr.toString().trim().replaceAll(testDir, "[dir]").replaceAll("\\", "/")).toMatchSnapshot(); - expect(exitCode).toBe(1); }); diff --git a/test/regression/issue/04011.test.ts b/test/regression/issue/04011.test.ts index a3db4270dd..0861cd74da 100644 --- a/test/regression/issue/04011.test.ts +++ b/test/regression/issue/04011.test.ts @@ -1,12 +1,15 @@ -import { expect, test } from "bun:test"; +import { describe, expect, test } from "bun:test"; import { bunEnv, bunExe } from "harness"; -test("running a missing script should return non zero exit code", () => { - const { stdout, exitCode } = Bun.spawnSync({ - cmd: [bunExe(), "run", "missing.ts"], - env: bunEnv, - stderr: "inherit", - }); +describe.concurrent("issue/04011", () => { + test("running a missing script should return non zero exit code", async () => { + await using proc = Bun.spawn({ + cmd: [bunExe(), "run", "missing.ts"], + env: bunEnv, + stderr: "inherit", + stdout: "pipe", + }); - expect(exitCode).toBe(1); + expect(await proc.exited).toBe(1); + }); }); diff --git a/test/regression/issue/04893.test.ts b/test/regression/issue/04893.test.ts index 3556faa815..2c493d638c 100644 --- a/test/regression/issue/04893.test.ts +++ b/test/regression/issue/04893.test.ts @@ -1,23 +1,26 @@ -import { expect, it } from "bun:test"; +import { describe, expect, it } from "bun:test"; import { mkdirSync, rmSync, writeFileSync } from "fs"; import { bunEnv, bunExe, tmpdirSync } from "harness"; import { join } from "path"; -it("correctly handles CRLF multiline string in CRLF terminated files", async () => { - const testDir = tmpdirSync(); +describe.concurrent("issue/04893", () => { + it("correctly handles CRLF multiline string in CRLF terminated files", async () => { + const testDir = tmpdirSync(); - // Clean up from prior runs if necessary - rmSync(testDir, { recursive: true, force: true }); + // Clean up from prior runs if necessary + rmSync(testDir, { recursive: true, force: true }); - // Create a directory with our test CRLF terminated file - mkdirSync(testDir, { recursive: true }); - writeFileSync(join(testDir, "crlf.js"), '"a\\\r\nb"'); + // Create a directory with our test CRLF terminated file + mkdirSync(testDir, { recursive: true }); + writeFileSync(join(testDir, "crlf.js"), '"a\\\r\nb"'); - const { stdout, exitCode } = Bun.spawnSync({ - cmd: [bunExe(), "run", join(testDir, "crlf.js")], - env: bunEnv, - stderr: "inherit", + await using proc = Bun.spawn({ + cmd: [bunExe(), "run", join(testDir, "crlf.js")], + env: bunEnv, + stderr: "inherit", + stdout: "pipe", + }); + + expect(await proc.exited).toBe(0); }); - - expect(exitCode).toBe(0); }); diff --git a/test/regression/issue/__snapshots__/03830.test.ts.snap b/test/regression/issue/__snapshots__/03830.test.ts.snap index 7ecf1cfe71..a0d6f782b2 100644 --- a/test/regression/issue/__snapshots__/03830.test.ts.snap +++ b/test/regression/issue/__snapshots__/03830.test.ts.snap @@ -1,6 +1,6 @@ // Bun Snapshot v1, https://bun.sh/docs/test/snapshots -exports[`macros should not lead to seg faults under any given input 1`] = ` +exports[`issue/03830 macros should not lead to seg faults under any given input 1`] = ` "2 | fn(\`©\${Number(0)}\`); ^ error: "Cannot convert argument type to JS" error in macro diff --git a/test/regression/issue/hashbang-still-works.test.ts b/test/regression/issue/hashbang-still-works.test.ts index 1d220cfc22..3353a08550 100644 --- a/test/regression/issue/hashbang-still-works.test.ts +++ b/test/regression/issue/hashbang-still-works.test.ts @@ -1,60 +1,64 @@ -import { expect, test } from "bun:test"; +import { describe, expect, test } from "bun:test"; import { bunEnv, bunExe, tempDirWithFiles } from "harness"; import path from "path"; -test("hashbang still works after bounds check fix", async () => { - const dir = tempDirWithFiles("hashbang", { - "script.js": "#!/usr/bin/env bun\nconsole.log('hello');", - }); - - await using proc = Bun.spawn({ - cmd: [bunExe(), "--bun", "script.js"], - env: bunEnv, - cwd: dir, - }); - - const [stdout, stderr, exitCode] = await Promise.all([ - new Response(proc.stdout).text(), - new Response(proc.stderr).text(), - proc.exited, - ]); - - expect(exitCode).toBe(0); - expect(stdout.trim()).toBe("hello"); -}); - -test("lexer handles single # character without bounds error", async () => { - const dir = tempDirWithFiles("single-hash", { - "single-hash.js": "#", - }); - - // Using Bun.build to exercise the lexer directly - try { - await Bun.build({ - entrypoints: [path.join(dir, "single-hash.js")], - target: "node", +describe.concurrent("hashbang-still-works", () => { + test("hashbang still works after bounds check fix", async () => { + const dir = tempDirWithFiles("hashbang", { + "script.js": "#!/usr/bin/env bun\nconsole.log('hello');", }); - expect.unreachable(); - } catch (e: any) { - const errorMessage = Bun.inspect((e as AggregateError).errors[0]); - expect(errorMessage).toContain("error: Syntax Error"); - } -}); -test("lexer should not crash on single # character", () => { - const dir = tempDirWithFiles("single-hash", { - "single-hash.js": "#", + await using proc = Bun.spawn({ + cmd: [bunExe(), "--bun", "script.js"], + env: bunEnv, + cwd: dir, + }); + + const [stdout, stderr, exitCode] = await Promise.all([ + new Response(proc.stdout).text(), + new Response(proc.stderr).text(), + proc.exited, + ]); + + expect(exitCode).toBe(0); + expect(stdout.trim()).toBe("hello"); }); - const { stdout, stderr, exitCode } = Bun.spawnSync({ - cmd: [bunExe(), "single-hash.js"], - env: bunEnv, - cwd: dir, - stdout: "pipe", - stderr: "pipe", + test("lexer handles single # character without bounds error", async () => { + const dir = tempDirWithFiles("single-hash", { + "single-hash.js": "#", + }); + + // Using Bun.build to exercise the lexer directly + try { + await Bun.build({ + entrypoints: [path.join(dir, "single-hash.js")], + target: "node", + }); + expect.unreachable(); + } catch (e: any) { + const errorMessage = Bun.inspect((e as AggregateError).errors[0]); + expect(errorMessage).toContain("error: Syntax Error"); + } }); - expect(exitCode).toBe(1); - const output = stdout.toString() + stderr.toString(); - expect(output).toContain("error: Syntax Error"); + test("lexer should not crash on single # character", async () => { + const dir = tempDirWithFiles("single-hash", { + "single-hash.js": "#", + }); + + await using proc = Bun.spawn({ + cmd: [bunExe(), "single-hash.js"], + env: bunEnv, + cwd: dir, + stdout: "pipe", + stderr: "pipe", + }); + + const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); + + const output = stdout + stderr; + expect(output).toContain("error: Syntax Error"); + expect(exitCode).toBe(1); + }); });