11import { expect } from '@playwright/test'
22import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
33import { test } from '../utils/playwright-helpers.js'
4+ import { join } from 'node:path'
5+ import { readdir } from 'node:fs/promises'
46
57export function waitFor ( millis : number ) {
68 return new Promise ( ( resolve ) => setTimeout ( resolve , millis ) )
@@ -614,6 +616,34 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
614616 / ( s - m a x a g e | m a x - a g e ) / ,
615617 )
616618 } )
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+ } )
617647} )
618648
619649test . describe ( 'Page Router with basePath and i18n' , ( ) => {
@@ -1352,9 +1382,9 @@ test.describe('Page Router with basePath and i18n', () => {
13521382
13531383 test ( 'requesting a non existing page route that needs to be fetched from the blob store like 404.html' , async ( {
13541384 page,
1355- pageRouter ,
1385+ pageRouterBasePathI18n ,
13561386 } ) => {
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 )
13581388 const headers = response ?. headers ( ) || { }
13591389 expect ( response ?. status ( ) ) . toBe ( 404 )
13601390
@@ -1375,9 +1405,9 @@ test.describe('Page Router with basePath and i18n', () => {
13751405
13761406 test ( 'requesting a non existing page route that needs to be fetched from the blob store like 404.html (notFound: true)' , async ( {
13771407 page,
1378- pageRouter ,
1408+ pageRouterBasePathI18n ,
13791409 } ) => {
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 )
13811411 const headers = response ?. headers ( ) || { }
13821412 expect ( response ?. status ( ) ) . toBe ( 404 )
13831413
@@ -1390,4 +1420,36 @@ test.describe('Page Router with basePath and i18n', () => {
13901420 )
13911421 expect ( headers [ 'cache-control' ] ) . toBe ( 'public,max-age=0,must-revalidate' )
13921422 } )
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+ } )
13931455} )
0 commit comments