11import chai from 'chai' ;
22import chalk from 'chalk' ;
3- import { execute } from './test-helpers.js' ;
43import { formatErrors } from 'check-html-links' ;
4+ import path from 'path' ;
5+ import { fileURLToPath } from 'url' ;
6+ import { execute } from './test-helpers.js' ;
7+ import { listFiles } from '../src/listFiles.js' ;
58
69const { expect } = chai ;
10+ const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
711
812async function executeAndFormat ( inPath ) {
913 const { errors, cleanup } = await execute ( inPath ) ;
10- return formatErrors ( cleanup ( errors ) ) ;
14+
15+ const testDir = path . join ( __dirname , inPath . split ( '/' ) . join ( path . sep ) ) ;
16+ const rootDir = path . resolve ( testDir ) ;
17+ const files = await listFiles ( '**/*.html' , rootDir ) ;
18+
19+ return formatErrors ( cleanup ( errors ) , { files } ) ;
1120}
1221
1322describe ( 'formatErrors' , ( ) => {
@@ -16,23 +25,34 @@ describe('formatErrors', () => {
1625 chalk . level = 0 ;
1726 } ) ;
1827
19- it ( 'prints a nice summery ' , async ( ) => {
20- const result = await executeAndFormat ( 'fixtures/test-case' ) ;
28+ it ( 'prints a nice summary ' , async ( ) => {
29+ const result = await executeAndFormat ( 'fixtures/test-case' , { skipSuggestions : true } ) ;
2130 expect ( result . trim ( ) . split ( '\n' ) ) . to . deep . equal ( [
2231 '1. missing id="my-teams" in fixtures/test-case/price/index.html' ,
2332 ' from fixtures/test-case/history/index.html:1:9 via href="/price/#my-teams"' ,
2433 '' ,
34+ 'Suggestion: did you mean test-node/fixtures/test-case/price/index.html instead?' ,
35+ '' ,
36+ '' ,
2537 '2. missing file fixtures/test-case/about/images/team.png' ,
2638 ' from fixtures/test-case/about/index.html:3:10 via src="./images/team.png"' ,
2739 '' ,
40+ 'Suggestion: did you mean test-node/fixtures/test-case/about/index.html instead?' ,
41+ '' ,
42+ '' ,
2843 '3. missing reference target fixtures/test-case/aboot' ,
2944 ' from fixtures/test-case/about/index.html:6:11 via href="/aboot"' ,
3045 ' from fixtures/test-case/history/index.html:4:11 via href="/aboot"' ,
3146 ' from fixtures/test-case/index.html:4:11 via href="/aboot"' ,
3247 ' ... 2 more references to this target' ,
3348 '' ,
49+ 'Suggestion: did you mean test-node/fixtures/test-case/index.html instead?' ,
50+ '' ,
51+ '' ,
3452 '4. missing reference target fixtures/test-case/prce' ,
3553 ' from fixtures/test-case/index.html:1:9 via href="./prce"' ,
54+ '' ,
55+ 'Suggestion: did you mean test-node/fixtures/test-case/index.html instead?' ,
3656 ] ) ;
3757 } ) ;
3858} ) ;
0 commit comments