rsnext/test/e2e/app-dir/actions/app-action-size-limit-invalid.test.ts
Josh Story 5528cc6d4e
Remove the experimental serverActions flag (#57145)
Remove the experimental `serverActions` flag

Co-authored-by: Shu Ding <3676859+shuding@users.noreply.github.com>
Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2023-10-20 20:45:25 +00:00

122 lines
3 KiB
TypeScript

import { createNextDescribe } from 'e2e-utils'
import { check } from 'next-test-utils'
const CONFIG_ERROR =
'Server Actions Size Limit must be a valid number or filesize format lager than 1MB'
createNextDescribe(
'app-dir action size limit invalid config',
{
files: __dirname,
skipDeployment: true,
dependencies: {
react: 'latest',
'react-dom': 'latest',
'server-only': 'latest',
},
},
({ next, isNextStart, isNextDeploy }) => {
if (!isNextStart) {
it('skip test for dev mode', () => {})
return
}
it('should error if serverActionsBodySizeLimit config is a negative number', async function () {
await next.patchFile(
'next.config.js',
`
module.exports = {
experimental: {
serverActionsBodySizeLimit: -3000,
},
}
`
)
await next.stop()
try {
await next.build()
} catch {}
expect(next.cliOutput).toContain(CONFIG_ERROR)
})
it('should error if serverActionsBodySizeLimit config is invalid', async function () {
await next.patchFile(
'next.config.js',
`
module.exports = {
experimental: {
serverActionsBodySizeLimit: 'testmb',
},
}
`
)
await next.stop()
try {
await next.build()
} catch {}
expect(next.cliOutput).toContain(CONFIG_ERROR)
})
it('should error if serverActionsBodySizeLimit config is a negative size', async function () {
await next.patchFile(
'next.config.js',
`
module.exports = {
experimental: {
serverActionsBodySizeLimit: '-3000mb',
},
}
`
)
await next.stop()
try {
await next.build()
} catch {}
expect(next.cliOutput).toContain(CONFIG_ERROR)
})
if (!isNextDeploy) {
it('should respect the size set in serverActionsBodySizeLimit', async function () {
await next.patchFile(
'next.config.js',
`
module.exports = {
experimental: {
serverActionsBodySizeLimit: '1.5mb',
},
}
`
)
await next.build()
await next.start()
const logs: string[] = []
next.on('stdout', (log) => {
logs.push(log)
})
next.on('stderr', (log) => {
logs.push(log)
})
const browser = await next.browser('/file')
await browser.elementByCss('#size-1mb').click()
await check(() => {
return logs.some((log) => log.includes('size = 1048576')) ? 'yes' : ''
}, 'yes')
await browser.elementByCss('#size-2mb').click()
await check(() => {
const fullLog = logs.join('')
return fullLog.includes('[Error]: Body exceeded 1.5mb limit') &&
fullLog.includes(
'To configure the body size limit for Server Actions, see'
)
? 'yes'
: ''
}, 'yes')
})
}
}
)