-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[after] duplicate test pages for edge instead of next.patch (#69477)
`unstable_after` needs to be tested in both nodejs and edge runtimes. Previously, we set the runtime via `next.patch()`, but this proved error-prone (e.g. because `sandbox()` call would override this patch, and not actually run anything in edge...) This PR makes this more static by splitting the test pages for `unstable_after` into `/nodejs` and `/edge`, each with a corresponding `export const runtime = "..."` in its root layout. The pages in `/edge` mirror the structure of `/nodejs` and reexport components from it (which makes the tests easier to update than simply duplicating everything). note that "use client" directives and route segment configs cannot be reexported and need to be duplicated.
- Loading branch information
1 parent
ae1efa4
commit 53201b1
Showing
42 changed files
with
213 additions
and
174 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...t-after-app/app/invalid-in-client/page.js → ...valid-usage/app/invalid-in-client/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
...app-dir/next-after-app/app/static/page.js → ...sage/app/invalid-in-dynamic-error/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import { unstable_after as after } from 'next/server' | ||
import { cliLog } from '../../utils/log' | ||
|
||
// (patched in tests) | ||
// export const dynamic = 'REPLACE_ME' | ||
export const dynamic = 'error' | ||
|
||
export default function Index() { | ||
after(async () => { | ||
cliLog({ source: '[page] /static' }) | ||
cliLog({ source: '[page] /invalid-in-dynamic-error' }) | ||
}) | ||
return <div>Page with after()</div> | ||
} |
11 changes: 11 additions & 0 deletions
11
...elopment/app-dir/next-after-app-invalid-usage/app/invalid-in-dynamic-force-static/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { unstable_after as after } from 'next/server' | ||
import { cliLog } from '../../utils/log' | ||
|
||
export const dynamic = 'force-static' | ||
|
||
export default function Index() { | ||
after(async () => { | ||
cliLog({ source: '[page] /invalid-in-dynamic-force-static' }) | ||
}) | ||
return <div>Page with after()</div> | ||
} |
10 changes: 10 additions & 0 deletions
10
test/development/app-dir/next-after-app-invalid-usage/app/layout.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default function AppLayout({ children }) { | ||
return ( | ||
<html> | ||
<head> | ||
<title>after</title> | ||
</head> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
50 changes: 50 additions & 0 deletions
50
test/development/app-dir/next-after-app-invalid-usage/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* eslint-env jest */ | ||
import { nextTestSetup } from 'e2e-utils' | ||
import * as Log from './utils/log' | ||
import { | ||
assertHasRedbox, | ||
getRedboxDescription, | ||
getRedboxSource, | ||
} from '../../../lib/next-test-utils' | ||
|
||
describe('unstable_after() - invalid usages', () => { | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
let currentCliOutputIndex = 0 | ||
beforeEach(() => { | ||
currentCliOutputIndex = next.cliOutput.length | ||
}) | ||
|
||
const getLogs = () => { | ||
if (next.cliOutput.length < currentCliOutputIndex) { | ||
// cliOutput shrank since we started the test, so something (like a `sandbox`) reset the logs | ||
currentCliOutputIndex = 0 | ||
} | ||
return Log.readCliLogs(next.cliOutput.slice(currentCliOutputIndex)) | ||
} | ||
|
||
it.each(['error', 'force-static'])( | ||
`errors at compile time with dynamic = "%s"`, | ||
async (dynamicValue) => { | ||
const pathname = '/invalid-in-dynamic-' + dynamicValue | ||
const session = await next.browser(pathname) | ||
|
||
await assertHasRedbox(session) | ||
expect(await getRedboxDescription(session)).toContain( | ||
`Route ${pathname} with \`dynamic = "${dynamicValue}"\` couldn't be rendered statically because it used \`unstable_after\`` | ||
) | ||
expect(getLogs()).toHaveLength(0) | ||
} | ||
) | ||
it('errors at compile time when used in a client module', async () => { | ||
const session = await next.browser('/invalid-in-client') | ||
|
||
await assertHasRedbox(session) | ||
expect(await getRedboxSource(session)).toMatch( | ||
/You're importing a component that needs "?unstable_after"?\. That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component\./ | ||
) | ||
expect(getLogs()).toHaveLength(0) | ||
}) | ||
}) |
6 changes: 6 additions & 0 deletions
6
test/development/app-dir/next-after-app-invalid-usage/next.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** @type {import('next').NextConfig} */ | ||
module.exports = { | ||
experimental: { | ||
after: true, | ||
}, | ||
} |
16 changes: 16 additions & 0 deletions
16
test/development/app-dir/next-after-app-invalid-usage/utils/log.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export function cliLog(/** @type {string | Record<string, any>} */ data) { | ||
console.log('<test-log>' + JSON.stringify(data) + '</test-log>') | ||
} | ||
|
||
export function readCliLogs(/** @type {string} */ output) { | ||
return output | ||
.split('\n') | ||
.map((line) => { | ||
const match = line.match(/^<test-log>(?<value>.+?)<\/test-log>$/) | ||
if (!match) { | ||
return null | ||
} | ||
return JSON.parse(match.groups.value) | ||
}) | ||
.filter(Boolean) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from '../../../nodejs/[id]/dynamic/page' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from '../../nodejs/[id]/layout' |
1 change: 1 addition & 0 deletions
1
test/e2e/app-dir/next-after-app/app/edge/[id]/setting-cookies/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from '../../../nodejs/[id]/setting-cookies/page' |
1 change: 1 addition & 0 deletions
1
test/e2e/app-dir/next-after-app/app/edge/[id]/with-action/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from '../../../nodejs/[id]/with-action/page' |
4 changes: 4 additions & 0 deletions
4
test/e2e/app-dir/next-after-app/app/edge/[id]/with-metadata/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { | ||
default, | ||
generateMetadata, | ||
} from '../../../nodejs/[id]/with-metadata/page' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default } from '../../nodejs/delay/page' | ||
|
||
export const dynamic = 'force-dynamic' |
1 change: 1 addition & 0 deletions
1
test/e2e/app-dir/next-after-app/app/edge/interrupted/calls-not-found/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from '../../../nodejs/interrupted/calls-not-found/page' |
5 changes: 5 additions & 0 deletions
5
test/e2e/app-dir/next-after-app/app/edge/interrupted/calls-redirect/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { createPage } from '../../../nodejs/interrupted/calls-redirect/page' | ||
|
||
// NOTE: this page is forked from /nodejs | ||
|
||
export default createPage('/edge') |
1 change: 1 addition & 0 deletions
1
test/e2e/app-dir/next-after-app/app/edge/interrupted/redirect-target/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from '../../../nodejs/interrupted/redirect-target/page' |
1 change: 1 addition & 0 deletions
1
test/e2e/app-dir/next-after-app/app/edge/interrupted/throws-error/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from '../../../nodejs/interrupted/throws-error/page' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default } from '../nodejs/layout' | ||
|
||
export const runtime = 'edge' |
1 change: 1 addition & 0 deletions
1
test/e2e/app-dir/next-after-app/app/edge/middleware/redirect/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from '../../../nodejs/middleware/redirect/page' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from '../../nodejs/nested-after/page' |
1 change: 1 addition & 0 deletions
1
test/e2e/app-dir/next-after-app/app/edge/provided-request-context/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from '../../nodejs/provided-request-context/page' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { GET } from '../../nodejs/route/route' | ||
|
||
export const runtime = 'edge' | ||
export const dynamic = 'force-dynamic' |
12 changes: 0 additions & 12 deletions
12
test/e2e/app-dir/next-after-app/app/interrupted/calls-redirect/page.js
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...r/next-after-app/app/[id]/dynamic/page.js → ...after-app/app/nodejs/[id]/dynamic/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...app-dir/next-after-app/app/[id]/layout.js → .../next-after-app/app/nodejs/[id]/layout.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...xt-after-app/app/[id]/with-action/page.js → ...r-app/app/nodejs/[id]/with-action/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...-after-app/app/[id]/with-metadata/page.js → ...app/app/nodejs/[id]/with-metadata/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../app-dir/next-after-app/app/delay/page.js → ...r/next-after-app/app/nodejs/delay/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...p/app/interrupted/calls-not-found/page.js → ...odejs/interrupted/calls-not-found/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
test/e2e/app-dir/next-after-app/app/nodejs/interrupted/calls-redirect/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { unstable_after as after } from 'next/server' | ||
import { redirect } from 'next/navigation' | ||
import { cliLog } from '../../../../utils/log' | ||
|
||
// NOTE: this page is forked in /edge | ||
|
||
export function createPage(pathPrefix) { | ||
return function Page() { | ||
after(() => { | ||
cliLog({ | ||
source: '[page] /interrupted/calls-redirect', | ||
}) | ||
}) | ||
|
||
redirect(pathPrefix + '/interrupted/redirect-target') | ||
} | ||
} | ||
|
||
export default createPage('/nodejs') |
2 changes: 1 addition & 1 deletion
2
...p/app/interrupted/redirect-target/page.js → ...odejs/interrupted/redirect-target/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...-app/app/interrupted/throws-error/page.js → ...p/nodejs/interrupted/throws-error/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
.../e2e/app-dir/next-after-app/app/layout.js → ...p-dir/next-after-app/app/nodejs/layout.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...r/next-after-app/app/nested-after/page.js → ...after-app/app/nodejs/nested-after/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...-app/app/provided-request-context/page.js → ...p/nodejs/provided-request-context/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
...app-dir/next-after-app/app/route/route.js → .../next-after-app/app/nodejs/route/route.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.