-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix flakiness of
error-hydration
test with turbopack
- Loading branch information
1 parent
7673889
commit b8b51e0
Showing
2 changed files
with
49 additions
and
73 deletions.
There are no files selected for viewing
115 changes: 46 additions & 69 deletions
115
test/production/error-hydration/error-hydration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,70 @@ | ||
import { NextInstance, nextTestSetup } from 'e2e-utils' | ||
|
||
async function setupErrorHydrationTests( | ||
next: NextInstance, | ||
targetPath: string | ||
) { | ||
const consoleMessages: string[] = [] | ||
|
||
const browser = await next.browser(targetPath, { | ||
beforePageLoad(page) { | ||
page.on('console', (event) => { | ||
consoleMessages.push(event.text()) | ||
}) | ||
}, | ||
}) | ||
|
||
return [browser, consoleMessages] as const | ||
} | ||
import { nextTestSetup } from 'e2e-utils' | ||
import { retry } from 'next-test-utils' | ||
|
||
describe('error-hydration', () => { | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
// Recommended for tests that need a full browser | ||
it('should log no error messages for server-side errors', async () => { | ||
const [, consoleMessages] = await setupErrorHydrationTests( | ||
next, | ||
'/with-error' | ||
it('should not log server-side errors', async () => { | ||
const browser = await next.browser('/with-error') | ||
const messages = await browser.log() | ||
|
||
expect(messages).not.toEqual( | ||
expect.arrayContaining([ | ||
{ | ||
message: expect.stringContaining('Error: custom error'), | ||
source: 'error', | ||
}, | ||
]) | ||
) | ||
|
||
expect( | ||
consoleMessages.find((message) => | ||
message.startsWith('A client-side exception has occurred') | ||
) | ||
).toBeUndefined() | ||
|
||
expect( | ||
consoleMessages.find( | ||
(message) => | ||
message === | ||
'{name: Internal Server Error., message: 500 - Internal Server Error., statusCode: 500}' | ||
) | ||
).toBeUndefined() | ||
}) | ||
|
||
it('should not invoke the error page getInitialProps client-side for server-side errors', async () => { | ||
const [b] = await setupErrorHydrationTests(next, '/with-error') | ||
const browser = await next.browser('/with-error') | ||
|
||
expect( | ||
await b.eval( | ||
await browser.eval( | ||
() => | ||
(window as any).__ERROR_PAGE_GET_INITIAL_PROPS_INVOKED_CLIENT_SIDE__ | ||
) | ||
).toBe(undefined) | ||
}) | ||
|
||
it('should log an message for client-side errors, including the full, custom error', async () => { | ||
const [browser, consoleMessages] = await setupErrorHydrationTests( | ||
next, | ||
'/no-error' | ||
) | ||
|
||
const link = await browser.elementByCss('a') | ||
await link.click() | ||
|
||
expect(consoleMessages.some((m) => m.includes('Error: custom error'))).toBe( | ||
true | ||
) | ||
|
||
expect( | ||
consoleMessages.some((m) => | ||
m.includes( | ||
'A client-side exception has occurred, see here for more info' | ||
) | ||
it('should log a message for client-side errors, including the full, custom error', async () => { | ||
const browser = await next.browser('/no-error') | ||
await browser.elementByCss('a').click() | ||
const messages = await browser.log() | ||
|
||
retry(() => { | ||
expect(messages).toEqual( | ||
expect.arrayContaining([ | ||
{ | ||
message: expect.stringContaining('Error: custom error'), | ||
source: 'error', | ||
}, | ||
{ | ||
message: expect.stringContaining( | ||
'A client-side exception has occurred, see here for more info' | ||
), | ||
source: 'error', | ||
}, | ||
]) | ||
) | ||
).toBe(true) | ||
}) | ||
}) | ||
|
||
it("invokes _error's getInitialProps for client-side errors", async () => { | ||
const [browser] = await setupErrorHydrationTests(next, '/no-error') | ||
|
||
const link = await browser.elementByCss('a') | ||
await link.click() | ||
|
||
expect( | ||
await browser.eval( | ||
() => | ||
(window as any).__ERROR_PAGE_GET_INITIAL_PROPS_INVOKED_CLIENT_SIDE__ | ||
) | ||
).toBe(true) | ||
const browser = await next.browser('/no-error') | ||
await browser.elementByCss('a').click() | ||
|
||
retry(async () => { | ||
expect( | ||
await browser.eval( | ||
() => | ||
(window as any).__ERROR_PAGE_GET_INITIAL_PROPS_INVOKED_CLIENT_SIDE__ | ||
) | ||
).toBe(true) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters