summaryrefslogtreecommitdiff
path: root/packages/integrations/node/test
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/node/test')
-rw-r--r--packages/integrations/node/test/createOutgoingHttpHeaders.test.js128
-rw-r--r--packages/integrations/node/test/headers.test.js.js269
2 files changed, 197 insertions, 200 deletions
diff --git a/packages/integrations/node/test/createOutgoingHttpHeaders.test.js b/packages/integrations/node/test/createOutgoingHttpHeaders.test.js
index 1876c9a00..2f7063b1c 100644
--- a/packages/integrations/node/test/createOutgoingHttpHeaders.test.js
+++ b/packages/integrations/node/test/createOutgoingHttpHeaders.test.js
@@ -3,76 +3,74 @@ import { expect } from 'chai';
import { createOutgoingHttpHeaders } from '../dist/createOutgoingHttpHeaders.js';
describe('createOutgoingHttpHeaders', () => {
+ it('undefined input headers', async () => {
+ const result = createOutgoingHttpHeaders(undefined);
+ expect(result).to.equal(undefined);
+ });
- it('undefined input headers', async () => {
- const result = createOutgoingHttpHeaders(undefined);
- expect(result).to.equal(undefined);
- });
+ it('null input headers', async () => {
+ const result = createOutgoingHttpHeaders(undefined);
+ expect(result).to.equal(undefined);
+ });
- it('null input headers', async () => {
- const result = createOutgoingHttpHeaders(undefined);
- expect(result).to.equal(undefined);
- });
+ it('Empty Headers', async () => {
+ const headers = new Headers();
+ const result = createOutgoingHttpHeaders(headers);
+ expect(result).to.equal(undefined);
+ });
- it('Empty Headers', async () => {
- const headers = new Headers();
- const result = createOutgoingHttpHeaders(headers);
- expect(result).to.equal(undefined);
- });
+ it('Headers with single key', async () => {
+ const headers = new Headers();
+ headers.append('x-test', 'hello world');
+ const result = createOutgoingHttpHeaders(headers);
+ expect(result).to.deep.equal({ 'x-test': 'hello world' });
+ });
- it('Headers with single key', async () => {
- const headers = new Headers();
- headers.append('x-test', 'hello world');
- const result = createOutgoingHttpHeaders(headers);
- expect(result).to.deep.equal({ 'x-test': 'hello world' });
- });
+ it('Headers with multiple keys', async () => {
+ const headers = new Headers();
+ headers.append('x-test1', 'hello');
+ headers.append('x-test2', 'world');
+ const result = createOutgoingHttpHeaders(headers);
+ expect(result).to.deep.equal({ 'x-test1': 'hello', 'x-test2': 'world' });
+ });
- it('Headers with multiple keys', async () => {
- const headers = new Headers();
- headers.append('x-test1', 'hello');
- headers.append('x-test2', 'world');
- const result = createOutgoingHttpHeaders(headers);
- expect(result).to.deep.equal({ 'x-test1': 'hello', 'x-test2': 'world' });
- });
+ it('Headers with multiple values (not set-cookie)', async () => {
+ const headers = new Headers();
+ headers.append('x-test', 'hello');
+ headers.append('x-test', 'world');
+ const result = createOutgoingHttpHeaders(headers);
+ expect(result).to.deep.equal({ 'x-test': 'hello, world' });
+ });
- it('Headers with multiple values (not set-cookie)', async () => {
- const headers = new Headers();
- headers.append('x-test', 'hello');
- headers.append('x-test', 'world');
- const result = createOutgoingHttpHeaders(headers);
- expect(result).to.deep.equal({ 'x-test': 'hello, world' });
- });
+ it('Headers with multiple values (set-cookie special case)', async () => {
+ const headers = new Headers();
+ headers.append('set-cookie', 'hello');
+ headers.append('set-cookie', 'world');
+ const result = createOutgoingHttpHeaders(headers);
+ expect(result).to.deep.equal({ 'set-cookie': ['hello', 'world'] });
+ });
- it('Headers with multiple values (set-cookie special case)', async () => {
- const headers = new Headers();
- headers.append('set-cookie', 'hello');
- headers.append('set-cookie', 'world');
- const result = createOutgoingHttpHeaders(headers);
- expect(result).to.deep.equal({ 'set-cookie': ['hello', 'world'] });
- });
+ it('Headers with multiple values (set-cookie case handling)', async () => {
+ const headers = new Headers();
+ headers.append('Set-cookie', 'hello');
+ headers.append('Set-Cookie', 'world');
+ const result = createOutgoingHttpHeaders(headers);
+ expect(result).to.deep.equal({ 'set-cookie': ['hello', 'world'] });
+ });
- it('Headers with multiple values (set-cookie case handling)', async () => {
- const headers = new Headers();
- headers.append('Set-cookie', 'hello');
- headers.append('Set-Cookie', 'world');
- const result = createOutgoingHttpHeaders(headers);
- expect(result).to.deep.equal({ 'set-cookie': ['hello', 'world'] });
- });
-
- it('Headers with all use cases', async () => {
- const headers = new Headers();
- headers.append('x-single', 'single');
- headers.append('x-triple', 'one');
- headers.append('x-triple', 'two');
- headers.append('x-triple', 'three');
- headers.append('Set-cookie', 'hello');
- headers.append('Set-Cookie', 'world');
- const result = createOutgoingHttpHeaders(headers);
- expect(result).to.deep.equal({
- 'x-single': 'single',
- 'x-triple': 'one, two, three',
- 'set-cookie': ['hello', 'world'],
- });
- });
-
-}); \ No newline at end of file
+ it('Headers with all use cases', async () => {
+ const headers = new Headers();
+ headers.append('x-single', 'single');
+ headers.append('x-triple', 'one');
+ headers.append('x-triple', 'two');
+ headers.append('x-triple', 'three');
+ headers.append('Set-cookie', 'hello');
+ headers.append('Set-Cookie', 'world');
+ const result = createOutgoingHttpHeaders(headers);
+ expect(result).to.deep.equal({
+ 'x-single': 'single',
+ 'x-triple': 'one, two, three',
+ 'set-cookie': ['hello', 'world'],
+ });
+ });
+});
diff --git a/packages/integrations/node/test/headers.test.js.js b/packages/integrations/node/test/headers.test.js.js
index 5b453dd56..17cfd3701 100644
--- a/packages/integrations/node/test/headers.test.js.js
+++ b/packages/integrations/node/test/headers.test.js.js
@@ -3,146 +3,145 @@ import { loadFixture, createRequestAndResponse } from './test-utils.js';
import { expect } from 'chai';
describe('Node Adapter Headers', () => {
- /** @type {import('./test-utils').Fixture} */
- let fixture;
-
- before(async () => {
- fixture = await loadFixture({
- root: './fixtures/headers/',
- output: 'server',
- adapter: nodejs({ mode: 'middleware' }),
- });
- await fixture.build();
- });
-
- it('Endpoint Simple Headers', async () => {
- await runTest('/endpoints/simple', {
- 'content-type': 'text/plain;charset=utf-8',
- 'x-hello': 'world',
- });
- });
-
- it('Endpoint Astro Single Cookie Header', async () => {
- await runTest('/endpoints/astro-cookies-single', {
- 'content-type': 'text/plain;charset=utf-8',
- 'set-cookie': 'from1=astro1',
- });
- });
-
- it('Endpoint Astro Multi Cookie Header', async () => {
- await runTest('/endpoints/astro-cookies-multi', {
- 'content-type': 'text/plain;charset=utf-8',
- 'set-cookie': ['from1=astro1', 'from2=astro2'],
- });
- });
-
- it('Endpoint Response Single Cookie Header', async () => {
- await runTest('/endpoints/response-cookies-single', {
- 'content-type': 'text/plain;charset=utf-8',
- 'set-cookie': 'hello1=world1',
- });
- });
-
- it('Endpoint Response Multi Cookie Header', async () => {
- await runTest('/endpoints/response-cookies-multi', {
- 'content-type': 'text/plain;charset=utf-8',
- 'set-cookie': ['hello1=world1', 'hello2=world2'],
- });
- });
-
- it('Endpoint Complex Headers Kitchen Sink', async () => {
- await runTest('/endpoints/kitchen-sink', {
- 'content-type': 'text/plain;charset=utf-8',
- 'x-single': 'single',
- 'x-triple': 'one, two, three',
- 'set-cookie': ['hello1=world1', 'hello2=world2'],
- });
- });
-
- it('Endpoint Astro and Response Single Cookie Header', async () => {
- await runTest('/endpoints/astro-response-cookie-single', {
- 'content-type': 'text/plain;charset=utf-8',
- 'set-cookie': ['from1=response1', 'from1=astro1'],
- });
- });
-
- it('Endpoint Astro and Response Multi Cookie Header', async () => {
- await runTest('/endpoints/astro-response-cookie-multi', {
- 'content-type': 'text/plain;charset=utf-8',
- 'set-cookie': ['from1=response1', 'from2=response2', 'from3=astro1', 'from4=astro2'],
- });
- });
-
- it('Endpoint Response Empty Headers Object', async () => {
- await runTest('/endpoints/response-empty-headers-object', {
- 'content-type': 'text/plain;charset=UTF-8',
- });
- });
-
- it('Endpoint Response undefined Headers Object', async () => {
- await runTest('/endpoints/response-undefined-headers-object', {
- 'content-type': 'text/plain;charset=UTF-8',
- });
- });
-
- it('Component Astro Single Cookie Header', async () => {
- await runTest('/astro/component-astro-cookies-single', {
- 'content-type': 'text/html',
- 'set-cookie': 'from1=astro1',
- });
- });
-
- it('Component Astro Multi Cookie Header', async () => {
- await runTest('/astro/component-astro-cookies-multi', {
- 'content-type': 'text/html',
- 'set-cookie': ['from1=astro1', 'from2=astro2'],
- });
- });
-
- it('Component Response Single Cookie Header', async () => {
- await runTest('/astro/component-response-cookies-single', {
- 'content-type': 'text/html',
- 'set-cookie': 'from1=value1',
- });
- });
-
- it('Component Response Multi Cookie Header', async () => {
- await runTest('/astro/component-response-cookies-multi', {
- 'content-type': 'text/html',
- 'set-cookie': ['from1=value1', 'from2=value2'],
- });
- });
-
- it('Component Astro and Response Single Cookie Header', async () => {
- await runTest('/astro/component-astro-response-cookie-single', {
- 'content-type': 'text/html',
- 'set-cookie': ['from1=response1', 'from1=astro1'],
- });
- });
-
- it('Component Astro and Response Multi Cookie Header', async () => {
- await runTest('/astro/component-astro-response-cookie-multi', {
- 'content-type': 'text/html',
- 'set-cookie': ['from1=response1', 'from2=response2', 'from3=astro1', 'from4=astro2'],
- });
- });
-
+ /** @type {import('./test-utils').Fixture} */
+ let fixture;
+
+ before(async () => {
+ fixture = await loadFixture({
+ root: './fixtures/headers/',
+ output: 'server',
+ adapter: nodejs({ mode: 'middleware' }),
+ });
+ await fixture.build();
+ });
+
+ it('Endpoint Simple Headers', async () => {
+ await runTest('/endpoints/simple', {
+ 'content-type': 'text/plain;charset=utf-8',
+ 'x-hello': 'world',
+ });
+ });
+
+ it('Endpoint Astro Single Cookie Header', async () => {
+ await runTest('/endpoints/astro-cookies-single', {
+ 'content-type': 'text/plain;charset=utf-8',
+ 'set-cookie': 'from1=astro1',
+ });
+ });
+
+ it('Endpoint Astro Multi Cookie Header', async () => {
+ await runTest('/endpoints/astro-cookies-multi', {
+ 'content-type': 'text/plain;charset=utf-8',
+ 'set-cookie': ['from1=astro1', 'from2=astro2'],
+ });
+ });
+
+ it('Endpoint Response Single Cookie Header', async () => {
+ await runTest('/endpoints/response-cookies-single', {
+ 'content-type': 'text/plain;charset=utf-8',
+ 'set-cookie': 'hello1=world1',
+ });
+ });
+
+ it('Endpoint Response Multi Cookie Header', async () => {
+ await runTest('/endpoints/response-cookies-multi', {
+ 'content-type': 'text/plain;charset=utf-8',
+ 'set-cookie': ['hello1=world1', 'hello2=world2'],
+ });
+ });
+
+ it('Endpoint Complex Headers Kitchen Sink', async () => {
+ await runTest('/endpoints/kitchen-sink', {
+ 'content-type': 'text/plain;charset=utf-8',
+ 'x-single': 'single',
+ 'x-triple': 'one, two, three',
+ 'set-cookie': ['hello1=world1', 'hello2=world2'],
+ });
+ });
+
+ it('Endpoint Astro and Response Single Cookie Header', async () => {
+ await runTest('/endpoints/astro-response-cookie-single', {
+ 'content-type': 'text/plain;charset=utf-8',
+ 'set-cookie': ['from1=response1', 'from1=astro1'],
+ });
+ });
+
+ it('Endpoint Astro and Response Multi Cookie Header', async () => {
+ await runTest('/endpoints/astro-response-cookie-multi', {
+ 'content-type': 'text/plain;charset=utf-8',
+ 'set-cookie': ['from1=response1', 'from2=response2', 'from3=astro1', 'from4=astro2'],
+ });
+ });
+
+ it('Endpoint Response Empty Headers Object', async () => {
+ await runTest('/endpoints/response-empty-headers-object', {
+ 'content-type': 'text/plain;charset=UTF-8',
+ });
+ });
+
+ it('Endpoint Response undefined Headers Object', async () => {
+ await runTest('/endpoints/response-undefined-headers-object', {
+ 'content-type': 'text/plain;charset=UTF-8',
+ });
+ });
+
+ it('Component Astro Single Cookie Header', async () => {
+ await runTest('/astro/component-astro-cookies-single', {
+ 'content-type': 'text/html',
+ 'set-cookie': 'from1=astro1',
+ });
+ });
+
+ it('Component Astro Multi Cookie Header', async () => {
+ await runTest('/astro/component-astro-cookies-multi', {
+ 'content-type': 'text/html',
+ 'set-cookie': ['from1=astro1', 'from2=astro2'],
+ });
+ });
+
+ it('Component Response Single Cookie Header', async () => {
+ await runTest('/astro/component-response-cookies-single', {
+ 'content-type': 'text/html',
+ 'set-cookie': 'from1=value1',
+ });
+ });
+
+ it('Component Response Multi Cookie Header', async () => {
+ await runTest('/astro/component-response-cookies-multi', {
+ 'content-type': 'text/html',
+ 'set-cookie': ['from1=value1', 'from2=value2'],
+ });
+ });
+
+ it('Component Astro and Response Single Cookie Header', async () => {
+ await runTest('/astro/component-astro-response-cookie-single', {
+ 'content-type': 'text/html',
+ 'set-cookie': ['from1=response1', 'from1=astro1'],
+ });
+ });
+
+ it('Component Astro and Response Multi Cookie Header', async () => {
+ await runTest('/astro/component-astro-response-cookie-multi', {
+ 'content-type': 'text/html',
+ 'set-cookie': ['from1=response1', 'from2=response2', 'from3=astro1', 'from4=astro2'],
+ });
+ });
});
async function runTest(url, expectedHeaders) {
- const { handler } = await import('./fixtures/headers/dist/server/entry.mjs');
+ const { handler } = await import('./fixtures/headers/dist/server/entry.mjs');
- let { req, res, done } = createRequestAndResponse({
- method: 'GET',
- url,
- });
+ let { req, res, done } = createRequestAndResponse({
+ method: 'GET',
+ url,
+ });
- handler(req, res);
+ handler(req, res);
- req.send();
+ req.send();
- await done;
- const headers = res.getHeaders();
+ await done;
+ const headers = res.getHeaders();
- expect(headers).to.deep.equal(expectedHeaders);
-} \ No newline at end of file
+ expect(headers).to.deep.equal(expectedHeaders);
+}