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+ const testDir = path . join ( __dirname , inPath . split ( '/' ) . join ( path . sep ) ) ;
15+ const rootDir = path . resolve ( testDir ) ;
16+ const files = await listFiles ( '**/*.html' , rootDir ) ;
17+ const packageDir = path . resolve ( __dirname , '../' ) ;
18+ return formatErrors ( cleanup ( errors ) , { relativeFrom : packageDir , files } ) ;
1119}
1220
1321describe ( 'formatErrors' , ( ) => {
@@ -16,23 +24,34 @@ describe('formatErrors', () => {
1624 chalk . level = 0 ;
1725 } ) ;
1826
19- it ( 'prints a nice summery ' , async ( ) => {
27+ it ( 'prints a nice summary ' , async ( ) => {
2028 const result = await executeAndFormat ( 'fixtures/test-case' ) ;
2129 expect ( result . trim ( ) . split ( '\n' ) ) . to . deep . equal ( [
2230 '1. missing id="my-teams" in fixtures/test-case/price/index.html' ,
2331 ' from fixtures/test-case/history/index.html:1:9 via href="/price/#my-teams"' ,
2432 '' ,
33+ 'Suggestion: did you mean test-node/fixtures/test-case/price/index.html instead?' ,
34+ '' ,
35+ '' ,
2536 '2. missing file fixtures/test-case/about/images/team.png' ,
2637 ' from fixtures/test-case/about/index.html:3:10 via src="./images/team.png"' ,
2738 '' ,
39+ 'Suggestion: did you mean test-node/fixtures/test-case/about/index.html instead?' ,
40+ '' ,
41+ '' ,
2842 '3. missing reference target fixtures/test-case/aboot' ,
2943 ' from fixtures/test-case/about/index.html:6:11 via href="/aboot"' ,
3044 ' from fixtures/test-case/history/index.html:4:11 via href="/aboot"' ,
3145 ' from fixtures/test-case/index.html:4:11 via href="/aboot"' ,
3246 ' ... 2 more references to this target' ,
3347 '' ,
48+ 'Suggestion: did you mean test-node/fixtures/test-case/index.html instead?' ,
49+ '' ,
50+ '' ,
3451 '4. missing reference target fixtures/test-case/prce' ,
3552 ' from fixtures/test-case/index.html:1:9 via href="./prce"' ,
53+ '' ,
54+ 'Suggestion: did you mean test-node/fixtures/test-case/index.html instead?' ,
3655 ] ) ;
3756 } ) ;
3857} ) ;
0 commit comments