File tree Expand file tree Collapse file tree 6 files changed +61
-10
lines changed Expand file tree Collapse file tree 6 files changed +61
-10
lines changed Original file line number Diff line number Diff line change 1
1
import { axe } from "axe-core/axe.min.js" ;
2
2
import report from "./reporter" ;
3
3
4
- export default function ( target ) {
4
+ export default function ( target , logger ) {
5
5
const options = {
6
6
"rules" : {
7
7
"color-contrast" : { enabled : false } ,
8
8
}
9
9
} ;
10
10
11
11
window . axe . a11yCheck ( target . parentNode , options , ( results ) => {
12
- report ( results ) ;
12
+ report ( results , logger ) ;
13
13
} ) ;
14
14
}
Original file line number Diff line number Diff line change 1
1
import auditor from "./auditor.js" ;
2
+ import Logger from "./logger" ;
2
3
3
4
( function ( ) {
5
+ var logger = new Logger ( ) ;
6
+
4
7
var load = function ( ) {
5
8
window . removeEventListener ( "load" , load , false ) ;
6
- auditor ( document ) ;
9
+ auditor ( document , logger ) ;
7
10
} ;
8
11
9
12
var observer = new MutationObserver ( function ( mutations ) {
10
13
mutations . forEach ( function ( mutation ) {
11
- auditor ( mutation . target ) ;
14
+ auditor ( mutation . target , logger ) ;
12
15
} ) ;
13
16
} ) ;
14
17
Original file line number Diff line number Diff line change
1
+ export default class Logger {
2
+ constructor ( ) {
3
+ this . logged = [ ]
4
+ }
5
+
6
+ warn ( violation ) {
7
+ if ( ! this . exists ( violation ) ) {
8
+ console . warn ( violation ) ;
9
+ this . logged . push ( violation ) ;
10
+ }
11
+ }
12
+
13
+ exists ( violation ) {
14
+ let exists = false ;
15
+
16
+ this . logged . forEach ( function ( entry ) {
17
+ if ( JSON . stringify ( entry ) === JSON . stringify ( violation ) ) {
18
+ exists = true ;
19
+ }
20
+ } ) ;
21
+
22
+ return exists ;
23
+ }
24
+ }
Original file line number Diff line number Diff line change @@ -2,14 +2,15 @@ import request from "browser-request";
2
2
3
3
const url = "/access_lint/errors" ;
4
4
5
- export default function ( message ) {
5
+ export default function ( message , logger ) {
6
+
6
7
var violations = message . violations . map ( function ( violation ) {
7
8
return {
8
9
description : violation . description ,
9
10
help : violation . help ,
10
11
impact : violation . impact ,
11
12
nodes : violation . nodes . map ( function ( n ) {
12
- return document . querySelectorAll ( n . target ) ;
13
+ return document . querySelector ( n . target ) ;
13
14
} ) ,
14
15
} ;
15
16
} ) ;
@@ -26,6 +27,8 @@ export default function(message) {
26
27
}
27
28
} , function ( ) { } ) ;
28
29
29
- console . warn ( violations ) ;
30
+ violations . forEach ( function ( violation ) {
31
+ logger . warn ( violation ) ;
32
+ } ) ;
30
33
}
31
34
}
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ let expect = chai.expect;
8
8
9
9
import auditor from "../../src/auditor" ;
10
10
import report from "../../src/reporter" ;
11
+ import Logger from "../../src/logger" ;
11
12
12
13
describe ( "auditor" , ( ) => {
13
14
it ( "runs axe-core tests" , ( ) => {
@@ -30,10 +31,11 @@ describe("report", () => {
30
31
nodes : [ ]
31
32
} ]
32
33
} ;
33
- sinon . spy ( console , "warn" ) ;
34
+ let logger = new Logger ( ) ;
35
+ sinon . spy ( logger , "warn" ) ;
34
36
35
- report ( results ) ;
37
+ report ( results , logger ) ;
36
38
37
- expect ( console . warn ) . to . have . been . called . once ;
39
+ expect ( logger . warn ) . to . have . been . called . once ;
38
40
} ) ;
39
41
} ) ;
Original file line number Diff line number Diff line change
1
+ let chai = require ( "chai" ) ;
2
+ let sinon = require ( "sinon" ) ;
3
+ let sinonChai = require ( "sinon-chai" ) ;
4
+ chai . use ( sinonChai ) ;
5
+ let expect = chai . expect ;
6
+
7
+ import Logger from "../../src/logger" ;
8
+
9
+ describe ( "warn" , ( ) => {
10
+ it ( "logs to console.warn" , ( ) => {
11
+ let logger = new Logger ( ) ;
12
+ sinon . spy ( console , "warn" ) ;
13
+ logger . warn ( "example" ) ;
14
+ logger . warn ( "example" ) ;
15
+
16
+ expect ( console . warn ) . to . be . have . been . calledWith ( "example" ) ;
17
+ expect ( console . warn ) . to . be . have . been . calledOnce ;
18
+ } ) ;
19
+ } ) ;
You can’t perform that action at this time.
0 commit comments