-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(reporter): adds the rawEnv reporter which wraps raw and env data
- Loading branch information
1 parent
727323c
commit 1170ecf
Showing
2 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); |