-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
61 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,22 @@ | ||
import { chdir } from "node:process"; | ||
import { Hawk } from "../lib/core"; | ||
import validateRoutes from "./utils/validate-routes"; | ||
import validateSitemap from "./utils/validate-sitemap"; | ||
|
||
const hawkInstance = new Hawk(); | ||
const testSampleRootPath = "./test/test-sample"; | ||
|
||
const cwd = process.cwd(); | ||
afterEach(() => { | ||
chdir(cwd); | ||
}); | ||
|
||
test("Sitemap.xml validation", async () => { | ||
expect(await validateSitemap(testSampleRootPath, hawkInstance)).toBe( | ||
true, | ||
); | ||
}); | ||
|
||
test("Routes validation", () => { | ||
expect(validateRoutes(testSampleRootPath, hawkInstance)).toBe(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { utimesSync } from "node:fs"; | ||
import { type Hawk } from "../../lib/core"; | ||
|
||
export default function validateRoutes( | ||
testSampleRoot: string, | ||
hawkInstance: Hawk, | ||
) { | ||
process.chdir(testSampleRoot); | ||
|
||
const { lookupPatterns, ignorePattern } = hawkInstance.configurations; | ||
|
||
const availableRoutes = hawkInstance.utils.lookupFiles( | ||
lookupPatterns, | ||
ignorePattern, | ||
); | ||
|
||
//change mod time of routes | ||
const simulatedLastSubmisssionTime = Date.now(); | ||
const newRouteModTime = new Date(simulatedLastSubmisssionTime + 10); //simulate as 10ms latest | ||
|
||
//pick some random number of routes and update | ||
const simulated_updatedRoutes = availableRoutes | ||
.slice(0, _getRandomInteger(1, availableRoutes.length)) | ||
.map((route) => { | ||
utimesSync(route, newRouteModTime, newRouteModTime); | ||
return route; | ||
}); | ||
|
||
const updatedRoutes = hawkInstance.utils.getUpdatedRoutesPath( | ||
simulatedLastSubmisssionTime, | ||
lookupPatterns, | ||
ignorePattern, | ||
); | ||
|
||
return simulated_updatedRoutes.length === updatedRoutes.length; | ||
} | ||
|
||
function _getRandomInteger(min: number, max: number) { | ||
return Math.floor(Math.random() * (max - min + 1)) + min; // Inclusive of both min and max | ||
} |