Skip to content

Commit ca831cf

Browse files
authored
test: fix actions deployment tests (#87279)
Fixes a few failing deployment tests that weren't validated when landed last week. - next.cliOutput is not available when deployed because it's part of runtime logs - status code changes on Vercel because POSTing to a static 404 page is treated differently.
1 parent 634cfd3 commit ca831cf

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

test/e2e/app-dir/actions-unrecognized/actions-unrecognized.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe('unrecognized server actions', () => {
8282
)
8383
}
8484

85-
it('should 404 when POSTing a urlencoded action to a nonexistent page', async () => {
85+
it('should error when POSTing a urlencoded action to a nonexistent page', async () => {
8686
const res = await next.fetch('/non-existent-route', {
8787
method: 'POST',
8888
headers: {
@@ -92,7 +92,8 @@ describe('unrecognized server actions', () => {
9292
body: 'foo=bar',
9393
})
9494

95-
expect(res.status).toBe(404)
95+
// On Vercel, this would hit the 404 route which is a static page, and returns a 405 instead.
96+
expect(res.status).toBe(isNextDeploy ? 405 : 404)
9697
})
9798

9899
describe.each(['nodejs', 'edge'])(
Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { nextTestSetup } from 'e2e-utils'
22

33
describe('app-dir - no server actions', () => {
4-
const { next } = nextTestSetup({
4+
const { next, isNextDeploy } = nextTestSetup({
55
files: __dirname,
66
})
77

8-
it('should 404 when triggering a fetch action on an app with no server actions', async () => {
8+
it('should error when triggering a fetch action on an app with no server actions', async () => {
99
const res = await next.fetch('/', {
1010
method: 'POST',
1111
headers: {
@@ -15,28 +15,36 @@ describe('app-dir - no server actions', () => {
1515

1616
expect(res.status).toBe(404)
1717
expect(res.headers.get('x-nextjs-action-not-found')).toBe('1')
18-
expect(next.cliOutput).toContain(
19-
'Failed to find Server Action "abc123". This request might be from an older or newer deployment.\nRead more: https://nextjs.org/docs/messages/failed-to-find-server-action'
20-
)
18+
19+
// Runtime logs and custom headers are not forwarded to the client when deployed.
20+
if (!isNextDeploy) {
21+
expect(next.cliOutput).toContain(
22+
'Failed to find Server Action "abc123". This request might be from an older or newer deployment.\nRead more: https://nextjs.org/docs/messages/failed-to-find-server-action'
23+
)
24+
}
2125
})
2226

23-
it('should 404 when triggering an MPA action on an app with no server actions', async () => {
27+
it('should error when triggering an MPA action on an app with no server actions', async () => {
2428
const formData = new FormData()
2529
formData.append('test', 'value')
2630

2731
const res = await next.fetch('/', {
2832
method: 'POST',
2933
headers: {
30-
'Content-Type': 'multipart/form-data',
34+
'Content-Type': 'multipart/form-data; boundary=test',
3135
},
3236
// @ts-expect-error: node-fetch types don't seem to like FormData
3337
body: formData,
3438
})
3539

3640
expect(res.status).toBe(404)
3741
expect(res.headers.get('x-nextjs-action-not-found')).toBe('1')
38-
expect(next.cliOutput).toContain(
39-
'Failed to find Server Action. This request might be from an older or newer deployment.\nRead more: https://nextjs.org/docs/messages/failed-to-find-server-action'
40-
)
42+
43+
// Runtime logs are not available when deployed.
44+
if (!isNextDeploy) {
45+
expect(next.cliOutput).toContain(
46+
'Failed to find Server Action. This request might be from an older or newer deployment.\nRead more: https://nextjs.org/docs/messages/failed-to-find-server-action'
47+
)
48+
}
4149
})
4250
})

0 commit comments

Comments
 (0)