Skip to content

Commit

Permalink
rename immedialety property to retryImmediately
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadimchesh committed Mar 20, 2024
1 parent 6cffa1b commit b4b3986
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 57 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- `[jest-circus, jest-cli, jest-config]` Add `waitNextEventLoopTurnForUnhandledRejectionEvents` flag to minimise performance impact of correct detection of unhandled promise rejections introduced in [#14315](https://github.com/jestjs/jest/pull/14315) ([#14681](https://github.com/jestjs/jest/pull/14681))
- `[jest-circus]` Add a `waitBeforeRetry` option to `jest.retryTimes` ([#14738](https://github.com/jestjs/jest/pull/14738))
- `[jest-circus]` Add a `immediately` option to `jest.retryTimes` ([#14696](https://github.com/jestjs/jest/pull/14696))
- `[jest-circus]` Add a `retryImmediately` option to `jest.retryTimes` ([#14696](https://github.com/jestjs/jest/pull/14696))
- `[jest-circus, jest-jasmine2]` Allow `setupFilesAfterEnv` to export an async function ([#10962](https://github.com/jestjs/jest/issues/10962))
- `[jest-config]` [**BREAKING**] Add `mts` and `cts` to default `moduleFileExtensions` config ([#14369](https://github.com/facebook/jest/pull/14369))
- `[jest-config]` [**BREAKING**] Update `testMatch` and `testRegex` default option for supporting `mjs`, `cjs`, `mts`, and `cts` ([#14584](https://github.com/jestjs/jest/pull/14584))
Expand Down
4 changes: 2 additions & 2 deletions docs/JestObjectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -1139,10 +1139,10 @@ test('will fail', () => {
});
```

`immediately` option is used to retry the failed test immediately after the failure. If this option is not specified, the tests are retried after Jest is finished running all test in a file.
`retryImmediately` option is used to retry the failed test immediately after the failure. If this option is not specified, the tests are retried after Jest is finished running all test in a file.

```js
jest.retryTimes(3, {immediately: true});
jest.retryTimes(3, {retryImmediately: true});

test('will fail', () => {
expect(true).toBe(false);
Expand Down
78 changes: 39 additions & 39 deletions e2e/__tests__/__snapshots__/testRetries.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,44 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Test Retries immediately retry after failed test 1`] = `
"LOGGING RETRY ERRORS retryTimes set
RETRY 1
expect(received).toBeFalsy()
Received: true
15 | expect(true).toBeTruthy();
16 | } else {
> 17 | expect(true).toBeFalsy();
| ^
18 | }
19 | });
20 | it('truthy test', () => {
at Object.toBeFalsy (__tests__/immediatelyRetry.test.js:17:18)
RETRY 2
expect(received).toBeFalsy()
Received: true
15 | expect(true).toBeTruthy();
16 | } else {
> 17 | expect(true).toBeFalsy();
| ^
18 | }
19 | });
20 | it('truthy test', () => {
at Object.toBeFalsy (__tests__/immediatelyRetry.test.js:17:18)
PASS __tests__/immediatelyRetry.test.js
retryTimes set
truthy test"
`;
exports[`Test Retries logs error(s) before retry 1`] = `
"LOGGING RETRY ERRORS retryTimes set
RETRY 1
Expand Down Expand Up @@ -152,3 +113,42 @@ exports[`Test Retries wait before retry with fake timers 1`] = `
PASS __tests__/waitBeforeRetryFakeTimers.test.js
✓ retryTimes set with fake timers"
`;

exports[`Test Retries with flag retryImmediately retry immediately after failed test 1`] = `
"LOGGING RETRY ERRORS retryTimes set
RETRY 1
expect(received).toBeFalsy()
Received: true
15 | expect(true).toBeTruthy();
16 | } else {
> 17 | expect(true).toBeFalsy();
| ^
18 | }
19 | });
20 | it('truthy test', () => {
at Object.toBeFalsy (__tests__/retryImmediately.test.js:17:18)
RETRY 2
expect(received).toBeFalsy()
Received: true
15 | expect(true).toBeTruthy();
16 | } else {
> 17 | expect(true).toBeFalsy();
| ^
18 | }
19 | });
20 | it('truthy test', () => {
at Object.toBeFalsy (__tests__/retryImmediately.test.js:17:18)
PASS __tests__/retryImmediately.test.js
retryTimes set
truthy test"
`;
8 changes: 4 additions & 4 deletions e2e/__tests__/testRetries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ describe('Test Retries', () => {
expect(extractSummary(result.stderr).rest).toMatchSnapshot();
});

it('immediately retry after failed test', () => {
it('with flag retryImmediately retry immediately after failed test', () => {
const logMessage = `console.log
FIRST TRUTHY TEST
at Object.log (__tests__/immediatelyRetry.test.js:14:13)
at Object.log (__tests__/retryImmediately.test.js:14:13)
console.log
SECOND TRUTHY TEST
at Object.log (__tests__/immediatelyRetry.test.js:21:11)`;
at Object.log (__tests__/retryImmediately.test.js:21:11)`;

const result = runJest('test-retries', ['immediatelyRetry.test.js']);
const result = runJest('test-retries', ['retryImmediately.test.js']);
const stdout = result.stdout.trim();
expect(result.exitCode).toBe(0);
expect(result.failed).toBe(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
'use strict';

jest.retryTimes(3, {immediately: true, logErrorsBeforeRetry: true});
jest.retryTimes(3, {logErrorsBeforeRetry: true, retryImmediately: true});
let i = 0;
it('retryTimes set', () => {
i++;
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-circus/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import shuffleArray, {
rngBuilder,
} from './shuffleArray';
import {dispatch, getState} from './state';
import {IMMEDIATELY, RETRY_TIMES, WAIT_BEFORE_RETRY} from './types';
import {RETRY_IMMEDIATELY, RETRY_TIMES, WAIT_BEFORE_RETRY} from './types';
import {
callAsyncCircusFn,
getAllHooksForDescribe,
Expand Down Expand Up @@ -81,7 +81,7 @@ const _runTestsForDescribeBlock = async (

const retryImmediately: boolean =
// eslint-disable-next-line no-restricted-globals
((global as Global.Global)[IMMEDIATELY] as any) || false;
((global as Global.Global)[RETRY_IMMEDIATELY] as any) || false;

const deferredRetryTests = [];

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-circus/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

export const STATE_SYM = Symbol('JEST_STATE_SYMBOL');
export const RETRY_TIMES = Symbol.for('RETRY_TIMES');
export const IMMEDIATELY = Symbol.for('IMMEDIATELY');
export const RETRY_IMMEDIATELY = Symbol.for('RETRY_IMMEDIATELY');
export const WAIT_BEFORE_RETRY = Symbol.for('WAIT_BEFORE_RETRY');
// To pass this value from Runtime object to state we need to use global[sym]
export const TEST_TIMEOUT_SYMBOL = Symbol.for('TEST_TIMEOUT_SYMBOL');
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-environment/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export interface Jest {
*
* `waitBeforeRetry` is the number of milliseconds to wait before retrying
*
* `immediately` is the flag to retry the failed tests immediately after
* `retryImmediately` is the flag to retry the failed test immediately after
* failure
*
* @remarks
Expand All @@ -309,8 +309,8 @@ export interface Jest {
retryTimes(
numRetries: number,
options?: {
immediately?: boolean;
logErrorsBeforeRetry?: boolean;
retryImmediately?: boolean;
waitBeforeRetry?: number;
},
): Jest;
Expand Down
5 changes: 3 additions & 2 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ type ResolveOptions = Parameters<typeof require.resolve>[1] & {
const testTimeoutSymbol = Symbol.for('TEST_TIMEOUT_SYMBOL');
const retryTimesSymbol = Symbol.for('RETRY_TIMES');
const waitBeforeRetrySymbol = Symbol.for('WAIT_BEFORE_RETRY');
const immediatelySybmbol = Symbol.for('IMMEDIATELY');
const retryImmediatelySybmbol = Symbol.for('RETRY_IMMEDIATELY');
const logErrorsBeforeRetrySymbol = Symbol.for('LOG_ERRORS_BEFORE_RETRY');

const NODE_MODULES = `${path.sep}node_modules${path.sep}`;
Expand Down Expand Up @@ -2293,7 +2293,8 @@ export default class Runtime {
options?.logErrorsBeforeRetry;
this._environment.global[waitBeforeRetrySymbol] =
options?.waitBeforeRetry;
this._environment.global[immediatelySybmbol] = options?.immediately;
this._environment.global[retryImmediatelySybmbol] =
options?.retryImmediately;

return jestObject;
};
Expand Down
8 changes: 5 additions & 3 deletions packages/jest-types/__typetests__/jest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,9 +667,11 @@ expect(jest.retryTimes(3, {logErrorsBeforeRetry: 'all'})).type.toRaiseError();
expect(jest.retryTimes({logErrorsBeforeRetry: true})).type.toRaiseError();
expect(jest.retryTimes(3, {waitBeforeRetry: 1000})).type.toEqual<typeof jest>();
expect(jest.retryTimes(3, {waitBeforeRetry: true})).type.toRaiseError();
expect(jest.retryTimes(3, {immediately: true})).type.toEqual<typeof jest>();
expect(jest.retryTimes(3, {immediately: 'now'})).type.toRaiseError();
expect(jest.retryTimes(3, {immediately: 1000})).type.toRaiseError();
expect(jest.retryTimes(3, {retryImmediately: true})).type.toEqual<
typeof jest
>();
expect(jest.retryTimes(3, {retryImmediately: 'now'})).type.toRaiseError();
expect(jest.retryTimes(3, {retryImmediately: 1000})).type.toRaiseError();
expect(jest.retryTimes({logErrorsBeforeRetry: 'all'})).type.toRaiseError();
expect(jest.retryTimes()).type.toRaiseError();

Expand Down

0 comments on commit b4b3986

Please sign in to comment.