File tree Expand file tree Collapse file tree 3 files changed +61
-10
lines changed Expand file tree Collapse file tree 3 files changed +61
-10
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ export default class Utils {
47
47
) : RouteMeta [ ] {
48
48
const routesMeta : RouteMeta [ ] = [ ] as RouteMeta [ ] ;
49
49
50
- _lookupFiles ( lookupPatterns , ignorePattern ) . forEach (
50
+ this . lookupFiles ( lookupPatterns , ignorePattern ) . forEach (
51
51
( filePath : string ) : void => {
52
52
let relativePath : string = relative ( process . cwd ( ) , filePath ) ;
53
53
@@ -398,15 +398,15 @@ export default class Utils {
398
398
}
399
399
return dataObject [ keyName ] ;
400
400
}
401
- }
402
401
403
- function _lookupFiles (
404
- lookupPatterns : string [ ] ,
405
- ignorePatterns : string [ ] ,
406
- ) : string [ ] {
407
- const webPageFilePaths : string [ ] = globSync ( lookupPatterns , {
408
- ignore : [ ...ignorePatterns , "node_modules/**" ] ,
409
- } ) ;
402
+ lookupFiles (
403
+ lookupPatterns : string [ ] ,
404
+ ignorePatterns : string [ ] ,
405
+ ) : string [ ] {
406
+ const webPageFilePaths : string [ ] = globSync ( lookupPatterns , {
407
+ ignore : [ ...ignorePatterns , "node_modules/**" ] ,
408
+ } ) ;
410
409
411
- return webPageFilePaths ;
410
+ return webPageFilePaths ;
411
+ }
412
412
}
Original file line number Diff line number Diff line change
1
+ import { chdir } from "node:process" ;
1
2
import { Hawk } from "../lib/core" ;
3
+ import validateRoutes from "./utils/validate-routes" ;
2
4
import validateSitemap from "./utils/validate-sitemap" ;
3
5
4
6
const hawkInstance = new Hawk ( ) ;
5
7
const testSampleRootPath = "./test/test-sample" ;
6
8
9
+ const cwd = process . cwd ( ) ;
10
+ afterEach ( ( ) => {
11
+ chdir ( cwd ) ;
12
+ } ) ;
13
+
7
14
test ( "Sitemap.xml validation" , async ( ) => {
8
15
expect ( await validateSitemap ( testSampleRootPath , hawkInstance ) ) . toBe (
9
16
true ,
10
17
) ;
11
18
} ) ;
19
+
20
+ test ( "Routes validation" , ( ) => {
21
+ expect ( validateRoutes ( testSampleRootPath , hawkInstance ) ) . toBe ( true ) ;
22
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { utimesSync } from "node:fs" ;
2
+ import { type Hawk } from "../../lib/core" ;
3
+
4
+ export default function validateRoutes (
5
+ testSampleRoot : string ,
6
+ hawkInstance : Hawk ,
7
+ ) {
8
+ process . chdir ( testSampleRoot ) ;
9
+
10
+ const { lookupPatterns, ignorePattern } = hawkInstance . configurations ;
11
+
12
+ const availableRoutes = hawkInstance . utils . lookupFiles (
13
+ lookupPatterns ,
14
+ ignorePattern ,
15
+ ) ;
16
+
17
+ //change mod time of routes
18
+ const simulatedLastSubmisssionTime = Date . now ( ) ;
19
+ const newRouteModTime = new Date ( simulatedLastSubmisssionTime + 10 ) ; //simulate as 10ms latest
20
+
21
+ //pick some random number of routes and update
22
+ const simulated_updatedRoutes = availableRoutes
23
+ . slice ( 0 , _getRandomInteger ( 1 , availableRoutes . length ) )
24
+ . map ( ( route ) => {
25
+ utimesSync ( route , newRouteModTime , newRouteModTime ) ;
26
+ return route ;
27
+ } ) ;
28
+
29
+ const updatedRoutes = hawkInstance . utils . getUpdatedRoutesPath (
30
+ simulatedLastSubmisssionTime ,
31
+ lookupPatterns ,
32
+ ignorePattern ,
33
+ ) ;
34
+
35
+ return simulated_updatedRoutes . length === updatedRoutes . length ;
36
+ }
37
+
38
+ function _getRandomInteger ( min : number , max : number ) {
39
+ return Math . floor ( Math . random ( ) * ( max - min + 1 ) ) + min ; // Inclusive of both min and max
40
+ }
You can’t perform that action at this time.
0 commit comments