From f7943d5f77d47dba913e5de01242d4fbae3e2af1 Mon Sep 17 00:00:00 2001 From: Duncan Beevers Date: Fri, 10 Dec 2021 21:01:32 -0800 Subject: [PATCH] [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. --- tests/helpers/parsers.js | 44 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/tests/helpers/parsers.js b/tests/helpers/parsers.js index 038705ba49..971844d8ec 100644 --- a/tests/helpers/parsers.js +++ b/tests/helpers/parsers.js @@ -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 ); }