This repository has been archived by the owner on Mar 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Added pa11y, set up testing for twig, scss reloading #95
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dab4e5d
Added pa11y, set up testing for twig, scss reloading
a56f034
separated out task, included in both css and twig
7ad782a
removing underscore files, adding try/catch
7b57aed
added other options for config
79a9c49
notes for developers to disable notices, warnings
314c245
switched to yaml to get allthecomponents
686a1e3
cleanup
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,83 @@ | ||
const fs = require('fs'); | ||
const pa11y = require('pa11y'); | ||
// eslint-disable-next-line | ||
const pa11yCli = require('pa11y-reporter-cli'); | ||
|
||
// function pa11yRun(pa11yUrl, config) { | ||
// | ||
// } | ||
|
||
async function pa11yRun(pa11yUrl, config) { | ||
try { | ||
await pa11y(pa11yUrl, { | ||
includeNotices: config.pa11y.includeNotices, | ||
includeWarnings: config.pa11y.includeWarnings, | ||
ignore: config.pa11y.ignore, | ||
hideElements: config.pa11y.hideElements, | ||
rootElement: config.pa11y.rootElement, | ||
rules: config.pa11y.rules, | ||
standard: config.pa11y.standard, | ||
wait: config.pa11y.wait, | ||
actions: config.pa11y.actions, | ||
}).then((results) => { | ||
if (results.issues === undefined || results.issues.length < 1) { | ||
console.log('[pa11y] No accessibility issues found!'); | ||
} else { | ||
console.log(pa11yCli.results(results)); | ||
if (config.pa11y.includeNotices === true) { | ||
console.log('Note: pa11y notices are enabled by default. To disable notices, edit local.gulp-config.js and set "includeNotices" to false.'); | ||
} | ||
if (config.pa11y.includeWarnings === true) { | ||
console.log('Note: pa11y warnings are enabled by default. To disable warnings, edit local.gulp-config.js and set "includeWarnings" to false.'); | ||
} | ||
if (config.pa11y.includeNotices === true || config.pa11y.includeWarnings === true) { | ||
console.log('See https://github.com/fourkitchens/emulsify/wiki/Gulp-Config for details.'); | ||
} | ||
} | ||
}); | ||
// Do something with the results | ||
} catch (error) { | ||
// Handle the error | ||
console.log(error); | ||
} | ||
} | ||
|
||
/** | ||
* Accessibility Testing | ||
*/ | ||
|
||
// Accessibility testing via pa11y. | ||
function pa11yTest(path, browserSync, config) { | ||
// Get local url. | ||
const localUrl = browserSync.getOption('urls').get('local'); | ||
const filePath = path; | ||
// Get remaining path after ../_patterns/. | ||
const pLPath = filePath.split('_patterns/').pop(); | ||
// Change remaining path string to array. | ||
const fileArray = pLPath.split('/'); | ||
// Remove filename (just want directory). | ||
fileArray.splice(-1, 1); | ||
|
||
// CSS returns a couple of paths and causes duplication. | ||
if (filePath.split('/').includes('pattern-lab')) { | ||
const fileDir = `${filePath.split('_patterns/')[0]}_patterns/${fileArray.join('/')}`; | ||
|
||
fs.readdir(fileDir, (err, items) => { | ||
items.forEach((item) => { | ||
// Select components based on YAML files. | ||
if (item.split('.').pop() === 'yml') { | ||
// Change array to string separated by dash. | ||
const twigFilePath = `${fileDir}/${item}`; | ||
const twigFilePlPath = twigFilePath.split('_patterns/').pop(); | ||
const filetoArray = twigFilePlPath.split('/'); | ||
const arraytoPath = filetoArray.join('-'); | ||
const arraytoPathTweak = arraytoPath.replace('~', '-').slice(0, -4); | ||
const pa11yPath = `${localUrl}patterns/${arraytoPathTweak}/${arraytoPathTweak}.html`; | ||
pa11yRun(pa11yPath, config); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
module.exports.pa11yTest = pa11yTest; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this commented out code be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, done. Thanks!