@@ -8,12 +8,7 @@ import {
88 runPlugin ,
99 type FixtureTestContext ,
1010} from '../utils/fixture.js'
11- import {
12- createBlobContext ,
13- generateRandomObjectID ,
14- getBlobEntries ,
15- startMockBlobStore ,
16- } from '../utils/helpers.js'
11+ import { generateRandomObjectID , getBlobEntries , startMockBlobStore } from '../utils/helpers.js'
1712
1813// Disable the verbose logging of the lambda-local runtime
1914getLogger ( ) . level = 'alert'
@@ -23,6 +18,8 @@ beforeEach<FixtureTestContext>(async (ctx) => {
2318 ctx . deployID = generateRandomObjectID ( )
2419 ctx . siteID = v4 ( )
2520 vi . stubEnv ( 'DEPLOY_ID' , ctx . deployID )
21+ // hide debug logs in tests
22+ // vi.spyOn(console, 'debug').mockImplementation(() => {})
2623
2724 await startMockBlobStore ( ctx )
2825} )
@@ -48,12 +45,12 @@ describe('page router', () => {
4845 expect ( call1 . headers , 'a cache hit on the first invocation of a prerendered page' ) . toEqual (
4946 expect . objectContaining ( {
5047 'x-nextjs-cache' : 'HIT' ,
51- 'netlify-cdn-cache-control' : 's-maxage=2 , stale-while-revalidate' ,
48+ 'netlify-cdn-cache-control' : 's-maxage=3 , stale-while-revalidate' ,
5249 } ) ,
5350 )
5451
5552 // wait to have a stale page
56- await new Promise < void > ( ( resolve ) => setTimeout ( resolve , 1_000 ) )
53+ await new Promise < void > ( ( resolve ) => setTimeout ( resolve , 2_000 ) )
5754
5855 // now it should be a cache miss
5956 const call2 = await invokeFunction ( ctx , { url : 'static/revalidate' } )
@@ -83,27 +80,6 @@ describe('page router', () => {
8380} )
8481
8582describe ( 'app router' , ( ) => {
86- test < FixtureTestContext > ( 'Test that the simple next app is working' , async ( ctx ) => {
87- await createFixture ( 'simple-next-app' , ctx )
88- await runPlugin ( ctx )
89- // check if the blob entries where successful set on the build plugin
90- const blobEntries = await getBlobEntries ( ctx )
91- expect ( blobEntries ) . toEqual ( [
92- { key : 'server/app/_not-found' , etag : expect . any ( String ) } ,
93- { key : 'server/app/index' , etag : expect . any ( String ) } ,
94- { key : 'server/app/other' , etag : expect . any ( String ) } ,
95- ] )
96-
97- // test the function call
98- const home = await invokeFunction ( ctx )
99- expect ( home . statusCode ) . toBe ( 200 )
100- expect ( load ( home . body ) ( 'h1' ) . text ( ) ) . toBe ( 'Home' )
101-
102- const other = await invokeFunction ( ctx , { url : 'other' } )
103- expect ( other . statusCode ) . toBe ( 200 )
104- expect ( load ( other . body ) ( 'h1' ) . text ( ) ) . toBe ( 'Other' )
105- } )
106-
10783 test < FixtureTestContext > ( 'should have a page prerendered, then wait for it to get stale and on demand revalidate it' , async ( ctx ) => {
10884 await createFixture ( 'revalidate-fetch' , ctx )
10985 console . time ( 'runPlugin' )
@@ -179,7 +155,9 @@ describe('app router', () => {
179155 } ) ,
180156 )
181157 } )
158+ } )
182159
160+ describe ( 'plugin' , ( ) => {
183161 test < FixtureTestContext > ( 'server-components blob store created correctly' , async ( ctx ) => {
184162 await createFixture ( 'server-components' , ctx )
185163 await runPlugin ( ctx )
@@ -202,7 +180,9 @@ describe('app router', () => {
202180 { key : 'server/app/static-fetch-2' , etag : expect . any ( String ) } ,
203181 ] )
204182 } )
183+ } )
205184
185+ describe ( 'route' , ( ) => {
206186 test < FixtureTestContext > ( 'route handler with revalidate' , async ( ctx ) => {
207187 await createFixture ( 'server-components' , ctx )
208188 await runPlugin ( ctx )
@@ -228,20 +208,20 @@ describe('app router', () => {
228208 } ) ,
229209 )
230210 // wait to have a stale route
231- await new Promise < void > ( ( resolve ) => setTimeout ( resolve , 1_500 ) )
211+ await new Promise < void > ( ( resolve ) => setTimeout ( resolve , 2_000 ) )
232212
233213 const call2 = await invokeFunction ( ctx , { url : '/api/revalidate-handler' } )
234214 const call2Body = JSON . parse ( call2 . body )
235215 const call2Time = call2Body . time
236216 expect ( call2 . statusCode ) . toBe ( 200 )
237217 // it should have a new date rendered
238- expect ( call1Time , 'the date is a new one on a stale route' ) . not . toBe ( call2Time )
239218 expect ( call2Body ) . toMatchObject ( { data : expect . objectContaining ( { id : 1 } ) } )
240219 expect ( call2 . headers , 'a cache miss on a stale route' ) . toEqual (
241220 expect . objectContaining ( {
242221 'x-nextjs-cache' : 'MISS' ,
243222 } ) ,
244223 )
224+ expect ( call1Time , 'the date is a new one on a stale route' ) . not . toBe ( call2Time )
245225
246226 // it does not wait for the cache.set so we have to manually wait here until the blob storage got populated
247227 await new Promise < void > ( ( resolve ) => setTimeout ( resolve , 100 ) )
@@ -250,12 +230,12 @@ describe('app router', () => {
250230 expect ( call3 . statusCode ) . toBe ( 200 )
251231 const call3Body = JSON . parse ( call3 . body )
252232 const call3Time = call3Body . time
253- expect ( call3Time , 'the date was cached as well' ) . toBe ( call2Time )
254233 expect ( call3Body ) . toMatchObject ( { data : expect . objectContaining ( { id : 1 } ) } )
255234 expect ( call3 . headers , 'a cache hit after dynamically regenerating the stale route' ) . toEqual (
256235 expect . objectContaining ( {
257236 'x-nextjs-cache' : 'HIT' ,
258237 } ) ,
259238 )
239+ expect ( call3Time , 'the date was cached as well' ) . toBe ( call2Time )
260240 } )
261241} )
0 commit comments