avyvar's picture
Add files using upload-large-folder tool
94786da verified
Raw
History Blame Contribute Delete
5.68 kB
diff --git a/test/production/app-dir/output-export-async-route-module/fixtures/invalid/app/api/data/route.ts b/test/production/app-dir/output-export-async-route-module/fixtures/invalid/app/api/data/route.ts
new file mode 100644
index 00000000..b26a97fd
--- /dev/null
+++ b/test/production/app-dir/output-export-async-route-module/fixtures/invalid/app/api/data/route.ts
@@ -0,0 +1,6 @@
+// Top-level await makes this an async module.
+await Promise.resolve()
+
+export async function GET() {
+ return Response.json({ ok: true })
+}
diff --git a/test/production/app-dir/output-export-async-route-module/fixtures/invalid/app/layout.tsx b/test/production/app-dir/output-export-async-route-module/fixtures/invalid/app/layout.tsx
new file mode 100644
index 00000000..888614de
--- /dev/null
+++ b/test/production/app-dir/output-export-async-route-module/fixtures/invalid/app/layout.tsx
@@ -0,0 +1,8 @@
+import { ReactNode } from 'react'
+export default function Root({ children }: { children: ReactNode }) {
+ return (
+ <html>
+ <body>{children}</body>
+ </html>
+ )
+}
diff --git a/test/production/app-dir/output-export-async-route-module/fixtures/invalid/app/page.tsx b/test/production/app-dir/output-export-async-route-module/fixtures/invalid/app/page.tsx
new file mode 100644
index 00000000..ff7159d9
--- /dev/null
+++ b/test/production/app-dir/output-export-async-route-module/fixtures/invalid/app/page.tsx
@@ -0,0 +1,3 @@
+export default function Page() {
+ return <p>hello world</p>
+}
diff --git a/test/production/app-dir/output-export-async-route-module/fixtures/invalid/next.config.js b/test/production/app-dir/output-export-async-route-module/fixtures/invalid/next.config.js
new file mode 100644
index 00000000..fecf9218
--- /dev/null
+++ b/test/production/app-dir/output-export-async-route-module/fixtures/invalid/next.config.js
@@ -0,0 +1,8 @@
+/**
+ * @type {import('next').NextConfig}
+ */
+const nextConfig = {
+ output: 'export',
+}
+
+module.exports = nextConfig
diff --git a/test/production/app-dir/output-export-async-route-module/fixtures/valid/app/api/data/route.ts b/test/production/app-dir/output-export-async-route-module/fixtures/valid/app/api/data/route.ts
new file mode 100644
index 00000000..c60b6bb7
--- /dev/null
+++ b/test/production/app-dir/output-export-async-route-module/fixtures/valid/app/api/data/route.ts
@@ -0,0 +1,8 @@
+// Top-level await makes this an async module.
+await Promise.resolve()
+
+export const dynamic = 'force-static'
+
+export async function GET() {
+ return Response.json({ ok: true })
+}
diff --git a/test/production/app-dir/output-export-async-route-module/fixtures/valid/app/layout.tsx b/test/production/app-dir/output-export-async-route-module/fixtures/valid/app/layout.tsx
new file mode 100644
index 00000000..888614de
--- /dev/null
+++ b/test/production/app-dir/output-export-async-route-module/fixtures/valid/app/layout.tsx
@@ -0,0 +1,8 @@
+import { ReactNode } from 'react'
+export default function Root({ children }: { children: ReactNode }) {
+ return (
+ <html>
+ <body>{children}</body>
+ </html>
+ )
+}
diff --git a/test/production/app-dir/output-export-async-route-module/fixtures/valid/app/page.tsx b/test/production/app-dir/output-export-async-route-module/fixtures/valid/app/page.tsx
new file mode 100644
index 00000000..ff7159d9
--- /dev/null
+++ b/test/production/app-dir/output-export-async-route-module/fixtures/valid/app/page.tsx
@@ -0,0 +1,3 @@
+export default function Page() {
+ return <p>hello world</p>
+}
diff --git a/test/production/app-dir/output-export-async-route-module/fixtures/valid/next.config.js b/test/production/app-dir/output-export-async-route-module/fixtures/valid/next.config.js
new file mode 100644
index 00000000..fecf9218
--- /dev/null
+++ b/test/production/app-dir/output-export-async-route-module/fixtures/valid/next.config.js
@@ -0,0 +1,8 @@
+/**
+ * @type {import('next').NextConfig}
+ */
+const nextConfig = {
+ output: 'export',
+}
+
+module.exports = nextConfig
diff --git a/test/production/app-dir/output-export-async-route-module/output-export-async-route-module.test.ts b/test/production/app-dir/output-export-async-route-module/output-export-async-route-module.test.ts
new file mode 100644
index 00000000..0c8ac29a
--- /dev/null
+++ b/test/production/app-dir/output-export-async-route-module/output-export-async-route-module.test.ts
@@ -0,0 +1,36 @@
+import { join } from 'path'
+import { nextTestSetup } from 'e2e-utils'
+
+describe('output-export-async-route-module', () => {
+ describe('invalid route', () => {
+ const { next } = nextTestSetup({
+ files: join(__dirname, 'fixtures', 'invalid'),
+ skipStart: true,
+ })
+
+ // The route module uses top-level await, so its `output: 'export'`
+ // validation runs after the module settles instead of throwing during
+ // require(). The resulting error must still fail the build.
+ it('fails the build when an async route module is not statically exportable', async () => {
+ const { exitCode, cliOutput } = await next.build()
+ expect(cliOutput).toContain(
+ 'not configured on route "/api/data" with "output: export"'
+ )
+ expect(exitCode).toEqual(expect.any(Number))
+ expect(exitCode).not.toBe(0)
+ })
+ })
+
+ describe('valid route', () => {
+ const { next } = nextTestSetup({
+ files: join(__dirname, 'fixtures', 'valid'),
+ skipStart: true,
+ })
+
+ it('exports an async route module that is statically exportable', async () => {
+ const { exitCode } = await next.build()
+ expect(exitCode).toBe(0)
+ expect(await next.readFile('out/api/data')).toBe('{"ok":true}')
+ })
+ })
+})