1
1
import chai from 'chai' ;
2
2
import chalk from 'chalk' ;
3
- import { execute } from './test-helpers.js' ;
4
3
import { 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' ;
5
8
6
9
const { expect } = chai ;
10
+ const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
7
11
8
12
async function executeAndFormat ( inPath ) {
9
13
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 } ) ;
11
18
}
12
19
13
20
describe ( 'formatErrors' , ( ) => {
@@ -16,23 +23,34 @@ describe('formatErrors', () => {
16
23
chalk . level = 0 ;
17
24
} ) ;
18
25
19
- it ( 'prints a nice summery ' , async ( ) => {
26
+ it ( 'prints a nice summary ' , async ( ) => {
20
27
const result = await executeAndFormat ( 'fixtures/test-case' ) ;
21
28
expect ( result . trim ( ) . split ( '\n' ) ) . to . deep . equal ( [
22
29
'1. missing id="my-teams" in fixtures/test-case/price/index.html' ,
23
30
' from fixtures/test-case/history/index.html:1:9 via href="/price/#my-teams"' ,
24
31
'' ,
32
+ 'Suggestion: did you mean test-node/fixtures/test-case/price/index.html instead?' ,
33
+ '' ,
34
+ '' ,
25
35
'2. missing file fixtures/test-case/about/images/team.png' ,
26
36
' from fixtures/test-case/about/index.html:3:10 via src="./images/team.png"' ,
27
37
'' ,
38
+ 'Suggestion: did you mean test-node/fixtures/test-case/about/index.html instead?' ,
39
+ '' ,
40
+ '' ,
28
41
'3. missing reference target fixtures/test-case/aboot' ,
29
42
' from fixtures/test-case/about/index.html:6:11 via href="/aboot"' ,
30
43
' from fixtures/test-case/history/index.html:4:11 via href="/aboot"' ,
31
44
' from fixtures/test-case/index.html:4:11 via href="/aboot"' ,
32
45
' ... 2 more references to this target' ,
33
46
'' ,
47
+ 'Suggestion: did you mean test-node/fixtures/test-case/index.html instead?' ,
48
+ '' ,
49
+ '' ,
34
50
'4. missing reference target fixtures/test-case/prce' ,
35
51
' 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?' ,
36
54
] ) ;
37
55
} ) ;
38
56
} ) ;
0 commit comments