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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test] parsers.all augments suggestion code output #3154

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 42 additions & 2 deletions tests/helpers/parsers.js
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