rsnext/test/e2e/app-dir/set-cookies/set-cookies.test.ts
Leah 5d54eaaf18
type check tests (and convert next-test-utils.js to ts) (#51071)
Enables type checking for tests in CI and fixes a bunch of things related to that
2023-06-23 17:42:50 +00:00

46 lines
1.2 KiB
TypeScript

import { createNextDescribe } from 'e2e-utils'
import type { Response } from 'node-fetch'
import cookies, { nextConfigHeaders } from './cookies.mjs'
function getSetCookieHeaders(res: Response): ReadonlyArray<string> {
return (
(res.headers as any).getSetCookie?.() ??
(res.headers as any).raw()['set-cookie']
)
}
createNextDescribe(
'set-cookies',
{
files: __dirname,
// TODO: re-enable once this behavior is corrected on deploy
skipDeployment: true,
},
({ next }) => {
describe.each(['edge', 'experimental-edge', 'node'])(
'for %s runtime',
(runtime) => {
describe.each(['pages', 'app'])('for /%s', (dir) => {
it('should set two set-cookie headers', async () => {
let res = await next.fetch(`/api/${dir}/${runtime}`)
let headers = getSetCookieHeaders(res)
expect(headers).toHaveLength(2)
expect(headers).toEqual(cookies)
res = await next.fetch(
`/api/${dir}/${runtime}?next-config-headers=true`
)
headers = getSetCookieHeaders(res)
expect(headers).toHaveLength(4)
expect(headers).toEqual([...nextConfigHeaders, ...cookies])
})
})
}
)
}
)