diff options
author | 2023-01-22 19:52:51 -0800 | |
---|---|---|
committer | 2023-01-22 19:52:51 -0800 | |
commit | 4dfc09018fe3fee391afc7b4edc129730bd037b8 (patch) | |
tree | c721e05549c028d5a22d81fbd7362612fb9e1ae3 /test/bun.js/test-test.test.ts | |
parent | 771db64cbe8ce24d9068812c3e00e7a4612e5c04 (diff) | |
download | bun-4dfc09018fe3fee391afc7b4edc129730bd037b8.tar.gz bun-4dfc09018fe3fee391afc7b4edc129730bd037b8.tar.zst bun-4dfc09018fe3fee391afc7b4edc129730bd037b8.zip |
[EventEmitter] Preserve `this` in event emitter callbacks
Diffstat (limited to '')
-rw-r--r-- | test/bun.js/test-test.test.ts | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/bun.js/test-test.test.ts b/test/bun.js/test-test.test.ts index 78a701f45..7f1918a94 100644 --- a/test/bun.js/test-test.test.ts +++ b/test/bun.js/test-test.test.ts @@ -1,4 +1,8 @@ +import { 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"; test("toStrictEqual() vs toEqual()", () => { expect([1, , 3]).toEqual([1, , 3]); @@ -2009,3 +2013,41 @@ describe("throw in describe scope doesn't enqueue tests after thrown", () => { 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", () => { + 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'); + }); + emitter.emit('event'); + }); + + `; + + rmSync("/tmp/test-throwing-bun/test-throwing-eventemitter.test.js", { + force: true, + }); + + try { + mkdirSync("/tmp/test-throwing-bun", { recursive: true }); + } catch (e) {} + writeFileSync( + "/tmp/test-throwing-bun/test-throwing-eventemitter.test.js", + code, + ); + + const { stdout, stderr, exitCode } = spawnSync( + [bunExe(), "wiptest", "test-throwing-eventemitter"], + { + cwd: realpathSync("/tmp/test-throwing-bun"), + env: bunEnv, + }, + ); + + expect(exitCode).toBe(1); + expect(stderr!.toString()).toContain("THIS TEST HAS PASSED"); +}); |