diff --git a/packages/astro/test/units/vite-plugin-astro-server/response.test.js b/packages/astro/test/units/vite-plugin-astro-server/response.test.js index a47769556e40..a9c06fd266f2 100644 --- a/packages/astro/test/units/vite-plugin-astro-server/response.test.js +++ b/packages/astro/test/units/vite-plugin-astro-server/response.test.js @@ -21,6 +21,28 @@ const fileSystem = { headers.append('Set-Cookie', 'world'); return new Response(null, { headers }); }`, + '/src/pages/streaming.js': `export const GET = ({ locals }) => { + let sentChunks = 0; + + const readableStream = new ReadableStream({ + async pull(controller) { + if (sentChunks === 3) return controller.close(); + else sentChunks++; + + await new Promise(resolve => setTimeout(resolve, 1000)); + controller.enqueue(new TextEncoder().encode('hello')); + }, + cancel() { + locals.cancelledByTheServer = true; + } + }); + + return new Response(readableStream, { + headers: { + "Content-Type": "text/event-stream" + } + }) + }`, }; describe('endpoints', () => { @@ -60,4 +82,23 @@ describe('endpoints', () => { 'set-cookie': ['hello', 'world'], }); }); + + it('Headers with multisple values (set-cookie special case)', async () => { + const { req, res, done } = createRequestAndResponse({ + method: 'GET', + url: '/streaming', + }); + + const locals = { cancelledByTheServer: false } + req[Symbol.for("astro.locals")] = locals + + container.handle(req, res); + + await new Promise(resolve => setTimeout(resolve, 500)); + res.emit('close'); + + await done; + + expect(locals).to.deep.equal({ cancelledByTheServer: true }); + }); });