Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(reporter): adds the rawEnv reporter which wraps raw and env data #1556

Merged
merged 1 commit into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
var rawResults;
const env = helpers.getEnvironmentData();

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() {});
};
axe.run({ reporter: 'raw' }, function(err, results) {
if (err) {
return {};
}
rawResults = results;
});
});

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

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