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+ return formatErrors ( cleanup ( errors ) , { files } ) ;
1118}
1219
1320describe ( 'formatErrors' , ( ) => {
@@ -16,23 +23,34 @@ describe('formatErrors', () => {
1623 chalk . level = 0 ;
1724 } ) ;
1825
19- it ( 'prints a nice summery ' , async ( ) => {
26+ it ( 'prints a nice summary ' , async ( ) => {
2027 const result = await executeAndFormat ( 'fixtures/test-case' ) ;
2128 expect ( result . trim ( ) . split ( '\n' ) ) . to . deep . equal ( [
2229 '1. missing id="my-teams" in fixtures/test-case/price/index.html' ,
2330 ' from fixtures/test-case/history/index.html:1:9 via href="/price/#my-teams"' ,
2431 '' ,
32+ 'Suggestion: did you mean test-node/fixtures/test-case/price/index.html instead?' ,
33+ '' ,
34+ '' ,
2535 '2. missing file fixtures/test-case/about/images/team.png' ,
2636 ' from fixtures/test-case/about/index.html:3:10 via src="./images/team.png"' ,
2737 '' ,
38+ 'Suggestion: did you mean test-node/fixtures/test-case/about/index.html instead?' ,
39+ '' ,
40+ '' ,
2841 '3. missing reference target fixtures/test-case/aboot' ,
2942 ' from fixtures/test-case/about/index.html:6:11 via href="/aboot"' ,
3043 ' from fixtures/test-case/history/index.html:4:11 via href="/aboot"' ,
3144 ' from fixtures/test-case/index.html:4:11 via href="/aboot"' ,
3245 ' ... 2 more references to this target' ,
3346 '' ,
47+ 'Suggestion: did you mean test-node/fixtures/test-case/index.html instead?' ,
48+ '' ,
49+ '' ,
3450 '4. missing reference target fixtures/test-case/prce' ,
3551 ' from fixtures/test-case/index.html:1:9 via href="./prce"' ,
52+ '' ,
53+ 'Suggestion: did you mean test-node/fixtures/test-case/index.html instead?' ,
3654 ] ) ;
3755 } ) ;
3856} ) ;
0 commit comments