Skip to content

Commit d184b6b

Browse files
committed
add test for pages router
1 parent 575bad3 commit d184b6b

File tree

8 files changed

+140
-0
lines changed

8 files changed

+140
-0
lines changed

test/e2e/turbopack-emit-collect/index.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,54 @@ import { nextTestSetup } from 'e2e-utils'
154154
}
155155
})
156156

157+
it('works for /pages/a', async () => {
158+
let $ = await next.render$('/pages/a')
159+
let response = JSON.parse($('#list').text())
160+
if (isNextDev) {
161+
expect(formatData(response)).toMatchInlineSnapshot(`
162+
[
163+
"pages-lib/a/unique.js [ssr] : "data-for-unique-pages-a" ==> "unique /pages/a"",
164+
"shared-pages-client.js [ssr] : "data-for-shared-pages-a" ==> "shared pages client"",
165+
]
166+
`)
167+
} else {
168+
expect(formatData(response)).toMatchInlineSnapshot(`
169+
[
170+
"app/client/shared-app-client.js [app-client] : "data-for-shared-app-client-a" ==> "app client"",
171+
"app/client/shared-app-client.js [app-ssr] : "data-for-shared-app-client-a" ==> "app client"",
172+
"app/rsc/shared-app/target.js [app-rsc] : "data-for-shared-app" ==> "shared-app"",
173+
"pages-lib/a/unique.js [ssr] : "data-for-unique-pages-a" ==> "unique /pages/a"",
174+
"shared-pages-client.js [client] : "data-for-shared-pages-client-only" ==> "shared pages client"",
175+
"shared-pages-client.js [ssr] : "data-for-shared-pages-client-only" ==> "shared pages client"",
176+
]
177+
`)
178+
}
179+
})
180+
181+
it('works for /pages/client-only', async () => {
182+
let $ = await next.render$('/pages/client-only')
183+
let response = JSON.parse($('#list').text())
184+
if (isNextDev) {
185+
expect(formatData(response)).toMatchInlineSnapshot(`
186+
[
187+
"pages-lib/client-only/unique.js [ssr] : "data-for-unique-pages-client-only" ==> "unique /pages/client-only"",
188+
"shared-pages-client.js [ssr] : "data-for-shared-pages-client-only" ==> "shared pages client"",
189+
]
190+
`)
191+
} else {
192+
expect(formatData(response)).toMatchInlineSnapshot(`
193+
[
194+
"app/client/shared-app-client.js [app-client] : "data-for-shared-app-client-a" ==> "app client"",
195+
"app/client/shared-app-client.js [app-ssr] : "data-for-shared-app-client-a" ==> "app client"",
196+
"app/rsc/shared-app/target.js [app-rsc] : "data-for-shared-app" ==> "shared-app"",
197+
"pages-lib/client-only/unique.js [ssr] : "data-for-unique-pages-client-only" ==> "unique /pages/client-only"",
198+
"shared-pages-client.js [client] : "data-for-shared-pages-client-only" ==> "shared pages client"",
199+
"shared-pages-client.js [ssr] : "data-for-shared-pages-client-only" ==> "shared pages client"",
200+
]
201+
`)
202+
}
203+
})
204+
157205
it('works for /api', async () => {
158206
const response = JSON.parse(await next.render('/api'))
159207
if (isNextDev) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use client'
2+
3+
__turbopack_emit__('./unique.js', {
4+
namespace: 'my-test',
5+
data: 'data-for-unique-pages-a',
6+
})
7+
8+
__turbopack_emit__('../../shared-pages-client.js', {
9+
namespace: 'my-test',
10+
data: 'data-for-shared-pages-a',
11+
scope: 'app',
12+
})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'unique /pages/a'
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
__turbopack_emit__('./unique.js', {
2+
namespace: 'my-test',
3+
data: 'data-for-unique-pages-client-only',
4+
})
5+
6+
__turbopack_emit__('../../shared-pages-client.js', {
7+
namespace: 'my-test',
8+
data: 'data-for-shared-pages-client-only',
9+
scope: 'app',
10+
})
11+
12+
export default function () {
13+
return 'client'
14+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'unique /pages/client-only'
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import '../../pages-lib/a/lib'
2+
3+
const getList = __turbopack_collect__({
4+
namespace: 'my-test',
5+
})
6+
7+
export async function getServerSideProps() {
8+
const list = await Promise.all(
9+
getList().map(async (v) => ({
10+
id: v.id,
11+
data: v.data,
12+
import: (await v.import()).default,
13+
}))
14+
)
15+
16+
return {
17+
props: {
18+
list,
19+
},
20+
}
21+
}
22+
23+
export default function Page({ list }) {
24+
return (
25+
<div>
26+
<code id="list">{JSON.stringify(list, null, 2)}</code>
27+
</div>
28+
)
29+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import dynamic from 'next/dynamic'
2+
3+
const Client = dynamic(() => import('../../pages-lib/client-only/lib'), {
4+
ssr: false,
5+
})
6+
7+
const getList = __turbopack_collect__({
8+
namespace: 'my-test',
9+
})
10+
11+
export async function getServerSideProps() {
12+
const list = await Promise.all(
13+
getList().map(async (v) => ({
14+
id: v.id,
15+
data: v.data,
16+
import: (await v.import()).default,
17+
}))
18+
)
19+
20+
return {
21+
props: {
22+
list,
23+
},
24+
}
25+
}
26+
27+
export default function Page({ list }) {
28+
return (
29+
<div>
30+
<Client />
31+
<code id="list">{JSON.stringify(list, null, 2)}</code>
32+
</div>
33+
)
34+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'shared pages client'

0 commit comments

Comments
 (0)