Unverified Commit deab0fec authored by Janka Uryga's avatar Janka Uryga Committed by GitHub

test: unflake instant-validation (#98854)

- in `dev`, wait for validation to run before asserting on a redbox
being open (encapsulated in `getInstantInsight`), which should reduce
flakiness in webpack
- in `start`, check if the build actually succeeded before running
tests. these builds seem to occasionally fail, but the cause is
currently unknown
parent 8a54c08e
...@@ -5280,7 +5280,13 @@ async function resolveLazyDevValidationInputs( ...@@ -5280,7 +5280,13 @@ async function resolveLazyDevValidationInputs(
} }
if ('syncInterruptReason' in inputs) { if ('syncInterruptReason' in inputs) {
await logMessagesAndSendErrorsToBrowser([inputs.syncInterruptReason], ctx) await logMessagesAndSendErrorsToBrowser(
[inputs.syncInterruptReason],
ctx,
// We're not going to run validation, so mark this as the validation result for tests.
{ logAsValidationResult: true }
)
return VALIDATION_BAILOUT return VALIDATION_BAILOUT
} }
return inputs return inputs
...@@ -5291,7 +5297,12 @@ function forwardErrorsFromWarmRender( ...@@ -5291,7 +5297,12 @@ function forwardErrorsFromWarmRender(
ctx: AppRenderContext ctx: AppRenderContext
) { ) {
if ('syncInterruptReason' in inputs) { if ('syncInterruptReason' in inputs) {
void logMessagesAndSendErrorsToBrowser([inputs.syncInterruptReason], ctx) void logMessagesAndSendErrorsToBrowser(
[inputs.syncInterruptReason],
ctx,
// We're not going to run validation, so mark this as the validation result for tests.
{ logAsValidationResult: true }
)
return true return true
} }
...@@ -6397,11 +6408,24 @@ function createAsyncApiPromises( ...@@ -6397,11 +6408,24 @@ function createAsyncApiPromises(
*/ */
async function logMessagesAndSendErrorsToBrowser( async function logMessagesAndSendErrorsToBrowser(
messages: unknown[], messages: unknown[],
ctx: AppRenderContext ctx: AppRenderContext,
options: { logAsValidationResult?: boolean } = {}
): Promise<void> { ): Promise<void> {
const { htmlRequestId, renderOpts } = ctx const logAsValidationResult =
process.env.__NEXT_TEST_MODE &&
process.env.NEXT_TEST_LOG_VALIDATION &&
options.logAsValidationResult
const { htmlRequestId, requestId, renderOpts } = ctx
const url = ctx.url.href
const { sendErrorsToBrowser } = renderOpts const { sendErrorsToBrowser } = renderOpts
if (logAsValidationResult) {
console.log(
formatValidationEvent({ type: 'validation_start', requestId, url })
)
}
const errors: Error[] = [] const errors: Error[] = []
for (const message of messages) { for (const message of messages) {
// Log the error to the CLI. Prevent the logs from being dimmed, which we // Log the error to the CLI. Prevent the logs from being dimmed, which we
...@@ -6421,6 +6445,12 @@ async function logMessagesAndSendErrorsToBrowser( ...@@ -6421,6 +6445,12 @@ async function logMessagesAndSendErrorsToBrowser(
} }
} }
if (logAsValidationResult) {
console.log(
formatValidationEvent({ type: 'validation_end', requestId, url })
)
}
if (errors.length > 0) { if (errors.length > 0) {
if (!sendErrorsToBrowser) { if (!sendErrorsToBrowser) {
throw new InvariantError( throw new InvariantError(
......
...@@ -42,7 +42,14 @@ describe('instant-validation-build', () => { ...@@ -42,7 +42,14 @@ describe('instant-validation-build', () => {
} }
beforeAll(async () => { beforeAll(async () => {
await next.build({ args: ['--experimental-build-mode', 'compile'] }) const result = await next.build({
args: ['--experimental-build-mode', 'compile'],
})
if (result.exitCode !== 0) {
throw new Error(
`Build exited with exit code ${result.exitCode}. CLI Output:\n\n${result.cliOutput}`
)
}
}) })
describe('basic dynamic hole detection', () => { describe('basic dynamic hole detection', () => {
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils' import { createGetInstantInsight } from 'e2e-utils/instant-validation'
import type { ValidationEvent } from 'next/dist/server/app-render/dev-validation-events'
describe('instant validation causes', () => { describe('instant validation causes', () => {
const { next, skipped, isNextDev } = nextTestSetup({ const { next, skipped, isNextDev } = nextTestSetup({
...@@ -28,67 +27,11 @@ describe('instant validation causes', () => { ...@@ -28,67 +27,11 @@ describe('instant validation causes', () => {
return next.cliOutput.slice(currentCliOutputIndex) return next.cliOutput.slice(currentCliOutputIndex)
} }
function parseValidationMessages(output: string): ValidationEvent[] { const getInstantInsight = createGetInstantInsight(getCliOutputSinceMark, next)
const messageRe = /<VALIDATION_MESSAGE>(.*?)<\/VALIDATION_MESSAGE>/g
const events: ValidationEvent[] = []
let match: RegExpExecArray | null
while ((match = messageRe.exec(output)) !== null) {
try {
events.push(JSON.parse(match[1]))
} catch (err) {
throw new Error(`Failed to parse message '${match[1]}'`, {
cause: err,
})
}
}
return events
}
function normalizeValidationUrl(url: string): string {
const parsed = new URL(url, 'http://n')
parsed.searchParams.delete('_rsc')
return parsed.pathname + parsed.search + parsed.hash
}
async function waitForValidation(targetUrl: string) {
const parsedTargetUrl = new URL(targetUrl)
const relativeTargetUrl =
parsedTargetUrl.pathname + parsedTargetUrl.search + parsedTargetUrl.hash
const requestId = await retry(
async () => {
const events = parseValidationMessages(getCliOutputSinceMark())
const start = events.find(
(e) =>
e.type === 'validation_start' &&
normalizeValidationUrl(e.url) === relativeTargetUrl
)
expect(start).toBeDefined()
return start!.requestId
},
undefined,
undefined,
`wait for validation of '${relativeTargetUrl}' to start`
)
await retry(
async () => {
const events = parseValidationMessages(getCliOutputSinceMark())
const end = events.find(
(e) => e.type === 'validation_end' && e.requestId === requestId
)
expect(end).toBeDefined()
},
undefined,
undefined,
'wait for validation to end'
)
}
it('named export - export { instant }', async () => { it('named export - export { instant }', async () => {
const browser = await next.browser('/named-export') const browser = await next.browser('/named-export')
await waitForValidation(await browser.url()) expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
await expect(browser).toDisplayCollapsedRedbox(`
{ {
"cause": [ "cause": [
{ {
...@@ -117,8 +60,7 @@ describe('instant validation causes', () => { ...@@ -117,8 +60,7 @@ describe('instant validation causes', () => {
it('aliased export - export { instantConfig as instant }', async () => { it('aliased export - export { instantConfig as instant }', async () => {
const browser = await next.browser('/aliased-export') const browser = await next.browser('/aliased-export')
await waitForValidation(await browser.url()) expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
await expect(browser).toDisplayCollapsedRedbox(`
{ {
"cause": [ "cause": [
{ {
...@@ -147,8 +89,7 @@ describe('instant validation causes', () => { ...@@ -147,8 +89,7 @@ describe('instant validation causes', () => {
it('re-export - export { instant } from "./config"', async () => { it('re-export - export { instant } from "./config"', async () => {
const browser = await next.browser('/reexport') const browser = await next.browser('/reexport')
await waitForValidation(await browser.url()) expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
await expect(browser).toDisplayCollapsedRedbox(`
{ {
"cause": [ "cause": [
{ {
...@@ -177,11 +118,10 @@ describe('instant validation causes', () => { ...@@ -177,11 +118,10 @@ describe('instant validation causes', () => {
it('indirect export - const instantConfig = _instant; export { instantConfig as instant }', async () => { it('indirect export - const instantConfig = _instant; export { instantConfig as instant }', async () => {
const browser = await next.browser('/indirect-export') const browser = await next.browser('/indirect-export')
await waitForValidation(await browser.url())
// Ideally we'd be pointing at the original value declaration. // Ideally we'd be pointing at the original value declaration.
// We're not following declarations recursively mostly to keep the implementation simpler // We're not following declarations recursively mostly to keep the implementation simpler
// presuming that almost all configs are just `export const instant = ...` // presuming that almost all configs are just `export const instant = ...`
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { expectBuildValidationSkipped } from 'e2e-utils/instant-validation' import {
createGetInstantInsight,
expectBuildValidationSkipped,
} from 'e2e-utils/instant-validation'
import { waitForNoErrorToast } from '../../../lib/next-test-utils' import { waitForNoErrorToast } from '../../../lib/next-test-utils'
// This fixture intentionally omits `experimental.instantInsights` from // This fixture intentionally omits `experimental.instantInsights` from
...@@ -27,9 +30,30 @@ describe('instant validation - default level', () => { ...@@ -27,9 +30,30 @@ describe('instant validation - default level', () => {
return return
} }
let currentCliOutputIndex = 0
beforeEach(() => {
currentCliOutputIndex = next.cliOutput.length
})
function getCliOutputSinceMark(): string {
if (next.cliOutput.length < currentCliOutputIndex) {
currentCliOutputIndex = 0
}
return next.cliOutput.slice(currentCliOutputIndex)
}
const getInstantInsight = createGetInstantInsight(getCliOutputSinceMark, next)
if (isNextStart) { if (isNextStart) {
beforeAll(async () => { beforeAll(async () => {
await next.build({ args: ['--experimental-build-mode', 'compile'] }) const result = await next.build({
args: ['--experimental-build-mode', 'compile'],
})
if (result.exitCode !== 0) {
throw new Error(
`Build exited with exit code ${result.exitCode}. CLI Output:\n\n${result.cliOutput}`
)
}
}) })
afterEach(async () => { afterEach(async () => {
await next.stop() await next.stop()
...@@ -55,7 +79,7 @@ describe('instant validation - default level', () => { ...@@ -55,7 +79,7 @@ describe('instant validation - default level', () => {
describe('dev', () => { describe('dev', () => {
it('bare page: framework default matches `warning`, implicit validation fires', async () => { it('bare page: framework default matches `warning`, implicit validation fires', async () => {
const browser = await next.browser('/bare') const browser = await next.browser('/bare')
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"description": "Next.js encountered uncached data during a navigation.", "description": "Next.js encountered uncached data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { import {
createGetInstantInsight,
expectBuildValidationSkipped, expectBuildValidationSkipped,
extractBuildValidationError, extractBuildValidationError,
} from 'e2e-utils/instant-validation' } from 'e2e-utils/instant-validation'
...@@ -21,9 +22,30 @@ describe('instant validation - level error', () => { ...@@ -21,9 +22,30 @@ describe('instant validation - level error', () => {
return return
} }
let currentCliOutputIndex = 0
beforeEach(() => {
currentCliOutputIndex = next.cliOutput.length
})
function getCliOutputSinceMark(): string {
if (next.cliOutput.length < currentCliOutputIndex) {
currentCliOutputIndex = 0
}
return next.cliOutput.slice(currentCliOutputIndex)
}
const getInstantInsight = createGetInstantInsight(getCliOutputSinceMark, next)
if (isNextStart) { if (isNextStart) {
beforeAll(async () => { beforeAll(async () => {
await next.build({ args: ['--experimental-build-mode', 'compile'] }) const result = await next.build({
args: ['--experimental-build-mode', 'compile'],
})
if (result.exitCode !== 0) {
throw new Error(
`Build exited with exit code ${result.exitCode}. CLI Output:\n\n${result.cliOutput}`
)
}
}) })
afterEach(async () => { afterEach(async () => {
await next.stop() await next.stop()
...@@ -58,7 +80,7 @@ describe('instant validation - level error', () => { ...@@ -58,7 +80,7 @@ describe('instant validation - level error', () => {
describe('dev', () => { describe('dev', () => {
it('bare page: implicit validation surfaces a redbox (error level fires)', async () => { it('bare page: implicit validation surfaces a redbox (error level fires)', async () => {
const browser = await next.browser('/bare') const browser = await next.browser('/bare')
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"description": "Next.js encountered uncached data during a navigation.", "description": "Next.js encountered uncached data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
...@@ -75,7 +97,7 @@ describe('instant validation - level error', () => { ...@@ -75,7 +97,7 @@ describe('instant validation - level error', () => {
it('explicit-error page: explicit override at the configured level, instant redbox in dev', async () => { it('explicit-error page: explicit override at the configured level, instant redbox in dev', async () => {
const browser = await next.browser('/explicit-error') const browser = await next.browser('/explicit-error')
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -104,7 +126,7 @@ describe('instant validation - level error', () => { ...@@ -104,7 +126,7 @@ describe('instant validation - level error', () => {
it('explicit-true page: aliases to error level, instant redbox in dev', async () => { it('explicit-true page: aliases to error level, instant redbox in dev', async () => {
const browser = await next.browser('/explicit-true') const browser = await next.browser('/explicit-true')
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -133,7 +155,7 @@ describe('instant validation - level error', () => { ...@@ -133,7 +155,7 @@ describe('instant validation - level error', () => {
it('explicit-warning page: per-segment de-escalation still validates in dev', async () => { it('explicit-warning page: per-segment de-escalation still validates in dev', async () => {
const browser = await next.browser('/explicit-warning') const browser = await next.browser('/explicit-warning')
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -171,7 +193,7 @@ describe('instant validation - level error', () => { ...@@ -171,7 +193,7 @@ describe('instant validation - level error', () => {
// that's per-segment — it doesn't shield descendants. The bare // that's per-segment — it doesn't shield descendants. The bare
// page should still surface an instant redbox in dev. // page should still surface an instant redbox in dev.
const browser = await next.browser('/layered') const browser = await next.browser('/layered')
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"description": "Next.js encountered uncached data during a navigation.", "description": "Next.js encountered uncached data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { import {
createGetInstantInsight,
expectBuildValidationSkipped, expectBuildValidationSkipped,
extractBuildValidationError, extractBuildValidationError,
} from 'e2e-utils/instant-validation' } from 'e2e-utils/instant-validation'
...@@ -21,9 +22,30 @@ describe('instant validation - level manual-error', () => { ...@@ -21,9 +22,30 @@ describe('instant validation - level manual-error', () => {
return return
} }
let currentCliOutputIndex = 0
beforeEach(() => {
currentCliOutputIndex = next.cliOutput.length
})
function getCliOutputSinceMark(): string {
if (next.cliOutput.length < currentCliOutputIndex) {
currentCliOutputIndex = 0
}
return next.cliOutput.slice(currentCliOutputIndex)
}
const getInstantInsight = createGetInstantInsight(getCliOutputSinceMark, next)
if (isNextStart) { if (isNextStart) {
beforeAll(async () => { beforeAll(async () => {
await next.build({ args: ['--experimental-build-mode', 'compile'] }) const result = await next.build({
args: ['--experimental-build-mode', 'compile'],
})
if (result.exitCode !== 0) {
throw new Error(
`Build exited with exit code ${result.exitCode}. CLI Output:\n\n${result.cliOutput}`
)
}
}) })
afterEach(async () => { afterEach(async () => {
await next.stop() await next.stop()
...@@ -65,7 +87,7 @@ describe('instant validation - level manual-error', () => { ...@@ -65,7 +87,7 @@ describe('instant validation - level manual-error', () => {
it('explicit-error page: explicit override at the configured level, instant redbox in dev', async () => { it('explicit-error page: explicit override at the configured level, instant redbox in dev', async () => {
const browser = await next.browser('/explicit-error') const browser = await next.browser('/explicit-error')
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -94,7 +116,7 @@ describe('instant validation - level manual-error', () => { ...@@ -94,7 +116,7 @@ describe('instant validation - level manual-error', () => {
it('explicit-true page: aliases to error level, instant redbox in dev', async () => { it('explicit-true page: aliases to error level, instant redbox in dev', async () => {
const browser = await next.browser('/explicit-true') const browser = await next.browser('/explicit-true')
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -123,7 +145,7 @@ describe('instant validation - level manual-error', () => { ...@@ -123,7 +145,7 @@ describe('instant validation - level manual-error', () => {
it('explicit-warning page: per-segment de-escalation still validates in dev', async () => { it('explicit-warning page: per-segment de-escalation still validates in dev', async () => {
const browser = await next.browser('/explicit-warning') const browser = await next.browser('/explicit-warning')
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { import {
createGetInstantInsight,
expectBuildValidationSkipped, expectBuildValidationSkipped,
extractBuildValidationError, extractBuildValidationError,
parseValidationMessages, parseValidationMessages,
...@@ -23,9 +24,30 @@ describe('instant validation - level manual-warning', () => { ...@@ -23,9 +24,30 @@ describe('instant validation - level manual-warning', () => {
return return
} }
let currentCliOutputIndex = 0
beforeEach(() => {
currentCliOutputIndex = next.cliOutput.length
})
function getCliOutputSinceMark(): string {
if (next.cliOutput.length < currentCliOutputIndex) {
currentCliOutputIndex = 0
}
return next.cliOutput.slice(currentCliOutputIndex)
}
const getInstantInsight = createGetInstantInsight(getCliOutputSinceMark, next)
if (isNextStart) { if (isNextStart) {
beforeAll(async () => { beforeAll(async () => {
await next.build({ args: ['--experimental-build-mode', 'compile'] }) const result = await next.build({
args: ['--experimental-build-mode', 'compile'],
})
if (result.exitCode !== 0) {
throw new Error(
`Build exited with exit code ${result.exitCode}. CLI Output:\n\n${result.cliOutput}`
)
}
}) })
afterEach(async () => { afterEach(async () => {
await next.stop() await next.stop()
...@@ -79,7 +101,7 @@ describe('instant validation - level manual-warning', () => { ...@@ -79,7 +101,7 @@ describe('instant validation - level manual-warning', () => {
const browser = await next.browser( const browser = await next.browser(
'/with-root-suspense/explicit-error' '/with-root-suspense/explicit-error'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -110,7 +132,7 @@ describe('instant validation - level manual-warning', () => { ...@@ -110,7 +132,7 @@ describe('instant validation - level manual-warning', () => {
const browser = await next.browser( const browser = await next.browser(
'/with-root-suspense/explicit-true' '/with-root-suspense/explicit-true'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -141,7 +163,7 @@ describe('instant validation - level manual-warning', () => { ...@@ -141,7 +163,7 @@ describe('instant validation - level manual-warning', () => {
const browser = await next.browser( const browser = await next.browser(
'/with-root-suspense/explicit-warning' '/with-root-suspense/explicit-warning'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -224,7 +246,7 @@ describe('instant validation - level manual-warning', () => { ...@@ -224,7 +246,7 @@ describe('instant validation - level manual-warning', () => {
// the top of the page. The captured snapshot should NOT contain // the top of the page. The captured snapshot should NOT contain
// the "Instant" label — that's the proof that instant validation // the "Instant" label — that's the proof that instant validation
// did not run under 'manual-warning'. // did not run under 'manual-warning'.
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"description": "Next.js encountered uncached data during prerendering.", "description": "Next.js encountered uncached data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
...@@ -243,7 +265,7 @@ describe('instant validation - level manual-warning', () => { ...@@ -243,7 +265,7 @@ describe('instant validation - level manual-warning', () => {
const browser = await next.browser( const browser = await next.browser(
'/without-root-suspense/explicit-error' '/without-root-suspense/explicit-error'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"description": "Next.js encountered uncached data during prerendering.", "description": "Next.js encountered uncached data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
...@@ -262,7 +284,7 @@ describe('instant validation - level manual-warning', () => { ...@@ -262,7 +284,7 @@ describe('instant validation - level manual-warning', () => {
const browser = await next.browser( const browser = await next.browser(
'/without-root-suspense/explicit-true' '/without-root-suspense/explicit-true'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"description": "Next.js encountered uncached data during prerendering.", "description": "Next.js encountered uncached data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
...@@ -281,7 +303,7 @@ describe('instant validation - level manual-warning', () => { ...@@ -281,7 +303,7 @@ describe('instant validation - level manual-warning', () => {
const browser = await next.browser( const browser = await next.browser(
'/without-root-suspense/explicit-warning' '/without-root-suspense/explicit-warning'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"description": "Next.js encountered uncached data during prerendering.", "description": "Next.js encountered uncached data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { import {
createGetInstantInsight,
expectBuildValidationSkipped, expectBuildValidationSkipped,
extractBuildValidationError, extractBuildValidationError,
} from 'e2e-utils/instant-validation' } from 'e2e-utils/instant-validation'
...@@ -21,9 +22,30 @@ describe('instant validation - level warning', () => { ...@@ -21,9 +22,30 @@ describe('instant validation - level warning', () => {
return return
} }
let currentCliOutputIndex = 0
beforeEach(() => {
currentCliOutputIndex = next.cliOutput.length
})
function getCliOutputSinceMark(): string {
if (next.cliOutput.length < currentCliOutputIndex) {
currentCliOutputIndex = 0
}
return next.cliOutput.slice(currentCliOutputIndex)
}
const getInstantInsight = createGetInstantInsight(getCliOutputSinceMark, next)
if (isNextStart) { if (isNextStart) {
beforeAll(async () => { beforeAll(async () => {
await next.build({ args: ['--experimental-build-mode', 'compile'] }) const result = await next.build({
args: ['--experimental-build-mode', 'compile'],
})
if (result.exitCode !== 0) {
throw new Error(
`Build exited with exit code ${result.exitCode}. CLI Output:\n\n${result.cliOutput}`
)
}
}) })
afterEach(async () => { afterEach(async () => {
await next.stop() await next.stop()
...@@ -58,7 +80,7 @@ describe('instant validation - level warning', () => { ...@@ -58,7 +80,7 @@ describe('instant validation - level warning', () => {
describe('dev', () => { describe('dev', () => {
it('bare page: implicit validation surfaces a redbox (warning level fires)', async () => { it('bare page: implicit validation surfaces a redbox (warning level fires)', async () => {
const browser = await next.browser('/bare') const browser = await next.browser('/bare')
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"description": "Next.js encountered uncached data during a navigation.", "description": "Next.js encountered uncached data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
...@@ -75,7 +97,7 @@ describe('instant validation - level warning', () => { ...@@ -75,7 +97,7 @@ describe('instant validation - level warning', () => {
it('explicit-error page: instant redbox surfaces in dev', async () => { it('explicit-error page: instant redbox surfaces in dev', async () => {
const browser = await next.browser('/explicit-error') const browser = await next.browser('/explicit-error')
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -104,7 +126,7 @@ describe('instant validation - level warning', () => { ...@@ -104,7 +126,7 @@ describe('instant validation - level warning', () => {
it('explicit-true page: aliases to warning level, instant redbox in dev', async () => { it('explicit-true page: aliases to warning level, instant redbox in dev', async () => {
const browser = await next.browser('/explicit-true') const browser = await next.browser('/explicit-true')
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -133,7 +155,7 @@ describe('instant validation - level warning', () => { ...@@ -133,7 +155,7 @@ describe('instant validation - level warning', () => {
it('explicit-warning page: explicit override at the configured level, instant redbox in dev', async () => { it('explicit-warning page: explicit override at the configured level, instant redbox in dev', async () => {
const browser = await next.browser('/explicit-warning') const browser = await next.browser('/explicit-warning')
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -171,7 +193,7 @@ describe('instant validation - level warning', () => { ...@@ -171,7 +193,7 @@ describe('instant validation - level warning', () => {
// that's per-segment — it doesn't shield descendants. The bare // that's per-segment — it doesn't shield descendants. The bare
// page should still surface an instant redbox in dev. // page should still surface an instant redbox in dev.
const browser = await next.browser('/layered') const browser = await next.browser('/layered')
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"description": "Next.js encountered uncached data during a navigation.", "description": "Next.js encountered uncached data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { createGetInstantInsight } from 'e2e-utils/instant-validation'
import { waitForNoErrorToast } from 'next-test-utils' import { waitForNoErrorToast } from 'next-test-utils'
import { join } from 'node:path' import { join } from 'node:path'
...@@ -35,14 +36,34 @@ describe('instant validation', () => { ...@@ -35,14 +36,34 @@ describe('instant validation', () => {
const { next, isNextDev } = nextTestSetup({ const { next, isNextDev } = nextTestSetup({
files: join(__dirname, 'fixtures', 'invalid-blocking-page-below-static'), files: join(__dirname, 'fixtures', 'invalid-blocking-page-below-static'),
skipStart: true, skipStart: true,
env: {
NEXT_TEST_LOG_VALIDATION: '1',
},
}) })
let currentCliOutputIndex = 0
beforeEach(() => {
currentCliOutputIndex = next.cliOutput.length
})
function getCliOutputSinceMark(): string {
if (next.cliOutput.length < currentCliOutputIndex) {
currentCliOutputIndex = 0
}
return next.cliOutput.slice(currentCliOutputIndex)
}
const getInstantInsight = createGetInstantInsight(
getCliOutputSinceMark,
next
)
if (isNextDev) { if (isNextDev) {
beforeAll(() => next.start()) beforeAll(() => next.start())
it('errors in dev', async () => { it('errors in dev', async () => {
const browser = await next.browser('/blocking-page-below-static') const browser = await next.browser('/blocking-page-below-static')
await browser.elementByCss('main') await browser.elementByCss('main')
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"description": "Next.js encountered uncached data during prerendering.", "description": "Next.js encountered uncached data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
......
...@@ -25,6 +25,7 @@ export function registerClientTests(ctx: InstantValidationCaseContext) { ...@@ -25,6 +25,7 @@ export function registerClientTests(ctx: InstantValidationCaseContext) {
isClientNav, isClientNav,
navigateTo, navigateTo,
expectNoDevValidationErrors, expectNoDevValidationErrors,
getInstantInsight,
getCliOutputSinceMark, getCliOutputSinceMark,
prerender, prerender,
} = ctx } = ctx
...@@ -35,7 +36,7 @@ export function registerClientTests(ctx: InstantValidationCaseContext) { ...@@ -35,7 +36,7 @@ export function registerClientTests(ctx: InstantValidationCaseContext) {
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/static/invalid-client-data-blocks-validation' '/suspense-in-root/static/invalid-client-data-blocks-validation'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -208,6 +209,7 @@ export function registerClientTests(ctx: InstantValidationCaseContext) { ...@@ -208,6 +209,7 @@ export function registerClientTests(ctx: InstantValidationCaseContext) {
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/static/invalid-client-error-in-parent-blocks-children' '/suspense-in-root/static/invalid-client-error-in-parent-blocks-children'
) )
await waitForValidation(await browser.url(), getCliOutputSinceMark)
// We expect a collapsed redbox. We need to open it to assert on the messages. // We expect a collapsed redbox. We need to open it to assert on the messages.
await openRedbox(browser) await openRedbox(browser)
...@@ -313,6 +315,7 @@ export function registerClientTests(ctx: InstantValidationCaseContext) { ...@@ -313,6 +315,7 @@ export function registerClientTests(ctx: InstantValidationCaseContext) {
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/static/invalid-error-in-node-modules-blocks-children' '/suspense-in-root/static/invalid-error-in-node-modules-blocks-children'
) )
await waitForValidation(await browser.url(), getCliOutputSinceMark)
// We expect a collapsed redbox. We need to open it to assert on the messages. // We expect a collapsed redbox. We need to open it to assert on the messages.
await openRedbox(browser) await openRedbox(browser)
...@@ -399,7 +402,7 @@ export function registerClientTests(ctx: InstantValidationCaseContext) { ...@@ -399,7 +402,7 @@ export function registerClientTests(ctx: InstantValidationCaseContext) {
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/static/invalid-csr-bailout-blocks-children' '/suspense-in-root/static/invalid-csr-bailout-blocks-children'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
[ [
{ {
"description": "Route "/suspense-in-root/static/invalid-csr-bailout-blocks-children": Could not validate \`instant\` because the target segment was prevented from rendering, likely due to the following error.", "description": "Route "/suspense-in-root/static/invalid-csr-bailout-blocks-children": Could not validate \`instant\` because the target segment was prevented from rendering, likely due to the following error.",
......
import { nextTestSetup, type NextInstance, type Playwright } from 'e2e-utils' import { nextTestSetup, type NextInstance, type Playwright } from 'e2e-utils'
import { waitForValidation } from 'e2e-utils/instant-validation' import {
createGetInstantInsight,
waitForValidation,
} from 'e2e-utils/instant-validation'
import { retry, waitForNoErrorToast } from '../../../lib/next-test-utils' import { retry, waitForNoErrorToast } from '../../../lib/next-test-utils'
export interface InstantValidationCaseContext { export interface InstantValidationCaseContext {
...@@ -20,6 +23,7 @@ export interface InstantValidationCaseContext { ...@@ -20,6 +23,7 @@ export interface InstantValidationCaseContext {
browser: Playwright, browser: Playwright,
url: string url: string
) => Promise<void> ) => Promise<void>
getInstantInsight: ReturnType<typeof createGetInstantInsight>
getCliOutputSinceMark: () => string getCliOutputSinceMark: () => string
/** Prerender a single page with `--experimental-build-mode generate` */ /** Prerender a single page with `--experimental-build-mode generate` */
...@@ -74,6 +78,11 @@ export function runInstantValidationTests( ...@@ -74,6 +78,11 @@ export function runInstantValidationTests(
return next.cliOutput.slice(currentCliOutputIndex) return next.cliOutput.slice(currentCliOutputIndex)
} }
const getInstantInsight = createGetInstantInsight(
getCliOutputSinceMark,
next
)
async function restartDevServerToEnsureColdCaches() { async function restartDevServerToEnsureColdCaches() {
if (isNextDev) { if (isNextDev) {
// Ensure caches are cold. // Ensure caches are cold.
...@@ -87,7 +96,14 @@ export function runInstantValidationTests( ...@@ -87,7 +96,14 @@ export function runInstantValidationTests(
if (isNextStart) { if (isNextStart) {
// Compile the app first so that `prerender` can run individual prerenders. // Compile the app first so that `prerender` can run individual prerenders.
beforeAll(async () => { beforeAll(async () => {
await next.build({ args: ['--experimental-build-mode', 'compile'] }) const result = await next.build({
args: ['--experimental-build-mode', 'compile'],
})
if (result.exitCode !== 0) {
throw new Error(
`Build exited with exit code ${result.exitCode}. CLI Output:\n\n${result.cliOutput}`
)
}
}) })
afterEach(async () => { afterEach(async () => {
await next.stop() await next.stop()
...@@ -246,6 +262,7 @@ export function runInstantValidationTests( ...@@ -246,6 +262,7 @@ export function runInstantValidationTests(
warmCachesAndNavigateTo, warmCachesAndNavigateTo,
restartDevServerToEnsureColdCaches, restartDevServerToEnsureColdCaches,
expectNoDevValidationErrors, expectNoDevValidationErrors,
getInstantInsight,
getCliOutputSinceMark, getCliOutputSinceMark,
prerender, prerender,
}) })
......
...@@ -18,6 +18,7 @@ export function registerHeadAndReportingTests( ...@@ -18,6 +18,7 @@ export function registerHeadAndReportingTests(
warmCachesAndNavigateTo, warmCachesAndNavigateTo,
restartDevServerToEnsureColdCaches, restartDevServerToEnsureColdCaches,
expectNoDevValidationErrors, expectNoDevValidationErrors,
getInstantInsight,
getCliOutputSinceMark, getCliOutputSinceMark,
prerender, prerender,
} = ctx } = ctx
...@@ -62,7 +63,7 @@ export function registerHeadAndReportingTests( ...@@ -62,7 +63,7 @@ export function registerHeadAndReportingTests(
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/head/invalid-runtime-viewport-in-static' '/suspense-in-root/head/invalid-runtime-viewport-in-static'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -120,7 +121,7 @@ export function registerHeadAndReportingTests( ...@@ -120,7 +121,7 @@ export function registerHeadAndReportingTests(
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/head/invalid-dynamic-viewport-in-runtime' '/suspense-in-root/head/invalid-dynamic-viewport-in-runtime'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -216,7 +217,7 @@ export function registerHeadAndReportingTests( ...@@ -216,7 +217,7 @@ export function registerHeadAndReportingTests(
'/suspense-in-root/head/invalid-dynamic-viewport-in-blocking-inside-static' '/suspense-in-root/head/invalid-dynamic-viewport-in-blocking-inside-static'
) )
// TODO(instant-validation): why aren't we pointing to `await connection()` here? // TODO(instant-validation): why aren't we pointing to `await connection()` here?
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -287,7 +288,7 @@ export function registerHeadAndReportingTests( ...@@ -287,7 +288,7 @@ export function registerHeadAndReportingTests(
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/static/multi-depth-deferred-fallback/inner' '/suspense-in-root/static/multi-depth-deferred-fallback/inner'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"description": "Next.js could not validate that a segment in your UI has instant navigation.", "description": "Next.js could not validate that a segment in your UI has instant navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
...@@ -344,7 +345,7 @@ export function registerHeadAndReportingTests( ...@@ -344,7 +345,7 @@ export function registerHeadAndReportingTests(
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/static/test-firstmod/inter/inner' '/suspense-in-root/static/test-firstmod/inter/inner'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"description": "Next.js could not validate that a segment in your UI has instant navigation.", "description": "Next.js could not validate that a segment in your UI has instant navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
...@@ -399,7 +400,7 @@ export function registerHeadAndReportingTests( ...@@ -399,7 +400,7 @@ export function registerHeadAndReportingTests(
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/static/test-multi-unrendered' '/suspense-in-root/static/test-multi-unrendered'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"description": "Next.js could not validate that a segment in your UI has instant navigation.", "description": "Next.js could not validate that a segment in your UI has instant navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
...@@ -530,7 +531,7 @@ export function registerHeadAndReportingTests( ...@@ -530,7 +531,7 @@ export function registerHeadAndReportingTests(
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/disable-validation/disable-build' '/suspense-in-root/disable-validation/disable-build'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -617,7 +618,7 @@ export function registerHeadAndReportingTests( ...@@ -617,7 +618,7 @@ export function registerHeadAndReportingTests(
it('invalid - unguarded params in a runtime-prefetchable shell', async () => { it('invalid - unguarded params in a runtime-prefetchable shell', async () => {
if (isNextDev) { if (isNextDev) {
const browser = await navigateTo('/shells/invalid-runtime-params/123') const browser = await navigateTo('/shells/invalid-runtime-params/123')
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -724,7 +725,7 @@ export function registerHeadAndReportingTests( ...@@ -724,7 +725,7 @@ export function registerHeadAndReportingTests(
}" }"
`) `)
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -785,7 +786,7 @@ export function registerHeadAndReportingTests( ...@@ -785,7 +786,7 @@ export function registerHeadAndReportingTests(
'/shells/invalid-static-with-gsp-metadata/123' '/shells/invalid-static-with-gsp-metadata/123'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -833,7 +834,7 @@ export function registerHeadAndReportingTests( ...@@ -833,7 +834,7 @@ export function registerHeadAndReportingTests(
const browser = await navigateTo( const browser = await navigateTo(
'/shells/invalid-static-with-gsp/123' '/shells/invalid-static-with-gsp/123'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -908,7 +909,7 @@ export function registerHeadAndReportingTests( ...@@ -908,7 +909,7 @@ export function registerHeadAndReportingTests(
it('with cold caches', async () => { it('with cold caches', async () => {
if (isNextDev) { if (isNextDev) {
const browser = await navigateTo(routeInBrowser) const browser = await navigateTo(routeInBrowser)
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -963,7 +964,7 @@ export function registerHeadAndReportingTests( ...@@ -963,7 +964,7 @@ export function registerHeadAndReportingTests(
it('with warm caches', async () => { it('with warm caches', async () => {
const browser = await warmCachesAndNavigateTo(routeInBrowser) const browser = await warmCachesAndNavigateTo(routeInBrowser)
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -1052,7 +1053,7 @@ export function registerHeadAndReportingTests( ...@@ -1052,7 +1053,7 @@ export function registerHeadAndReportingTests(
const browser = await navigateTo( const browser = await navigateTo(
'/shells/invalid-navigation-without-suspense' '/shells/invalid-navigation-without-suspense'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -1125,7 +1126,7 @@ export function registerHeadAndReportingTests( ...@@ -1125,7 +1126,7 @@ export function registerHeadAndReportingTests(
const browser = await navigateTo( const browser = await navigateTo(
'/shells/invalid-prefetch-without-suspense' '/shells/invalid-prefetch-without-suspense'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -1309,7 +1310,7 @@ export function registerHeadAndReportingTests( ...@@ -1309,7 +1310,7 @@ export function registerHeadAndReportingTests(
it('with cold caches', async () => { it('with cold caches', async () => {
if (isNextDev) { if (isNextDev) {
const browser = await navigateTo(route) const browser = await navigateTo(route)
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -1365,7 +1366,7 @@ export function registerHeadAndReportingTests( ...@@ -1365,7 +1366,7 @@ export function registerHeadAndReportingTests(
it('with warm caches', async () => { it('with warm caches', async () => {
const browser = await warmCachesAndNavigateTo(route) const browser = await warmCachesAndNavigateTo(route)
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -1404,7 +1405,7 @@ export function registerHeadAndReportingTests( ...@@ -1404,7 +1405,7 @@ export function registerHeadAndReportingTests(
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/blocking-attribution/dynamic-then-dynamic' '/suspense-in-root/blocking-attribution/dynamic-then-dynamic'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -1465,7 +1466,7 @@ export function registerHeadAndReportingTests( ...@@ -1465,7 +1466,7 @@ export function registerHeadAndReportingTests(
'/suspense-in-root/blocking-attribution/runtime-then-runtime' '/suspense-in-root/blocking-attribution/runtime-then-runtime'
) )
if (partialPrefetching) { if (partialPrefetching) {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -1492,7 +1493,7 @@ export function registerHeadAndReportingTests( ...@@ -1492,7 +1493,7 @@ export function registerHeadAndReportingTests(
} }
`) `)
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -1580,7 +1581,7 @@ export function registerHeadAndReportingTests( ...@@ -1580,7 +1581,7 @@ export function registerHeadAndReportingTests(
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/blocking-attribution/session-then-dynamic' '/suspense-in-root/blocking-attribution/session-then-dynamic'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
......
import { nextTestSetup, type Playwright } from 'e2e-utils' import { nextTestSetup, type Playwright } from 'e2e-utils'
import { import {
createGetInstantInsight,
expectBuildValidationSkipped, expectBuildValidationSkipped,
expectNoBuildValidationErrors, expectNoBuildValidationErrors,
extractBuildValidationError, extractBuildValidationError,
...@@ -26,7 +27,12 @@ describe('instant validation - parallel slot configs', () => { ...@@ -26,7 +27,12 @@ describe('instant validation - parallel slot configs', () => {
if (isNextStart) { if (isNextStart) {
beforeAll(async () => { beforeAll(async () => {
await next.build({ args: ['--experimental-build-mode', 'compile'] }) const result = await next.build({
args: ['--experimental-build-mode', 'compile'],
})
if (result.exitCode !== 0) {
throw new Error('Failed to build. CLI Output:\n\n' + result.cliOutput)
}
}) })
afterEach(async () => { afterEach(async () => {
await next.stop() await next.stop()
...@@ -49,6 +55,8 @@ describe('instant validation - parallel slot configs', () => { ...@@ -49,6 +55,8 @@ describe('instant validation - parallel slot configs', () => {
return next.cliOutput.slice(currentCliOutputIndex) return next.cliOutput.slice(currentCliOutputIndex)
} }
const getInstantInsight = createGetInstantInsight(getCliOutputSinceMark, next)
const prerender = async (pathname: string) => { const prerender = async (pathname: string) => {
const args = [ const args = [
'--experimental-build-mode', '--experimental-build-mode',
...@@ -110,7 +118,7 @@ describe('instant validation - parallel slot configs', () => { ...@@ -110,7 +118,7 @@ describe('instant validation - parallel slot configs', () => {
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/parallel/slot-config-only' '/suspense-in-root/parallel/slot-config-only'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -168,7 +176,7 @@ describe('instant validation - parallel slot configs', () => { ...@@ -168,7 +176,7 @@ describe('instant validation - parallel slot configs', () => {
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/parallel/slot-layout-config' '/suspense-in-root/parallel/slot-layout-config'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -247,7 +255,7 @@ describe('instant validation - parallel slot configs', () => { ...@@ -247,7 +255,7 @@ describe('instant validation - parallel slot configs', () => {
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/parallel/children-config-with-slot' '/suspense-in-root/parallel/children-config-with-slot'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -306,7 +314,7 @@ describe('instant validation - parallel slot configs', () => { ...@@ -306,7 +314,7 @@ describe('instant validation - parallel slot configs', () => {
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/parallel/fork-layout-config-with-slot' '/suspense-in-root/parallel/fork-layout-config-with-slot'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
[ [
{ {
"cause": [ "cause": [
...@@ -470,7 +478,7 @@ describe('instant validation - parallel slot configs', () => { ...@@ -470,7 +478,7 @@ describe('instant validation - parallel slot configs', () => {
'/suspense-in-root/parallel/conditional-breadcrumbs/show-both/blocked' '/suspense-in-root/parallel/conditional-breadcrumbs/show-both/blocked'
if (isNextDev) { if (isNextDev) {
const browser = await navigateTo(href) const browser = await navigateTo(href)
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -528,7 +536,7 @@ describe('instant validation - parallel slot configs', () => { ...@@ -528,7 +536,7 @@ describe('instant validation - parallel slot configs', () => {
'/suspense-in-root/parallel/conditional-breadcrumbs/show-only-breadcrumbs/unblocked' '/suspense-in-root/parallel/conditional-breadcrumbs/show-only-breadcrumbs/unblocked'
if (isNextDev) { if (isNextDev) {
const browser = await navigateTo(href) const browser = await navigateTo(href)
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"description": "Next.js could not validate that a segment in your UI has instant navigation.", "description": "Next.js could not validate that a segment in your UI has instant navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
...@@ -560,7 +568,7 @@ describe('instant validation - parallel slot configs', () => { ...@@ -560,7 +568,7 @@ describe('instant validation - parallel slot configs', () => {
'/suspense-in-root/parallel/conditional-breadcrumbs/show-only-breadcrumbs/blocked' '/suspense-in-root/parallel/conditional-breadcrumbs/show-only-breadcrumbs/blocked'
if (isNextDev) { if (isNextDev) {
const browser = await navigateTo(href) const browser = await navigateTo(href)
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
......
...@@ -24,7 +24,14 @@ describe('instant validation - server errors', () => { ...@@ -24,7 +24,14 @@ describe('instant validation - server errors', () => {
if (isNextStart) { if (isNextStart) {
beforeAll(async () => { beforeAll(async () => {
await next.build({ args: ['--experimental-build-mode', 'compile'] }) const result = await next.build({
args: ['--experimental-build-mode', 'compile'],
})
if (result.exitCode !== 0) {
throw new Error(
`Build exited with exit code ${result.exitCode}. CLI Output:\n\n${result.cliOutput}`
)
}
}) })
afterEach(async () => { afterEach(async () => {
await next.stop() await next.stop()
...@@ -74,8 +81,8 @@ describe('instant validation - server errors', () => { ...@@ -74,8 +81,8 @@ describe('instant validation - server errors', () => {
: await next.browser( : await next.browser(
'/suspense-in-root/static/server-error-blocks-children' '/suspense-in-root/static/server-error-blocks-children'
) )
await waitForRedbox(browser)
await waitForValidation(await browser.url(), getCliOutputSinceMark) await waitForValidation(await browser.url(), getCliOutputSinceMark)
await waitForRedbox(browser)
const errors = await createRedboxSnapshot(browser, next) const errors = await createRedboxSnapshot(browser, next)
expect(errors).toMatchInlineSnapshot(` expect(errors).toMatchInlineSnapshot(`
{ {
...@@ -134,8 +141,8 @@ describe('instant validation - server errors', () => { ...@@ -134,8 +141,8 @@ describe('instant validation - server errors', () => {
: await next.browser( : await next.browser(
'/suspense-in-root/static/server-error-inside-boundary' '/suspense-in-root/static/server-error-inside-boundary'
) )
await waitForRedbox(browser)
await waitForValidation(await browser.url(), getCliOutputSinceMark) await waitForValidation(await browser.url(), getCliOutputSinceMark)
await waitForRedbox(browser)
const errors = await createRedboxSnapshot(browser, next) const errors = await createRedboxSnapshot(browser, next)
expect(errors).toMatchInlineSnapshot(` expect(errors).toMatchInlineSnapshot(`
{ {
......
...@@ -7,7 +7,13 @@ import { type InstantValidationCaseContext } from './harness.util' ...@@ -7,7 +7,13 @@ import { type InstantValidationCaseContext } from './harness.util'
const partialPrefetching = !!process.env.__NEXT_PARTIAL_PREFETCHING const partialPrefetching = !!process.env.__NEXT_PARTIAL_PREFETCHING
export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) { export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) {
const { isNextDev, navigateTo, expectNoDevValidationErrors, prerender } = ctx const {
isNextDev,
navigateTo,
expectNoDevValidationErrors,
getInstantInsight,
prerender,
} = ctx
describe('invalid - missing suspense in parallel slot', () => { describe('invalid - missing suspense in parallel slot', () => {
// The "caused by" source differs between bundlers due to parallel // The "caused by" source differs between bundlers due to parallel
...@@ -20,7 +26,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) { ...@@ -20,7 +26,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) {
// This page uses a runtime shell, so it can use cookies // This page uses a runtime shell, so it can use cookies
await expectNoDevValidationErrors(browser, await browser.url()) await expectNoDevValidationErrors(browser, await browser.url())
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -90,7 +96,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) { ...@@ -90,7 +96,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) {
// This page uses a runtime shell, so it can use cookies // This page uses a runtime shell, so it can use cookies
await expectNoDevValidationErrors(browser, await browser.url()) await expectNoDevValidationErrors(browser, await browser.url())
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -160,7 +166,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) { ...@@ -160,7 +166,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) {
// This page uses a runtime shell, so it can use cookies // This page uses a runtime shell, so it can use cookies
await expectNoDevValidationErrors(browser, await browser.url()) await expectNoDevValidationErrors(browser, await browser.url())
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -231,7 +237,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) { ...@@ -231,7 +237,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) {
// This page uses a runtime shell, so it can use cookies // This page uses a runtime shell, so it can use cookies
await expectNoDevValidationErrors(browser, await browser.url()) await expectNoDevValidationErrors(browser, await browser.url())
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -300,7 +306,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) { ...@@ -300,7 +306,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) {
// This page uses a runtime shell, so it can use cookies // This page uses a runtime shell, so it can use cookies
await expectNoDevValidationErrors(browser, await browser.url()) await expectNoDevValidationErrors(browser, await browser.url())
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -370,7 +376,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) { ...@@ -370,7 +376,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) {
// This page uses a runtime shell, so it can use cookies // This page uses a runtime shell, so it can use cookies
await expectNoDevValidationErrors(browser, await browser.url()) await expectNoDevValidationErrors(browser, await browser.url())
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -440,7 +446,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) { ...@@ -440,7 +446,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) {
// This page uses a runtime shell, so it can use cookies // This page uses a runtime shell, so it can use cookies
await expectNoDevValidationErrors(browser, await browser.url()) await expectNoDevValidationErrors(browser, await browser.url())
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -510,7 +516,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) { ...@@ -510,7 +516,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) {
// This page uses a runtime shell, so it can use cookies // This page uses a runtime shell, so it can use cookies
await expectNoDevValidationErrors(browser, await browser.url()) await expectNoDevValidationErrors(browser, await browser.url())
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -587,7 +593,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) { ...@@ -587,7 +593,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) {
// This page uses a runtime shell, so it can use cookies // This page uses a runtime shell, so it can use cookies
await expectNoDevValidationErrors(browser, await browser.url()) await expectNoDevValidationErrors(browser, await browser.url())
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -671,7 +677,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) { ...@@ -671,7 +677,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) {
// This page uses a runtime shell, so it can use cookies // This page uses a runtime shell, so it can use cookies
await expectNoDevValidationErrors(browser, await browser.url()) await expectNoDevValidationErrors(browser, await browser.url())
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -749,7 +755,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) { ...@@ -749,7 +755,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) {
// This page uses a runtime shell, so it can use cookies // This page uses a runtime shell, so it can use cookies
await expectNoDevValidationErrors(browser, await browser.url()) await expectNoDevValidationErrors(browser, await browser.url())
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -829,7 +835,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) { ...@@ -829,7 +835,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) {
// This page uses a runtime shell, so it can use cookies // This page uses a runtime shell, so it can use cookies
await expectNoDevValidationErrors(browser, await browser.url()) await expectNoDevValidationErrors(browser, await browser.url())
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -905,7 +911,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) { ...@@ -905,7 +911,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) {
// This page uses a runtime shell, so it can use cookies // This page uses a runtime shell, so it can use cookies
await expectNoDevValidationErrors(browser, await browser.url()) await expectNoDevValidationErrors(browser, await browser.url())
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -960,7 +966,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) { ...@@ -960,7 +966,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) {
// This page uses a runtime shell, so it can use cookies // This page uses a runtime shell, so it can use cookies
await expectNoDevValidationErrors(browser, await browser.url()) await expectNoDevValidationErrors(browser, await browser.url())
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -1032,7 +1038,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) { ...@@ -1032,7 +1038,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) {
// This page uses a runtime shell, so it can use cookies // This page uses a runtime shell, so it can use cookies
await expectNoDevValidationErrors(browser, await browser.url()) await expectNoDevValidationErrors(browser, await browser.url())
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -1105,7 +1111,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) { ...@@ -1105,7 +1111,7 @@ export function registerSlotsAndGroupsTests(ctx: InstantValidationCaseContext) {
// This page uses a runtime shell, so it can use cookies // This page uses a runtime shell, so it can use cookies
await expectNoDevValidationErrors(browser, await browser.url()) await expectNoDevValidationErrors(browser, await browser.url())
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
......
...@@ -17,6 +17,7 @@ export function registerSuspenseBoundariesTests( ...@@ -17,6 +17,7 @@ export function registerSuspenseBoundariesTests(
warmCachesAndNavigateTo, warmCachesAndNavigateTo,
restartDevServerToEnsureColdCaches, restartDevServerToEnsureColdCaches,
expectNoDevValidationErrors, expectNoDevValidationErrors,
getInstantInsight,
getCliOutputSinceMark, getCliOutputSinceMark,
prerender, prerender,
} = ctx } = ctx
...@@ -58,7 +59,7 @@ export function registerSuspenseBoundariesTests( ...@@ -58,7 +59,7 @@ export function registerSuspenseBoundariesTests(
// This page uses a runtime shell, so it can use cookies // This page uses a runtime shell, so it can use cookies
await expectNoDevValidationErrors(browser, await browser.url()) await expectNoDevValidationErrors(browser, await browser.url())
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -122,7 +123,7 @@ export function registerSuspenseBoundariesTests( ...@@ -122,7 +123,7 @@ export function registerSuspenseBoundariesTests(
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/static/missing-suspense-around-dynamic' '/suspense-in-root/static/missing-suspense-around-dynamic'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -181,7 +182,7 @@ export function registerSuspenseBoundariesTests( ...@@ -181,7 +182,7 @@ export function registerSuspenseBoundariesTests(
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/runtime/missing-suspense-around-dynamic' '/suspense-in-root/runtime/missing-suspense-around-dynamic'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -247,7 +248,7 @@ export function registerSuspenseBoundariesTests( ...@@ -247,7 +248,7 @@ export function registerSuspenseBoundariesTests(
// This page uses a runtime shell, so it can use cookies // This page uses a runtime shell, so it can use cookies
await expectNoDevValidationErrors(browser, await browser.url()) await expectNoDevValidationErrors(browser, await browser.url())
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -310,7 +311,7 @@ export function registerSuspenseBoundariesTests( ...@@ -310,7 +311,7 @@ export function registerSuspenseBoundariesTests(
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/runtime/missing-suspense-around-dynamic-layout' '/suspense-in-root/runtime/missing-suspense-around-dynamic-layout'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -373,7 +374,7 @@ export function registerSuspenseBoundariesTests( ...@@ -373,7 +374,7 @@ export function registerSuspenseBoundariesTests(
'/suspense-in-root/static/missing-suspense-around-params/123' '/suspense-in-root/static/missing-suspense-around-params/123'
) )
if (partialPrefetching) { if (partialPrefetching) {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -400,7 +401,7 @@ export function registerSuspenseBoundariesTests( ...@@ -400,7 +401,7 @@ export function registerSuspenseBoundariesTests(
} }
`) `)
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -434,7 +435,7 @@ export function registerSuspenseBoundariesTests( ...@@ -434,7 +435,7 @@ export function registerSuspenseBoundariesTests(
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/runtime/invalid-no-suspense-around-params/123' '/suspense-in-root/runtime/invalid-no-suspense-around-params/123'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -575,7 +576,7 @@ export function registerSuspenseBoundariesTests( ...@@ -575,7 +576,7 @@ export function registerSuspenseBoundariesTests(
} }
} else { } else {
if (partialPrefetching) { if (partialPrefetching) {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -601,7 +602,7 @@ export function registerSuspenseBoundariesTests( ...@@ -601,7 +602,7 @@ export function registerSuspenseBoundariesTests(
} }
`) `)
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -724,7 +725,7 @@ export function registerSuspenseBoundariesTests( ...@@ -724,7 +725,7 @@ export function registerSuspenseBoundariesTests(
}" }"
`) `)
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -809,7 +810,7 @@ export function registerSuspenseBoundariesTests( ...@@ -809,7 +810,7 @@ export function registerSuspenseBoundariesTests(
// This page uses a runtime shell, so it can use cookies // This page uses a runtime shell, so it can use cookies
await expectNoDevValidationErrors(browser, await browser.url()) await expectNoDevValidationErrors(browser, await browser.url())
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -876,7 +877,7 @@ export function registerSuspenseBoundariesTests( ...@@ -876,7 +877,7 @@ export function registerSuspenseBoundariesTests(
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/runtime/suspense-too-high' '/suspense-in-root/runtime/suspense-too-high'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -954,7 +955,7 @@ export function registerSuspenseBoundariesTests( ...@@ -954,7 +955,7 @@ export function registerSuspenseBoundariesTests(
it('with cold caches', async () => { it('with cold caches', async () => {
if (isNextDev) { if (isNextDev) {
const browser = await navigateTo(route) const browser = await navigateTo(route)
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -1011,7 +1012,7 @@ export function registerSuspenseBoundariesTests( ...@@ -1011,7 +1012,7 @@ export function registerSuspenseBoundariesTests(
it('with warm caches', async () => { it('with warm caches', async () => {
const browser = await warmCachesAndNavigateTo(route) const browser = await warmCachesAndNavigateTo(route)
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -1066,7 +1067,7 @@ export function registerSuspenseBoundariesTests( ...@@ -1066,7 +1067,7 @@ export function registerSuspenseBoundariesTests(
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/static/invalid-loading-above-route-group' '/suspense-in-root/static/invalid-loading-above-route-group'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -1129,7 +1130,7 @@ export function registerSuspenseBoundariesTests( ...@@ -1129,7 +1130,7 @@ export function registerSuspenseBoundariesTests(
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/static/invalid-dynamic-layout-with-loading' '/suspense-in-root/static/invalid-dynamic-layout-with-loading'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
......
...@@ -10,7 +10,13 @@ const partialPrefetching = !!process.env.__NEXT_PARTIAL_PREFETCHING ...@@ -10,7 +10,13 @@ const partialPrefetching = !!process.env.__NEXT_PARTIAL_PREFETCHING
export function registerSyncIoAndBlockingTests( export function registerSyncIoAndBlockingTests(
ctx: InstantValidationCaseContext ctx: InstantValidationCaseContext
) { ) {
const { isNextDev, navigateTo, expectNoDevValidationErrors, prerender } = ctx const {
isNextDev,
navigateTo,
expectNoDevValidationErrors,
getInstantInsight,
prerender,
} = ctx
describe('Sync IO', () => { describe('Sync IO', () => {
it('sync IO after session data', async () => { it('sync IO after session data', async () => {
...@@ -19,7 +25,7 @@ export function registerSyncIoAndBlockingTests( ...@@ -19,7 +25,7 @@ export function registerSyncIoAndBlockingTests(
'/suspense-in-root/sync-io/sync-io-after-cookies' '/suspense-in-root/sync-io/sync-io-after-cookies'
) )
if (partialPrefetching) { if (partialPrefetching) {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"description": "Next.js encountered the unstable value Date.now() while prerendering.", "description": "Next.js encountered the unstable value Date.now() while prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
...@@ -79,7 +85,7 @@ export function registerSyncIoAndBlockingTests( ...@@ -79,7 +85,7 @@ export function registerSyncIoAndBlockingTests(
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/sync-io/sync-io-after-navigation' '/suspense-in-root/sync-io/sync-io-after-navigation'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"description": "Next.js encountered the unstable value Date.now() while prerendering.", "description": "Next.js encountered the unstable value Date.now() while prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
...@@ -137,7 +143,7 @@ export function registerSyncIoAndBlockingTests( ...@@ -137,7 +143,7 @@ export function registerSyncIoAndBlockingTests(
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/sync-io/sync-io-after-prefetch' '/suspense-in-root/sync-io/sync-io-after-prefetch'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"description": "Next.js encountered the unstable value Date.now() while prerendering.", "description": "Next.js encountered the unstable value Date.now() while prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
...@@ -196,7 +202,7 @@ export function registerSyncIoAndBlockingTests( ...@@ -196,7 +202,7 @@ export function registerSyncIoAndBlockingTests(
'/suspense-in-root/sync-io/sync-io-after-cache-with-cookie-input' '/suspense-in-root/sync-io/sync-io-after-cache-with-cookie-input'
) )
if (partialPrefetching) { if (partialPrefetching) {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"description": "Next.js encountered the unstable value Date.now() while prerendering.", "description": "Next.js encountered the unstable value Date.now() while prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
...@@ -265,7 +271,7 @@ export function registerSyncIoAndBlockingTests( ...@@ -265,7 +271,7 @@ export function registerSyncIoAndBlockingTests(
'/suspense-in-root/sync-io/sync-io-after-cookies-in-generate-metadata' '/suspense-in-root/sync-io/sync-io-after-cookies-in-generate-metadata'
) )
if (partialPrefetching) { if (partialPrefetching) {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"description": "Next.js encountered the unstable value Date.now() while prerendering.", "description": "Next.js encountered the unstable value Date.now() while prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
...@@ -360,7 +366,7 @@ export function registerSyncIoAndBlockingTests( ...@@ -360,7 +366,7 @@ export function registerSyncIoAndBlockingTests(
// This page uses a runtime shell, so it can use cookies // This page uses a runtime shell, so it can use cookies
await expectNoDevValidationErrors(browser, await browser.url()) await expectNoDevValidationErrors(browser, await browser.url())
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -456,7 +462,7 @@ export function registerSyncIoAndBlockingTests( ...@@ -456,7 +462,7 @@ export function registerSyncIoAndBlockingTests(
// This page uses a runtime shell, so it can use cookies // This page uses a runtime shell, so it can use cookies
await expectNoDevValidationErrors(browser, await browser.url()) await expectNoDevValidationErrors(browser, await browser.url())
} else { } else {
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
...@@ -521,7 +527,7 @@ export function registerSyncIoAndBlockingTests( ...@@ -521,7 +527,7 @@ export function registerSyncIoAndBlockingTests(
const browser = await navigateTo( const browser = await navigateTo(
'/suspense-in-root/runtime/invalid-blocking-inside-runtime' '/suspense-in-root/runtime/invalid-blocking-inside-runtime'
) )
await expect(browser).toDisplayCollapsedRedbox(` expect(await getInstantInsight(browser)).toMatchInlineSnapshot(`
{ {
"cause": [ "cause": [
{ {
......
...@@ -8,7 +8,14 @@ describe('use-cache-og-image-top-level-await', () => { ...@@ -8,7 +8,14 @@ describe('use-cache-og-image-top-level-await', () => {
if (isNextStart) { if (isNextStart) {
beforeAll(async () => { beforeAll(async () => {
await next.build({ args: ['--experimental-build-mode', 'compile'] }) const result = await next.build({
args: ['--experimental-build-mode', 'compile'],
})
if (result.exitCode !== 0) {
throw new Error(
`Build exited with exit code ${result.exitCode}. CLI Output:\n\n${result.cliOutput}`
)
}
}) })
it('should prerender a page whose opengraph image uses a top-level await', async () => { it('should prerender a page whose opengraph image uses a top-level await', async () => {
......
import { retry } from '../next-test-utils' import { openRedbox, retry } from '../next-test-utils'
import {
createRedboxSnapshot,
type RedboxSnapshot,
} from '../add-redbox-matchers'
import { getDeterministicOutput } from '../../e2e/app-dir/cache-components-errors/utils' import { getDeterministicOutput } from '../../e2e/app-dir/cache-components-errors/utils'
import { inspect } from 'util' import { inspect } from 'util'
import type { Playwright } from '../browsers/playwright'
import type { NextInstance } from '../next-modes/base'
import type { import type {
ValidationEvent, ValidationEvent,
ValidationStartEvent, ValidationStartEvent,
...@@ -114,6 +120,8 @@ export function normalizeValidationUrl(url: string): string { ...@@ -114,6 +120,8 @@ export function normalizeValidationUrl(url: string): string {
return parsed.pathname + parsed.search + parsed.hash return parsed.pathname + parsed.search + parsed.hash
} }
const MAX_VALIDATION_WAIT = 5000
export async function waitForValidationStart( export async function waitForValidationStart(
targetUrl: string, targetUrl: string,
getOutput: () => string getOutput: () => string
...@@ -130,10 +138,12 @@ export async function waitForValidationStart( ...@@ -130,10 +138,12 @@ export async function waitForValidationStart(
e.type === 'validation_start' && e.type === 'validation_start' &&
normalizeValidationUrl(e.url) === relativeTargetUrl normalizeValidationUrl(e.url) === relativeTargetUrl
) )
expect(start).toBeDefined() if (start === undefined) {
return start! as ValidationStartEvent throw new Error('Could not find "validation_start" marker')
}
return start as ValidationStartEvent
}, },
undefined, MAX_VALIDATION_WAIT,
undefined, undefined,
`wait for validation of '${relativeTargetUrl}' to start` `wait for validation of '${relativeTargetUrl}' to start`
) )
...@@ -153,10 +163,12 @@ export async function waitForValidationEnd( ...@@ -153,10 +163,12 @@ export async function waitForValidationEnd(
const end = events.find( const end = events.find(
(e) => e.type === 'validation_end' && e.requestId === start.requestId (e) => e.type === 'validation_end' && e.requestId === start.requestId
) )
expect(end).toBeDefined() if (end === undefined) {
throw new Error('Could not find "validation_end" marker')
}
return end as ValidationEndEvent return end as ValidationEndEvent
}, },
undefined, MAX_VALIDATION_WAIT,
undefined, undefined,
'wait for validation to end' 'wait for validation to end'
) )
...@@ -179,6 +191,19 @@ export async function waitForValidation(url: string, getOutput: () => string) { ...@@ -179,6 +191,19 @@ export async function waitForValidation(url: string, getOutput: () => string) {
return { start, end } return { start, end }
} }
export function createGetInstantInsight(
getOutput: () => string,
next: NextInstance
): (browser: Playwright) => Promise<RedboxSnapshot> {
return async function getInstantInsight(browser) {
// Wait for instant validation to actually run before asserting on it.
// This reduces flakiness in case a redbox is slow to open in CI.
await waitForValidation(await browser.url(), getOutput)
await openRedbox(browser)
return createRedboxSnapshot(browser, next)
}
}
type PrerenderResult = { type PrerenderResult = {
cliOutput: string cliOutput: string
exitCode: number | NodeJS.Signals exitCode: number | NodeJS.Signals
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment