diff options
author | 2023-02-17 18:05:41 -0800 | |
---|---|---|
committer | 2023-02-17 18:05:41 -0800 | |
commit | 20d9483cd068358d364cd91e518dfb852521cd8b (patch) | |
tree | 813382d62ed4e56e84563904e501379bb199ae45 | |
parent | 155e3706b1ee3096f0b5df2ab1da02cd125df1d0 (diff) | |
download | bun-20d9483cd068358d364cd91e518dfb852521cd8b.tar.gz bun-20d9483cd068358d364cd91e518dfb852521cd8b.tar.zst bun-20d9483cd068358d364cd91e518dfb852521cd8b.zip |
Fix issue with express body-parser introduced by our async_hooks polyfill
-rw-r--r-- | src/bun.js/async_hooks.exports.js | 12 | ||||
-rw-r--r-- | test/bun.js/third-party/body-parser-test/express-body-parser-test.test.ts | 5 |
2 files changed, 14 insertions, 3 deletions
diff --git a/src/bun.js/async_hooks.exports.js b/src/bun.js/async_hooks.exports.js index 1b5664bc2..055159934 100644 --- a/src/bun.js/async_hooks.exports.js +++ b/src/bun.js/async_hooks.exports.js @@ -145,11 +145,19 @@ class AsyncResource { constructor(type, triggerAsyncId) { this.type = type; this.triggerAsyncId = triggerAsyncId; + + if (AsyncResource.allowedRunInAsyncScope.has(type)) { + this.runInAsyncScope = this.#runInAsyncScope; + } } type; triggerAsyncId; + // We probably will not fully support AsyncResource + // But some packages in the wild do depend on it + static allowedRunInAsyncScope = new Set(["prisma-client-request"]); + emitBefore() { return true; } @@ -160,7 +168,9 @@ class AsyncResource { emitDestroy() {} - runInAsyncScope(fn, ...args) { + runInAsyncScope; + + #runInAsyncScope(fn, ...args) { notImplemented(); var result, err; process.nextTick(fn => { diff --git a/test/bun.js/third-party/body-parser-test/express-body-parser-test.test.ts b/test/bun.js/third-party/body-parser-test/express-body-parser-test.test.ts index 8e0523b7c..1f95b318e 100644 --- a/test/bun.js/third-party/body-parser-test/express-body-parser-test.test.ts +++ b/test/bun.js/third-party/body-parser-test/express-body-parser-test.test.ts @@ -28,6 +28,7 @@ test("httpServer", async done => { const httpServer = require("http").createServer(app); app.on("error", err => { + console.error(err); done(err); }); app.use(json()); @@ -50,9 +51,9 @@ test("httpServer", async done => { "Content-Type": "application/json", }, }); - - expect(resp.status).toBe(200); expect(await resp.text()).toBe("POST - pong"); + expect(resp.status).toBe(200); + expect(reached).toBe(true); done(); }); |