-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: added accessibility tests (CMC-1487) (#52)
- Loading branch information
1 parent
1d49742
commit 0a21fa0
Showing
58 changed files
with
11,541 additions
and
23 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,3 @@ | ||
*.min.js | ||
node_modules/* | ||
|
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,25 +1,26 @@ | ||
module.exports = { | ||
"plugins": [ | ||
"codeceptjs" | ||
'plugins': [ | ||
'codeceptjs' | ||
], | ||
"env": { | ||
"browser": true, | ||
"commonjs": true, | ||
"es2020": true, | ||
"codeceptjs/codeceptjs": true | ||
'env': { | ||
'browser': true, | ||
'commonjs': true, | ||
'es2020': true, | ||
'codeceptjs/codeceptjs': true, | ||
'node': true | ||
}, | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"ecmaVersion": 11 | ||
'extends': 'eslint:recommended', | ||
'parserOptions': { | ||
'ecmaVersion': 11 | ||
}, | ||
"rules": { | ||
"quotes": [ | ||
"error", | ||
"single" | ||
'rules': { | ||
'quotes': [ | ||
'error', | ||
'single' | ||
], | ||
"semi": [ | ||
"error", | ||
"always" | ||
'semi': [ | ||
'error', | ||
'always' | ||
] | ||
} | ||
}; |
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
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
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
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
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
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
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
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,87 @@ | ||
const HTMLCS = require('html_codesniffer'); | ||
const fs = require('fs'); | ||
const testConfig = require('../../config.js'); | ||
|
||
const result = { | ||
PASSED: 'passed', | ||
FAILED: 'failed', | ||
}; | ||
|
||
const resultObj = { | ||
appName: 'Civil', | ||
passCount: 0, | ||
failCount: 0, | ||
tests: [], | ||
}; | ||
|
||
async function runAccessibility(url, page) { | ||
//Add HMTL code sniffer script | ||
await page.addScriptTag({ | ||
path: 'node_modules/html_codesniffer/build/HTMLCS.js', | ||
}); | ||
|
||
const screenshotPath = testConfig.TestOutputDir + '/assets'; | ||
const screenshotName = Date.now() + '.png'; | ||
const screenshotReportRef = 'assets/' + screenshotName; | ||
|
||
const accessibilityErrorsOnThePage = await page.evaluate(() => { | ||
const processIssue = function(issue) { | ||
return { | ||
code: issue.code, | ||
message: issue.msg, | ||
type: 'error', | ||
element: issue.element, | ||
runner: 'htmlcs', | ||
}; | ||
}; | ||
|
||
const STANDARD = 'WCAG2AA'; | ||
let messages; | ||
|
||
HTMLCS.process(STANDARD, window.document, function () { | ||
messages = HTMLCS | ||
.getMessages() | ||
.filter(function (m) { | ||
return m.type === HTMLCS.ERROR; | ||
}) | ||
.map(processIssue); | ||
}); | ||
return messages; | ||
}); | ||
|
||
try { | ||
await page.screenshot({path: screenshotPath + '/' + screenshotName, fullPage: true}); | ||
} catch (err) { | ||
fs.mkdirSync(screenshotPath, {recursive: true}); | ||
await page.screenshot({path: screenshotPath + '/' + screenshotName, fullPage: true}); | ||
} | ||
|
||
updateResultObject(url, await page.title(), screenshotReportRef, accessibilityErrorsOnThePage); | ||
} | ||
|
||
function updateResultObject(url, pageTitle, screenshotReportRef, accessibilityErrorsOnThePage) { | ||
const isPageAccessible = accessibilityErrorsOnThePage.length === 0 ? result.PASSED : result.FAILED; | ||
|
||
const urlArr = url.split('/'); | ||
|
||
if (isPageAccessible === result.PASSED) { | ||
resultObj.passCount += 1; | ||
} else { | ||
resultObj.failCount += 1; | ||
} | ||
|
||
resultObj.tests.push({ | ||
name: urlArr[urlArr.length -2] + '/' + urlArr[urlArr.length -1], | ||
pageUrl: url, | ||
documentTitle: pageTitle, | ||
status: isPageAccessible, | ||
screenshot: screenshotReportRef, | ||
a11yIssues: accessibilityErrorsOnThePage, | ||
}); | ||
} | ||
|
||
function getAccessibilityTestResult() { | ||
return resultObj; | ||
} | ||
|
||
module.exports = {runAccessibility, getAccessibilityTestResult}; |
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,15 @@ | ||
const {getAccessibilityTestResult} = require('./accessibility/runner'); | ||
const {generateAccessibilityReport} = require('../reporters/accessibility-reporter/customReporter'); | ||
const testConfig = require('../config.js'); | ||
|
||
class Generate_report_helper extends Helper { | ||
|
||
_finishTest() { | ||
if (!testConfig.TestForAccessibility) { | ||
return; | ||
} | ||
generateAccessibilityReport(getAccessibilityTestResult()); | ||
} | ||
|
||
} | ||
module.exports = Generate_report_helper; |
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
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
Oops, something went wrong.