Skip to content

Commit

Permalink
feat(reporter): adds the rawEnv reporter which wraps raw and env data
Browse files Browse the repository at this point in the history
  • Loading branch information
AutoSponge committed May 10, 2019
1 parent 727323c commit d251e0b
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/core/reporters/raw-env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*global helpers */
axe.addReporter('rawEnv', function(results, options, callback) {
if (typeof options === 'function') {
callback = options;
options = {};
}
function rawCallback(raw) {
const env = helpers.getEnvironmentData();
callback({ raw, env });
}
axe.getReporter('raw')(results, options, rawCallback);
});
142 changes: 142 additions & 0 deletions test/core/reporters/raw-env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*global helpers */
describe('reporters - raw-env', function() {
'use strict';

var fixture = document.getElementById('fixture');

function createDqElement() {
var node = document.createElement('div');
fixture.appendChild(node);
return new axe.utils.DqElement(node);
}

var mockResults;
var orig;

before(function() {
mockResults = [
{
id: 'gimmeLabel',
helpUrl: 'things',
description: 'something nifty',
tags: ['tag1'],
result: 'passed',
violations: [],
passes: [
{
result: 'passed',
any: [
{
result: true,
data: 'minkey'
}
],
all: [],
none: [],
node: createDqElement()
}
]
},
{
id: 'idkStuff',
description: 'something more nifty',
pageLevel: true,
result: 'failed',
impact: 'cats',
tags: ['tag2'],
passes: [],
violations: [
{
result: 'failed',
all: [
{
result: false,
data: 'pillock',
impact: 'cats'
}
],
any: [],
none: [],
node: createDqElement(),
impact: 'cats'
}
]
},
{
id: 'bypass',
description: 'something even more nifty',
tags: ['tag3'],
impact: 'monkeys',
result: 'failed',
passes: [],
violations: [
{
result: 'failed',
impact: 'monkeys',
none: [
{
data: 'foon',
impact: 'monkeys',
result: true
}
],
any: [],
all: [],
node: createDqElement()
}
]
},
{
id: 'blinky',
description: 'something awesome',
tags: ['tag4'],
violations: [],
result: 'passed',
passes: [
{
result: 'passed',
none: [
{
data: 'clueso',
result: true
}
],
node: createDqElement()
}
]
}
];

axe.testUtils.fixtureSetup();

axe._load({});
orig = axe._runRules;
axe._runRules = function(_, __, cb) {
cb(mockResults, function noop() {});
};
});

after(function() {
axe._runRules = orig;
fixture.innerHTML = '';
});

it('should pass raw results and env object', function(done) {
var rawResults;
const env = helpers.getEnvironmentData();
axe.run({ reporter: 'raw' }, function(err, results) {
if (err) {
return done(err);
}
rawResults = results;
});
axe.run({ reporter: 'rawEnv' }, function(err, results) {
if (err) {
return done(err);
}
assert.deepEqual(results.raw, rawResults);
assert.deepEqual(results.env, env);
done();
});
});
});

0 comments on commit d251e0b

Please sign in to comment.