Unverified Commit a919e4a3 authored by Justin Ridgewell's avatar Justin Ridgewell Committed by GitHub

Add test case for App Route cookies (#49124)

A simple test case to ensure `cookies()` is usable inside App Routes,
based on a prior bug report.

Closes WEB-627

---------
Co-authored-by: 's avatarTobias Koppers <tobias.koppers@googlemail.com>
parent f2e6d420
import { cookies } from 'next/headers'
export async function GET(request: Request) {
const cookieStore = cookies()
const token = cookieStore.get('token')?.value ?? Math.random()
return new Response(String(token), {
status: 200,
headers: { 'Set-Cookie': `token=${token}` },
})
}
export default function RootLayout({ children }: { children: any }) {
return (
<html>
<body>{children}</body>
</html>
)
}
import Test from './test'
export default function Page() {
return (
<div>
<Test />
</div>
)
}
'use client'
import { useTestHarness } from '@turbo/pack-test-harness'
function test() {
it('should handle cookies in Route request', async () => {
const first = await fetch('/api/test')
const text = await first.text()
expect(text).toMatch(/[\d.]+/)
const second = await fetch('/api/test')
expect(await second.text()).toEqual(text)
}, 20000)
}
export default function Test() {
useTestHarness(test)
}
PlainIssue {
severity: Warning,
context: "[project]/packages/next/dist/compiled/edge-runtime/index.js",
category: "parse",
title: "error TP1003 require.resolve(???*0*, {\"paths\": [???*1*]}) is not statically analyse-able",
description: "- *0* arguments[1]\n ⚠\u{fe0f} function calls are not analysed yet\n- *1* ???*2*[\"dirname\"](a)\n ⚠\u{fe0f} unknown callee object\n- *2* ???(17)\n ⚠\u{fe0f} unknown callee",
detail: "",
documentation_link: "",
source: Some(
PlainIssueSource {
asset: PlainAsset {
ident: "[project]/packages/next/dist/compiled/edge-runtime/index.js",
},
start: SourcePos {
line: 0,
column: 6730,
},
end: SourcePos {
line: 0,
column: 6730,
},
},
),
sub_issues: [],
processing_path: Some(
[
PlainIssueProcessingPathItem {
context: Some(
"[project]/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/route-WEB-627/input/app",
),
description: "Next.js App Route /api/test",
},
],
),
}
\ No newline at end of file
PlainIssue {
severity: Warning,
context: "[project]/packages/next/dist/compiled/@edge-runtime/primitives/crypto.js",
category: "parse",
title: "lint TP1200 passing an ID to AMD define() is not yet fully supported",
description: "",
detail: "",
documentation_link: "",
source: Some(
PlainIssueSource {
asset: PlainAsset {
ident: "[project]/packages/next/dist/compiled/@edge-runtime/primitives/crypto.js",
},
start: SourcePos {
line: 70,
column: 8,
},
end: SourcePos {
line: 70,
column: 8,
},
},
),
sub_issues: [],
processing_path: Some(
[
PlainIssueProcessingPathItem {
context: Some(
"[project]/packages/next-swc/crates/next-dev-tests/tests/integration/next/app/route-WEB-627/input/app",
),
description: "Next.js App Route /api/test",
},
],
),
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment