Skip to content

Commit 9576042

Browse files
committed
add test for pages router
1 parent 2394d32 commit 9576042

File tree

8 files changed

+154
-0
lines changed

8 files changed

+154
-0
lines changed

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ import { nextTestSetup } from 'e2e-utils'
4646
"app/client/shared-app-client.js [app-ssr] : "data-for-shared-app-client-a" ==> "app client"",
4747
"app/layout-target.js [app-rsc] : "data-for-layout" ==> "layout"",
4848
"app/rsc/shared-app/target.js [app-rsc] : "data-for-shared-app" ==> "shared-app"",
49+
"shared-pages-client.js [client] : "data-for-shared-pages-client-only" ==> "shared pages client"",
50+
"shared-pages-client.js [ssr] : "data-for-shared-pages-client-only" ==> "shared pages client"",
4951
]
5052
`)
5153
}
@@ -73,6 +75,8 @@ import { nextTestSetup } from 'e2e-utils'
7375
"app/client/shared-app-client.js [app-ssr] : "data-for-shared-app-client-a" ==> "app client"",
7476
"app/layout-target.js [app-rsc] : "data-for-layout" ==> "layout"",
7577
"app/rsc/shared-app/target.js [app-rsc] : "data-for-shared-app" ==> "shared-app"",
78+
"shared-pages-client.js [client] : "data-for-shared-pages-client-only" ==> "shared pages client"",
79+
"shared-pages-client.js [ssr] : "data-for-shared-pages-client-only" ==> "shared pages client"",
7680
]
7781
`)
7882
}
@@ -99,6 +103,8 @@ import { nextTestSetup } from 'e2e-utils'
99103
"app/rsc/a/unique.js [app-rsc] : "data-for-unique-rsc-a" ==> "unique /rsc/a"",
100104
"app/rsc/shared-app/target.js [app-rsc] : "data-for-shared-app" ==> "shared-app"",
101105
"app/rsc/shared-page/target.js [app-rsc] : "data-for-shared-page" ==> "shared-page"",
106+
"shared-pages-client.js [client] : "data-for-shared-pages-client-only" ==> "shared pages client"",
107+
"shared-pages-client.js [ssr] : "data-for-shared-pages-client-only" ==> "shared pages client"",
102108
]
103109
`)
104110
}
@@ -125,6 +131,8 @@ import { nextTestSetup } from 'e2e-utils'
125131
"app/rsc/b/unique.js [app-rsc] : "data-for-unique-rsc-b" ==> "unique /rsc/b"",
126132
"app/rsc/shared-app/target.js [app-rsc] : "data-for-shared-app" ==> "shared-app"",
127133
"app/rsc/shared-page/target.js [app-rsc] : "data-for-shared-page" ==> "shared-page"",
134+
"shared-pages-client.js [client] : "data-for-shared-pages-client-only" ==> "shared pages client"",
135+
"shared-pages-client.js [ssr] : "data-for-shared-pages-client-only" ==> "shared pages client"",
128136
]
129137
`)
130138
}
@@ -149,6 +157,56 @@ import { nextTestSetup } from 'e2e-utils'
149157
"app/layout-target.js [app-rsc] : "data-for-layout" ==> "layout"",
150158
"app/rsc/shared-app/target.js [app-rsc] : "data-for-shared-app" ==> "shared-app"",
151159
"app/rsc/shared-page/target.js [app-rsc] : "data-for-shared-page" ==> "shared-page"",
160+
"shared-pages-client.js [client] : "data-for-shared-pages-client-only" ==> "shared pages client"",
161+
"shared-pages-client.js [ssr] : "data-for-shared-pages-client-only" ==> "shared pages client"",
162+
]
163+
`)
164+
}
165+
})
166+
167+
it('works for /pages/a', async () => {
168+
let $ = await next.render$('/pages/a')
169+
let response = JSON.parse($('#list').text())
170+
if (isNextDev) {
171+
expect(formatData(response)).toMatchInlineSnapshot(`
172+
[
173+
"pages-lib/a/unique.js [ssr] : "data-for-unique-pages-a" ==> "unique /pages/a"",
174+
"shared-pages-client.js [ssr] : "data-for-shared-pages-a" ==> "shared pages client"",
175+
]
176+
`)
177+
} else {
178+
expect(formatData(response)).toMatchInlineSnapshot(`
179+
[
180+
"app/client/shared-app-client.js [app-client] : "data-for-shared-app-client-a" ==> "app client"",
181+
"app/client/shared-app-client.js [app-ssr] : "data-for-shared-app-client-a" ==> "app client"",
182+
"app/rsc/shared-app/target.js [app-rsc] : "data-for-shared-app" ==> "shared-app"",
183+
"pages-lib/a/unique.js [ssr] : "data-for-unique-pages-a" ==> "unique /pages/a"",
184+
"shared-pages-client.js [client] : "data-for-shared-pages-client-only" ==> "shared pages client"",
185+
"shared-pages-client.js [ssr] : "data-for-shared-pages-client-only" ==> "shared pages client"",
186+
]
187+
`)
188+
}
189+
})
190+
191+
it('works for /pages/client-only', async () => {
192+
let $ = await next.render$('/pages/client-only')
193+
let response = JSON.parse($('#list').text())
194+
if (isNextDev) {
195+
expect(formatData(response)).toMatchInlineSnapshot(`
196+
[
197+
"pages-lib/client-only/unique.js [ssr] : "data-for-unique-pages-client-only" ==> "unique /pages/client-only"",
198+
"shared-pages-client.js [ssr] : "data-for-shared-pages-client-only" ==> "shared pages client"",
199+
]
200+
`)
201+
} else {
202+
expect(formatData(response)).toMatchInlineSnapshot(`
203+
[
204+
"app/client/shared-app-client.js [app-client] : "data-for-shared-app-client-a" ==> "app client"",
205+
"app/client/shared-app-client.js [app-ssr] : "data-for-shared-app-client-a" ==> "app client"",
206+
"app/rsc/shared-app/target.js [app-rsc] : "data-for-shared-app" ==> "shared-app"",
207+
"pages-lib/client-only/unique.js [ssr] : "data-for-unique-pages-client-only" ==> "unique /pages/client-only"",
208+
"shared-pages-client.js [client] : "data-for-shared-pages-client-only" ==> "shared pages client"",
209+
"shared-pages-client.js [ssr] : "data-for-shared-pages-client-only" ==> "shared pages client"",
152210
]
153211
`)
154212
}
@@ -169,6 +227,8 @@ import { nextTestSetup } from 'e2e-utils'
169227
"app/client/shared-app-client.js [app-client] : "data-for-shared-app-client-a" ==> "app client"",
170228
"app/client/shared-app-client.js [app-ssr] : "data-for-shared-app-client-a" ==> "app client"",
171229
"app/rsc/shared-app/target.js [app-rsc] : "data-for-shared-app" ==> "shared-app"",
230+
"shared-pages-client.js [client] : "data-for-shared-pages-client-only" ==> "shared pages client"",
231+
"shared-pages-client.js [ssr] : "data-for-shared-pages-client-only" ==> "shared pages client"",
172232
]
173233
`)
174234
}
@@ -184,6 +244,8 @@ import { nextTestSetup } from 'e2e-utils'
184244
"app/client/shared-app-client.js [app-client] : "data-for-shared-app-client-a" ==> "app client"",
185245
"app/client/shared-app-client.js [app-ssr] : "data-for-shared-app-client-a" ==> "app client"",
186246
"app/rsc/shared-app/target.js [app-rsc] : "data-for-shared-app" ==> "shared-app"",
247+
"shared-pages-client.js [client] : "data-for-shared-pages-client-only" ==> "shared pages client"",
248+
"shared-pages-client.js [ssr] : "data-for-shared-pages-client-only" ==> "shared pages client"",
187249
]
188250
`)
189251
}
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)