|
26 | 26 | * import that is never *called* ships a harmless empty object and is invisible |
27 | 27 | * to this smoke by design — an unused Node import doesn't crash the app.) |
28 | 28 | * |
29 | | - * `console.error` is NOT a hard failure: the console is where Chromium also |
30 | | - * reports benign things a boot smoke shouldn't fail on — a failed subresource |
31 | | - * load (e.g. the Google-Fonts `<link>` in index.html on a network-restricted |
32 | | - * box) or a React key/prop warning. Console errors are printed as diagnostics. |
| 29 | + * Two channels carry the failure. A *synchronous* uncaught exception (the |
| 30 | + * CASE-1 shape above — a stub call during module init) fires `pageerror`. Its |
| 31 | + * *async* twin — the same `TypeError` reached through an `await`/`.then()`, or a |
| 32 | + * failed dynamic import (this app lazy-loads chunks) — is NOT a `pageerror`; |
| 33 | + * Chromium logs it on the **console** channel as `Uncaught (in promise) …` / |
| 34 | + * `Failed to fetch dynamically imported module`. Both are hard failures. |
| 35 | + * |
| 36 | + * Every *other* `console.error` is NOT a hard failure: the console is where |
| 37 | + * Chromium also reports benign things a boot smoke shouldn't fail on — a failed |
| 38 | + * subresource load (e.g. the Google-Fonts `<link>` in index.html on a |
| 39 | + * network-restricted box) or a React key/prop warning. Those are printed as |
| 40 | + * diagnostics. The `Uncaught` / dynamic-import prefixes are unambiguous — a |
| 41 | + * font/CDN miss reads `Failed to load resource: net::ERR_…` and a React warning |
| 42 | + * never starts with `Uncaught` — so hard-failing on them can't reintroduce that |
| 43 | + * flake. |
33 | 44 | * |
34 | 45 | * Playwright lives in clients/web's node_modules, so it's resolved with a |
35 | 46 | * `createRequire` based at clients/web/package.json rather than a bare |
@@ -61,6 +72,12 @@ const HOST = "127.0.0.1"; |
61 | 72 | const PORT = process.env.SMOKE_WEB_BROWSER_PORT ?? "6298"; |
62 | 73 | const TOKEN = "smoke-web-browser-token"; |
63 | 74 |
|
| 75 | +// Console messages that are the async half of the uncaught-crash class (an |
| 76 | +// unhandled promise rejection or a failed dynamic import). Hard failures, unlike |
| 77 | +// benign console noise. See the header comment for why this can't reintroduce |
| 78 | +// the font/CDN flake. |
| 79 | +const FATAL_CONSOLE = /^Uncaught\b|Failed to fetch dynamically imported module/; |
| 80 | + |
64 | 81 | const server = startProdWebServer({ host: HOST, port: PORT, token: TOKEN }); |
65 | 82 | let browser = null; |
66 | 83 |
|
@@ -105,11 +122,12 @@ try { |
105 | 122 | browser = await loadChromium(); |
106 | 123 | const page = await browser.newPage(); |
107 | 124 |
|
108 | | - // Uncaught page errors are the hard failure — a Node-only module reaching the |
109 | | - // browser bundle surfaces here as a TypeError when its empty stub is called. |
| 125 | + // Uncaught (synchronous) page errors are a hard failure — a Node-only module |
| 126 | + // reaching the browser bundle surfaces here as a TypeError when its empty stub |
| 127 | + // is called during module init. |
110 | 128 | const pageErrors = []; |
111 | | - // Console errors are diagnostic only (see the header comment for why they're |
112 | | - // not a blanket failure). |
| 129 | + // Console errors are diagnostic only EXCEPT those matching FATAL_CONSOLE (the |
| 130 | + // async half of the same crash class) — see the header comment. |
113 | 131 | const consoleErrors = []; |
114 | 132 | page.on("pageerror", (err) => |
115 | 133 | pageErrors.push(err instanceof Error ? err.message : String(err)), |
@@ -161,15 +179,21 @@ try { |
161 | 179 | ); |
162 | 180 | } |
163 | 181 |
|
164 | | - if (pageErrors.length > 0) { |
165 | | - await fail(`app logged uncaught page error(s): ${pageErrors.join("; ")}`); |
| 182 | + // Hard failures: any uncaught (sync) page error, plus console errors that are |
| 183 | + // the async half of the class (unhandled rejection / failed dynamic import). |
| 184 | + const fatalConsole = consoleErrors.filter((m) => FATAL_CONSOLE.test(m)); |
| 185 | + if (pageErrors.length > 0 || fatalConsole.length > 0) { |
| 186 | + await fail( |
| 187 | + `app logged uncaught error(s): ${[...pageErrors, ...fatalConsole].join("; ")}`, |
| 188 | + ); |
166 | 189 | } |
167 | 190 |
|
168 | 191 | // Non-fatal console errors: surface them so a real problem isn't invisible, |
169 | 192 | // without failing the smoke on benign subresource/warning noise. |
170 | | - if (consoleErrors.length > 0) { |
| 193 | + const benignConsole = consoleErrors.filter((m) => !FATAL_CONSOLE.test(m)); |
| 194 | + if (benignConsole.length > 0) { |
171 | 195 | console.log( |
172 | | - `smoke:web:browser note — ${consoleErrors.length} non-fatal console error(s): ${consoleErrors.join("; ")}`, |
| 196 | + `smoke:web:browser note — ${benignConsole.length} non-fatal console error(s): ${benignConsole.join("; ")}`, |
173 | 197 | ); |
174 | 198 | } |
175 | 199 |
|
|
0 commit comments