Skip to content

Commit

Permalink
feat: Add environment details to results (#1353)
Browse files Browse the repository at this point in the history
* feat: add version information to results

* feat: add version information to results

* use tabs instead of spaces

* add definitions to typescript

* create helper function for environment data

* add done to tests
  • Loading branch information
straker authored and WilcoFiers committed Feb 11, 2019
1 parent 4b50f7d commit e795f7d
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 43 deletions.
18 changes: 18 additions & 0 deletions axe.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ declare namespace axe {

type ElementContext = Node | string | RunOnlyObject;

interface TestEngine {
name: string;
version: string;
}
interface TestRunner {
name: string;
}
interface TestEnvironment {
userAgent: string;
windowWidth: number;
windowHeight: number;
orientationAngle?: number;
orientationType?: string;
}
interface RunOnly {
type: RunOnlyType;
values?: TagValue[] | string[] | RunOnlyObject;
Expand All @@ -35,6 +49,10 @@ declare namespace axe {
resultTypes?: resultGroups[];
}
interface AxeResults {
toolOptions: RunOptions;
testEngine: TestEngine;
testRunner: TestRunner;
testEnvironment: TestEnvironment;
url: string;
timestamp: string;
passes: Result[];
Expand Down
32 changes: 32 additions & 0 deletions lib/core/reporters/helpers/get-environment-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*global helpers */

/**
* 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 || {})
: {};

return {
testEngine: {
name: 'axe-core',
version: axe.version
},
testRunner: {
name: axe._audit.brand
},
testEnvironment: {
userAgent: navigator.userAgent,
windowWidth: window.innerWidth,
windowHeight: window.innerHeight,
orientationAngle: orientation.angle,
orientationType: orientation.type
},
timestamp: new Date().toISOString(),
url: window.location.href
};
};
3 changes: 0 additions & 3 deletions lib/core/reporters/helpers/process-aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ var resultKeys = axe.constants.resultGroups;
helpers.processAggregate = function(results, options) {
var resultObject = axe.utils.aggregateResult(results);

resultObject.timestamp = new Date().toISOString();
resultObject.url = window.location.href;

resultKeys.forEach(function(key) {
if (options.resultTypes && !options.resultTypes.includes(key)) {
// If the user asks us to, truncate certain finding types to maximum one finding
Expand Down
6 changes: 3 additions & 3 deletions lib/core/reporters/na.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ axe.addReporter('na', function(results, options, callback) {

var out = helpers.processAggregate(results, options);
callback({
...helpers.getEnvironmentData(),
toolOptions: options,
violations: out.violations,
passes: out.passes,
incomplete: out.incomplete,
inapplicable: out.inapplicable,
timestamp: out.timestamp,
url: out.url
inapplicable: out.inapplicable
});
});
6 changes: 3 additions & 3 deletions lib/core/reporters/no-passes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ axe.addReporter('no-passes', function(results, options, callback) {
var out = helpers.processAggregate(results, options);

callback({
violations: out.violations,
timestamp: out.timestamp,
url: out.url
...helpers.getEnvironmentData(),
toolOptions: options,
violations: out.violations
});
});
6 changes: 3 additions & 3 deletions lib/core/reporters/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ axe.addReporter('v1', function(results, options, callback) {
);

callback({
...helpers.getEnvironmentData(),
toolOptions: options,
violations: out.violations,
passes: out.passes,
incomplete: out.incomplete,
inapplicable: out.inapplicable,
timestamp: out.timestamp,
url: out.url
inapplicable: out.inapplicable
});
});
6 changes: 3 additions & 3 deletions lib/core/reporters/v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ axe.addReporter(
}
var out = helpers.processAggregate(results, options);
callback({
...helpers.getEnvironmentData(),
toolOptions: options,
violations: out.violations,
passes: out.passes,
incomplete: out.incomplete,
inapplicable: out.inapplicable,
timestamp: out.timestamp,
url: out.url
inapplicable: out.inapplicable
});
},
true
Expand Down
36 changes: 36 additions & 0 deletions test/core/reporters/helpers/get-environment-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
describe('helpers.getEnvironmentData', function() {
'use strict';

it('should return a `testEngine` property', function() {
var data = helpers.getEnvironmentData();
assert.isObject(data.testEngine);
assert.equal(data.testEngine.name, 'axe-core');
assert.equal(data.testEngine.version, axe.version);
});

it('should return a `testRunner` property', function() {
var data = helpers.getEnvironmentData();
assert.isObject(data.testRunner);
assert.equal(data.testRunner.name, axe._audit.brand);
});

it('should return a `testEnvironment` property', function() {
var data = helpers.getEnvironmentData();
assert.isObject(data.testEnvironment);
assert.ok(data.testEnvironment.userAgent);
assert.ok(data.testEnvironment.windowWidth);
assert.ok(data.testEnvironment.windowHeight);
assert.isNotNull(data.testEnvironment.orientationAngle);
assert.isNotNull(data.testEnvironment.orientationType);
});

it('should return a `timestamp` property`', function() {
var data = helpers.getEnvironmentData();
assert.isDefined(data.timestamp);
});

it('should return a `url` property', function() {
var data = helpers.getEnvironmentData();
assert.isDefined(data.url);
});
});
10 changes: 0 additions & 10 deletions test/core/reporters/helpers/process-aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,6 @@ describe('helpers.processAggregate', function() {
];
});

it('should add a `timestamp` property to the `resultObject`', function() {
var resultObject = helpers.processAggregate(results, {});
assert.isDefined(resultObject.timestamp);
});

it('should add a `url` property to the `resultObject`', function() {
var resultObject = helpers.processAggregate(results, {});
assert.isDefined(resultObject.url);
});

it('should remove the `result` property from each node in each ruleResult', function() {
assert.isDefined(
results.find(function(r) {
Expand Down
13 changes: 7 additions & 6 deletions test/core/reporters/na.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,20 @@ describe('reporters - na', function() {
done();
});
});
it('should include URL', function(done) {
it('should add environment data', function(done) {
axe.run(naOption, function(err, results) {
assert.isNull(err);
assert.equal(results.url, window.location.href);
assert.isNotNull(results.url);
assert.isNotNull(results.timestamp);
assert.isNotNull(results.testEnvironement);
assert.isNotNull(results.testRunner);
done();
});
});
it('should include timestamp', function(done) {
it('should add toolOptions property', function(done) {
axe.run(naOption, function(err, results) {
assert.isNull(err);
var timestamp = new Date(results.timestamp);
assert.instanceOf(timestamp, Date);
assert.closeTo(timestamp.getTime(), Date.now(), 50);
assert.isNotNull(results.toolOptions);
done();
});
});
Expand Down
13 changes: 7 additions & 6 deletions test/core/reporters/no-passes.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,20 @@ describe('reporters - no-passes', function() {
done();
});
});
it('should include URL', function(done) {
it('should add environment data', function(done) {
axe.run(noPassOpt, function(err, results) {
assert.isNull(err);
assert.equal(results.url, window.location.href);
assert.isNotNull(results.url);
assert.isNotNull(results.timestamp);
assert.isNotNull(results.testEnvironement);
assert.isNotNull(results.testRunner);
done();
});
});
it('should include timestamp', function(done) {
it('should add toolOptions property', function(done) {
axe.run(noPassOpt, function(err, results) {
assert.isNull(err);
var timestamp = new Date(results.timestamp);
assert.instanceOf(timestamp, Date);
assert.closeTo(timestamp.getTime(), Date.now(), 50);
assert.isNotNull(results.toolOptions);
done();
});
});
Expand Down
17 changes: 17 additions & 0 deletions test/core/reporters/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,21 @@ describe('reporters - v1', function() {
done();
});
});
it('should add environment data', function(done) {
axe.run(optionsV1, function(err, results) {
assert.isNull(err);
assert.isNotNull(results.url);
assert.isNotNull(results.timestamp);
assert.isNotNull(results.testEnvironement);
assert.isNotNull(results.testRunner);
done();
});
});
it('should add toolOptions property', function(done) {
axe.run(optionsV1, function(err, results) {
assert.isNull(err);
assert.isNotNull(results.toolOptions);
done();
});
});
});
13 changes: 7 additions & 6 deletions test/core/reporters/v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,20 @@ describe('reporters - v2', function() {
done();
});
});
it('should include URL', function(done) {
it('should add environment data', function(done) {
axe.run(optionsV2, function(err, results) {
assert.isNull(err);
assert.equal(results.url, window.location.href);
assert.isNotNull(results.url);
assert.isNotNull(results.timestamp);
assert.isNotNull(results.testEnvironement);
assert.isNotNull(results.testRunner);
done();
});
});
it('should include timestamp', function(done) {
it('should add toolOptions property', function(done) {
axe.run(optionsV2, function(err, results) {
assert.isNull(err);
var timestamp = new Date(results.timestamp);
assert.instanceOf(timestamp, Date);
assert.closeTo(timestamp.getTime(), Date.now(), 50);
assert.isNotNull(results.toolOptions);
done();
});
});
Expand Down

0 comments on commit e795f7d

Please sign in to comment.