2023-06-24 01:24:18 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-10-26 08:51:32 +02:00
|
|
|
it('should error if serverActions.bodySizeLimit config is a negative number', async function () {
|
2023-06-24 01:24:18 +02:00
|
|
|
await next.patchFile(
|
|
|
|
'next.config.js',
|
|
|
|
`
|
|
|
|
module.exports = {
|
|
|
|
experimental: {
|
2023-10-26 08:51:32 +02:00
|
|
|
serverActions: { bodySizeLimit: -3000 }
|
2023-06-24 01:24:18 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
`
|
|
|
|
)
|
|
|
|
await next.stop()
|
|
|
|
try {
|
|
|
|
await next.build()
|
|
|
|
} catch {}
|
|
|
|
expect(next.cliOutput).toContain(CONFIG_ERROR)
|
|
|
|
})
|
|
|
|
|
2023-10-26 08:51:32 +02:00
|
|
|
it('should error if serverActions.bodySizeLimit config is invalid', async function () {
|
2023-06-24 01:24:18 +02:00
|
|
|
await next.patchFile(
|
|
|
|
'next.config.js',
|
|
|
|
`
|
|
|
|
module.exports = {
|
|
|
|
experimental: {
|
2023-10-26 08:51:32 +02:00
|
|
|
serverActions: { bodySizeLimit: 'testmb' }
|
2023-06-24 01:24:18 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
`
|
|
|
|
)
|
|
|
|
await next.stop()
|
|
|
|
try {
|
|
|
|
await next.build()
|
|
|
|
} catch {}
|
|
|
|
expect(next.cliOutput).toContain(CONFIG_ERROR)
|
|
|
|
})
|
|
|
|
|
2023-10-26 08:51:32 +02:00
|
|
|
it('should error if serverActions.bodySizeLimit config is a negative size', async function () {
|
2023-06-24 01:24:18 +02:00
|
|
|
await next.patchFile(
|
|
|
|
'next.config.js',
|
|
|
|
`
|
|
|
|
module.exports = {
|
|
|
|
experimental: {
|
2023-10-26 08:51:32 +02:00
|
|
|
serverActions: { bodySizeLimit: '-3000mb' }
|
2023-06-24 01:24:18 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
`
|
|
|
|
)
|
|
|
|
await next.stop()
|
|
|
|
try {
|
|
|
|
await next.build()
|
|
|
|
} catch {}
|
|
|
|
expect(next.cliOutput).toContain(CONFIG_ERROR)
|
|
|
|
})
|
|
|
|
|
|
|
|
if (!isNextDeploy) {
|
2023-10-26 08:51:32 +02:00
|
|
|
it('should respect the size set in serverActions.bodySizeLimit', async function () {
|
2023-06-24 01:24:18 +02:00
|
|
|
await next.patchFile(
|
|
|
|
'next.config.js',
|
|
|
|
`
|
|
|
|
module.exports = {
|
|
|
|
experimental: {
|
2023-10-26 08:51:32 +02:00
|
|
|
serverActions: { bodySizeLimit: '1.5mb' }
|
2023-06-24 01:24:18 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
`
|
|
|
|
)
|
|
|
|
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(() => {
|
2023-06-24 18:16:09 +02:00
|
|
|
const fullLog = logs.join('')
|
2023-09-08 18:05:29 +02:00
|
|
|
return fullLog.includes('[Error]: Body exceeded 1.5mb limit') &&
|
2023-06-24 18:16:09 +02:00
|
|
|
fullLog.includes(
|
|
|
|
'To configure the body size limit for Server Actions, see'
|
|
|
|
)
|
2023-06-24 01:24:18 +02:00
|
|
|
? 'yes'
|
|
|
|
: ''
|
|
|
|
}, 'yes')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|