1- import { HtmlValidate , formatterFactory } from "html-validate" ;
1+ import { HtmlValidate , FileSystemConfigLoader , formatterFactory , esmResolver } from "html-validate" ;
22import { glob } from "glob" ;
3- import plugin from "./plugin.html-validate.mjs" ;
43
54// Find and sort all HTML files in the 'build' directory
65const targets = glob . sync ( "build/**/*.html" ) . sort ( ) ;
76
87// Initialize HtmlValidate instance
9- const htmlValidate = new HtmlValidate ( {
10- extends : [ "html-validate:prettier" ] ,
11- plugins : [ plugin ] ,
12- rules : {
13- "mailto-awesome" : "error" ,
14- "external-links" : "error" ,
15- "no-jquery" : "error" ,
16- "canonical-link" : "error" ,
17- "latest-packages" : "error" ,
18- "https-links" : "error" ,
19- "internal-links" : "error" ,
20- } ,
21- } ) ;
22-
8+ const resolver = esmResolver ( ) ;
9+ const loader = new FileSystemConfigLoader ( [ resolver ] ) ;
10+ const htmlValidate = new HtmlValidate ( loader ) ;
2311const formatter = formatterFactory ( "stylish" ) ;
2412let allTestsPassed = true ;
2513
2614// Validate each target file
27- for ( const target of targets ) {
15+ const outcomes = targets . map ( async ( target ) => {
2816 try {
2917 const report = await htmlValidate . validateFile ( target ) ;
3018 if ( ! report . valid ) {
@@ -37,10 +25,14 @@ for (const target of targets) {
3725 console . error ( `Error validating ${ target } :` , error ) ;
3826 allTestsPassed = false ;
3927 }
40- }
28+ } ) ;
4129
42- if ( allTestsPassed ) {
43- console . log ( "✨✨ All tests passed! ✨✨" ) ;
44- } else {
45- process . exit ( 1 ) ;
46- }
30+ console . log ( "🧪 Testing pages" ) ;
31+ Promise . all ( outcomes ) . then ( ( ) => {
32+ if ( allTestsPassed ) {
33+ console . log ( "✨ All tests passed!\n" ) ;
34+ } else {
35+ console . log ( "❌ Some tests failed." ) ;
36+ process . exit ( 1 ) ;
37+ }
38+ } ) ;
0 commit comments