Skip to content

Commit 6d89ed4

Browse files
bjohansebasclaude
andcommitted
test(e2e): snapshot the console wherever it is asserted
hot.statsOptions warnings-filtering runs in the browser — its snapshot is a lone "connected", the warning never entering the payload, while the overlay={"warnings":false} snapshot shows the warning reaching the console and stopping there. Three hot unit tests fall away: the late-connect sync and post-close handling are covered by the e2e and framework suites, and statsOptions forwarding by the new run. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 6a7670a commit 6d89ed4

3 files changed

Lines changed: 50 additions & 67 deletions

File tree

test/e2e/__snapshots__/overlay.test.js.snap.webpack5

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

3+
exports[`error overlay (browser) keeps warnings out of the payload with hot.statsOptions 1`] = `
4+
[
5+
"[webpack-dev-middleware] connected",
6+
]
7+
`;
8+
9+
exports[`error overlay (browser) overlay={"warnings":false} suppresses warnings (dev-server shape) 1`] = `
10+
[
11+
"[webpack-dev-middleware] connected",
12+
"[webpack-dev-middleware] bundle has 1 warnings",
13+
"[webpack-dev-middleware] ./app.js 5:10-22
14+
Critical dependency: the request of a dependency is an expression",
15+
]
16+
`;
17+
318
exports[`error overlay (browser) paginates multiple problems with a counter 1`] = `
419
[
520
"[webpack-dev-middleware] connected",

test/e2e/overlay.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,41 @@ describe("error overlay (browser)", () => {
261261
await console_.waitFor("Critical dependency");
262262

263263
expect(await page.$(`#${OVERLAY_ID}`)).toBeNull();
264+
expect(normalizeConsole(console_.messages)).toMatchSnapshot();
265+
});
266+
267+
it("keeps warnings out of the payload with hot.statsOptions", async () => {
268+
hotApp = await createHotApp({
269+
// The README's documented recipe: keep warnings in the build output
270+
// but out of the SSE payload entirely.
271+
hot: { statsOptions: { warnings: false } },
272+
code: `
273+
document.getElementById("app").textContent = "v1";
274+
const dep = "./nothing";
275+
try {
276+
require(dep);
277+
} catch (err) {
278+
// expected
279+
}
280+
if (module.hot) {
281+
module.hot.accept();
282+
}
283+
`,
284+
});
285+
({ page, browser } = await runBrowser());
286+
const console_ = collectConsole(page);
287+
288+
await page.goto(hotApp.url);
289+
await console_.waitFor("connected");
290+
291+
// The sync arrived (connected implies it); give rendering a beat.
292+
await new Promise((resolve) => {
293+
setTimeout(resolve, 500);
294+
});
295+
296+
expect(await page.$(`#${OVERLAY_ID}`)).toBeNull();
297+
// Just the connect — the warning never entered the payload.
298+
expect(normalizeConsole(console_.messages)).toMatchSnapshot();
264299
});
265300

266301
it("applies a warnings filter function from the query (dev-server parity)", async () => {

test/hot.test.js

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -366,44 +366,6 @@ describe("createHot", () => {
366366
hot.close();
367367
});
368368

369-
it("sends a sync payload to a client that connects after a build", () => {
370-
const compiler = makeFakeCompiler();
371-
const hot = createHot(compiler, {});
372-
373-
// A build finishes BEFORE anyone connects.
374-
compiler.emitDone(makeFakeStats());
375-
376-
const { writes } = attachClient({ handler: hot.handle });
377-
378-
expect(writes.some((w) => w.includes('"action":"sync"'))).toBe(true);
379-
380-
hot.close();
381-
});
382-
383-
it("responds 404 instead of hanging when a client connects after close()", () => {
384-
const compiler = makeFakeCompiler();
385-
const hot = createHot(compiler, {});
386-
387-
hot.close();
388-
389-
/** @type {number | undefined} */
390-
let statusCode;
391-
let ended = false;
392-
const res = {
393-
writeHead: (code) => {
394-
statusCode = code;
395-
},
396-
end: () => {
397-
ended = true;
398-
},
399-
};
400-
401-
hot.handle({}, res);
402-
403-
expect(statusCode).toBe(404);
404-
expect(ended).toBe(true);
405-
});
406-
407369
it("does not re-send the catch-up sync to already connected clients", () => {
408370
const compiler = makeFakeCompiler();
409371
const hot = createHot(compiler, {});
@@ -479,35 +441,6 @@ describe("createHot", () => {
479441
hot.close();
480442
});
481443

482-
it("forwards custom statsOptions to stats.toJson", () => {
483-
const compiler = makeFakeCompiler();
484-
const hot = createHot(compiler, {
485-
statsOptions: { modules: true, ids: true },
486-
});
487-
attachClient({ handler: hot.handle });
488-
489-
/** @type {EXPECTED_OBJECT} */
490-
let receivedOptions;
491-
492-
compiler.emitDone({
493-
toJson(statsOptions) {
494-
receivedOptions = statsOptions;
495-
return {
496-
time: 1,
497-
hash: "h",
498-
warnings: [],
499-
errors: [],
500-
modules: [],
501-
};
502-
},
503-
compilation: undefined,
504-
});
505-
506-
expect(receivedOptions).toMatchObject({ modules: true, ids: true });
507-
508-
hot.close();
509-
});
510-
511444
it("publishes throttled progress events when progress is enabled", () => {
512445
const compiler = makeFakeCompiler();
513446
/** @type {EXPECTED_OBJECT} */

0 commit comments

Comments
 (0)