Skip to content

Commit

Permalink
fix: Avoid "screen is not defined" error [#1404] (#1415)
Browse files Browse the repository at this point in the history
* fix: Avoid "screen is not defined" error (#1404)

* add comments for temp solution
  • Loading branch information
WilcoFiers authored and stephenmathieson committed Mar 7, 2019
1 parent 58acd42 commit c9653a5
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 9 deletions.
25 changes: 16 additions & 9 deletions lib/core/reporters/helpers/get-environment-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@
* Add information about the environment axe was run in.
* @return {Object}
*/
helpers.getEnvironmentData = function getEnvironmentData() {
'use strict';
var orientation = window.screen
? screen.msOrientation ||
(screen.orientation || screen.mozOrientation || {})
: {};
helpers.getEnvironmentData = function getEnvironmentData(win = window) {
// TODO: remove parameter once we are testing axe-core in jsdom and other
// supported environments
const {
screen = {},
navigator = {},
location = {},
innerHeight,
innerWidth
} = win;

const orientation =
screen.msOrientation || screen.orientation || screen.mozOrientation || {};

return {
testEngine: {
Expand All @@ -21,12 +28,12 @@ helpers.getEnvironmentData = function getEnvironmentData() {
},
testEnvironment: {
userAgent: navigator.userAgent,
windowWidth: window.innerWidth,
windowHeight: window.innerHeight,
windowWidth: innerWidth,
windowHeight: innerHeight,
orientationAngle: orientation.angle,
orientationType: orientation.type
},
timestamp: new Date().toISOString(),
url: window.location.href
url: location.href
};
};
50 changes: 50 additions & 0 deletions test/core/reporters/helpers/get-environment-data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
describe('helpers.getEnvironmentData', function() {
'use strict';
var __audit;
before(function() {
__audit = axe._audit;
axe._audit = { brand: 'Deque' };
});

after(function() {
axe._audit = __audit;
});

it('should return a `testEngine` property', function() {
var data = helpers.getEnvironmentData();
Expand Down Expand Up @@ -33,4 +42,45 @@ describe('helpers.getEnvironmentData', function() {
var data = helpers.getEnvironmentData();
assert.isDefined(data.url);
});

// TODO: remove or update test once we are testing axe-core in jsdom and
// other supported environments as what this is testing should be done in
// those environment tests
it('gets data from the `win` parameter when passed', function() {
var data = helpers.getEnvironmentData({
screen: {
orientation: {
type: 'fictional',
angle: 'slanted'
}
},
navigator: {
userAgent: 'foo'
},
location: {
href: 'foo://'
},
innerWidth: 321,
innerHeight: 123
});

delete data.timestamp;
assert.deepEqual(data, {
testEngine: {
name: 'axe-core',
version: axe.version
},
testRunner: {
name: axe._audit.brand
},
testEnvironment: {
userAgent: 'foo',
windowWidth: 321,
windowHeight: 123,
orientationAngle: 'slanted',
orientationType: 'fictional'
},
url: 'foo://'
});
});
});

0 comments on commit c9653a5

Please sign in to comment.