e2e retry blog post - initial retry 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
// run_tests_with_retries.js | |
import { runCLI } from 'jest'; | |
import jestConfig from './jest.config'; | |
const NUM_RETRIES = 3; | |
async function runTestsAndRetry(jestConfig, retriesRemaining) { | |
const { results } = await runCLI(jestConfig, ['e2e/test']); | |
// If there were no failures or we're out of retries, return | |
if (!results.numFailedTests && !results.numFailedTestSuites) { | |
return Promise.resolve(); | |
} | |
if (retriesRemaining === 1) { | |
return Promise.reject(new Error('Out of retries. Some tests are still failing.')); | |
} | |
// Compile a list of the test suites that failed and tell Jest to only run those files next time | |
const failedTestPaths = results.testResults | |
.filter((testResult) => testResult.numFailingTests > 0 || testResult.failureMessage) | |
.map((testResult) => testResult.testFilePath); | |
jestConfig.testMatch = failedTestsPaths; | |
// Decrement retries remaining and retry | |
retriesRemaining = retriesRemaining - 1; | |
console.log(`Retrying failed tests. ${retriesRemaining} attempts remaining.`); | |
return await runTestsAndRetry(jestConfig, retriesRemaining); | |
} | |
runTestsAndRetry(jestConfig, NUM_RETRIES); |
Yes, we use this code in production many times a day. For more information, you can see the corresponding blog post here: https://eng.wealthfront.com/2022/04/21/retrying-e2e-test-suites-with-jest/
You did not get my question.
The above piece of code will not compile at all.
failedTestsPaths
is an undefined variable. It should be failedTestPaths
not failedTestsPaths
(look for the plural in Test(s))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Have you even compiled this code?
what is
failedTestsPaths
?