Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d8534f3

Browse files
committedJul 29, 2015
Build: add accessibility testing
Fixes jquery-archive#99
1 parent 6a9565e commit d8534f3

File tree

8 files changed

+160
-29
lines changed

8 files changed

+160
-29
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ external/
1010
icons/svg-min/
1111
.sass-cache/
1212
dist/
13+
tmp/

‎demos/typography.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!doctype html>
2-
<html>
2+
<html lang="en">
33
<head>
44
<meta charset="utf-8">
55
<title>CSS Chassis - Typography</title>

‎lib/reporter.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
3+
function color(code, str) {
4+
return "\u001b[" + code + "m" + str + "\u001b[0m";
5+
}
6+
7+
exports = module.exports = function( grunt, results, threshold ) {
8+
var pass = true;
9+
results.forEach( function ( result ) {
10+
grunt.log.subhead( result.url );
11+
var violations = result.violations;
12+
if ( violations.length ) {
13+
if ( violations.length > threshold ) {
14+
pass = false;
15+
grunt.log.error( "Found " + result.violations.length + " accessibility violations:" );
16+
} else {
17+
grunt.log.ok( "Found " + result.violations.length + " accessibility violations: (under threshold of " + threshold + ")" );
18+
}
19+
result.violations.forEach( function( ruleResult ) {
20+
grunt.log.subhead( " " + color(31, "\u00D7") + " " + ruleResult.help );
21+
22+
ruleResult.nodes.forEach( function( violation, index ) {
23+
grunt.log.writeln( " " + ( index + 1 ) + ". " + JSON.stringify( violation.target ) );
24+
25+
if ( violation.any.length ) {
26+
grunt.log.writeln( " Fix any of the following:" );
27+
violation.any.forEach( function( check ) {
28+
grunt.log.writeln( " \u2022 " + check.message );
29+
} );
30+
}
31+
32+
var alls = violation.all.concat( violation.none );
33+
if ( alls.length ) {
34+
grunt.log.writeln( " Fix all of the following:" );
35+
alls.forEach( function( check ) {
36+
grunt.log.writeln( " \u2022 " + check.message );
37+
} );
38+
}
39+
grunt.log.writeln();
40+
});
41+
});
42+
return;
43+
} else {
44+
grunt.log.ok( "Found no accessibility violations." );
45+
}
46+
} );
47+
return pass;
48+
};

‎package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,17 @@
3737
},
3838
"dependencies": {},
3939
"devDependencies": {
40+
"axe-webdriverjs": "^0.1.0",
4041
"browser-perf": "1.2.3",
4142
"chromedriver": "2.13.0",
4243
"commitplease": "2.0.0",
4344
"ejs-template": "0.1.0",
4445
"grunt": "0.4.5",
4546
"grunt-autoprefixer": "2.1.0",
46-
"grunt-contrib-cssmin": "0.10.0",
47+
"grunt-contrib-connect": "0.9.0",
4748
"grunt-contrib-csslint": "0.4.0",
49+
"grunt-contrib-cssmin": "0.10.0",
4850
"grunt-contrib-jshint": "0.10.0",
49-
"grunt-contrib-connect": "0.9.0",
5051
"grunt-contrib-watch": "0.6.1",
5152
"grunt-csscomb": "3.0.0",
5253
"grunt-git-authors": "2.0.0",
@@ -58,7 +59,9 @@
5859
"grunt-svgstore": "0.5.0",
5960
"jsass-vars": "0.0.3",
6061
"load-grunt-config": "0.16.0",
61-
"perfjankie": "1.2.2"
62+
"perfjankie": "1.2.2",
63+
"promise": "^7.0.3",
64+
"selenium-webdriver": "^2.46.1"
6265
},
6366
"keywords": []
6467
}

