Skip to content

Commit f7943d5

Browse files
committed
[Test] parsers.all augments suggestion code output
parsers.all generates an extraComment which is appended to test case examples and their expected output. Eslint's suggestions API also allows recommended code changes, and RuleTester compares expected changes against generated changes. However, parsers.all didn't augment these expected outputs with the extraComment.
1 parent e3d3525 commit f7943d5

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

tests/helpers/parsers.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,52 @@ const parsers = {
6666
testObject.parserOptions ? `parserOptions: ${JSON.stringify(testObject.parserOptions)}` : [],
6767
testObject.options ? `options: ${JSON.stringify(testObject.options)}` : []
6868
);
69+
6970
const extraComment = `\n// ${extras.join(', ')}`;
71+
72+
// Augment expected fix code output with extraComment
73+
const nextCode = { code: testObject.code + extraComment };
74+
const nextOutput = testObject.output && { output: testObject.output + extraComment };
75+
76+
// Augment expected suggestion outputs with extraComment
77+
// `errors` may be a number (expected number of errors) or an array of
78+
// error objects.
79+
const nextErrors = testObject.errors
80+
&& typeof testObject.errors !== 'number'
81+
&& {
82+
errors: testObject.errors.map(
83+
(errorObject) => {
84+
const nextSuggestions = errorObject.suggestions && {
85+
suggestions: errorObject.suggestions.map(
86+
(suggestion) => {
87+
const nextSuggestion = Object.assign(
88+
{},
89+
suggestion,
90+
{ output: suggestion.output + extraComment }
91+
);
92+
93+
return nextSuggestion;
94+
}
95+
),
96+
};
97+
98+
const nextErrorObject = Object.assign(
99+
{},
100+
errorObject,
101+
nextSuggestions
102+
);
103+
104+
return nextErrorObject;
105+
}
106+
),
107+
};
108+
70109
return Object.assign(
71110
{},
72111
testObject,
73-
{ code: testObject.code + extraComment },
74-
testObject.output && { output: testObject.output + extraComment }
112+
nextCode,
113+
nextOutput,
114+
nextErrors
75115
);
76116
}
77117

0 commit comments

Comments
 (0)