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
+
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 } ) ;
11
20
}
12
21
13
22
describe ( 'formatErrors' , ( ) => {
@@ -16,23 +25,34 @@ describe('formatErrors', () => {
16
25
chalk . level = 0 ;
17
26
} ) ;
18
27
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 } ) ;
21
30
expect ( result . trim ( ) . split ( '\n' ) ) . to . deep . equal ( [
22
31
'1. missing id="my-teams" in fixtures/test-case/price/index.html' ,
23
32
' from fixtures/test-case/history/index.html:1:9 via href="/price/#my-teams"' ,
24
33
'' ,
34
+ 'Suggestion: did you mean test-node/fixtures/test-case/price/index.html instead?' ,
35
+ '' ,
36
+ '' ,
25
37
'2. missing file fixtures/test-case/about/images/team.png' ,
26
38
' from fixtures/test-case/about/index.html:3:10 via src="./images/team.png"' ,
27
39
'' ,
40
+ 'Suggestion: did you mean test-node/fixtures/test-case/about/index.html instead?' ,
41
+ '' ,
42
+ '' ,
28
43
'3. missing reference target fixtures/test-case/aboot' ,
29
44
' from fixtures/test-case/about/index.html:6:11 via href="/aboot"' ,
30
45
' from fixtures/test-case/history/index.html:4:11 via href="/aboot"' ,
31
46
' from fixtures/test-case/index.html:4:11 via href="/aboot"' ,
32
47
' ... 2 more references to this target' ,
33
48
'' ,
49
+ 'Suggestion: did you mean test-node/fixtures/test-case/index.html instead?' ,
50
+ '' ,
51
+ '' ,
34
52
'4. missing reference target fixtures/test-case/prce' ,
35
53
' 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?' ,
36
56
] ) ;
37
57
} ) ;
38
58
} ) ;
0 commit comments