Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(reporter): Run inside isolated contexts #3129

Merged
merged 3 commits into from
Aug 23, 2021
Merged

Conversation

WilcoFiers
Copy link
Contributor

@WilcoFiers WilcoFiers commented Aug 20, 2021

This PR sets the axe reporters up so they can run without access to the top-level browsing context. This is needed so that axe.finishRun() can be called outside the context of a web page.

  • Write the code
  • Write the tests
  • Update types
  • Update documentation

.eslintrc.js Show resolved Hide resolved

const noPassesReporter = (results, options, callback) => {
if (typeof options === 'function') {
callback = options;
options = {};
}
const environmentData = options.environmentData;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than delete on options we should just destructor it

const { environmentData, ...toolOptions } = options;

var out = processAggregate(results, toolOptions);

callback({
  ...getEnvironmentData(environmentData),
  toolOptions,
  violations: out.violations
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... yeah that feels like a thing I should have thought of. Good one.

},
testEnvironment: getTestEnvironment(win),
timestamp: new Date().toISOString(),
url: win?.location?.href
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already know win is an object so no need to optionally chain it

Suggested change
url: win?.location?.href
url: win.location?.href

}

function getTestEnvironment(win) {
if (typeof window !== 'object' || typeof window.navigator !== 'object') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already know win is an object from the top-level call (also need to use win instead of window)

Suggested change
if (typeof window !== 'object' || typeof window.navigator !== 'object') {
if (typeof win.navigator !== 'object') {

const { navigator, innerHeight, innerWidth } = win;
const orientation = getOrientation(win);
return {
userAgent: navigator?.userAgent,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already know win.navigator is an object so no need to optionally chain it

Suggested change
userAgent: navigator?.userAgent,
userAgent: navigator.userAgent,

@@ -129,6 +129,30 @@ describe('axe.runPartial', function() {
});
});

describe('environmentData', function () {
it('is include environment data for the initiator', function (done) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('is include environment data for the initiator', function (done) {
it('includes environment data for the initiator', function (done) {

@@ -204,15 +204,27 @@ describe('reporters - na', function() {
});
it('should add environment data', function() {
axe.getReporter('na')(runResults, {}, function(results) {
assert.isNotNull(results.url);
assert.isNotNull(results.timestamp);
assert.isNotNull(results.testEnvironement);
Copy link
Contributor

@straker straker Aug 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch on the typo!

@@ -107,22 +107,22 @@ describe('reporters - no-passes', function() {
});
});
it('should add the rule id to the rule result', function() {
axe.getReporter('na')(runResults, {}, function(results) {
axe.getReporter('no-passes')(runResults, {}, function(results) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another nice catch

@WilcoFiers WilcoFiers requested a review from straker August 23, 2021 10:28
@WilcoFiers WilcoFiers marked this pull request as ready for review August 23, 2021 10:28
@WilcoFiers WilcoFiers requested a review from a team as a code owner August 23, 2021 10:29
parserOptions: {
sourceType: 'module'
},
env: {},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid the exclusion above, just do:

Suggested change
env: {},
env: {
browser: false,
etc: ...
},

.eslintrc.js Show resolved Hide resolved
Copy link
Member

@stephenmathieson stephenmathieson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should properly use overrides rather than excludedFiles.

.eslintrc.js Show resolved Hide resolved
@WilcoFiers
Copy link
Contributor Author

@stephenmathieson Yes, but one override doesn't cascade to another.

@stephenmathieson stephenmathieson dismissed their stale review August 23, 2021 21:02

Not worth requesting changes for

.eslintrc.js Show resolved Hide resolved
Co-authored-by: Steven Lambert <2433219+straker@users.noreply.github.com>
@stephenmathieson stephenmathieson merged commit afe6675 into develop Aug 23, 2021
@stephenmathieson stephenmathieson deleted the runPartial-meta branch August 23, 2021 21:33
straker added a commit that referenced this pull request Aug 24, 2021
This PR sets the axe reporters up so they can run without access to the top-level browsing context. This is needed so that `axe.finishRun()` can be called outside the context of a web page.

Co-authored-by: Steven Lambert <2433219+straker@users.noreply.github.com>
Co-authored-by: Stephen Mathieson <me@stephenmathieson.com>
Co-authored-by: Steven Lambert <2433219+straker@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants