-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add tests for remote ACT repo (#2744)
* test: Add tests for remote ACT repo * chore: npm install act-rules instead * chore: resolve review feedback * chore: move act dir * chore: resolve comments
- Loading branch information
1 parent
e0d30e5
commit b297571
Showing
29 changed files
with
301 additions
and
3 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,5 @@ | ||
{ | ||
"id": "6cfa84", | ||
"title": "Element with aria-hidden has no focusable content", | ||
"axeRules": ["aria-hidden-focus"] | ||
} |
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,5 @@ | ||
{ | ||
"id": "5c01ea", | ||
"title": "ARIA state or property is permitted", | ||
"axeRules": ["aria-allowed-attr"] | ||
} |
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,5 @@ | ||
{ | ||
"id": "73f2c2", | ||
"title": "autocomplete attribute has valid value", | ||
"axeRules": ["autocomplete-valid"] | ||
} |
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,5 @@ | ||
{ | ||
"id": "97a4e1", | ||
"title": "Button has non-empty accessible name", | ||
"axeRules": ["button-name", "aria-command-name"] | ||
} |
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,5 @@ | ||
{ | ||
"id": "b33eff", | ||
"title": "Orientation of the page is not restricted using CSS transform property", | ||
"axeRules": ["css-orientation-lock"] | ||
} |
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,10 @@ | ||
{ | ||
"id": "e086e5", | ||
"title": "Form field has non-empty accessible name", | ||
"axeRules": [ | ||
"label", | ||
"select-name", | ||
"aria-input-field-name", | ||
"aria-toggle-field-name" | ||
] | ||
} |
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,5 @@ | ||
{ | ||
"id": "3ea0c8", | ||
"title": "id attribute value is unique", | ||
"axeRules": ["duplicate-id", "duplicate-id-aria", "duplicate-id-active"] | ||
} |
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,5 @@ | ||
{ | ||
"id": "59796f", | ||
"title": "Image button has non-empty accessible name", | ||
"axeRules": ["input-image-alt"] | ||
} |
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,5 @@ | ||
{ | ||
"id": "23a2a8", | ||
"title": "Image has non-empty accessible name", | ||
"axeRules": ["image-alt", "role-img-alt"] | ||
} |
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,39 @@ | ||
module.exports = function(config) { | ||
config.set({ | ||
basePath: '../../', | ||
singleRun: true, | ||
autoWatch: false, | ||
plugins: [ | ||
'karma-mocha', | ||
'karma-chai', | ||
'karma-mocha-reporter', | ||
'karma-chrome-launcher', | ||
require('./preprocessor') | ||
], | ||
frameworks: ['mocha', 'chai'], | ||
files: [ | ||
'axe.js', | ||
'test/act-mapping/*.json', | ||
{ | ||
pattern: 'node_modules/act-rules.github.io/test-assets/**/*', | ||
included: false, | ||
served: true | ||
} | ||
], | ||
browsers: ['ChromeHeadless'], | ||
proxies: { | ||
'/test-assets': '/base/node_modules/act-rules.github.io/test-assets' | ||
}, | ||
reporters: ['mocha'], | ||
preprocessors: { | ||
'**/*.json': ['act'] | ||
}, | ||
client: { | ||
useIframe: false, | ||
mocha: { | ||
timeout: 4000, | ||
reporter: 'html' | ||
} | ||
} | ||
}); | ||
}; |
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,5 @@ | ||
{ | ||
"id": "c487ae", | ||
"title": "Link has non-empty accessible name", | ||
"axeRules": ["link-name", "area-alt"] | ||
} |
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,5 @@ | ||
{ | ||
"id": "fd3a94", | ||
"title": "Links with identical accessible names and context serve equivalent purpose", | ||
"axeRules": ["identical-links-same-purpose"] | ||
} |
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,5 @@ | ||
{ | ||
"id": "b20e66", | ||
"title": "Links with identical accessible names have equivalent purpose", | ||
"axeRules": ["identical-links-same-purpose"] | ||
} |
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,5 @@ | ||
{ | ||
"id": "m6b1q3", | ||
"title": "Menuitem has non-empty accessible name", | ||
"axeRules": ["aria-command-name", "button-name", "link-name"] | ||
} |
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,5 @@ | ||
{ | ||
"id": "b4f0c3", | ||
"title": "meta viewport allows for zoom", | ||
"axeRules": ["meta-viewport"] | ||
} |
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,5 @@ | ||
{ | ||
"id": "8fc3b6", | ||
"title": "Object element rendering non-text content has non-empty accessible name", | ||
"axeRules": ["object-alt"] | ||
} |
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,5 @@ | ||
{ | ||
"id": "b5c3f8", | ||
"title": "HTML page has lang attribute", | ||
"axeRules": ["html-has-lang"] | ||
} |
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,5 @@ | ||
{ | ||
"id": "2779a5", | ||
"title": "HTML page has non-empty title", | ||
"axeRules": ["document-title"] | ||
} |
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,5 @@ | ||
{ | ||
"id": "bf051a", | ||
"title": "HTML page lang attribute has valid language tag", | ||
"axeRules": ["html-lang-valid"] | ||
} |
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,5 @@ | ||
{ | ||
"actRuleId": "5b7ae0", | ||
"title": "HTML page lang and xml:lang attributes have matching values", | ||
"axeRules": ["html-xml-lang-mismatch"] | ||
} |
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,49 @@ | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var template = fs.readFileSync(path.resolve(__dirname, 'runner.js'), 'utf-8'); | ||
|
||
var actRepoDir = 'node_modules/act-rules.github.io/'; | ||
var testcaseFilePath = path.resolve(actRepoDir, 'testcases.json'); | ||
var testcaseContent = require(testcaseFilePath); | ||
var testcases = testcaseContent.testcases; | ||
|
||
createActPreprocessor.$inject = ['logger']; | ||
// Simple Karma preprocessor, takes JSON, outputs a JS file that can run tests | ||
function createActPreprocessor(logger) { | ||
var log = logger.create('preprocessor.act'); | ||
|
||
return function(actRuleJson, file, done) { | ||
try { | ||
log.debug('Processing "%s".', file.originalPath); | ||
file.path = file.originalPath.replace(/\.json$/, '.js'); | ||
|
||
var actRule = JSON.parse(actRuleJson); | ||
var actRule = applyTestCases(actRule); | ||
var testContent = JSON.stringify(actRule, null, 2); | ||
var testFileContent = template.replace('{}; /*tests*/', testContent); | ||
|
||
done(null, testFileContent); | ||
} catch (e) { | ||
console.error(e); | ||
done(e, null); | ||
} | ||
}; | ||
} | ||
|
||
module.exports = { | ||
'preprocessor:act': ['factory', createActPreprocessor] | ||
}; | ||
|
||
function applyTestCases(actRule) { | ||
actRule = Object.assign({}, actRule); | ||
|
||
actRule.testcases = testcases.filter(function(testcase) { | ||
return testcase.ruleId === actRule.id; | ||
}); | ||
actRule.testcases.forEach(function(testcase) { | ||
var testcasePath = path.resolve(actRepoDir, testcase.relativePath); | ||
testcase.html = fs.readFileSync(testcasePath, 'utf-8'); | ||
}); | ||
|
||
return actRule; | ||
} |
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,75 @@ | ||
(function() { | ||
// this line is replaced with the test object in preprocessor.js | ||
var actRule = {}; /*tests*/ | ||
|
||
describe(actRule.title + ' (' + actRule.id + ')', function() { | ||
var bodyContent; | ||
before(function() { | ||
var title = document.querySelector('title'); | ||
if (title) { | ||
document.head.removeChild(title); | ||
} | ||
document.head.innerHTML = ''; | ||
bodyContent = document.body.innerHTML; | ||
}); | ||
|
||
afterEach(function() { | ||
document.body.innerHTML = bodyContent; | ||
document.head.innerHTML = ''; | ||
var htmlAttrs = Array.from(document.documentElement.attributes); | ||
htmlAttrs.forEach(function(attr) { | ||
document.documentElement.removeAttribute(attr.name); | ||
}); | ||
}); | ||
|
||
actRule.testcases.forEach(function(testcase) { | ||
runTestCase(testcase, { | ||
runOnly: actRule.axeRules | ||
}); | ||
}); | ||
}); | ||
|
||
function runTestCase(testcase, axeOptions) { | ||
var test = shouldSkip(testcase) ? xit : it; | ||
test(testcase.testcaseTitle, function(done) { | ||
exampleSetup(testcase.html); | ||
axe | ||
.run(axeOptions) | ||
.then(function(result) { | ||
assertResultsCorrect(testcase, result); | ||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
} | ||
|
||
function exampleSetup(html) { | ||
var parser = new DOMParser(); | ||
var newDoc = parser.parseFromString(html, 'text/html'); | ||
document.head.innerHTML = newDoc.head.innerHTML; | ||
document.body.innerHTML += newDoc.body.innerHTML; | ||
var htmlAttrs = Array.from(newDoc.documentElement.attributes); | ||
htmlAttrs.forEach(function(attr) { | ||
document.documentElement.setAttribute(attr.name, attr.value); | ||
}); | ||
} | ||
|
||
function shouldSkip(testcase) { | ||
if (testcase.html.substr(0, 15) !== '<!DOCTYPE html>') { | ||
return true; // Can't test SVG / MathML | ||
} | ||
return false; | ||
} | ||
|
||
function assertResultsCorrect(testcase, result) { | ||
if (testcase.expected !== 'failed') { | ||
return assert.lengthOf(result.violations, 0); | ||
} | ||
var issues = result.violations[0] || result.incomplete[0]; | ||
if (!issues) { | ||
console.log(testcase.html); | ||
} | ||
assert.isDefined(issues); | ||
assert.isAtLeast(issues.nodes.length, 1); | ||
} | ||
})(); |
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,5 @@ | ||
{ | ||
"id": "0ssw9k", | ||
"title": "Scrollable element is keyboard accessible", | ||
"axeRules": ["scrollable-region-focusable"] | ||
} |
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,5 @@ | ||
{ | ||
"id": "7d6734", | ||
"title": "svg element with explicit role has non-empty accessible name", | ||
"axeRules": ["svg-img-alt"] | ||
} |
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,5 @@ | ||
{ | ||
"id": "a25f45", | ||
"title": "headers attribute specified on a cell refers to cells in the same table element", | ||
"axeRules": ["td-headers-attr"] | ||
} |
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