File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const CDN = require ( './cdn.js' ) ;
2+
3+ describe ( 'CDN Tests' , ( ) => {
4+ const cdn = new CDN ( {
5+ dir : './cdn/' ,
6+ extension : '.cdn.json' ,
7+ ttl : 3600 ,
8+ } ) ;
9+
10+ test ( 'Constructor' , ( ) => {
11+ expect ( cdn . dir ) . toBe ( './cdn/' ) ;
12+ expect ( cdn . extension ) . toBe ( '.cdn.json' ) ;
13+ expect ( cdn . ttl ) . toBe ( 3600 ) ;
14+ } ) ;
15+
16+ async function cmsdata ( ) { // Example fetching and caching CMS data
17+ if ( cdn . valid ( 'cms' ) ) return cdn . get ( 'cms' ) ; // Return cached CMS data if valid
18+ try {
19+ console . log ( 'Writing...' )
20+ cdn . cache ( 'cms' , { 1 : 2 } ) ; // Cache the CMS data
21+ return { 1 : 2 } ;
22+ } catch {
23+ try {
24+ return cdn . get ( 'cms' ) ; // Retrieve cached CMS data
25+ } catch {
26+ console . error ( 'Failed to fetch CMS data and no cached data found.' ) ;
27+ return null ;
28+ } ;
29+ } ;
30+ } ;
31+
32+ test ( 'Cache' , async ( ) => {
33+ var cms = await cmsdata ( ) ;
34+ expect ( cms ) . toEqual ( { 1 : 2 } ) ;
35+ } ) ;
36+
37+ test ( 'Get' , async ( ) => {
38+ var cms = await cmsdata ( ) ;
39+ expect ( cms ) . toEqual ( { 1 : 2 } ) ;
40+ } ) ;
41+ } ) ;
Original file line number Diff line number Diff line change 1+ module . exports = {
2+ testEnvironment : 'node' ,
3+ collectCoverage : false ,
4+ testMatch : [ '**/*.test.js' ] ,
5+ verbose : true
6+ } ;
You can’t perform that action at this time.
0 commit comments