| |
| |
| |
| |
| @@ -1,25 +1,28 @@ |
| import { nextTestSetup } from 'e2e-utils' |
| import { retry } from 'next-test-utils' |
| +import type { Response } from 'playwright' |
| |
| describe('app-dir action progressive enhancement', () => { |
| const { next } = nextTestSetup({ |
| files: __dirname, |
| dependencies: { |
| nanoid: '4.0.1', |
| - 'server-only': 'latest', |
| + 'server-only': '0.0.1', |
| }, |
| }) |
| |
| it('should support formData and redirect without JS', async () => { |
| - let responseCode: number | undefined |
| + let actionResponse: Response | undefined |
| const browser = await next.browser('/server', { |
| disableJavaScript: true, |
| beforePageLoad(page) { |
| page.on('response', (response) => { |
| const url = new URL(response.url()) |
| - const status = response.status() |
| - if (url.pathname.includes('/server')) { |
| - responseCode = status |
| + if ( |
| + url.pathname === '/server' && |
| + response.request().method() === 'POST' |
| + ) { |
| + actionResponse = response |
| } |
| }) |
| }, |
| @@ -34,7 +37,10 @@ describe('app-dir action progressive enhancement', () => { |
| ) |
| }) |
| |
| - expect(responseCode).toBe(303) |
| + expect(actionResponse).toBeDefined() |
| + expect(actionResponse!.status()).toBe(303) |
| + const headers = await actionResponse!.allHeaders() |
| + expect(headers.location).toBe('/header?name=test&hidden-info=hi') |
| }) |
| |
| it('should support actions from client without JS', async () => { |
| |
| |
| |
| |
| @@ -6,7 +6,7 @@ describe('app dir - basepath', () => { |
| const { next, isNextDev } = nextTestSetup({ |
| files: __dirname, |
| dependencies: { |
| - sass: 'latest', |
| + sass: '1.54.0', |
| }, |
| }) |
| |
| @@ -156,7 +156,12 @@ describe('app dir - basepath', () => { |
| |
| expect(request.url()).toEqual(`${next.url}${initialPagePath}`) |
| expect(request.method()).toEqual('POST') |
| - expect(response.status()).toEqual(303) |
| + expect(response.status()).toEqual(200) |
| + |
| + const headers = await response.allHeaders() |
| + expect(headers['x-action-redirect']).toBeDefined() |
| + expect(headers.location).toBeUndefined() |
| + expect(headers['content-type']).toContain('text/x-component') |
| } |
| ) |
| |
| @@ -204,7 +209,10 @@ describe('app dir - basepath', () => { |
| expect(secondRequest.url()).toEqual(`${next.url}${destinationPagePath}`) |
| expect(secondRequest.method()).toEqual('GET') |
| |
| - expect(firstResponse.status()).toEqual(303) |
| + expect(firstResponse.status()).toEqual(200) |
| + const headers = await firstResponse.allHeaders() |
| + expect(headers['x-action-redirect']).toBeDefined() |
| + expect(headers.location).toBeUndefined() |
| // Since this is an external request to a resource outside of NextJS |
| // we expect to see a separate request resolving the external URL. |
| expect(secondResponse.status()).toEqual(200) |
|
|