From 71e973f0f7d4737a88948c5655a695b4ab522502 Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Mon, 2 Jun 2025 18:02:49 -0500 Subject: [PATCH 1/2] test: ensure compatibility with AsyncLocalStorage Signed-off-by: Sebastian Beltran --- test/express-integration.js | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/test/express-integration.js b/test/express-integration.js index 22bd988f..b7bf456a 100644 --- a/test/express-integration.js +++ b/test/express-integration.js @@ -2,6 +2,7 @@ import assert from 'node:assert' import { promisify } from 'node:util' +import { AsyncLocalStorage } from 'node:async_hooks' import express from 'express' import FormData from 'form-data' @@ -10,6 +11,7 @@ import _onFinished from 'on-finished' import * as util from './_util.js' import multer from '../index.js' +import http from 'node:http' const onFinished = promisify(_onFinished) @@ -105,4 +107,49 @@ describe('Express Integration', () => { assert.strictEqual(result.body.toString(), 'SUCCESS') assert.strictEqual(result.res.statusCode, 200) }) + + it('should handle async local storage', async () => { + const upload = multer() + const router = new express.Router() + const form = new FormData() + + const als = new AsyncLocalStorage() + + form.append('avatar', util.file('large')) + + router.use((_req, _res, next) => { + als.run({ hello: 'world' }, () => { + next() + }) + }) + + router.post('/profile', upload.single('avatar'), (_, res) => { + res.status(200).end('SUCCESS') + }) + + router.get('/hello', (_, res) => { + const store = als.getStore() + res.status(200).json(store) + }) + + app.use('/t3', router) + + const result = await submitForm(form, '/t3/profile') + + assert.strictEqual(result.body.toString(), 'SUCCESS') + assert.strictEqual(result.res.statusCode, 200) + + http.get(`http://localhost:${port}/t3/hello`, (res) => { + let data = '' + + res.on('data', (chunk) => { + data += chunk + }) + + res.on('end', () => { + const store = JSON.parse(data) + assert.deepStrictEqual(store, { hello: 'world' }) + }) + }) + }) }) From 617a6a0c6fd15a1003c431e9cfa48e141447b01c Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Tue, 3 Jun 2025 14:18:42 -0500 Subject: [PATCH 2/2] fix macos test Signed-off-by: Sebastian Beltran --- test/express-integration.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/express-integration.js b/test/express-integration.js index b7bf456a..03791ef7 100644 --- a/test/express-integration.js +++ b/test/express-integration.js @@ -20,9 +20,9 @@ const port = 34279 describe('Express Integration', () => { let app, server - before((done) => { + before(() => { app = express() - server = app.listen(port, done) + server = app.listen(port) }) after((done) => {