@@ -410,33 +410,38 @@ describe('Prefetching Links in viewport', () => {
410
410
expect ( found ) . toBe ( false )
411
411
} )
412
412
413
- it ( 'should not prefetch already loaded scripts' , async ( ) => {
414
- const browser = await webdriver ( appPort , '/' )
413
+ // Turbopack handling of chunks is different, by default it does not include a script tag for the page itself.
414
+ ; ( process . env . TURBOPACK ? it . skip : it ) (
415
+ 'should not prefetch already loaded scripts' ,
416
+ async ( ) => {
417
+ const browser = await webdriver ( appPort , '/' )
415
418
416
- const scriptSrcs = await browser . eval ( `(function() {
419
+ const scriptSrcs = await browser . eval ( `(function() {
417
420
return Array.from(document.querySelectorAll('script'))
418
421
.map(function(el) {
419
422
return el.src && new URL(el.src).pathname
420
423
}).filter(Boolean)
421
424
})()` )
422
425
423
- await browser . eval ( 'next.router.prefetch("/")' )
426
+ await browser . eval ( 'next.router.prefetch("/")' )
424
427
425
- const linkHrefs = await browser . eval ( `(function() {
428
+ const linkHrefs = await browser . eval ( `(function() {
426
429
return Array.from(document.querySelectorAll('link'))
427
430
.map(function(el) {
428
431
return el.href && new URL(el.href).pathname
429
432
}).filter(Boolean)
430
433
})()` )
431
434
432
- console . log ( { linkHrefs, scriptSrcs } )
433
- expect ( scriptSrcs . some ( ( src ) => src . includes ( 'pages/index-' ) ) ) . toBe (
434
- true
435
- )
436
- expect ( linkHrefs . some ( ( href ) => href . includes ( 'pages/index-' ) ) ) . toBe (
437
- false
438
- )
439
- } )
435
+ // eslint-disable-next-line jest/no-standalone-expect
436
+ expect ( scriptSrcs . some ( ( src ) => src . includes ( 'pages/index-' ) ) ) . toBe (
437
+ true
438
+ )
439
+ // eslint-disable-next-line jest/no-standalone-expect
440
+ expect ( linkHrefs . some ( ( href ) => href . includes ( 'pages/index-' ) ) ) . toBe (
441
+ false
442
+ )
443
+ }
444
+ )
440
445
441
446
it ( 'should not duplicate prefetches' , async ( ) => {
442
447
const browser = await webdriver ( appPort , '/multi-prefetch' )
@@ -454,7 +459,7 @@ describe('Prefetching Links in viewport', () => {
454
459
expect ( hrefs ) . toEqual ( [ ...new Set ( hrefs ) ] )
455
460
456
461
// Verify encoding
457
- expect ( hrefs . some ( ( e ) => e . includes ( `%5Bhello%5D- ` ) ) ) . toBe ( true )
462
+ expect ( hrefs . some ( ( e ) => e . includes ( `%5Bhello%5D` ) ) ) . toBe ( true )
458
463
} )
459
464
460
465
it ( 'should not re-prefetch for an already prefetched page' , async ( ) => {
0 commit comments