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