Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions packages/kit/src/exports/node/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EventEmitter, once } from 'node:events';
import { validateHeaderValue } from 'node:http';
import { PassThrough } from 'node:stream';
import { expect, test, vi } from 'vitest';
import { getRequest, setResponse } from './index.js';
Expand Down Expand Up @@ -92,11 +93,17 @@ function create_response(req) {
res.destroyed = false;
res.headers = new Map();
res.chunks = [];
res.setHeader = (/** @type {string} */ name, /** @type {unknown} */ value) =>
res.setHeader = (/** @type {string} */ name, /** @type {string} */ value) => {
validateHeaderValue(name, value);
res.headers.set(name.toLowerCase(), value);
};
res.hasHeader = (/** @type {string} */ name) => res.headers.has(name.toLowerCase());
res.getHeaderNames = () => [...res.headers.keys()];
res.writeHead = () => res;
res.removeHeader = (/** @type {string} */ name) => res.headers.delete(name.toLowerCase());
res.writeHead = (/** @type {number} */ status) => {
res.statusCode = status;
return res;
};
res.write = (/** @type {unknown} */ chunk) => {
res.chunks.push(chunk);
return true;
Expand Down Expand Up @@ -255,6 +262,18 @@ test('does not abort the request signal when the response finishes normally', as
expect(request.signal.aborted).toBe(false);
});

test('responds with a 500 when Node rejects a header, instead of leaving the request open', async () => {
const res = /** @type {any} */ (create_response());
const finished = once(res, 'finish');

setResponse(res, new Response('{}', { headers: { 'x-test': '\u001f' } }));

await finished;
expect(res.statusCode).toBe(500);
expect(res.headers.size).toBe(0);
expect(Buffer.concat(res.chunks.map(Buffer.from)).toString()).toMatch('ERR_INVALID_CHAR');
});

test('sends fixed response bodies with a content-length', async () => {
const res = /** @type {any} */ (create_response());
const finished = once(res, 'finish');
Expand Down
5 changes: 3 additions & 2 deletions packages/kit/test/apps/basics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"preview": "vite preview",
"check": "svelte-kit sync && node node_modules/@typescript/native/bin/tsc && svelte-check --tsgo --incremental",
"test": "pnpm test:dev && pnpm test:build",
"test:dev": "node test/setup.js && DEV=true playwright test",
"test:build": "node test/setup.js && PUBLIC_PRERENDERING=false playwright test",
"test:dev": "node test/setup.js && DEV=true playwright test && KIT_TEST_DEV=true vitest run -c vitest.server.config.js",
"test:build": "node test/setup.js && PUBLIC_PRERENDERING=false playwright test && vitest run -c vitest.server.config.js",
"test:cross-platform:dev": "pnpm test:client-import && node test/setup.js && DEV=true playwright test test/cross-platform/",
"test:cross-platform:build": "node test/setup.js && playwright test test/cross-platform/",
"test:server-side-route-resolution:dev": "node test/setup.js && DEV=true ROUTER_RESOLUTION=server playwright test",
Expand All @@ -25,6 +25,7 @@
"@sveltejs/kit": "workspace:^",
"@sveltejs/vite-plugin-svelte": "catalog:",
"@vitest/browser-playwright": "catalog:",
"jsdom": "catalog:",
"svelte": "catalog:",
"svelte-check": "catalog:",
"test-redirect-importer": "workspace:*",
Expand Down

This file was deleted.

This file was deleted.

Loading
Loading