Skip to content

Commit cebf827

Browse files
committed
Update raw reporter
1 parent 71a1323 commit cebf827

File tree

4 files changed

+55
-20
lines changed

4 files changed

+55
-20
lines changed

lib/core/reporters/raw.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { nodeSerializer } from '../utils';
2+
13
const rawReporter = (results, options, callback) => {
24
if (typeof options === 'function') {
35
callback = options;
@@ -13,16 +15,9 @@ const rawReporter = (results, options, callback) => {
1315
const transformedResult = { ...result };
1416
const types = ['passes', 'violations', 'incomplete', 'inapplicable'];
1517
for (const type of types) {
16-
// Some tests don't include all of the types, so we have to guard against that here.
17-
// TODO: ensure tests always use "proper" results to avoid having these hacks in production code paths.
18-
if (transformedResult[type] && Array.isArray(transformedResult[type])) {
19-
transformedResult[type] = transformedResult[type].map(
20-
({ node, ...typeResult }) => {
21-
node = typeof node?.toJSON === 'function' ? node.toJSON() : node;
22-
return { node, ...typeResult };
23-
}
24-
);
25-
}
18+
transformedResult[type] = nodeSerializer.mapRawNodeResults(
19+
transformedResult[type]
20+
);
2621
}
2722

2823
return transformedResult;

lib/core/utils/merge-results.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import findBy from './find-by';
77
* @private
88
* @param {Array} resultSet `nodes` array on a `RuleResult`
99
* @param {Object} options Propagated from axe.run/etc
10-
* @param {Object} frameSpec The spec describing the owning frame (see DqElement.toJSON())
10+
* @param {Object} frameSpec The spec describing the owning frame (see nodeSerializer.toSpec)
1111
*/
1212
function pushFrame(resultSet, options, frameSpec) {
1313
resultSet.forEach(res => {
@@ -69,7 +69,7 @@ function normalizeResult(result) {
6969
* Merges one or more RuleResults (possibly from different frames) into one RuleResult
7070
* @private
7171
* @param {Array} frameResults Array of objects including the RuleResults as `results` and
72-
* owning frame as either an Element `frameElement` or a spec `frameSpec` (see DqElement.toJSON)
72+
* owning frame as either an Element `frameElement` or a spec `frameSpec` (see nodeSerializer.toSpec)
7373
* @param {Object} options Propagated from axe.run/etc
7474
* @return {Array} The merged RuleResults; should only have one result per rule
7575
*/

test/core/reporters/raw-env.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ describe('reporters - raw-env', function () {
2626
any: [
2727
{
2828
result: true,
29-
data: 'minkey'
29+
data: 'minkey',
30+
relatedNodes: []
3031
}
3132
],
3233
all: [],
@@ -50,7 +51,8 @@ describe('reporters - raw-env', function () {
5051
{
5152
result: false,
5253
data: 'pillock',
53-
impact: 'cats'
54+
impact: 'cats',
55+
relatedNodes: []
5456
}
5557
],
5658
any: [],
@@ -75,7 +77,8 @@ describe('reporters - raw-env', function () {
7577
{
7678
data: 'foon',
7779
impact: 'monkeys',
78-
result: true
80+
result: true,
81+
relatedNodes: []
7982
}
8083
],
8184
any: [],
@@ -93,10 +96,13 @@ describe('reporters - raw-env', function () {
9396
passes: [
9497
{
9598
result: 'passed',
99+
any: [],
100+
all: [],
96101
none: [
97102
{
98103
data: 'clueso',
99-
result: true
104+
result: true,
105+
relatedNodes: []
100106
}
101107
],
102108
node: createDqElement()
@@ -149,4 +155,18 @@ describe('reporters - raw-env', function () {
149155
}
150156
);
151157
});
158+
159+
it('uses nodeSerializer', done => {
160+
var rawReporter = axe.getReporter('rawEnv');
161+
var spy = sinon.spy(axe.utils.nodeSerializer, 'mapRawNodeResults');
162+
rawReporter(
163+
runResults,
164+
{},
165+
function () {
166+
assert.isTrue(spy.called);
167+
done();
168+
},
169+
done
170+
);
171+
});
152172
});

test/core/reporters/raw.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ describe('reporters - raw', function () {
2626
any: [
2727
{
2828
result: true,
29-
data: 'minkey'
29+
data: 'minkey',
30+
relatedNodes: []
3031
}
3132
],
3233
all: [],
@@ -50,7 +51,8 @@ describe('reporters - raw', function () {
5051
{
5152
result: false,
5253
data: 'pillock',
53-
impact: 'cats'
54+
impact: 'cats',
55+
relatedNodes: []
5456
}
5557
],
5658
any: [],
@@ -75,7 +77,8 @@ describe('reporters - raw', function () {
7577
{
7678
data: 'foon',
7779
impact: 'monkeys',
78-
result: true
80+
result: true,
81+
relatedNodes: []
7982
}
8083
],
8184
any: [],
@@ -93,10 +96,13 @@ describe('reporters - raw', function () {
9396
passes: [
9497
{
9598
result: 'passed',
99+
any: [],
100+
all: [],
96101
none: [
97102
{
98103
data: 'clueso',
99-
result: true
104+
result: true,
105+
relatedNodes: []
100106
}
101107
],
102108
node: createDqElement()
@@ -138,4 +144,18 @@ describe('reporters - raw', function () {
138144
});
139145
});
140146
});
147+
148+
it('uses nodeSerializer', done => {
149+
var rawReporter = axe.getReporter('raw');
150+
var spy = sinon.spy(axe.utils.nodeSerializer, 'mapRawNodeResults');
151+
rawReporter(
152+
runResults,
153+
{},
154+
function () {
155+
assert.isTrue(spy.called);
156+
done();
157+
},
158+
done
159+
);
160+
});
141161
});

0 commit comments

Comments
 (0)