index.test.ts
References the toString conversion methodCalls JavaScript toString conversion method
SHA-256f5b5fea00a1cac6d6038137f06d2923d823c368d662693e95d78522b53568500
MaleculeH₃(Cm₂DbMg)Md(Pa)
Evidence
1import { createNext } from 'e2e-utils'
2import { NextInstance } from 'e2e-utils'
3import { fetchViaHTTP } from 'next-test-utils'
4
5describe('Middleware fetches with body', () => {
6 let next: NextInstance
7
⋯5 lines
13 `,
14 'pages/api/size_limit_5kb.js': `
15 export const config = { api: { bodyParser: { sizeLimit: '5kb' } } }
16 export default (req, res) => res.json({ body: req.body })
17 `,
18 'pages/api/size_limit_5mb.js': `
19 export const config = { api: { bodyParser: { sizeL …
20:56… req.body })
21 `,
22 'pages/api/body_parser_false.js': `
23 export const config = { api: { bodyParser: false } }
24
25 async function buffer(readable) {
26 const chunks = []
27 for await (const chunk of readable) {
28 chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk)
29 }
30 return …
31:8… }
32
33 export default async (req, res) => {
34 const buf = await buffer(req)
35 const rawBody = buf.toString('utf8');
36
37 res.json({ rawBody, body: req.body })
38 }
39 `,
⋯10 lines
50
51 describe('with default bodyParser sizeLimit (1mb)', () => {
52 it('should return 413 for body greater than 1mb', async () => {
53 const bodySize = 1024 * 1024 + 1
54 const body = 'r'.repeat(bodySize)
55
⋯4 lines
60 {
61 body,
62 method: 'POST',
63 }
64 )
65
66 try {
67 expect(res.status).toBe(413)
68
69 if (!(global as any).isNextDeploy) {
70 expect(res.statusText).toBe('Body exceeded 1mb …