chore: test server directly - #16879
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/4bea7740859d2cf9d0e77ae5e51bc4e88f4bc24dOpen in |
|
| if (event.request.method === 'HEAD' && response.body !== null) { | ||
| response = new Response(null, response); | ||
| } |
There was a problem hiding this comment.
there's definitely a better place for this to live, perhaps in the server.respond method. otherwise it'll end up duplicated all over
| test('invalid headers return a 500', async () => { | ||
| const response = await get('/endpoint-output/head-write-error'); | ||
| expect(response.status).toBe(500); | ||
| expect(await response.text()).toMatch( | ||
| 'TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["x-test"]' | ||
| ); | ||
| }); |
There was a problem hiding this comment.
Turns out this isn't testing anything in SvelteKit itself, it's just testing a Node.js behaviour
There was a problem hiding this comment.
Have a strong feeling we do things like this for a lot of tests... I'll try to get an agent to do a full pass through.
| // globalSetup: fileURLToPath( | ||
| // new URL('./test/apps/basics/unit-test/server.setup.js', import.meta.url) | ||
| // ) |
There was a problem hiding this comment.
I commented this out for the sake of my sanity but I do think we probably don't want to do this setup here, otherwise we'll be building the app twice — once for Vitest, once for Playwright. It should probably happen as part of the pnpm test:build script instead
|
Yeah. This is good. I'll go through this properly tomorrow. |
|
The unit CI rows run vitest alone, so the globalSetup build is the only thing that creates Stripping in |
|
Went through the rest of the suite for the same class. The only other candidate is |
Companion to #16872. I wanted to see if we can make direct calls to
server.respondwith no HTTP intermediary. For the most part it looks like we can, and in fact by doing so I learned that we respond toHEADrequests incorrectly by including a body (probably immaterial, since the body is likely discarded by any layer between the user and the server, includingfetchitself, but still interesting to note).Note that it requires us to explicitly pass
accept: '*/*'(whichfetchimplies) and handle redirects ourselves.