‎tasks/alias.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module.exports = function( grunt ) {
22
grunt.registerTask( "default", [ "test" ] );
3-
grunt.registerTask( "test", [ "build", "jshint", "jscs", "csslint" ] );
4-
grunt.registerTask( "build", [ "svg", "sass", "csscomb", "cssmin" ] );
3+
grunt.registerTask( "accessibility", [ "connect:accessibility", "axe-webdriver"])
4+
grunt.registerTask( "test", [ "build", "jshint", "jscs", "csslint", "accessibility" ] );
5+
grunt.registerTask( "build", [ "buildVariables", "svg", "sass", "csscomb", "cssmin" ] );
56
grunt.registerTask( "perf", [
67
"start-selenium-server",
78
"connect:perf",

‎tasks/axe-webdriver.js

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*! aXe-grunt-webdriver
2+
* Copyright (c) 2015 Deque Systems, Inc.
3+
*
4+
* Your use of this Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7+
*
8+
* This entire copyright notice must appear in every copy of this file you
9+
* distribute or in any file that contains substantial portions of this source
10+
* code.
11+
*/
12+
13+
'use strict';
14+
15+
module.exports = function( grunt ) {
16+
var WebDriver = require( "selenium-webdriver" ),
17+
AxeBuilder = require( "axe-webdriverjs" ),
18+
Promise = require( "promise" ),
19+
path = require( "path" ),
20+
reporter = require( "../lib/reporter" );
21+
22+
grunt.registerMultiTask( "axe-webdriver", "Grunt plugin for aXe utilizing WebDriverJS", function () {
23+
var options = this.options( {
24+
browser: "firefox",
25+
server: null,
26+
threshold: 0
27+
} );
28+
29+
var done = this.async ();
30+
var driver = new WebDriver.Builder ()
31+
.forBrowser( options.browser )
32+
.build ();
33+
34+
var dest = this.data.dest;
35+
Promise.all( this.data.urls.map( function( url ) {
36+
return new Promise( function( resolve, reject ) {
37+
38+
driver
39+
.get( url )
40+
.then( function() {
41+
new AxeBuilder( driver )
42+
.analyze( function( results ) {
43+
results.url = url;
44+
resolve( results );
45+
} );
46+
} );
47+
} );
48+
})).then( function( results ) {
49+
if ( dest ) {
50+
grunt.file.write( dest, JSON.stringify( results, null, " " ) );
51+
}
52+
var result = reporter( grunt, results, options.threshold );
53+
driver.quit().then( function () {
54+
done( result );
55+
} );
56+
} );
57+
} );
58+
};

‎tasks/options/axe-webdriver.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
firefox: {
3+
options: {
4+
threshold: 0
5+
},
6+
urls: ['http://localhost:4200/demos/typography.html'],
7+
dest: 'tmp/gu.json'
8+
},
9+
chrome: {
10+
options: {
11+
browser: 'chrome',
12+
threshold: 0
13+
},
14+
urls: ['http://localhost:4200/demos/typography.html']
15+
}
16+
};

‎tasks/options/connect.js

+27-23
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,36 @@ var template = require( "ejs-template" ),
55
module.exports = {
66
options: {
77
port: 4200,
8-
base: ".",
9-
middleware: [
10-
template.middleware({ basedir: __dirname }),
11-
function( req, res ) {
12-
var data, i,
13-
url = urlParser.parse( req.url, true ),
14-
query = {},
15-
parts = url.pathname.split( "/" ),
16-
file = req.url.replace( /^\//, "" ).split( "?" )[ 0 ];
8+
base: "."
9+
},
10+
perf: {
11+
options: {
12+
middleware: [
13+
template.middleware({ basedir: __dirname }),
14+
function( req, res ) {
15+
var data, i,
16+
url = urlParser.parse( req.url, true ),
17+
query = {},
18+
parts = url.pathname.split( "/" ),
19+
file = req.url.replace( /^\//, "" ).split( "?" )[ 0 ];
1720

18-
for ( i = 1; i < parts.length; i += 2 ) {
19-
query[ parts[ i ] ] = parts[ i + 1 ];
21+
for ( i = 1; i < parts.length; i += 2 ) {
22+
query[ parts[ i ] ] = parts[ i + 1 ];
23+
}
24+
if ( file.split( "." ).length <= 1 ) {
25+
data = componentGenerator.generate(
26+
query.framework,
27+
query.component,
28+
query.count
29+
);
30+
file = "../../performance/component.html";
31+
}
32+
res.endTemplate( file, data );
2033
}
21-
if ( file.split( "." ).length <= 1 ) {
22-
data = componentGenerator.generate(
23-
query.framework,
24-
query.component,
25-
query.count
26-
);
27-
file = "../../performance/component.html";
28-
}
29-
res.endTemplate( file, data );
30-
}
31-
]
34+
]
35+
}
3236
},
33-
perf: {},
37+
accessibility: {},
3438
dev: {
3539
options: {
3640
keepalive: true

0 commit comments

Comments
 (0)
Please sign in to comment.