-
Notifications
You must be signed in to change notification settings - Fork 792
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
Conversation
lib/core/reporters/no-passes.js
Outdated
|
||
const noPassesReporter = (results, options, callback) => { | ||
if (typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
const environmentData = options.environmentData; |
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.
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
});
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.
... yeah that feels like a thing I should have thought of. Good one.
}, | ||
testEnvironment: getTestEnvironment(win), | ||
timestamp: new Date().toISOString(), | ||
url: win?.location?.href |
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.
We already know win
is an object so no need to optionally chain it
url: win?.location?.href | |
url: win.location?.href |
} | ||
|
||
function getTestEnvironment(win) { | ||
if (typeof window !== 'object' || typeof window.navigator !== 'object') { |
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.
Already know win
is an object from the top-level call (also need to use win
instead of window
)
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, |
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.
Already know win.navigator
is an object so no need to optionally chain it
userAgent: navigator?.userAgent, | |
userAgent: navigator.userAgent, |
test/core/public/run-partial.js
Outdated
@@ -129,6 +129,30 @@ describe('axe.runPartial', function() { | |||
}); | |||
}); | |||
|
|||
describe('environmentData', function () { | |||
it('is include environment data for the initiator', function (done) { |
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.
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); |
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.
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) { |
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.
Another nice catch
parserOptions: { | ||
sourceType: 'module' | ||
}, | ||
env: {}, |
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.
To avoid the exclusion above, just do:
env: {}, | |
env: { | |
browser: false, | |
etc: ... | |
}, |
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 properly use overrides
rather than excludedFiles
.
@stephenmathieson Yes, but one override doesn't cascade to another. |
Not worth requesting changes for
Co-authored-by: Steven Lambert <2433219+straker@users.noreply.github.com>
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>
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.