Skip to content

Commit

Permalink
unskip middleware deploy test
Browse files Browse the repository at this point in the history
  • Loading branch information
ztanner committed Sep 19, 2024
1 parent 979fedb commit 08ef1db
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 43 deletions.
33 changes: 11 additions & 22 deletions test/e2e/app-dir/app-middleware/app-middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ import { nextTestSetup, FileRef } from 'e2e-utils'
import type { Response } from 'node-fetch'

describe('app-dir with middleware', () => {
const { next, skipped } = nextTestSetup({
const { next } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})

if (skipped) {
return
}

it('should filter correctly after middleware rewrite', async () => {
const browser = await next.browser('/start')

Expand Down Expand Up @@ -179,8 +174,10 @@ describe('app-dir with middleware', () => {

await browser.elementById('submit-server-action').click()

await retry(() => {
expect(next.cliOutput).toMatch(/\[Cookie From Action\]: \d+\.\d+/)
await retry(async () => {
expect(await browser.elementById('action-result').text()).toMatch(
/Action Result: \d+\.\d+/
)
})

// ensure that we still can't read the secure cookie
Expand Down Expand Up @@ -210,16 +207,18 @@ describe('app-dir with middleware', () => {

await browser.elementById('submit-server-action').click()

await retry(() => {
expect(next.cliOutput).toMatch(/\[Cookie From Action\]: \d+\.\d+/)
await retry(async () => {
expect(await browser.elementById('action-result').text()).toMatch(
/Action Result: \d+\.\d+/
)
})

await browser.deleteCookies()
})
})

describe('app dir - middleware without pages dir', () => {
const { next, skipped } = nextTestSetup({
const { next } = nextTestSetup({
files: {
app: new FileRef(path.join(__dirname, 'app')),
'next.config.js': new FileRef(path.join(__dirname, 'next.config.js')),
Expand All @@ -235,13 +234,8 @@ describe('app dir - middleware without pages dir', () => {
}
`,
},
skipDeployment: true,
})

if (skipped) {
return
}

// eslint-disable-next-line jest/no-identical-title
it('Updates headers', async () => {
const html = await next.render('/headers')
Expand All @@ -251,7 +245,7 @@ describe('app dir - middleware without pages dir', () => {
})

describe('app dir - middleware with middleware in src dir', () => {
const { next, skipped } = nextTestSetup({
const { next } = nextTestSetup({
files: {
'src/app': new FileRef(path.join(__dirname, 'app')),
'next.config.js': new FileRef(path.join(__dirname, 'next.config.js')),
Expand All @@ -265,13 +259,8 @@ describe('app dir - middleware with middleware in src dir', () => {
}
`,
},
skipDeployment: true,
})

if (skipped) {
return
}

it('works without crashing when using requestAsyncStorage', async () => {
const browser = await next.browser('/')
await browser.addCookie({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import { cookies } from 'next/headers'
import Link from 'next/link'
import { Form } from '../form'

export default function Page() {
return (
<div>
<p id="total-cookies">Total Cookie Length: {cookies().size}</p>
<Link href="/rsc-cookies-delete">To Delete Cookies Route</Link>

<form
<Form
action={async () => {
'use server'
console.log(
'[Cookie From Action]:',
cookies().get('rsc-secure-cookie').value
)
return cookies().get('rsc-secure-cookie').value
}}
>
<button type="submit" id="submit-server-action">
server action
</button>
</form>
/>
</div>
)
}
16 changes: 16 additions & 0 deletions test/e2e/app-dir/app-middleware/app/rsc-cookies/form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use client'

import { useActionState } from 'react'

export function Form({ action }) {
const [state, formAction] = useActionState(action, null)

return (
<form action={formAction}>
<div id="action-result">Action Result: {state}</div>
<button type="submit" id="submit-server-action">
server action
</button>
</form>
)
}
16 changes: 5 additions & 11 deletions test/e2e/app-dir/app-middleware/app/rsc-cookies/page.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { cookies } from 'next/headers'
import Link from 'next/link'
import { Form } from './form'

export default function Page() {
const rscCookie1 = cookies().get('rsc-cookie-value-1')?.value
Expand All @@ -11,20 +12,13 @@ export default function Page() {
<p id="rsc-cookie-2">Cookie 2: {rscCookie2}</p>
<p id="total-cookies">Total Cookie Length: {cookies().size}</p>
<Link href="/rsc-cookies-delete">To Delete Cookies Route</Link>

<form
<Form
action={async () => {
'use server'
console.log(
'[Cookie From Action]:',
cookies().get('rsc-cookie-value-1').value
)

return cookies().get('rsc-cookie-value-1')?.value
}}
>
<button type="submit" id="submit-server-action">
server action
</button>
</form>
/>
</div>
)
}

0 comments on commit 08ef1db

Please sign in to comment.