Skip to content

Test Runner add support for retries #48754

@Filipoliko

Description

@Filipoliko

What is the problem this feature will solve?

If the test runner is used for some integration, or end-2-end testing, there tends to be some flakiness because of the more complex setup relying on the stability of not just the tests, but also the environment that tests are running against.

What is the feature you are proposing to solve the problem?

Implement support for retries configuration. If a test fails and there is a configuration retries: 1, it will re-run the test one more time and if the second run succeeds, the test is considered as successful. Also all surrounding beforeEach and afterEach scripts should be also executed again as they can contain some necessary setups and cleanups. By default retries should be disabled as it is not something most users would like to have configured by default.

Reporters should also consider this possibility and could report on flaky/retried tests.

Inspiration can be taken from playwright documentation on retries.

CLI
Usage: node --test --test-retries=1 ./tests/test.js

TestRunner.run

import { run } from 'node:test';
import path from 'node:path';

run({
  files: [path.resolve('./tests/test.js')],
  retries: 1
})

The same configuration can be also useful in describe and test/it options object.

What alternatives have you considered?

I considered extending Node Test Runner with my own implementation of retries just for my use-case. But there does not seem to be an elegant solution how to accomplish this right now as the Test Runner does not seem to be very well extensible in this way.

The solution that would work, but wouldn't be very nice, is implementing wrapper function for the tests, that would handle retrying. But this would require wrapping all the test functions to be able to accomplish some global behaviour. Also Test Reporters would not display nice information about flakiness.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.staletest_runnerIssues and PRs related to the test runner subsystem.

    Type

    No type

    Projects

    Status

    In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions