Jest: Add `jest.retryTimes` metadata to `TestResult` for custom reporters

Created on 15 Feb 2019  路  5Comments  路  Source: facebook/jest

馃殌 Feature Proposal

I love using circus's retryTimes to run several integration tests. It would be very helpful to have access to the number of retries required for the test to pass in a custom reporter. For example, if a test passed on the second run, the TestResult passed to onTestResult would have testResult.retryCount == 1.

Motivation

I use Jest to run several smoke tests using puppeteer in my company's staging and production environments to ensure our services are properly configured to work well together. As with many browser level integration tests, they tend to have false positive failures frequently. retryTimes is a great feature to address these false positives. However, I'd like to track metrics for how frequently each test requires a retry to pass. This will help us understand if our failure rate for each test changes over time.

We recently had a test which went from close to a 0% failure rate to a 30% failure rate. We didn't realize how big the problem was until I did an analysis of the historic logs. I'd like to be able to set up alerts when the error rate changes compared to historic values.

Example

const StatsD = require('hot-shots');
const statsdClient = new StatsD({ port: 8020, globalTags: { env: process.env.NODE_ENV }); 

class StatsdRetryCountReporter {
  onTestResult(_test, testResult) {
    statsdClient.increment(testResult.displayName, {value: testResult.retryCount})
  }
}

module.exports = StatsdRetryCountReporter;

Pitch

I believe jest core is the right place for this feature because retryTimes is part of circus. Additionally, this metric seems very valuable to custom reporters when using retryTimes.

Feature Request Help Wanted good first issue

All 5 comments

I agree! It should be pretty easy to include as well, since we keep track of it. Wanna send a PR for it? _Should_ be in https://github.com/facebook/jest/blob/d9d501ac342212b8a58ddb23a31518beb7b56f47/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.js#L135-L169

You might need to add some breakpoints and see at what point the information is discarded - it probably should be part of the test state: https://github.com/facebook/jest/blob/d9d501ac342212b8a58ddb23a31518beb7b56f47/packages/jest-circus/src/run.js#L47-L70

/cc @palmerj3

So reporters can already see the number of times a test was retried by looking at the "invocations" field in the test report.

Unless a test is retried this number is always going to be 1 but if it's retried it will be higher.

@SimenB ^^

Awesome, thanks!

Was this page helpful?
0 / 5 - 0 ratings