Skip to content

Commit

Permalink
Update SharedCacheControls test
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed Feb 28, 2025
1 parent 152a496 commit 6c3e63b
Showing 1 changed file with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { PrerenderManifestRoute } from '../../../build'
import type {
DynamicPrerenderManifestRoute,
PrerenderManifestRoute,
} from '../../../build'
import { RenderingMode } from '../../../build/rendering-mode'
import { SharedCacheControls } from './shared-cache-controls'

Expand Down Expand Up @@ -30,7 +33,23 @@ describe('SharedCacheControls', () => {
allowHeader: [],
} satisfies PrerenderManifestRoute,
},
dynamicRoutes: {},
dynamicRoutes: {
'/route4': {
fallbackRevalidate: 30,
fallbackExpire: 50,
fallback: true,
fallbackRootParams: undefined,
fallbackSourceRoute: undefined,
dataRoute: null,
dataRouteRegex: null,
prefetchDataRoute: null,
prefetchDataRouteRegex: null,
routeRegex: '',
experimentalPPR: undefined,
renderingMode: RenderingMode.PARTIALLY_STATIC,
allowHeader: [],
} satisfies DynamicPrerenderManifestRoute,
},
}
sharedCacheControls = new SharedCacheControls(prerenderManifest)
})
Expand All @@ -40,7 +59,7 @@ describe('SharedCacheControls', () => {
})

it('should get cache control from in-memory cache', () => {
sharedCacheControls.set('/route1', { revalidate: 15 })
sharedCacheControls.set('/route1', { revalidate: 15, expire: undefined })
const cacheControl = sharedCacheControls.get('/route1')
expect(cacheControl).toEqual({ revalidate: 15 })
})
Expand All @@ -56,15 +75,20 @@ describe('SharedCacheControls', () => {
})

it('should set cache control in cache', () => {
sharedCacheControls.set('/route3', { revalidate: 30 })
sharedCacheControls.set('/route3', { revalidate: 30, expire: undefined })
const cacheControl = sharedCacheControls.get('/route3')
expect(cacheControl).toEqual({ revalidate: 30 })
})

it('should clear the in-memory cache', () => {
sharedCacheControls.set('/route3', { revalidate: 30 })
sharedCacheControls.set('/route3', { revalidate: 30, expire: undefined })
sharedCacheControls.clear()
const cacheControl = sharedCacheControls.get('/route3')
expect(cacheControl).toBeUndefined()
})

it('should get cache control from prerender manifest for dynamic route with fallback', () => {
const cacheControl = sharedCacheControls.get('/route4')
expect(cacheControl).toEqual({ revalidate: 30, expire: 50 })
})
})

0 comments on commit 6c3e63b

Please sign in to comment.