From e795f7db20da8a4aa4a3eb4b413611bd83890145 Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Mon, 11 Feb 2019 04:46:36 -0700 Subject: [PATCH] feat: Add environment details to results (#1353) * 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 --- axe.d.ts | 18 ++++++++++ .../reporters/helpers/get-environment-data.js | 32 +++++++++++++++++ .../reporters/helpers/process-aggregate.js | 3 -- lib/core/reporters/na.js | 6 ++-- lib/core/reporters/no-passes.js | 6 ++-- lib/core/reporters/v1.js | 6 ++-- lib/core/reporters/v2.js | 6 ++-- .../reporters/helpers/get-environment-data.js | 36 +++++++++++++++++++ .../reporters/helpers/process-aggregate.js | 10 ------ test/core/reporters/na.js | 13 +++---- test/core/reporters/no-passes.js | 13 +++---- test/core/reporters/v1.js | 17 +++++++++ test/core/reporters/v2.js | 13 +++---- 13 files changed, 136 insertions(+), 43 deletions(-) create mode 100644 lib/core/reporters/helpers/get-environment-data.js create mode 100644 test/core/reporters/helpers/get-environment-data.js diff --git a/axe.d.ts b/axe.d.ts index 285b486b75..3f615c56c7 100644 --- a/axe.d.ts +++ b/axe.d.ts @@ -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; @@ -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[]; diff --git a/lib/core/reporters/helpers/get-environment-data.js b/lib/core/reporters/helpers/get-environment-data.js new file mode 100644 index 0000000000..6284a5cc25 --- /dev/null +++ b/lib/core/reporters/helpers/get-environment-data.js @@ -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 + }; +}; diff --git a/lib/core/reporters/helpers/process-aggregate.js b/lib/core/reporters/helpers/process-aggregate.js index 16cf2db71d..75218c7a0b 100644 --- a/lib/core/reporters/helpers/process-aggregate.js +++ b/lib/core/reporters/helpers/process-aggregate.js @@ -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 diff --git a/lib/core/reporters/na.js b/lib/core/reporters/na.js index 016d86d655..29e8c5ae1e 100644 --- a/lib/core/reporters/na.js +++ b/lib/core/reporters/na.js @@ -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 }); }); diff --git a/lib/core/reporters/no-passes.js b/lib/core/reporters/no-passes.js index b26957c9be..ad94610494 100644 --- a/lib/core/reporters/no-passes.js +++ b/lib/core/reporters/no-passes.js @@ -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 }); }); diff --git a/lib/core/reporters/v1.js b/lib/core/reporters/v1.js index 1a48f6914d..cd2d727ee0 100644 --- a/lib/core/reporters/v1.js +++ b/lib/core/reporters/v1.js @@ -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 }); }); diff --git a/lib/core/reporters/v2.js b/lib/core/reporters/v2.js index 5077051333..50fc198ad3 100644 --- a/lib/core/reporters/v2.js +++ b/lib/core/reporters/v2.js @@ -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 diff --git a/test/core/reporters/helpers/get-environment-data.js b/test/core/reporters/helpers/get-environment-data.js new file mode 100644 index 0000000000..315390c469 --- /dev/null +++ b/test/core/reporters/helpers/get-environment-data.js @@ -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); + }); +}); diff --git a/test/core/reporters/helpers/process-aggregate.js b/test/core/reporters/helpers/process-aggregate.js index 1ff9ca7328..c248acf39e 100644 --- a/test/core/reporters/helpers/process-aggregate.js +++ b/test/core/reporters/helpers/process-aggregate.js @@ -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) { diff --git a/test/core/reporters/na.js b/test/core/reporters/na.js index 1a2146a560..820c288d65 100644 --- a/test/core/reporters/na.js +++ b/test/core/reporters/na.js @@ -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(); }); }); diff --git a/test/core/reporters/no-passes.js b/test/core/reporters/no-passes.js index aa7372a6b5..185d2d708d 100644 --- a/test/core/reporters/no-passes.js +++ b/test/core/reporters/no-passes.js @@ -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(); }); }); diff --git a/test/core/reporters/v1.js b/test/core/reporters/v1.js index 3e78aa4a85..93c9b9836a 100644 --- a/test/core/reporters/v1.js +++ b/test/core/reporters/v1.js @@ -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(); + }); + }); }); diff --git a/test/core/reporters/v2.js b/test/core/reporters/v2.js index 5ff4720ee5..eae0bc0f65 100644 --- a/test/core/reporters/v2.js +++ b/test/core/reporters/v2.js @@ -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(); }); });