Skip to content

Commit

Permalink
add test case for #49235
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding committed May 8, 2023
1 parent 20e1349 commit d6f84fd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
20 changes: 20 additions & 0 deletions test/e2e/app-dir/actions/app-action.test.ts
Expand Up @@ -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[]
Expand Down
5 changes: 5 additions & 0 deletions 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
Expand Down
7 changes: 6 additions & 1 deletion test/e2e/app-dir/actions/app/client/page.js
Expand Up @@ -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)
Expand Down Expand Up @@ -52,6 +52,11 @@ export default function Counter() {
redirect external
</button>
</form>
<form action={getHeaders}>
<button type="submit" id="get-header">
submit
</button>
</form>
</div>
)
}

0 comments on commit d6f84fd

Please sign in to comment.