e2e retry blog post - merge JUnit test results script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function runTestsAndRetry(jestConfig, retriesRemaining, mergedResults) { | |
const { results } = await runCLI(jestConfig, ['e2e/test']); | |
mergedResults = mergeTestResults(mergedResults, results); | |
// configure jest-junit for our test run | |
const junit = new JestJunit( | |
{}, | |
{ | |
outputDirectory: './test-results/', | |
outputName: 'jest-puppeteer.xml', | |
} | |
); | |
junit.onRunComplete(null, mergedResults); | |
// ... | |
return await runTestsAndRetry(jestConfig, retriesRemaining, mergedResults); | |
} | |
function mergeTestResults(oldResults, newResults) { | |
// if it's the first run, we can just return the results | |
if (!oldResults.testResults) { | |
return newResults; | |
} | |
// make a copy of the old results so we don't mutate the input | |
const mergedResults = JSON.parse(JSON.stringify(oldResults)); | |
// for each new result, input it in the old results alongside | |
// the previous result for that test | |
newResults.testResults.forEach((newResult) => { | |
const oldResultIdx = mergedResults.testResults.findIndex( | |
(result) => result.testFilePath === newResult.testFilePath | |
); | |
mergedResults.testResults.splice(oldResultIdx, 0, newResult); | |
}); | |
return mergedResults; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment