Skip to content

Commit 711f0ef

Browse files
bjohansebasclaude
andcommitted
test(e2e): snapshot the logging=log module detail and drop the covered unit tests
A logging=log e2e run now snapshots the collapsed "Updated modules:" group and its per-module entries straight from the browser console (puppeteer surfaces group frames as console events). The jsdom equivalents — the process-update logging describe and the building-message log test, whose output already appears verbatim in the info-level e2e snapshot — are removed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent fbb2400 commit 711f0ef

4 files changed

Lines changed: 32 additions & 76 deletions

File tree

test/client.test.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,6 @@ describe("client", () => {
115115
jest.restoreAllMocks();
116116
});
117117

118-
it("logs the changed file on building messages", () => {
119-
EventSourceStub.lastInstance().onmessage(
120-
makeMessage({ action: "building", file: "/src/index.js" }),
121-
);
122-
expect(
123-
console.info.mock.calls.some(([msg]) =>
124-
msg.includes("rebuilding (/src/index.js changed)"),
125-
),
126-
).toBe(true);
127-
});
128-
129118
it("calls subscribeAll handler on default messages", () => {
130119
const spy = jest.fn();
131120
client.subscribeAll(spy);

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ You may need an appropriate loader to handle this file type, currently no loader
1010
]
1111
`;
1212

13+
exports[`client logging (browser) logging=log adds the collapsed per-module detail 1`] = `
14+
[
15+
"[webpack-dev-middleware] connected",
16+
"[webpack-dev-middleware] bundle rebuilding (<fixture>/app.js changed)",
17+
"[webpack-dev-middleware] bundle rebuilt in Xms",
18+
"[webpack-dev-middleware] Checking for updates on the server...",
19+
"[webpack-dev-middleware] Hot updated 1 modules.",
20+
"[webpack-dev-middleware] Updated modules:",
21+
"[webpack-dev-middleware] - ./app.js",
22+
"console.groupEnd",
23+
"[webpack-dev-middleware] App is up to date.",
24+
]
25+
`;
26+
1327
exports[`client logging (browser) logging=none silences the whole cycle 1`] = `[]`;
1428

1529
exports[`client logging (browser) logging=warn keeps warnings only 1`] = `

test/e2e/logging.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,24 @@ describe("client logging (browser)", () => {
7070
expect(normalizeConsole(console_.messages)).toMatchSnapshot();
7171
});
7272

73+
it("logging=log adds the collapsed per-module detail", async () => {
74+
hotApp = await createHotApp({ query: "?logging=log", code: app("v1") });
75+
({ page, browser } = await runBrowser());
76+
const console_ = collectConsole(page);
77+
78+
await page.goto(hotApp.url);
79+
await waitForAppText(page, "v1");
80+
await console_.waitFor("connected");
81+
82+
hotApp.edit(app("v2"));
83+
await waitForAppText(page, "v2");
84+
await console_.waitFor("App is up to date");
85+
86+
// Includes the "Updated modules:" collapsed group and its " - ./app.js"
87+
// entry, which the info level gates off.
88+
expect(normalizeConsole(console_.messages)).toMatchSnapshot();
89+
});
90+
7391
it("logging=none silences the whole cycle", async () => {
7492
hotApp = await createHotApp({ query: "?logging=none", code: app("v1") });
7593
({ page, browser } = await runBrowser());

test/process-update.test.js

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -220,69 +220,4 @@ describe("process-update", () => {
220220

221221
expect(reloadPage).toHaveBeenCalledTimes(1);
222222
});
223-
224-
describe("logging", () => {
225-
/**
226-
* @param {jest.Mock} spy console spy
227-
* @param {string} text expected substring
228-
* @returns {boolean} true when some call contains the text
229-
*/
230-
function logged(spy, text) {
231-
return spy.mock.calls.some((call) => call.join(" ").includes(text));
232-
}
233-
234-
beforeEach(() => {
235-
if (typeof console.groupCollapsed !== "function") {
236-
console.groupCollapsed = () => {};
237-
}
238-
if (typeof console.groupEnd !== "function") {
239-
console.groupEnd = () => {};
240-
}
241-
jest.spyOn(console, "groupCollapsed").mockImplementation(() => {});
242-
jest.spyOn(console, "groupEnd").mockImplementation(() => {});
243-
});
244-
245-
it("logs a one-line summary at the default info level", async () => {
246-
applyUpdate = loadApplyUpdate(
247-
makeFakeHot({
248-
checkResult: ["./a.js", "./b.js"],
249-
applyImpl: () => Promise.resolve(["./a.js", "./b.js"]),
250-
}),
251-
);
252-
253-
applyUpdate("new-hash", { reload: true });
254-
globalThis.__webpack_hash__ = "new-hash";
255-
await flushPromises();
256-
257-
expect(logged(console.info, "Hot updated 2 modules.")).toBe(true);
258-
// Groups are gated below the "log" level.
259-
expect(console.groupCollapsed).not.toHaveBeenCalled();
260-
expect(logged(console.log, "./a.js")).toBe(false);
261-
});
262-
263-
it("adds a collapsed group with the module detail at the log level", async () => {
264-
applyUpdate = loadApplyUpdate(
265-
makeFakeHot({
266-
checkResult: ["./a.js", "./b.js"],
267-
applyImpl: () => Promise.resolve(["./a.js", "./b.js"]),
268-
}),
269-
);
270-
setLogLevel("log");
271-
272-
applyUpdate("new-hash", { reload: true });
273-
globalThis.__webpack_hash__ = "new-hash";
274-
await flushPromises();
275-
276-
expect(logged(console.info, "Hot updated 2 modules.")).toBe(true);
277-
expect(
278-
logged(
279-
/** @type {jest.Mock} */ (console.groupCollapsed),
280-
"Updated modules:",
281-
),
282-
).toBe(true);
283-
expect(logged(console.log, "./a.js")).toBe(true);
284-
expect(logged(console.log, "./b.js")).toBe(true);
285-
expect(console.groupEnd).toHaveBeenCalled();
286-
});
287-
});
288223
});

0 commit comments

Comments
 (0)