Skip to content

Commit

Permalink
Update tests to new error strings
Browse files Browse the repository at this point in the history
  • Loading branch information
gnoff committed Oct 20, 2024
1 parent 62e093c commit fc6103b
Show file tree
Hide file tree
Showing 15 changed files with 442 additions and 587 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,20 @@ describe('dynamic-requests warnings', () => {
.map((log) => log.message)
const terminalOutput = next.cliOutput.slice(nextDevBootstrapOutputIndex)
const terminalCookieErrors = terminalOutput.split('\n').filter((line) => {
return line.includes('In route /request/cookies')
return line.includes('Route "/request/cookies')
})
expect({ browserConsoleErrors, terminalCookieErrors }).toEqual({
browserConsoleErrors: [
expect.stringContaining(
"In route /request/cookies a cookie property was accessed directly with `cookies().get('page')`."
),
expect.stringContaining(
"In route /request/cookies a cookie property was accessed directly with `cookies().get('component')`."
),
expect.stringContaining(
"In route /request/cookies a cookie property was accessed directly with `cookies().has('component')`."
),
expect.stringContaining(
'In route /request/cookies cookies were iterated over'
),
expect.stringContaining("`cookies().get('page')`."),
expect.stringContaining("`cookies().get('component')`."),
expect.stringContaining("`cookies().has('component')`."),
expect.stringContaining('`...cookies()` or similar iteration'),
],
terminalCookieErrors: [
expect.stringContaining(
"In route /request/cookies a cookie property was accessed directly with `cookies().get('page')`."
),
expect.stringContaining(
"In route /request/cookies a cookie property was accessed directly with `cookies().get('component')`."
),
expect.stringContaining(
"In route /request/cookies a cookie property was accessed directly with `cookies().has('component')`."
),
expect.stringContaining(
'In route /request/cookies cookies were iterated over'
),
expect.stringContaining("`cookies().get('page')`."),
expect.stringContaining("`cookies().get('component')`."),
expect.stringContaining("`cookies().has('component')`."),
expect.stringContaining('`...cookies()` or similar iteration'),
],
})
})
Expand All @@ -61,36 +45,20 @@ describe('dynamic-requests warnings', () => {
.map((log) => log.message)
const terminalOutput = next.cliOutput.slice(nextDevBootstrapOutputIndex)
const terminalCookieErrors = terminalOutput.split('\n').filter((line) => {
return line.includes('In route /request/draftMode')
return line.includes('Route "/request/draftMode')
})
expect({ browserConsoleErrors, terminalCookieErrors }).toEqual({
browserConsoleErrors: [
expect.stringContaining(
'In route /request/draftMode a `draftMode()` property was accessed directly with `draftMode().isEnabled`.'
),
expect.stringContaining(
'In route /request/draftMode a `draftMode()` property was accessed directly with `draftMode().isEnabled`.'
),
expect.stringContaining(
'In route /request/draftMode a `draftMode()` property was accessed directly with `draftMode().enable()`.'
),
expect.stringContaining(
'In route /request/draftMode a `draftMode()` property was accessed directly with `draftMode().isEnabled`.'
),
expect.stringContaining('`draftMode().isEnabled`.'),
expect.stringContaining('`draftMode().isEnabled`.'),
expect.stringContaining('`draftMode().enable()`.'),
expect.stringContaining('`draftMode().isEnabled`.'),
],
terminalCookieErrors: [
expect.stringContaining(
'In route /request/draftMode a `draftMode()` property was accessed directly with `draftMode().isEnabled`.'
),
expect.stringContaining(
'In route /request/draftMode a `draftMode()` property was accessed directly with `draftMode().isEnabled`.'
),
expect.stringContaining(
'In route /request/draftMode a `draftMode()` property was accessed directly with `draftMode().enable()`.'
),
expect.stringContaining(
'In route /request/draftMode a `draftMode()` property was accessed directly with `draftMode().isEnabled`.'
),
expect.stringContaining('`draftMode().isEnabled`.'),
expect.stringContaining('`draftMode().isEnabled`.'),
expect.stringContaining('`draftMode().enable()`.'),
expect.stringContaining('`draftMode().isEnabled`.'),
],
})
})
Expand All @@ -106,36 +74,20 @@ describe('dynamic-requests warnings', () => {
.map((log) => log.message)
const terminalOutput = next.cliOutput.slice(nextDevBootstrapOutputIndex)
const terminalCookieErrors = terminalOutput.split('\n').filter((line) => {
return line.includes('In route /request/headers')
return line.includes('Route "/request/headers')
})
expect({ browserConsoleErrors, terminalCookieErrors }).toEqual({
browserConsoleErrors: [
expect.stringContaining(
"In route /request/headers a header property was accessed directly with `headers().get('page')`."
),
expect.stringContaining(
"In route /request/headers a header property was accessed directly with `headers().get('component')`."
),
expect.stringContaining(
"In route /request/headers a header property was accessed directly with `headers().has('component')`."
),
expect.stringContaining(
'In route /request/headers headers were iterated over'
),
expect.stringContaining("`headers().get('page')`."),
expect.stringContaining("`headers().get('component')`."),
expect.stringContaining("`headers().has('component')`."),
expect.stringContaining('`...headers()` or similar iteration'),
],
terminalCookieErrors: [
expect.stringContaining(
"In route /request/headers a header property was accessed directly with `headers().get('page')`."
),
expect.stringContaining(
"In route /request/headers a header property was accessed directly with `headers().get('component')`."
),
expect.stringContaining(
"In route /request/headers a header property was accessed directly with `headers().has('component')`."
),
expect.stringContaining(
'In route /request/headers headers were iterated over'
),
expect.stringContaining("`headers().get('page')`."),
expect.stringContaining("`headers().get('component')`."),
expect.stringContaining("`headers().has('component')`."),
expect.stringContaining('`...headers()` or similar iteration'),
],
})
})
Expand All @@ -151,36 +103,20 @@ describe('dynamic-requests warnings', () => {
.map((log) => log.message)
const terminalOutput = next.cliOutput.slice(nextDevBootstrapOutputIndex)
const terminalCookieErrors = terminalOutput.split('\n').filter((line) => {
return line.includes('In route /request/params/[slug]')
return line.includes('Route "/request/params/[slug]')
})
expect({ browserConsoleErrors, terminalCookieErrors }).toEqual({
browserConsoleErrors: [
expect.stringContaining(
'In route /request/params/[slug] a param property was accessed directly with `params.slug`.'
),
expect.stringContaining(
'In route /request/params/[slug] a param property was accessed directly with `params.slug`.'
),
expect.stringContaining(
'In route /request/params/[slug] a param property was accessed directly with `params.slug`.'
),
expect.stringContaining(
'In route /request/params/[slug] params are being enumerated'
),
expect.stringContaining('`params.slug`.'),
expect.stringContaining('`params.slug`.'),
expect.stringContaining('`params.slug`.'),
expect.stringContaining('`...params` or similar expression'),
],
terminalCookieErrors: [
expect.stringContaining(
'In route /request/params/[slug] a param property was accessed directly with `params.slug`.'
),
expect.stringContaining(
'In route /request/params/[slug] a param property was accessed directly with `params.slug`.'
),
expect.stringContaining(
'In route /request/params/[slug] a param property was accessed directly with `params.slug`.'
),
expect.stringContaining(
'In route /request/params/[slug] params are being enumerated'
),
expect.stringContaining('`params.slug`.'),
expect.stringContaining('`params.slug`.'),
expect.stringContaining('`params.slug`.'),
expect.stringContaining('`...params` or similar expression'),
],
})
})
Expand All @@ -196,36 +132,20 @@ describe('dynamic-requests warnings', () => {
.map((log) => log.message)
const terminalOutput = next.cliOutput.slice(nextDevBootstrapOutputIndex)
const terminalCookieErrors = terminalOutput.split('\n').filter((line) => {
return line.includes('In route /request/searchParams')
return line.includes('Route "/request/searchParams')
})
expect({ browserConsoleErrors, terminalCookieErrors }).toEqual({
browserConsoleErrors: [
expect.stringContaining(
'In route /request/searchParams a searchParam property was accessed directly with `searchParams.slug`.'
),
expect.stringContaining(
'In route /request/searchParams a searchParam property was accessed directly with `searchParams.slug`.'
),
expect.stringContaining(
'In route /request/searchParams a searchParam property was accessed directly with `searchParams.slug`.'
),
expect.stringContaining(
'In route /request/searchParams searchParams are being enumerated'
),
expect.stringContaining('`searchParams.slug`.'),
expect.stringContaining('`searchParams.slug`.'),
expect.stringContaining('`searchParams.slug`.'),
expect.stringContaining('`Object.keys(searchParams)` or similar'),
],
terminalCookieErrors: [
expect.stringContaining(
'In route /request/searchParams a searchParam property was accessed directly with `searchParams.slug`.'
),
expect.stringContaining(
'In route /request/searchParams a searchParam property was accessed directly with `searchParams.slug`.'
),
expect.stringContaining(
'In route /request/searchParams a searchParam property was accessed directly with `searchParams.slug`.'
),
expect.stringContaining(
'In route /request/searchParams searchParams are being enumerated'
),
expect.stringContaining('`searchParams.slug`.'),
expect.stringContaining('`searchParams.slug`.'),
expect.stringContaining('`searchParams.slug`.'),
expect.stringContaining('`Object.keys(searchParams)` or similar'),
],
})
})
Expand Down
12 changes: 0 additions & 12 deletions test/e2e/app-dir/dynamic-data/dynamic-data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,14 @@ describe('dynamic-data', () => {
// in dev we expect the entire page to be rendered at runtime
expect($('#layout').text()).toBe('at runtime')
expect($('#page').text()).toBe('at runtime')
// we expect there to be no suspense boundary in fallback state
expect($('#boundary').html()).toBeNull()
} else if (process.env.__NEXT_EXPERIMENTAL_PPR) {
// in PPR we expect the shell to be rendered at build and the page to be rendered at runtime
expect($('#layout').text()).toBe('at buildtime')
expect($('#page').text()).toBe('at runtime')
// we expect there to be a suspense boundary in fallback state
expect($('#boundary').html()).not.toBeNull()
} else {
// in static generation we expect the entire page to be rendered at runtime
expect($('#layout').text()).toBe('at runtime')
expect($('#page').text()).toBe('at runtime')
// we expect there to be no suspense boundary in fallback state
expect($('#boundary').html()).toBeNull()
}

expect($('#headers .fooheader').text()).toBe('foo header value')
Expand All @@ -64,21 +58,15 @@ describe('dynamic-data', () => {
// in dev we expect the entire page to be rendered at runtime
expect($('#layout').text()).toBe('at runtime')
expect($('#page').text()).toBe('at runtime')
// we expect there to be no suspense boundary in fallback state
expect($('#boundary').html()).toBeNull()
} else if (process.env.__NEXT_EXPERIMENTAL_PPR) {
// @TODO this should actually be build but there is a bug in how we do segment level dynamic in PPR at the moment
// see note in create-component-tree
expect($('#layout').text()).toBe('at runtime')
expect($('#page').text()).toBe('at runtime')
// we expect there to be a suspense boundary in fallback state
expect($('#boundary').html()).toBeNull()
} else {
// in static generation we expect the entire page to be rendered at runtime
expect($('#layout').text()).toBe('at runtime')
expect($('#page').text()).toBe('at runtime')
// we expect there to be no suspense boundary in fallback state
expect($('#boundary').html()).toBeNull()
}

expect($('#headers .fooheader').text()).toBe('foo header value')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ function createExpectError(cliOutput: string) {
}

function runTests(options: { withMinification: boolean }) {
const isTurbopack = !!process.env.TURBOPACK
const { withMinification } = options
describe(`Dynamic IO Errors - ${withMinification ? 'With Minification' : 'Without Minification'}`, () => {
describe('Sync Dynamic - With Fallback - Math.random()', () => {
Expand Down Expand Up @@ -126,11 +125,6 @@ function runTests(options: { withMinification: boolean }) {
expectError(
'Error: Route "/" used `Math.random()` outside of `"use cache"` and without explicitly calling `await connection()` beforehand. See more info here: https://nextjs.org/docs/messages/next-prerender-random'
)
expectError(
'Error: In Route "/" this parent component stack may help you locate where `Math.random()` was used.',
// Turbopack doesn't support disabling minification yet
withMinification || isTurbopack ? undefined : 'IndirectionTwo'
)
expectError('Error occurred prerendering page "/"')
expectError('Error: Route "/" could not be prerendered.')
expectError('exiting the build.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ function createExpectError(cliOutput: string) {
}

function runTests(options: { withMinification: boolean }) {
const isTurbopack = !!process.env.TURBOPACK
const { withMinification } = options
describe(`Dynamic IO Errors - ${withMinification ? 'With Minification' : 'Without Minification'}`, () => {
describe('Sync Dynamic - With Fallback - client searchParams', () => {
Expand Down Expand Up @@ -123,14 +122,7 @@ function runTests(options: { withMinification: boolean }) {
}
const expectError = createExpectError(next.cliOutput)

expectError(
'Error: Route "/" used `searchParams.foo`. `searchParams` is now a Promise and should be `awaited` before accessing search param values. See more info here: https://nextjs.org/docs/messages/next-prerender-sync-params'
)
expectError(
'Error: In Route "/" this parent component stack may help you locate where `searchParams.foo` was used.',
// Turbopack doesn't support disabling minification yet
withMinification || isTurbopack ? undefined : 'IndirectionTwo'
)
expectError('Route "/" used `searchParams.foo`')
expectError('Error occurred prerendering page "/"')
expectError('Error: Route "/" could not be prerendered.')
expectError('exiting the build.')
Expand Down Expand Up @@ -218,14 +210,7 @@ function runTests(options: { withMinification: boolean }) {
}
const expectError = createExpectError(next.cliOutput)

expectError(
'Error: Route "/" used `searchParams.foo`. `searchParams` is now a Promise and should be `awaited` before accessing search param values. See more info here: https://nextjs.org/docs/messages/next-prerender-sync-params'
)
expectError(
'Error: In Route "/" this parent component stack may help you locate where `searchParams.foo` was used.',
// Turbopack doesn't support disabling minification yet
withMinification || isTurbopack ? undefined : 'IndirectionTwo'
)
expectError('Route "/" used `searchParams.foo`')
expectError('Error occurred prerendering page "/"')
expectError('Error: Route "/" could not be prerendered.')
expectError('exiting the build.')
Expand Down Expand Up @@ -313,14 +298,7 @@ function runTests(options: { withMinification: boolean }) {
}
const expectError = createExpectError(next.cliOutput)

expectError(
"Error: Route \"/\" used cookies().get('token'). `cookies()` now returns a Promise and should be `awaited` before using it's value. See more info here: https://nextjs.org/docs/messages/next-prerender-sync-headers"
)
expectError(
'Error: In Route "/" this parent component stack may help you locate where cookies().get(\'token\') was used.',
// Turbopack doesn't support disabling minification yet
withMinification || isTurbopack ? undefined : 'IndirectionTwo'
)
expectError('Route "/" used `cookies().get(\'token\')`')
expectError('Error occurred prerendering page "/"')
expectError('Route "/" could not be prerendered.')
expectError('exiting the build.')
Expand Down
Loading

0 comments on commit fc6103b

Please sign in to comment.