rsnext/test/e2e/app-dir/app-invalid-revalidate/app-invalid-revalidate.test.ts
JJ Kasper 75a8303f1b
Add unstable_cache validate test case (#59828)
Follow-up to https://github.com/vercel/next.js/pull/59822 adding an
additional test case.

Closes NEXT-1918
2023-12-20 18:00:23 -06:00

100 lines
2.9 KiB
TypeScript

import { createNextDescribe } from 'e2e-utils'
import { check } from 'next-test-utils'
createNextDescribe(
'app-invalid-revalidate',
{
files: __dirname,
skipStart: true,
skipDeployment: true,
},
({ next, isNextDev }) => {
it('should error properly for invalid revalidate at layout', async () => {
await next.stop().catch(() => {})
const origText = await next.readFile('app/layout.tsx')
try {
await next.patchFile(
'app/layout.tsx',
origText.replace('// export', 'export')
)
await next.start().catch(() => {})
await check(async () => {
if (isNextDev) {
await next.fetch('/')
}
return next.cliOutput
}, /Invalid revalidate value "1" on "\/", must be a non-negative number or "false"/)
} finally {
await next.patchFile('app/layout.tsx', origText)
}
})
it('should error properly for invalid revalidate at page', async () => {
await next.stop().catch(() => {})
const origText = await next.readFile('app/page.tsx')
try {
await next.patchFile(
'app/page.tsx',
origText.replace('// export', 'export')
)
await next.start().catch(() => {})
await check(async () => {
if (isNextDev) {
await next.fetch('/')
}
return next.cliOutput
}, /Invalid revalidate value "1" on "\/", must be a non-negative number or "false"/)
} finally {
await next.patchFile('app/page.tsx', origText)
}
})
it('should error properly for invalid revalidate on fetch', async () => {
await next.stop().catch(() => {})
const origText = await next.readFile('app/page.tsx')
try {
await next.patchFile(
'app/page.tsx',
origText.replace('// await', 'await')
)
await next.start().catch(() => {})
await check(async () => {
if (isNextDev) {
await next.fetch('/')
}
return next.cliOutput
}, /Invalid revalidate value "1" on "\/", must be a non-negative number or "false"/)
} finally {
await next.patchFile('app/page.tsx', origText)
}
})
it('should error properly for invalid revalidate on unstable_cache', async () => {
await next.stop().catch(() => {})
const origText = await next.readFile('app/page.tsx')
try {
await next.patchFile(
'app/page.tsx',
origText.replace('// await unstable', 'await unstable')
)
await next.start().catch(() => {})
await check(async () => {
if (isNextDev) {
await next.fetch('/')
}
return next.cliOutput
}, /Invalid revalidate value "1" on "unstable_cache/)
} finally {
await next.patchFile('app/page.tsx', origText)
}
})
}
)