Skip to content

Commit

Permalink
[Test] parsers.all augments suggestion code output
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
duncanbeevers committed Dec 11, 2021
1 parent e3d3525 commit f7943d5
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions tests/helpers/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,52 @@ const parsers = {
testObject.parserOptions ? `parserOptions: ${JSON.stringify(testObject.parserOptions)}` : [],
testObject.options ? `options: ${JSON.stringify(testObject.options)}` : []
);

const extraComment = `\n// ${extras.join(', ')}`;

// Augment expected fix code output with extraComment
const nextCode = { code: testObject.code + extraComment };
const nextOutput = testObject.output && { output: testObject.output + extraComment };

// Augment expected suggestion outputs with extraComment
// `errors` may be a number (expected number of errors) or an array of
// error objects.
const nextErrors = testObject.errors
&& typeof testObject.errors !== 'number'
&& {
errors: testObject.errors.map(
(errorObject) => {
const nextSuggestions = errorObject.suggestions && {
suggestions: errorObject.suggestions.map(
(suggestion) => {
const nextSuggestion = Object.assign(
{},
suggestion,
{ output: suggestion.output + extraComment }
);

return nextSuggestion;
}
),
};

const nextErrorObject = Object.assign(
{},
errorObject,
nextSuggestions
);

return nextErrorObject;
}
),
};

return Object.assign(
{},
testObject,
{ code: testObject.code + extraComment },
testObject.output && { output: testObject.output + extraComment }
nextCode,
nextOutput,
nextErrors
);
}

Expand Down

0 comments on commit f7943d5

Please sign in to comment.