fix(reporter): Run inside isolated contexts#3129
Conversation
lib/core/reporters/no-passes.js
Outdated
| callback = options; | ||
| options = {}; | ||
| } | ||
| const environmentData = options.environmentData; |
There was a problem hiding this comment.
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.
... 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.
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.
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.
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
| }); | ||
|
|
||
| describe('environmentData', function () { | ||
| it('is include environment data for the initiator', function (done) { |
There was a problem hiding this comment.
| it('is include environment data for the initiator', function (done) { | |
| it('includes environment data for the initiator', function (done) { |
| axe.getReporter('na')(runResults, {}, function(results) { | ||
| assert.isNotNull(results.url); | ||
| assert.isNotNull(results.timestamp); | ||
| assert.isNotNull(results.testEnvironement); |
| }); | ||
| it('should add the rule id to the rule result', function() { | ||
| axe.getReporter('na')(runResults, {}, function(results) { | ||
| axe.getReporter('no-passes')(runResults, {}, function(results) { |
| parserOptions: { | ||
| sourceType: 'module' | ||
| }, | ||
| env: {}, |
There was a problem hiding this comment.
To avoid the exclusion above, just do:
| env: {}, | |
| env: { | |
| browser: false, | |
| etc: ... | |
| }, |
stephenmathieson
left a comment
There was a problem hiding this comment.
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.