This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
[terra-functional-testing] Remove axe option from the Terra Service #466
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
45 changes: 17 additions & 28 deletions
45
packages/terra-functional-testing/src/commands/axe/run.js
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,49 +1,38 @@ | ||
/* global browser, axe */ | ||
/* global browser, axe, Terra */ | ||
const injectAxe = require('./inject'); | ||
|
||
/** | ||
* Executes axe on the browser. | ||
* @param {Object} overrides - The axe options. | ||
* @param {Array} overrides.rules - The rule overrides. | ||
* @param {Object} options - The axe options. | ||
* @param {Array} options.rules - The rule overrides. | ||
*/ | ||
const runAxe = (overrides = {}) => { | ||
// Extract the axe options for the Terra service from the global browser object. | ||
const [, options = {}] = browser.options.services.find(([service]) => ( | ||
typeof service === 'function' && service.name === 'TerraService' | ||
)); | ||
|
||
const { axe: axeOptions } = options; | ||
const runAxe = (options = {}) => { | ||
const isAxeUnavailable = browser.execute(() => window.axe === undefined); | ||
|
||
// Inject axe-core onto the page if it has not already been initialized. | ||
if (isAxeUnavailable) { | ||
injectAxe(axeOptions); | ||
} | ||
/** | ||
* Converts the global rule overrides into an array. | ||
* The axe.configure API requires the rules to be an array of objects. The axe.run API requires | ||
* the rules to be an object keyed by the rule ID. | ||
*/ | ||
const globalRuleArray = Object.keys(Terra.axe.rules).map((rule) => ( | ||
{ ...Terra.axe.rules[rule], id: rule } | ||
)); | ||
|
||
/** | ||
* This rule was introduced in axe-core v3.3 and causes failures in many Terra components. | ||
* The solution to address this failure vary by component. It is being disabled until a solution is identified in the future. | ||
* | ||
* Reference: https://github.com/cerner/terra-framework/issues/991 | ||
*/ | ||
const ruleOverrides = { | ||
'scrollable-region-focusable': { enabled: false }, | ||
}; | ||
injectAxe({ rules: globalRuleArray }); | ||
} | ||
|
||
// Merge the global rules and overrides together. | ||
const rules = { | ||
...ruleOverrides, | ||
...axeOptions && axeOptions.rules, | ||
...overrides.rules, | ||
}; | ||
// Merge the global rules and option overrides together. | ||
const rules = { ...Terra.axe.rules, ...options.rules }; | ||
|
||
// eslint-disable-next-line prefer-arrow-callback, func-names | ||
return browser.executeAsync(function (opts, done) { | ||
// eslint-disable-next-line prefer-arrow-callback, func-names | ||
axe.run(document, opts, function (error, result) { | ||
done({ error, result }); | ||
}); | ||
}, { rules, restoreScroll: true, runOnly: ['wcag2a', 'wcag2aa', 'wcag21aa', 'section508'] }); | ||
}, { rules, runOnly: ['wcag2a', 'wcag2aa', 'wcag21aa', 'section508'] }); | ||
}; | ||
|
||
module.exports = runAxe; |
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 |
---|---|---|
|
@@ -8,30 +8,54 @@ const hideInputCaret = require('../commands/hide-input-caret'); | |
|
||
class TerraService { | ||
constructor(options = {}) { | ||
this.formFactor = options.formFactor; | ||
const { formFactor, theme } = options; | ||
|
||
this.formFactor = formFactor; | ||
this.theme = theme || 'terra-default-theme'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In #464 I'm exposing the entire service options object thru There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the TerraService should default the option if it needs a default rather than requiring a theme be set in the wdio.config |
||
} | ||
|
||
/** | ||
* Service hook executed prior to test execution. | ||
* Initializes the Terra Service's custom commands. | ||
*/ | ||
before(capabilities) { | ||
// Add the Jest expect module the use the Jest matchers. | ||
// Set Jest's expect module as the global assertion framework. | ||
global.expect = expect; | ||
global.expect.extend({ toBeAccessible }); | ||
|
||
// Add a Terra global with access to Mocha-Chai test helpers. | ||
global.Terra = { | ||
validates: { accessibility }, | ||
|
||
// viewports provides access Terra's list of test viewports. | ||
// Provides access to Terra's list of supported testing viewports. | ||
viewports: getViewports, | ||
|
||
// describeViewports provides a custom describe block for looping test viewports. | ||
// Provides a custom describe block for looping test viewports. | ||
describeViewports, | ||
|
||
// hideInputCaret hides the blinking input caret that appears in inputs or editable text areas. | ||
// Hides the blinking input caret that appears in inputs or editable text areas. | ||
hideInputCaret, | ||
|
||
axe: { | ||
/** | ||
* Global rule overrides. | ||
* Rules modified here will be applied globally for all tests. | ||
*/ | ||
rules: { | ||
/** | ||
* This rule was introduced in axe-core v3.3 and causes failures in many Terra components. | ||
* The solution to address this failure vary by component. It is being disabled until a solution is identified in the future. | ||
* | ||
* Reference: https://github.com/cerner/terra-framework/issues/991 | ||
*/ | ||
'scrollable-region-focusable': { enabled: false }, | ||
/** | ||
* The lowlight theme adheres to a non-default color contrast ratio and fails the default ratio check. | ||
* The color-contrast ratio check is disabled for lowlight theme testing. | ||
*/ | ||
'color-contrast': { enabled: this.theme !== 'clinical-lowlight-theme' }, | ||
}, | ||
}, | ||
}; | ||
|
||
// IE driver takes longer to be ready for browser interactions. | ||
|
@@ -46,10 +70,10 @@ class TerraService { | |
setViewport(this.formFactor); | ||
} | ||
|
||
afterCommand(commandName, args, result, error) { | ||
afterCommand(commandName, _args, _result, error) { | ||
if ((commandName === 'refresh' || commandName === 'url') && !error) { | ||
try { | ||
// This is only meant as a convenience so failure is not particularly concerning | ||
// This is only meant as a convenience so failure is not particularly concerning. | ||
global.Terra.hideInputCaret('body'); | ||
|
||
if (global.browser.$('[data-terra-dev-site-loading]').isExisting()) { | ||
|
@@ -59,8 +83,7 @@ class TerraService { | |
}); | ||
} | ||
} catch (err) { | ||
// Intentionally blank | ||
// If this fails we don't want to warn because the user can't fix the issue. | ||
// Intentionally blank. If this fails we don't want to warn because the user can't fix the issue. | ||
} | ||
} | ||
} | ||
|
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.
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.