This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da33cdc
commit 15a4bea
Showing
10 changed files
with
384 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/*jshint node: true*/ | ||
'use strict'; | ||
|
||
// Defaults derived from: https://github.com/dequelabs/axe-core | ||
const defaults = { | ||
rules: { | ||
'area-alt': { 'enabled': true }, | ||
'audio-caption': { 'enabled': true }, | ||
'button-name': { 'enabled': true }, | ||
'document-title': { 'enabled': true }, | ||
'empty-heading': { 'enabled': true }, | ||
'frame-title': { 'enabled': true }, | ||
'frame-title-unique': { 'enabled': true }, | ||
'image-alt': { 'enabled': true }, | ||
'image-redundant-alt': { 'enabled': true }, | ||
'input-image-alt': { 'enabled': true }, | ||
'link-name': { 'enabled': true }, | ||
'object-alt': { 'enabled': true }, | ||
'server-side-image-map': { 'enabled': true }, | ||
'video-caption': { 'enabled': true }, | ||
'video-description': { 'enabled': true }, | ||
|
||
'definition-list': { 'enabled': true }, | ||
'dlitem': { 'enabled': true }, | ||
'heading-order': { 'enabled': true }, | ||
'href-no-hash': { 'enabled': true }, | ||
'layout-table': { 'enabled': true }, | ||
'list': { 'enabled': true }, | ||
'listitem': { 'enabled': true }, | ||
'p-as-heading': { 'enabled': true }, | ||
|
||
'scope-attr-valid': { 'enabled': true }, | ||
'table-duplicate-name': { 'enabled': true }, | ||
'table-fake-caption': { 'enabled': true }, | ||
'td-has-header': { 'enabled': true }, | ||
'td-headers-attr': { 'enabled': true }, | ||
'th-has-data-cells': { 'enabled': true }, | ||
|
||
'duplicate-id': { 'enabled': true }, | ||
'html-has-lang': { 'enabled': true }, | ||
'html-lang-valid': { 'enabled': true }, | ||
'meta-refresh': { 'enabled': true }, | ||
'valid-lang': { 'enabled': true }, | ||
|
||
'checkboxgroup': { 'enabled': true }, | ||
'label': { 'enabled': true }, | ||
'radiogroup': { 'enabled': true }, | ||
|
||
'accesskeys': { 'enabled': true }, | ||
'bypass': { 'enabled': true }, | ||
'tabindex': { 'enabled': true }, | ||
|
||
'aria-allowed-attr': { 'enabled': true }, | ||
'aria-required-attr': { 'enabled': true }, | ||
'aria-required-children': { 'enabled': true }, | ||
'aria-required-parent': { 'enabled': true }, | ||
'aria-roles': { 'enabled': true }, | ||
'aria-valid-attr': { 'enabled': true }, | ||
'aria-valid-attr-value': { 'enabled': true }, | ||
|
||
'blink': { 'enabled': true }, | ||
'color-contrast': { 'enabled': true }, | ||
'link-in-text-block': { 'enabled': true }, | ||
'marquee': { 'enabled': true }, | ||
'meta-viewport': { 'enabled': true }, | ||
'meta-viewport-large': { 'enabled': true } | ||
} | ||
}; | ||
|
||
module.exports = { | ||
getConfig: () => { | ||
const skyPagesConfigUtil = require('../sky-pages/sky-pages.config'); | ||
const skyPagesConfig = skyPagesConfigUtil.getSkyPagesConfig(); | ||
|
||
let config = {}; | ||
|
||
// Merge rules from skyux config. | ||
if (skyPagesConfig.skyux.a11y && skyPagesConfig.skyux.a11y.rules) { | ||
config.rules = Object.assign({}, defaults.rules, skyPagesConfig.skyux.a11y.rules); | ||
} | ||
|
||
// The consuming SPA wishes to disable all rules. | ||
if (skyPagesConfig.skyux.a11y === false) { | ||
config.rules = Object.assign({}, defaults.rules); | ||
Object.keys(config.rules).forEach((key) => { | ||
config.rules[key].enabled = false; | ||
}); | ||
} | ||
|
||
if (!config.rules) { | ||
return defaults; | ||
} | ||
|
||
return config; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/*jshint node: true */ | ||
'use strict'; | ||
|
||
const axeBuilder = require('axe-webdriverjs'); | ||
const logger = require('../utils/logger'); | ||
const axeConfig = require('../config/axe/axe.config'); | ||
const { browser } = require('protractor'); | ||
|
||
function SkyA11y() {} | ||
|
||
SkyA11y.run = function () { | ||
return browser | ||
.getCurrentUrl() | ||
.then(url => new Promise((resolve) => { | ||
const config = axeConfig.getConfig(); | ||
|
||
logger.info(`Starting accessibility checks for ${url}...`); | ||
|
||
axeBuilder(browser.driver) | ||
.options(config) | ||
.analyze((results) => { | ||
const numViolations = results.violations.length; | ||
const subject = (numViolations === 1) ? 'violation' : 'violations'; | ||
|
||
logger.info(`Accessibility checks finished with ${numViolations} ${subject}.\n`); | ||
|
||
if (numViolations > 0) { | ||
logViolations(results); | ||
} | ||
|
||
resolve(numViolations); | ||
}); | ||
})); | ||
}; | ||
|
||
function logViolations(results) { | ||
results.violations.forEach((violation) => { | ||
const wcagTags = violation.tags | ||
.filter(tag => tag.match(/wcag\d{3}|^best*/gi)) | ||
.join(', '); | ||
|
||
const html = violation.nodes | ||
.reduce( | ||
(accumulator, node) => `${accumulator}\n${node.html}\n`, | ||
' Elements:\n' | ||
); | ||
|
||
const error = [ | ||
`aXe - [Rule: \'${violation.id}\'] ${violation.help} - WCAG: ${wcagTags}`, | ||
` Get help at: ${violation.helpUrl}\n`, | ||
`${html}\n\n` | ||
].join('\n'); | ||
|
||
logger.error(error); | ||
}); | ||
} | ||
|
||
module.exports = SkyA11y; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export declare class SkyA11y { | ||
static run(): Promise<any>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const analyzer = require('../../../lib/a11y-analyzer'); | ||
module.exports = { SkyA11y: analyzer }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './host-browser'; | ||
export * from './a11y'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/*jshint jasmine: true, node: true */ | ||
'use strict'; | ||
|
||
const mock = require('mock-require'); | ||
|
||
describe('config axe', () => { | ||
afterEach(() => { | ||
mock.stopAll(); | ||
}); | ||
|
||
it('should return a config object', () => { | ||
mock('../config/sky-pages/sky-pages.config', { | ||
getSkyPagesConfig: () => { | ||
return { | ||
skyux: {} | ||
}; | ||
} | ||
}); | ||
const lib = mock.reRequire('../config/axe/axe.config'); | ||
const config = lib.getConfig(); | ||
expect(config).toBeDefined(); | ||
expect(config.rules.label.enabled).toEqual(true); | ||
}); | ||
|
||
it('should merge config from a consuming SPA', () => { | ||
mock('../config/sky-pages/sky-pages.config', { | ||
getSkyPagesConfig: () => { | ||
return { | ||
skyux: { | ||
a11y: { | ||
rules: { | ||
label: { enabled: false } | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
}); | ||
const lib = mock.reRequire('../config/axe/axe.config'); | ||
const config = lib.getConfig(); | ||
expect(config.rules.label.enabled).toEqual(false); | ||
}); | ||
|
||
it('should return defaults if rules are not defined', () => { | ||
mock('../config/sky-pages/sky-pages.config', { | ||
getSkyPagesConfig: () => { | ||
return { | ||
skyux: { | ||
a11y: {} | ||
} | ||
}; | ||
} | ||
}); | ||
const lib = mock.reRequire('../config/axe/axe.config'); | ||
const config = lib.getConfig(); | ||
expect(config.rules.label.enabled).toEqual(true); | ||
}); | ||
|
||
it('should disabled all rules if accessibility is set to false', () => { | ||
mock('../config/sky-pages/sky-pages.config', { | ||
getSkyPagesConfig: () => { | ||
return { | ||
skyux: { | ||
a11y: false | ||
} | ||
}; | ||
} | ||
}); | ||
const lib = mock.reRequire('../config/axe/axe.config'); | ||
const config = lib.getConfig(); | ||
expect(config.rules.label.enabled).toEqual(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.