diff options
author | 2023-01-30 11:55:32 +0200 | |
---|---|---|
committer | 2023-01-30 01:55:32 -0800 | |
commit | c11bb9355267fbad50f82fa47bc654d5edbf5747 (patch) | |
tree | b1efcce505bd66fe1a80b089e222bc9ae77968ed | |
parent | 5c30983d5dd1fcf6c256feec119ed136b5dd408a (diff) | |
download | bun-c11bb9355267fbad50f82fa47bc654d5edbf5747.tar.gz bun-c11bb9355267fbad50f82fa47bc654d5edbf5747.tar.zst bun-c11bb9355267fbad50f82fa47bc654d5edbf5747.zip |
report invalid input file as test failure (#1938)
fixes #1935
-rw-r--r-- | src/cli/test_command.zig | 1 | ||||
-rw-r--r-- | test/bun.js/test-test.test.ts | 32 |
2 files changed, 31 insertions, 2 deletions
diff --git a/src/cli/test_command.zig b/src/cli/test_command.zig index bac8f69d6..bc8d7d06a 100644 --- a/src/cli/test_command.zig +++ b/src/cli/test_command.zig @@ -567,6 +567,7 @@ pub const TestCommand = struct { .Rejected => { var result = promise.result(vm.global.vm()); vm.runErrorHandler(result, null); + reporter.summary.fail += 1; return; }, else => {}, diff --git a/test/bun.js/test-test.test.ts b/test/bun.js/test-test.test.ts index 34a94e6e5..321abd5e3 100644 --- a/test/bun.js/test-test.test.ts +++ b/test/bun.js/test-test.test.ts @@ -1,8 +1,11 @@ -import { spawnSync } from "bun"; +import { spawn, spawnSync } from "bun"; import { describe, expect, it, test } from "bun:test"; import { bunEnv } from "bunEnv"; import { bunExe } from "bunExe"; import { mkdirSync, realpathSync, rmSync, writeFileSync } from "fs"; +import { mkdtemp, rm, writeFile } from "fs/promises"; +import { tmpdir } from "os"; +import { join } from "path"; test("toStrictEqual() vs toEqual()", () => { expect([1, , 3]).toEqual([1, , 3]); @@ -2036,7 +2039,7 @@ test("test async exceptions fail tests", () => { }); test('test throwing inside a process.nextTick callback fails', async () => { - + process.nextTick(() => { throw new Error('test throwing inside an EventEmitter #FAIL003'); }); @@ -2107,3 +2110,28 @@ test("test async exceptions fail tests", () => { expect(exitCode).toBe(1); }); + +it("should return non-zero exit code for invalid syntax", async() => { + const test_dir = realpathSync(await mkdtemp(join(tmpdir(), "test"))); + try { + await writeFile(join(test_dir, "bad.test.js"), "!!!"); + const { stdout, stderr, exited } = spawn({ + cmd: [bunExe(), "wiptest", "bad.test.js"], + cwd: test_dir, + stdout: null, + stdin: "pipe", + stderr: "pipe", + bunEnv, + }); + const err = await new Response(stderr).text(); + expect(err).toContain("error: Unexpected end of file"); + expect(err).toContain(" 0 pass"); + expect(err).toContain(" 1 fail"); + expect(err).toContain("Ran 1 tests across 1 files"); + expect(stdout).toBeDefined(); + expect(await new Response(stdout).text()).toBe(""); + expect(await exited).toBe(1); + } finally { + await rm(test_dir, { force: true, recursive: true }); + } +}); |