Skip to content

Commit 8befad3

Browse files
committed
test(vite): send sec-fetch-dest: script for client module fetch
The HMR test fetches /app/entry-client.ts without sec-fetch-dest, causing the Nitro dev middleware to route it through SSR instead of letting Vite serve the transformed module.
1 parent 30003d9 commit 8befad3

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

test/vite/hmr.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ describe("vite:hmr", { sequential: true }, () => {
7070

7171
test("Editing client entry (no full-reload)", async () => {
7272
files.client.update((content) => content.replace(`+ ""`, `+ " (modified)"`));
73-
await pollResponse(`${serverURL}/app/entry-client.ts`, /modified/);
73+
await pollResponse(`${serverURL}/app/entry-client.ts`, /modified/, 5000, {
74+
"sec-fetch-dest": "script",
75+
});
7476
expect(wsMessages.length).toBe(0);
7577
});
7678

@@ -128,14 +130,15 @@ function waitFor(check: () => boolean, duration: number): Promise<void> {
128130
function pollResponse(
129131
url: string,
130132
match: RegExp | ((txt: string) => boolean),
131-
timeout = 5000
133+
timeout = 5000,
134+
headers?: Record<string, string>
132135
): Promise<string> {
133136
const start = Date.now();
134137
let lastResponse = "";
135138
return new Promise((resolve, reject) => {
136139
const check = async () => {
137140
try {
138-
const response = await fetch(url);
141+
const response = await fetch(url, headers ? { headers } : undefined);
139142
lastResponse = await response.text();
140143
if (typeof match === "function" ? match(lastResponse) : match.test(lastResponse)) {
141144
resolve(lastResponse);

0 commit comments

Comments
 (0)