@@ -34,24 +34,21 @@ export default function (context, { runtime, env }) {
34
34
} )
35
35
36
36
// TODO: support RSC index route
37
- it . skip ( 'should render server components correctly' , async ( ) => {
37
+ it ( 'should render server components correctly' , async ( ) => {
38
38
const homeHTML = await renderViaHTTP ( context . appPort , '/' , null , {
39
39
headers : {
40
40
'x-next-test-client' : 'test-util' ,
41
41
} ,
42
42
} )
43
43
44
- const browser = await webdriver ( context . appPort , '/' )
45
- const scriptTagContent = await browser . elementById ( 'client-script' ) . text ( )
46
44
// should have only 1 DOCTYPE
47
45
expect ( homeHTML ) . toMatch ( / ^ < ! D O C T Y P E h t m l > < h t m l / )
48
- expect ( homeHTML ) . toMatch ( '<meta name="rsc-title" content="index"/>' )
46
+ // TODO: support next/head
47
+ // expect(homeHTML).toMatch('<meta name="rsc-title" content="index"/>')
49
48
expect ( homeHTML ) . toContain ( 'component:index.server' )
50
- expect ( homeHTML ) . toContain ( 'env:env_var_test' )
49
+ // TODO: support env
50
+ // expect(homeHTML).toContain('env:env_var_test')
51
51
expect ( homeHTML ) . toContain ( 'header:test-util' )
52
- expect ( homeHTML ) . toMatch ( / < \/ b o d y > < \/ h t m l > $ / )
53
-
54
- expect ( scriptTagContent ) . toBe ( ';' )
55
52
56
53
const inlineFlightContents = [ ]
57
54
const $ = cheerio . load ( homeHTML )
@@ -150,104 +147,101 @@ export default function (context, { runtime, env }) {
150
147
expect ( dynamicRoute1HTML ) . toContain ( 'router pathname: /routes/[dynamic]' )
151
148
} )
152
149
153
- // FIXME: chunks missing in prod mode
154
- if ( env === 'dev' ) {
155
- it ( 'should be able to navigate between rsc pages' , async ( ) => {
156
- const browser = await webdriver ( context . appPort , '/root' )
157
-
158
- await browser . waitForElementByCss ( '#goto-next-link' ) . click ( )
159
- await new Promise ( ( res ) => setTimeout ( res , 1000 ) )
160
- expect ( await browser . url ( ) ) . toBe (
161
- `http://localhost:${ context . appPort } /next-api/link`
162
- )
163
- await browser . waitForElementByCss ( '#goto-home' ) . click ( )
164
- await new Promise ( ( res ) => setTimeout ( res , 1000 ) )
165
- expect ( await browser . url ( ) ) . toBe (
166
- `http://localhost:${ context . appPort } /root`
167
- )
168
- const content = await browser . elementByCss ( 'body' ) . text ( )
169
- expect ( content ) . toContain ( 'component:root.server' )
170
-
171
- await browser . waitForElementByCss ( '#goto-streaming-rsc' ) . click ( )
150
+ it ( 'should be able to navigate between rsc pages' , async ( ) => {
151
+ const browser = await webdriver ( context . appPort , '/root' )
172
152
173
- // Wait for navigation and streaming to finish.
174
- await check (
175
- ( ) => browser . elementByCss ( '#content' ) . text ( ) ,
176
- 'next_streaming_data'
177
- )
178
- expect ( await browser . url ( ) ) . toBe (
179
- `http://localhost:${ context . appPort } /streaming-rsc`
180
- )
181
- } )
153
+ await browser . waitForElementByCss ( '#goto-next-link' ) . click ( )
154
+ await new Promise ( ( res ) => setTimeout ( res , 1000 ) )
155
+ expect ( await browser . url ( ) ) . toBe (
156
+ `http://localhost:${ context . appPort } /next-api/link`
157
+ )
158
+ await browser . waitForElementByCss ( '#goto-home' ) . click ( )
159
+ await new Promise ( ( res ) => setTimeout ( res , 1000 ) )
160
+ expect ( await browser . url ( ) ) . toBe ( `http://localhost:${ context . appPort } /root` )
161
+ const content = await browser . elementByCss ( 'body' ) . text ( )
162
+ expect ( content ) . toContain ( 'component:root.server' )
163
+
164
+ await browser . waitForElementByCss ( '#goto-streaming-rsc' ) . click ( )
165
+
166
+ // Wait for navigation and streaming to finish.
167
+ await check (
168
+ ( ) => browser . elementByCss ( '#content' ) . text ( ) ,
169
+ 'next_streaming_data'
170
+ )
171
+ expect ( await browser . url ( ) ) . toBe (
172
+ `http://localhost:${ context . appPort } /streaming-rsc`
173
+ )
174
+ } )
182
175
183
- it ( 'should handle streaming server components correctly' , async ( ) => {
184
- const browser = await webdriver ( context . appPort , '/streaming-rsc' )
185
- const content = await browser . eval (
186
- `document.querySelector('#content').innerText`
187
- )
188
- expect ( content ) . toMatchInlineSnapshot ( '"next_streaming_data"' )
189
- } )
176
+ it ( 'should handle streaming server components correctly' , async ( ) => {
177
+ const browser = await webdriver ( context . appPort , '/streaming-rsc' )
178
+ const content = await browser . eval (
179
+ `document.querySelector('#content').innerText`
180
+ )
181
+ expect ( content ) . toMatchInlineSnapshot ( '"next_streaming_data"' )
182
+ } )
190
183
191
- it ( 'should support next/link in server components' , async ( ) => {
192
- const linkHTML = await renderViaHTTP ( context . appPort , '/next-api/link' )
193
- const linkText = getNodeBySelector (
194
- linkHTML ,
195
- 'body > div > a[href="/root"]'
196
- ) . text ( )
184
+ it ( 'should support next/link in server components' , async ( ) => {
185
+ const linkHTML = await renderViaHTTP ( context . appPort , '/next-api/link' )
186
+ const linkText = getNodeBySelector (
187
+ linkHTML ,
188
+ 'body > div > a[href="/root"]'
189
+ ) . text ( )
197
190
198
- expect ( linkText ) . toContain ( 'home' )
191
+ expect ( linkText ) . toContain ( 'home' )
199
192
200
- const browser = await webdriver ( context . appPort , '/next-api/link' )
193
+ const browser = await webdriver ( context . appPort , '/next-api/link' )
201
194
202
- // We need to make sure the app is fully hydrated before clicking, otherwise
203
- // it will be a full redirection instead of being taken over by the next
204
- // router. This timeout prevents it being flaky caused by fast refresh's
205
- // rebuilding event.
206
- await new Promise ( ( res ) => setTimeout ( res , 1000 ) )
207
- await browser . eval ( 'window.beforeNav = 1' )
195
+ // We need to make sure the app is fully hydrated before clicking, otherwise
196
+ // it will be a full redirection instead of being taken over by the next
197
+ // router. This timeout prevents it being flaky caused by fast refresh's
198
+ // rebuilding event.
199
+ await new Promise ( ( res ) => setTimeout ( res , 1000 ) )
200
+ await browser . eval ( 'window.beforeNav = 1' )
208
201
209
- await browser . waitForElementByCss ( '#next_id' ) . click ( )
210
- await check ( ( ) => browser . elementByCss ( '#query' ) . text ( ) , 'query:1' )
202
+ await browser . waitForElementByCss ( '#next_id' ) . click ( )
203
+ await check ( ( ) => browser . elementByCss ( '#query' ) . text ( ) , 'query:1' )
211
204
212
- await browser . waitForElementByCss ( '#next_id' ) . click ( )
213
- await check ( ( ) => browser . elementByCss ( '#query' ) . text ( ) , 'query:2' )
205
+ await browser . waitForElementByCss ( '#next_id' ) . click ( )
206
+ await check ( ( ) => browser . elementByCss ( '#query' ) . text ( ) , 'query:2' )
214
207
208
+ if ( env === 'dev' ) {
215
209
expect ( await browser . eval ( 'window.beforeNav' ) ) . toBe ( 1 )
216
- } )
210
+ }
211
+ } )
217
212
218
- it ( 'should refresh correctly with next/link' , async ( ) => {
219
- // Select the button which is not hidden but rendered
220
- const selector = '#goto-next-link'
221
- let hasFlightRequest = false
222
- const browser = await webdriver ( context . appPort , '/root' , {
223
- beforePageLoad ( page ) {
224
- page . on ( 'request' , ( request ) => {
225
- const url = request . url ( )
226
- if ( / \? _ _ f l i g h t _ _ = 1 / . test ( url ) ) {
227
- hasFlightRequest = true
228
- }
229
- } )
230
- } ,
231
- } )
232
-
233
- // wait for hydration
234
- await new Promise ( ( res ) => setTimeout ( res , 1000 ) )
235
- if ( env === 'dev' ) {
236
- expect ( hasFlightRequest ) . toBe ( false )
237
- }
238
- await browser . elementByCss ( selector ) . click ( )
239
-
240
- // wait for re-hydration
241
- if ( env === 'dev' ) {
242
- await check (
243
- ( ) => ( hasFlightRequest ? 'success' : hasFlightRequest ) ,
244
- 'success'
245
- )
246
- }
247
- const refreshText = await browser . elementByCss ( selector ) . text ( )
248
- expect ( refreshText ) . toBe ( 'next link' )
213
+ it ( 'should refresh correctly with next/link' , async ( ) => {
214
+ // Select the button which is not hidden but rendered
215
+ const selector = '#goto-next-link'
216
+ let hasFlightRequest = false
217
+ const browser = await webdriver ( context . appPort , '/root' , {
218
+ beforePageLoad ( page ) {
219
+ page . on ( 'request' , ( request ) => {
220
+ const url = request . url ( )
221
+ if ( / \? _ _ f l i g h t _ _ = 1 / . test ( url ) ) {
222
+ hasFlightRequest = true
223
+ }
224
+ } )
225
+ } ,
249
226
} )
250
- }
227
+
228
+ // wait for hydration
229
+ await new Promise ( ( res ) => setTimeout ( res , 1000 ) )
230
+ if ( env === 'dev' ) {
231
+ expect ( hasFlightRequest ) . toBe ( false )
232
+ }
233
+ await browser . elementByCss ( selector ) . click ( )
234
+
235
+ // wait for re-hydration
236
+ if ( env === 'dev' ) {
237
+ await check (
238
+ ( ) => ( hasFlightRequest ? 'success' : hasFlightRequest ) ,
239
+ 'success'
240
+ )
241
+ }
242
+ const refreshText = await browser . elementByCss ( selector ) . text ( )
243
+ expect ( refreshText ) . toBe ( 'next link' )
244
+ } )
251
245
252
246
it ( 'should escape streaming data correctly' , async ( ) => {
253
247
const browser = await webdriver ( context . appPort , '/escaping-rsc' )
@@ -347,7 +341,7 @@ export default function (context, { runtime, env }) {
347
341
expect ( getNodeBySelector ( pageUnknownHTML , id ) . text ( ) ) . toBe ( content )
348
342
} )
349
343
350
- it . skip ( 'should support streaming for flight response' , async ( ) => {
344
+ it ( 'should support streaming for flight response' , async ( ) => {
351
345
await fetchViaHTTP ( context . appPort , '/?__flight__=1' ) . then (
352
346
async ( response ) => {
353
347
const result = await resolveStreamResponse ( response )
0 commit comments