Skip to content

Commit e29bef1

Browse files
bjohansebasclaude
andcommitted
test(e2e): assert linkification on real error messages
The build-error e2e verifies webpack's own "See https://…" becomes a safe new-tab link (href, target, rel), and the runtime-error e2e keeps the sentence-ending dot out of the href. The two jsdom linkify tests are removed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 3ff5d95 commit e29bef1

2 files changed

Lines changed: 28 additions & 19 deletions

File tree

test/e2e/overlay.test.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@ describe("error overlay (browser)", () => {
7979

8080
expect(text).toContain("Module parse failed");
8181

82+
// webpack's own "See https://…" is linkified into a safe new-tab link.
83+
expect(
84+
await frame.evaluate(() => {
85+
const link = document.querySelector("a");
86+
return (
87+
link && {
88+
href: link.getAttribute("href"),
89+
target: link.getAttribute("target"),
90+
rel: link.getAttribute("rel"),
91+
}
92+
);
93+
}),
94+
).toEqual({
95+
href: "https://webpack.js.org/concepts#loaders",
96+
target: "_blank",
97+
rel: "noopener noreferrer",
98+
});
99+
82100
hotApp.edit(app("fixed"));
83101
await waitForNoOverlay(page);
84102

@@ -162,13 +180,22 @@ describe("error overlay (browser)", () => {
162180

163181
// The message doubles as an XSS probe: it must render as text.
164182
await page.evaluate(() => {
165-
globalThis.boom('runtime boom <img src=x onerror="window.__xss=1">');
183+
globalThis.boom(
184+
'runtime boom <img src=x onerror="window.__xss=1"> See https://example.com/a.',
185+
);
166186
});
167187

168188
const frame = await waitForOverlay(page);
169189
const text = await frame.evaluate(() => document.body.textContent);
170190

171191
expect(text).toContain("runtime boom");
192+
// Linkified with the sentence-ending dot kept out of the href.
193+
expect(
194+
await frame.evaluate(() =>
195+
document.querySelector("a")?.getAttribute("href"),
196+
),
197+
).toBe("https://example.com/a");
198+
expect(text).toContain("https://example.com/a.");
172199
expect(
173200
await frame.evaluate(() => document.querySelector("img") !== null),
174201
).toBe(false);

test/overlay.test.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,6 @@ describe("overlay", () => {
7575
expect(findSpanByColor("rgb(255, 107, 107)")).toBeDefined();
7676
});
7777

78-
it("turns URLs into links that open in a new tab", () => {
79-
showProblems("errors", ["See https://webpack.js.org/concepts#loaders"]);
80-
const link = getCard().querySelector("a");
81-
expect(link).not.toBeNull();
82-
expect(link.getAttribute("href")).toBe(
83-
"https://webpack.js.org/concepts#loaders",
84-
);
85-
expect(link.getAttribute("target")).toBe("_blank");
86-
expect(link.getAttribute("rel")).toBe("noopener noreferrer");
87-
});
88-
89-
it("keeps trailing punctuation out of the link href", () => {
90-
showProblems("errors", ["Docs: https://example.com/a."]);
91-
const link = getCard().querySelector("a");
92-
expect(link.getAttribute("href")).toBe("https://example.com/a");
93-
expect(getCard().textContent).toContain("https://example.com/a.");
94-
});
95-
9678
it("re-mounts the overlay when the iframe was removed without clear()", () => {
9779
showProblems("errors", ["boom"]);
9880
// A framework wiping `document.body` removes the iframe behind our back.

0 commit comments

Comments
 (0)