Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Oct 26, 2022
1 parent a5ba770 commit 8eab3a1
Showing 1 changed file with 63 additions and 68 deletions.
131 changes: 63 additions & 68 deletions test/e2e/edge-can-read-request-body/index.test.ts
@@ -1,13 +1,9 @@
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { EdgeRuntime } from 'next/dist/compiled/edge-runtime'
import { renderViaHTTP } from 'next-test-utils'
import { fetch } from 'next/dist/compiled/@edge-runtime/primitives'
import path from 'path'

const runtime = new EdgeRuntime()
const fetch = runtime.evaluate('fetch')
const FormData = runtime.evaluate('FormData')

async function serialize(response: Response) {
return {
text: await response.text(),
Expand All @@ -33,32 +29,31 @@ describe('Edge can read request body', () => {
})

describe('middleware', () => {
it('reads a JSON body', async () => {
const response = await fetch(
`${next.url}/api/nothing?middleware-handler=json`,
{
method: 'POST',
body: JSON.stringify({ hello: 'world' }),
}
)
expect(await serialize(response)).toMatchObject({
text: expect.stringContaining('ok'),
status: 200,
headers: {
'x-req-type': 'json',
'x-serialized': '{"hello":"world"}',
},
})
})
// it('reads a JSON body', async () => {
// const response = await fetch(
// `${next.url}/api/nothing?middleware-handler=json`,
// {
// method: 'POST',
// body: JSON.stringify({ hello: 'world' }),
// }
// )
// expect(await serialize(response)).toMatchObject({
// text: expect.stringContaining('ok'),
// status: 200,
// headers: {
// 'x-req-type': 'json',
// 'x-serialized': '{"hello":"world"}',
// },
// })
// })

it('reads a text body', async () => {
const response = await fetch(
`${next.url}/api/nothing?middleware-handler=text`,
{
method: 'POST',
body: JSON.stringify({ hello: 'world' }),
}
)
const url = `${next.url}/api/nothing?middleware-handler=text`
console.log('URL', url)
const response = await fetch(url, {
method: 'POST',
body: JSON.stringify({ hello: 'world' }),
})
expect(await serialize(response)).toMatchObject({
text: expect.stringContaining('ok'),
status: 200,
Expand All @@ -69,45 +64,45 @@ describe('Edge can read request body', () => {
})
})

it('reads an URL encoded form data', async () => {
const response = await fetch(
`${next.url}/api/nothing?middleware-handler=formData`,
{
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({ hello: 'world' }).toString(),
}
)
expect(await serialize(response)).toMatchObject({
text: expect.stringContaining('ok'),
status: 200,
headers: {
'x-req-type': 'formData',
'x-serialized': '{"hello":"world"}',
},
})
})
// it('reads an URL encoded form data', async () => {
// const response = await fetch(
// `${next.url}/api/nothing?middleware-handler=formData`,
// {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/x-www-form-urlencoded',
// },
// body: new URLSearchParams({ hello: 'world' }).toString(),
// }
// )
// expect(await serialize(response)).toMatchObject({
// text: expect.stringContaining('ok'),
// status: 200,
// headers: {
// 'x-req-type': 'formData',
// 'x-serialized': '{"hello":"world"}',
// },
// })
// })

it('reads a multipart form data', async () => {
const formData = new FormData()
formData.set('hello', 'world')
const response = await fetch(
`${next.url}/api/nothing?middleware-handler=formData`,
{
method: 'POST',
body: formData,
}
)
expect(await serialize(response)).toMatchObject({
text: expect.stringContaining('ok'),
status: 200,
headers: {
'x-req-type': 'formData',
'x-serialized': '{"hello":"world"}',
},
})
})
// it('reads a multipart form data', async () => {
// const formData = new FormData()
// formData.set('hello', 'world')
// const response = await fetch(
// `${next.url}/api/nothing?middleware-handler=formData`,
// {
// method: 'POST',
// body: formData,
// }
// )
// expect(await serialize(response)).toMatchObject({
// text: expect.stringContaining('ok'),
// status: 200,
// headers: {
// 'x-req-type': 'formData',
// 'x-serialized': '{"hello":"world"}',
// },
// })
// })
})
})

0 comments on commit 8eab3a1

Please sign in to comment.