Skip to content

Instantly share code, notes, and snippets.

@aeaston
Created April 20, 2022 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aeaston/b1412e511592ec86a5fbc8980f4c2c1a to your computer and use it in GitHub Desktop.
Save aeaston/b1412e511592ec86a5fbc8980f4c2c1a to your computer and use it in GitHub Desktop.
e2e retry blog post - merge JUnit test results script
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