1
1
import { expect } from '@playwright/test'
2
2
import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
3
3
import { test } from '../utils/playwright-helpers.js'
4
+ import { join } from 'node:path'
5
+ import { readdir } from 'node:fs/promises'
4
6
5
7
export function waitFor ( millis : number ) {
6
8
return new Promise ( ( resolve ) => setTimeout ( resolve , millis ) )
@@ -614,6 +616,34 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
614
616
/ ( s - m a x a g e | m a x - a g e ) / ,
615
617
)
616
618
} )
619
+
620
+ test . describe ( 'static assets and function invocations' , ( ) => {
621
+ test ( 'should return 200 for an existing static asset without invoking a function' , async ( {
622
+ page,
623
+ pageRouter,
624
+ } ) => {
625
+ // Since assets are hashed, we can't hardcode anything here. Find something to fetch.
626
+ const [ staticAsset ] = await readdir (
627
+ join ( pageRouter . isolatedFixtureRoot , '.next' , 'static' , 'chunks' ) ,
628
+ )
629
+ expect ( staticAsset ) . toBeDefined ( )
630
+
631
+ const response = await page . goto ( `${ pageRouter . url } /_next/static/chunks/${ staticAsset } ` )
632
+
633
+ expect ( response ?. status ( ) ) . toBe ( 200 )
634
+ expect ( response ?. headers ( ) ) . not . toHaveProperty ( 'x-nf-function-type' )
635
+ } )
636
+
637
+ test ( 'should return 404 for a nonexistent static asset without invoking a function' , async ( {
638
+ page,
639
+ pageRouter,
640
+ } ) => {
641
+ const response = await page . goto ( `${ pageRouter . url } /_next/static/stale123abcdef.js` )
642
+
643
+ expect ( response ?. status ( ) ) . toBe ( 404 )
644
+ expect ( response ?. headers ( ) ) . not . toHaveProperty ( 'x-nf-function-type' )
645
+ } )
646
+ } )
617
647
} )
618
648
619
649
test . describe ( 'Page Router with basePath and i18n' , ( ) => {
@@ -1352,9 +1382,9 @@ test.describe('Page Router with basePath and i18n', () => {
1352
1382
1353
1383
test ( 'requesting a non existing page route that needs to be fetched from the blob store like 404.html' , async ( {
1354
1384
page,
1355
- pageRouter ,
1385
+ pageRouterBasePathI18n ,
1356
1386
} ) => {
1357
- const response = await page . goto ( new URL ( 'non-existing' , pageRouter . url ) . href )
1387
+ const response = await page . goto ( new URL ( 'non-existing' , pageRouterBasePathI18n . url ) . href )
1358
1388
const headers = response ?. headers ( ) || { }
1359
1389
expect ( response ?. status ( ) ) . toBe ( 404 )
1360
1390
@@ -1375,9 +1405,9 @@ test.describe('Page Router with basePath and i18n', () => {
1375
1405
1376
1406
test ( 'requesting a non existing page route that needs to be fetched from the blob store like 404.html (notFound: true)' , async ( {
1377
1407
page,
1378
- pageRouter ,
1408
+ pageRouterBasePathI18n ,
1379
1409
} ) => {
1380
- const response = await page . goto ( new URL ( 'static/not-found' , pageRouter . url ) . href )
1410
+ const response = await page . goto ( new URL ( 'static/not-found' , pageRouterBasePathI18n . url ) . href )
1381
1411
const headers = response ?. headers ( ) || { }
1382
1412
expect ( response ?. status ( ) ) . toBe ( 404 )
1383
1413
@@ -1390,4 +1420,36 @@ test.describe('Page Router with basePath and i18n', () => {
1390
1420
)
1391
1421
expect ( headers [ 'cache-control' ] ) . toBe ( 'public,max-age=0,must-revalidate' )
1392
1422
} )
1423
+
1424
+ test . describe ( 'static assets and function invocations' , ( ) => {
1425
+ test ( 'should return 200 for an existing static asset without invoking a function' , async ( {
1426
+ page,
1427
+ pageRouterBasePathI18n,
1428
+ } ) => {
1429
+ // Since assets are hashed, we can't hardcode anything here. Find something to fetch.
1430
+ const [ staticAsset ] = await readdir (
1431
+ join ( pageRouterBasePathI18n . isolatedFixtureRoot , '.next' , 'static' , 'chunks' ) ,
1432
+ )
1433
+ expect ( staticAsset ) . toBeDefined ( )
1434
+
1435
+ const response = await page . goto (
1436
+ `${ pageRouterBasePathI18n . url } /_next/static/chunks/${ staticAsset } ` ,
1437
+ )
1438
+
1439
+ expect ( response ?. status ( ) ) . toBe ( 200 )
1440
+ expect ( response ?. headers ( ) ) . not . toHaveProperty ( 'x-nf-function-type' )
1441
+ } )
1442
+
1443
+ test ( 'should return 404 for a nonexistent static asset without invoking a function' , async ( {
1444
+ page,
1445
+ pageRouterBasePathI18n,
1446
+ } ) => {
1447
+ const response = await page . goto (
1448
+ `${ pageRouterBasePathI18n . url } /_next/static/stale123abcdef.js` ,
1449
+ )
1450
+
1451
+ expect ( response ?. status ( ) ) . toBe ( 404 )
1452
+ expect ( response ?. headers ( ) ) . not . toHaveProperty ( 'x-nf-function-type' )
1453
+ } )
1454
+ } )
1393
1455
} )
0 commit comments