From d6f84fd5d43b701bfca0aec98e99bcd318fa2326 Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Tue, 9 May 2023 00:28:01 +0200 Subject: [PATCH] add test case for #49235 --- test/e2e/app-dir/actions/app-action.test.ts | 20 +++++++++++++++++++ .../e2e/app-dir/actions/app/client/actions.js | 5 +++++ test/e2e/app-dir/actions/app/client/page.js | 7 ++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/test/e2e/app-dir/actions/app-action.test.ts b/test/e2e/app-dir/actions/app-action.test.ts index b94b72f54ea8..b402d6f70fb3 100644 --- a/test/e2e/app-dir/actions/app-action.test.ts +++ b/test/e2e/app-dir/actions/app-action.test.ts @@ -59,6 +59,26 @@ createNextDescribe( }, 'same') }) + it('should support headers in client imported actions', async () => { + const logs: string[] = [] + next.on('stdout', (log) => { + logs.push(log) + }) + next.on('stderr', (log) => { + logs.push(log) + }) + + const browser = await next.browser('/client') + await browser.elementByCss('#get-header').click() + await check(() => { + return logs.some((log) => + log.includes('accept header: text/x-component') + ) + ? 'yes' + : '' + }, 'yes') + }) + it('should support setting cookies in route handlers with the correct overrides', async () => { const res = await next.fetch('/handler') const setCookieHeader = res.headers.get('set-cookie') as string[] diff --git a/test/e2e/app-dir/actions/app/client/actions.js b/test/e2e/app-dir/actions/app/client/actions.js index a1aa005a571d..a311e5958de8 100644 --- a/test/e2e/app-dir/actions/app/client/actions.js +++ b/test/e2e/app-dir/actions/app/client/actions.js @@ -1,6 +1,11 @@ 'use server' import { redirect } from 'next/navigation' +import { headers } from 'next/headers' + +export async function getHeaders() { + console.log('accept header:', headers().get('accept')) +} export async function inc(value) { return value + 1 diff --git a/test/e2e/app-dir/actions/app/client/page.js b/test/e2e/app-dir/actions/app/client/page.js index 68043e4c0cfc..bec2e5e4e23f 100644 --- a/test/e2e/app-dir/actions/app/client/page.js +++ b/test/e2e/app-dir/actions/app/client/page.js @@ -2,7 +2,7 @@ import { useState } from 'react' -import double, { inc, dec, redirectAction } from './actions' +import double, { inc, dec, redirectAction, getHeaders } from './actions' export default function Counter() { const [count, setCount] = useState(0) @@ -52,6 +52,11 @@ export default function Counter() { redirect external +
+ +
) }