diff options
author | 2023-01-22 20:49:21 -0800 | |
---|---|---|
committer | 2023-01-22 20:49:21 -0800 | |
commit | 407088f6ab5edeb1ecf2bb36846cd07f3559d1cb (patch) | |
tree | 69e8e66c9b860fafd91f1d53398452e9ae901558 /test/bun.js | |
parent | 2cce810190001acf9d55e53770cb02a51682258e (diff) | |
download | bun-407088f6ab5edeb1ecf2bb36846cd07f3559d1cb.tar.gz bun-407088f6ab5edeb1ecf2bb36846cd07f3559d1cb.tar.zst bun-407088f6ab5edeb1ecf2bb36846cd07f3559d1cb.zip |
Add tests for async failure
Diffstat (limited to 'test/bun.js')
-rw-r--r-- | test/bun.js/test-test.test.ts | 66 |
1 files changed, 61 insertions, 5 deletions
diff --git a/test/bun.js/test-test.test.ts b/test/bun.js/test-test.test.ts index 7f1918a94..34a94e6e5 100644 --- a/test/bun.js/test-test.test.ts +++ b/test/bun.js/test-test.test.ts @@ -2014,18 +2014,65 @@ it("a describe scope throwing doesn't cause all other tests in the file to fail" expect(true).toBe(true); }); -test("test throwing inside an EventEmitter fails the test", () => { +test("test async exceptions fail tests", () => { const code = ` import {test, expect} from 'bun:test'; import {EventEmitter} from 'events'; test('test throwing inside an EventEmitter fails the test', () => { const emitter = new EventEmitter(); emitter.on('event', () => { - throw new Error('THIS TEST HAS PASSED'); + throw new Error('test throwing inside an EventEmitter #FAIL001'); }); emitter.emit('event'); }); - + + test('test throwing inside a queueMicrotask callback fails', async () => { + + queueMicrotask(() => { + throw new Error('test throwing inside an EventEmitter #FAIL002'); + }); + + await 1; + }); + + test('test throwing inside a process.nextTick callback fails', async () => { + + process.nextTick(() => { + throw new Error('test throwing inside an EventEmitter #FAIL003'); + }); + + await 1; + }); + + test('test throwing inside a setTimeout', async () => { + await new Promise((resolve, reject) => { + setTimeout(() => { + resolve(); + throw new Error('test throwing inside an EventEmitter #FAIL004'); + }, 0); + }); + }); + + test('test throwing inside an async setTimeout', async () => { + await new Promise((resolve, reject) => { + setTimeout(async () => { + await 1; + resolve(); + throw new Error('test throwing inside an EventEmitter #FAIL005'); + }, 0); + }); + }); + + + test('test throwing inside an async setTimeout no await' , async () => { + await new Promise((resolve, reject) => { + setTimeout(async () => { + resolve(); + throw new Error('test throwing inside an EventEmitter #FAIL006'); + }, 0); + }); + }); + `; rmSync("/tmp/test-throwing-bun/test-throwing-eventemitter.test.js", { @@ -2040,7 +2087,7 @@ test("test throwing inside an EventEmitter fails the test", () => { code, ); - const { stdout, stderr, exitCode } = spawnSync( + const { stderr, exitCode } = spawnSync( [bunExe(), "wiptest", "test-throwing-eventemitter"], { cwd: realpathSync("/tmp/test-throwing-bun"), @@ -2048,6 +2095,15 @@ test("test throwing inside an EventEmitter fails the test", () => { }, ); + const str = stderr!.toString(); + expect(str).toContain("#FAIL001"); + expect(str).toContain("#FAIL002"); + expect(str).toContain("#FAIL003"); + expect(str).toContain("#FAIL004"); + expect(str).toContain("#FAIL005"); + expect(str).toContain("#FAIL006"); + expect(str).toContain("6 fail"); + expect(str).toContain("0 pass"); + expect(exitCode).toBe(1); - expect(stderr!.toString()).toContain("THIS TEST HAS PASSED"); }); |