File size: 5,682 Bytes
94786da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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}')
+    })
+  })
+})