-
Notifications
You must be signed in to change notification settings - Fork 791
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(reporter): Run inside isolated contexts (#3129)
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>
- Loading branch information
1 parent
a1f637f
commit 98066f8
Showing
23 changed files
with
282 additions
and
134 deletions.
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
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
This file was deleted.
Oops, something went wrong.
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
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,17 +1,16 @@ | ||
import { getEnvironmentData } from './helpers'; | ||
import { getEnvironmentData } from '../utils'; | ||
import rawReporter from './raw'; | ||
|
||
const rawEnvReporter = (results, options, callback) => { | ||
if (typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
function rawCallback(raw) { | ||
const env = getEnvironmentData(); | ||
const { environmentData, ...toolOptions } = options; | ||
rawReporter(results, toolOptions, (raw) => { | ||
const env = getEnvironmentData(environmentData); | ||
callback({ raw, env }); | ||
} | ||
|
||
rawReporter(results, options, rawCallback); | ||
}); | ||
}; | ||
|
||
export default rawEnvReporter; |
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,47 @@ | ||
/** | ||
* Add information about the environment axe was run in. | ||
* @return {EnvironmentData} | ||
*/ | ||
export default function getEnvironmentData(metadata = null, win = window) { | ||
if (metadata && typeof metadata === 'object') { | ||
return metadata; | ||
} else if (typeof win !== 'object') { | ||
return {} | ||
} | ||
|
||
return { | ||
testEngine: { | ||
name: 'axe-core', | ||
version: axe.version | ||
}, | ||
testRunner: { | ||
name: axe._audit.brand | ||
}, | ||
testEnvironment: getTestEnvironment(win), | ||
timestamp: new Date().toISOString(), | ||
url: win.location?.href | ||
}; | ||
} | ||
|
||
function getTestEnvironment(win) { | ||
if (!win.navigator || typeof win.navigator !== 'object') { | ||
return {} | ||
} | ||
const { navigator, innerHeight, innerWidth } = win; | ||
const { angle, type } = getOrientation(win) || {} | ||
return { | ||
userAgent: navigator.userAgent, | ||
windowWidth: innerWidth, | ||
windowHeight: innerHeight, | ||
orientationAngle: angle, | ||
orientationType: type | ||
} | ||
} | ||
|
||
function getOrientation({ screen }) { | ||
return ( | ||
screen.orientation || | ||
screen.msOrientation || | ||
screen.mozOrientation | ||
); | ||
} |
Oops, something went wrong.