Skip to content

Commit ffe34e0

Browse files
committed
Fix errors surfaced in e2e smoke tests
1 parent 0f14508 commit ffe34e0

2 files changed

Lines changed: 36 additions & 18 deletions

File tree

astro.config.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,25 @@ export default defineConfig({
197197
* POST /_actions/webmentions.list with ERR_REQUIRE_ESM in production.
198198
* Bundle the sanitizer and its parser dependency chain into the ESM
199199
* server output so no runtime require() of these packages occurs.
200+
*
201+
* Build-only: in the dev server, Vite's SSR module runner evaluates
202+
* noExternal'd CommonJS packages as ESM, crashing the same action with
203+
* "ReferenceError: require is not defined". When the chain is
204+
* externalized in dev, Node 24 loads it natively (require of ESM is
205+
* supported), so the bundling is only needed for build output.
200206
*/
201-
noExternal: [
202-
'sanitize-html',
203-
'htmlparser2',
204-
'dom-serializer',
205-
'domelementtype',
206-
'domhandler',
207-
'domutils',
208-
'entities',
209-
],
207+
noExternal:
208+
process.env['NODE_ENV'] === 'production'
209+
? [
210+
'sanitize-html',
211+
'htmlparser2',
212+
'dom-serializer',
213+
'domelementtype',
214+
'domhandler',
215+
'domutils',
216+
'entities',
217+
]
218+
: [],
210219
},
211220
/**
212221
* Astro 6 reads `environments.client.build.sourcemap` for client bundles

test/e2e/helpers/consoleErrors.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function setupConsoleErrorChecker(page: Page): ConsoleErrorChecker {
3131
const failed404s: string[] = []
3232

3333
// Capture 404 responses with full details
34-
page.on('response', (response) => {
34+
page.on('response', response => {
3535
if (response.status() === 404) {
3636
const url = response.url()
3737
const requestType = response.request().resourceType()
@@ -40,7 +40,7 @@ export function setupConsoleErrorChecker(page: Page): ConsoleErrorChecker {
4040
})
4141

4242
// Capture ALL console messages of type error
43-
page.on('console', (msg) => {
43+
page.on('console', msg => {
4444
if (msg.type() === 'error') {
4545
const text = msg.text()
4646
const location = msg.location()
@@ -52,7 +52,7 @@ export function setupConsoleErrorChecker(page: Page): ConsoleErrorChecker {
5252
})
5353

5454
// Also capture page errors (uncaught exceptions)
55-
page.on('pageerror', (error) => {
55+
page.on('pageerror', error => {
5656
consoleErrors.push(`Uncaught: ${error.message}\n${error.stack}`)
5757
})
5858

@@ -62,26 +62,35 @@ export function setupConsoleErrorChecker(page: Page): ConsoleErrorChecker {
6262
// Filter out ONLY known acceptable issues - computed lazily
6363
getFilteredErrors: () => {
6464
// Get list of acceptable 404 URLs (strip resource type suffix)
65-
const acceptable404Urls = failed404s.filter((url) => {
65+
const acceptable404Urls = failed404s.filter(url => {
6666
const urlWithoutType = url.split(' (')[0]
6767
return url.includes('favicon.ico') || urlWithoutType?.endsWith('/')
6868
})
6969

70-
return consoleErrors.filter((error) => {
70+
return consoleErrors.filter(error => {
7171
// Filter known browser quirks
7272
if (error.includes('ResizeObserver loop completed')) return false
7373

7474
// Filter Vite dev server 504 errors (Outdated Optimize Dep)
7575
if (error.includes('504') && error.includes('Outdated Optimize Dep')) return false
7676

77+
// Filter Vite dev server HMR websocket noise: the Vite client only exists
78+
// in dev, and a full reload (e.g. after dependency re-optimization) or a
79+
// navigation mid-handshake closes the socket. Firefox surfaces that as an
80+
// uncaught error while Chromium silently reconnects.
81+
if (error.includes('[vite] failed to connect to websocket')) return false
82+
if (error.includes('WebSocket closed without opened') && error.includes('/@vite/client')) {
83+
return false
84+
}
85+
7786
// Filter generic "Failed to load resource: 404" errors if we have acceptable 404s
7887
// These console errors don't include the URL, so if we filtered out 404s,
7988
// we should also filter out the corresponding console errors
8089
if (
8190
error.includes('Failed to load resource') &&
8291
error.includes('404') &&
8392
acceptable404Urls.length > 0 &&
84-
failed404s.every((url) => acceptable404Urls.includes(url))
93+
failed404s.every(url => acceptable404Urls.includes(url))
8594
) {
8695
return false
8796
}
@@ -90,7 +99,7 @@ export function setupConsoleErrorChecker(page: Page): ConsoleErrorChecker {
9099
})
91100
},
92101
getFiltered404s: () =>
93-
failed404s.filter((url) => {
102+
failed404s.filter(url => {
94103
// favicon 404s are acceptable in dev
95104
if (url.includes('favicon.ico')) return false
96105

@@ -117,11 +126,11 @@ export function logConsoleErrors(errorChecker: ConsoleErrorChecker): void {
117126
// Always log what we found for debugging
118127
if (errorChecker.failed404s.length > 0) {
119128
console.log('\n🔍 404 Resources:')
120-
errorChecker.failed404s.forEach((url) => console.log(` - ${url}`))
129+
errorChecker.failed404s.forEach(url => console.log(` - ${url}`))
121130
}
122131
if (errorChecker.consoleErrors.length > 0) {
123132
console.log('\n❌ Console Errors:')
124-
errorChecker.consoleErrors.forEach((error) => {
133+
errorChecker.consoleErrors.forEach(error => {
125134
// Log full error message for diagnosis
126135
console.log(` - ${error}`)
127136
})

0 commit comments

Comments
 (0)