@@ -23,54 +23,79 @@ describe('useChecker', () => {
23
23
vi . clearAllMocks ( )
24
24
} )
25
25
26
- it ( 'logs an error' , async ( ) => {
27
- const mockValidator = vi . fn ( ) . mockImplementation ( ( ) => ( { valid : false , results : [ ] } ) )
28
- const { checkHTML : checker } = useChecker ( { validateString : mockValidator } as any )
29
-
30
- await checker ( 'https://test.com/' , '<a><a>Link</a></a>' )
31
- expect ( mockValidator ) . toHaveBeenCalled ( )
32
- expect ( console . error ) . toHaveBeenCalled ( )
33
- } )
34
-
35
- it ( 'prints an error when invalid html is provided' , async ( ) => {
36
- const mockValidator = vi . fn ( ) . mockImplementation ( ( ) => ( { valid : false , results : [ ] } ) )
26
+ it ( 'logs valid output' , async ( ) => {
27
+ const mockValidator = vi . fn ( ) . mockImplementation ( ( ) => ( { valid : true , results : [ ] } ) )
37
28
const { checkHTML : checker } = useChecker ( { validateString : mockValidator } as any , false )
38
29
39
- await checker ( 'https://test.com/' , '<a>Link</a>' )
40
- expect ( mockValidator ) . toHaveBeenCalled ( )
41
- expect ( console . error ) . toHaveBeenCalled ( )
42
- } )
43
-
44
- it ( 'prints a warning when invalid html is provided and log level is set to verbose' , async ( ) => {
45
- const mockValidator = vi . fn ( ) . mockImplementation ( ( ) => ( { valid : true , results : [ { messages : [ { message : '' } ] } ] } ) )
46
- const { checkHTML : checker } = useChecker ( { validateString : mockValidator } as any , false , 'verbose' )
47
-
48
- await checker ( 'https://test.com/' , '<a>Link</a>' )
49
- expect ( mockValidator ) . toHaveBeenCalled ( )
50
- expect ( console . warn ) . toHaveBeenCalled ( )
30
+ await checker ( 'https://test.com/' , Symbol as any )
31
+ expect ( console . log ) . toHaveBeenCalledWith (
32
+ `No HTML validation errors found for ${ chalk . bold ( 'https://test.com/' ) } `
33
+ )
34
+ expect ( console . warn ) . not . toHaveBeenCalled ( )
51
35
expect ( console . error ) . not . toHaveBeenCalled ( )
52
36
} )
53
37
54
- it ( 'prints a warning when invalid html is provided and log level is set to warning ' , async ( ) => {
38
+ it ( 'logs valid output ' , async ( ) => {
55
39
const mockValidator = vi . fn ( ) . mockImplementation ( ( ) => ( { valid : true , results : [ ] } ) )
56
- const { checkHTML : checker } = useChecker ( { validateString : mockValidator } as any , false , 'warning ' )
40
+ const { checkHTML : checker } = useChecker ( { validateString : mockValidator } as any , false , 'verbose ' )
57
41
58
- await checker ( 'https://test.com/' , '<a>Link</a>' )
59
- expect ( mockValidator ) . toHaveBeenCalled ( )
60
- expect ( console . warn ) . toHaveBeenCalled ( )
42
+ await checker ( 'https://test.com/' , Symbol as any )
43
+ expect ( console . log ) . toHaveBeenCalledWith (
44
+ `No HTML validation errors found for ${ chalk . bold ( 'https://test.com/' ) } `
45
+ )
46
+ expect ( console . warn ) . not . toHaveBeenCalled ( )
61
47
expect ( console . error ) . not . toHaveBeenCalled ( )
62
48
} )
63
49
64
- it ( 'prints no warning when invalid html is provided and log level is set to error' , async ( ) => {
65
- const mockValidator = vi . fn ( ) . mockImplementation ( ( ) => ( { valid : true , results : [ ] } ) )
50
+ for ( const logLevel of [ 'warning' , 'error' ] as const ) {
51
+ it ( `does not log valid output when logging on level ${ logLevel } ` , async ( ) => {
52
+ const mockValidator = vi . fn ( ) . mockImplementation ( ( ) => ( { valid : true , results : [ ] } ) )
53
+ const { checkHTML : checker } = useChecker ( { validateString : mockValidator } as any , false , logLevel )
54
+
55
+ await checker ( 'https://test.com/' , Symbol as any )
56
+ expect ( console . log ) . not . toHaveBeenCalled ( )
57
+ expect ( console . warn ) . not . toHaveBeenCalled ( )
58
+ expect ( console . error ) . not . toHaveBeenCalled ( )
59
+ } )
60
+ }
61
+
62
+ for ( const logLevel of [ undefined , 'verbose' , 'warning' ] as const ) {
63
+ it ( `logs a warning when valid html is provided with warnings and log level is set to ${ logLevel } ` , async ( ) => {
64
+ const mockValidator = vi . fn ( ) . mockImplementation ( ( ) => ( { valid : true , results : [ { messages : [ { message : '' } ] } ] } ) )
65
+ const { checkHTML : checker } = useChecker ( { validateString : mockValidator } as any , false , logLevel )
66
+
67
+ await checker ( 'https://test.com/' , Symbol as any )
68
+ expect ( console . log ) . not . toHaveBeenCalled ( )
69
+ expect ( console . warn ) . toHaveBeenCalled ( )
70
+ expect ( console . error ) . not . toHaveBeenCalled ( )
71
+ } )
72
+ }
73
+
74
+ it ( 'does not log a warning when valid html is provided with warnings and log level is set to error' , async ( ) => {
75
+ const mockValidator = vi . fn ( ) . mockImplementation ( ( ) => ( { valid : true , results : [ { messages : [ { message : '' } ] } ] } ) )
66
76
const { checkHTML : checker } = useChecker ( { validateString : mockValidator } as any , false , 'error' )
67
77
68
- await checker ( 'https://test.com/' , '<a>Link</a>' )
69
- expect ( mockValidator ) . toHaveBeenCalled ( )
78
+ await checker ( 'https://test.com/' , Symbol as any )
79
+ expect ( console . log ) . not . toHaveBeenCalled ( )
70
80
expect ( console . warn ) . not . toHaveBeenCalled ( )
71
81
expect ( console . error ) . not . toHaveBeenCalled ( )
72
82
} )
73
83
84
+ for ( const logLevel of [ undefined , 'verbose' , 'warning' , 'error' ] as const ) {
85
+ it ( `logs an error when invalid html is provided and log level is set to ${ logLevel } ` , async ( ) => {
86
+ const mockValidator = vi . fn ( ) . mockImplementation ( ( ) => ( { valid : false , results : [ { messages : [ { message : '' } ] } ] } ) )
87
+ const { checkHTML : checker } = useChecker ( { validateString : mockValidator } as any , false , logLevel )
88
+
89
+ await checker ( 'https://test.com/' , '<a>Link</a>' )
90
+ expect ( mockValidator ) . toHaveBeenCalled ( )
91
+ expect ( console . log ) . not . toHaveBeenCalled ( )
92
+ expect ( console . warn ) . not . toHaveBeenCalled ( )
93
+ expect ( console . error ) . toHaveBeenCalledWith (
94
+ `HTML validation errors found for ${ chalk . bold ( 'https://test.com/' ) } `
95
+ )
96
+ } )
97
+ }
98
+
74
99
it ( 'records urls when invalid html is provided' , async ( ) => {
75
100
const mockValidator = vi . fn ( ) . mockImplementation ( ( ) => ( { valid : false , results : [ ] } ) )
76
101
const { checkHTML : checker , invalidPages } = useChecker ( { validateString : mockValidator } as any , false )
@@ -90,6 +115,10 @@ describe('useChecker', () => {
90
115
expect ( mockValidator ) . toHaveBeenCalledWith (
91
116
'<a>Link</a>'
92
117
)
118
+ expect ( console . log ) . toHaveBeenCalledWith (
119
+ `No HTML validation errors found for ${ chalk . bold ( 'https://test.com/' ) } `
120
+ )
121
+ expect ( console . warn ) . not . toHaveBeenCalled ( )
93
122
expect ( console . error ) . not . toHaveBeenCalled ( )
94
123
} )
95
124
@@ -112,27 +141,13 @@ describe('useChecker', () => {
112
141
await checker ( 'https://test.com/' , Symbol as any )
113
142
const { format } = await import ( 'prettier' )
114
143
expect ( format ) . toHaveBeenCalledWith ( Symbol , { parser : 'html' } )
115
- expect ( console . error ) . toHaveBeenCalled ( )
144
+ expect ( console . log ) . not . toHaveBeenCalled ( )
145
+ expect ( console . warn ) . not . toHaveBeenCalled ( )
146
+ expect ( console . error ) . toHaveBeenCalledWith (
147
+ `HTML validation errors found for ${ chalk . bold ( 'https://test.com/' ) } `
148
+ )
116
149
117
150
const validate = await import ( 'html-validate' )
118
151
expect ( validate . formatterFactory ) . not . toHaveBeenCalledWith ( 'codeframe' )
119
152
} )
120
-
121
- it ( 'logs valid output' , async ( ) => {
122
- const mockValidator = vi . fn ( ) . mockImplementation ( ( ) => ( { valid : true , results : [ ] } ) )
123
- const { checkHTML : checker } = useChecker ( { validateString : mockValidator } as any , false , 'verbose' )
124
-
125
- await checker ( 'https://test.com/' , Symbol as any )
126
- expect ( console . log ) . toHaveBeenCalledWith (
127
- `No HTML validation errors found for ${ chalk . bold ( 'https://test.com/' ) } `
128
- )
129
- } )
130
-
131
- it ( 'does not log valid output when logging on level warning' , async ( ) => {
132
- const mockValidator = vi . fn ( ) . mockImplementation ( ( ) => ( { valid : true , results : [ ] } ) )
133
- const { checkHTML : checker } = useChecker ( { validateString : mockValidator } as any , false , 'warning' )
134
-
135
- await checker ( 'https://test.com/' , Symbol as any )
136
- expect ( console . log ) . not . toHaveBeenCalled ( )
137
- } )
138
153
} )
0 commit comments