Skip to content

Commit

Permalink
use new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Dec 25, 2023
1 parent d099675 commit 5516a56
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 12 deletions.
52 changes: 45 additions & 7 deletions e2e/__tests__/__snapshots__/testRetries.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,44 @@ exports[`Test Retries logs error(s) before retry 1`] = `
expect(received).toBeFalsy()
Received: true
14 | expect(true).toBeTruthy();
15 | } else {
> 16 | expect(true).toBeFalsy();
| ^
17 | }
18 | });
19 |
at Object.toBeFalsy (__tests__/logErrorsBeforeRetries.test.js:16:18)
RETRY 2
expect(received).toBeFalsy()
Received: true
14 | expect(true).toBeTruthy();
15 | } else {
> 16 | expect(true).toBeFalsy();
| ^
17 | }
18 | });
19 |
at Object.toBeFalsy (__tests__/logErrorsBeforeRetries.test.js:16:18)
PASS __tests__/logErrorsBeforeRetries.test.js
✓ retryTimes set"
`;

exports[`Test Retries wait before retry 1`] = `
"LOGGING RETRY ERRORS retryTimes set
RETRY 1
expect(received).toBeFalsy()
Received: true
15 | expect(new Date().getTime() - startTimeInSeconds).toBeGreaterThan(200);
Expand All @@ -16,7 +54,7 @@ exports[`Test Retries logs error(s) before retry 1`] = `
19 | });
20 |
at Object.toBeFalsy (__tests__/logErrorsBeforeRetries.test.js:17:18)
at Object.toBeFalsy (__tests__/waitBeforeRetry.test.js:17:18)
RETRY 2
Expand All @@ -32,13 +70,13 @@ exports[`Test Retries logs error(s) before retry 1`] = `
19 | });
20 |
at Object.toBeFalsy (__tests__/logErrorsBeforeRetries.test.js:17:18)
at Object.toBeFalsy (__tests__/waitBeforeRetry.test.js:17:18)
PASS __tests__/logErrorsBeforeRetries.test.js
PASS __tests__/waitBeforeRetry.test.js
✓ retryTimes set"
`;

exports[`Test Retries logs error(s) before retry with fake timers 1`] = `
exports[`Test Retries wait before retry with fake timers 1`] = `
"LOGGING RETRY ERRORS retryTimes set with fake timers
RETRY 1
Expand All @@ -54,7 +92,7 @@ exports[`Test Retries logs error(s) before retry with fake timers 1`] = `
20 | }
21 | });
at Object.toBeFalsy (__tests__/logErrorsBeforeRetriesFakeTimers.test.js:18:18)
at Object.toBeFalsy (__tests__/waitBeforeRetryFakeTimers.test.js:18:18)
RETRY 2
Expand All @@ -70,8 +108,8 @@ exports[`Test Retries logs error(s) before retry with fake timers 1`] = `
20 | }
21 | });
at Object.toBeFalsy (__tests__/logErrorsBeforeRetriesFakeTimers.test.js:18:18)
at Object.toBeFalsy (__tests__/waitBeforeRetryFakeTimers.test.js:18:18)
PASS __tests__/logErrorsBeforeRetriesFakeTimers.test.js
PASS __tests__/waitBeforeRetryFakeTimers.test.js
✓ retryTimes set with fake timers"
`;
12 changes: 10 additions & 2 deletions e2e/__tests__/testRetries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,17 @@ describe('Test Retries', () => {
expect(extractSummary(result.stderr).rest).toMatchSnapshot();
});

it('logs error(s) before retry with fake timers', () => {
it('wait before retry', () => {
const result = runJest('test-retries', ['waitBeforeRetry.test.js']);
expect(result.exitCode).toBe(0);
expect(result.failed).toBe(false);
expect(result.stderr).toContain(logErrorsBeforeRetryErrorMessage);
expect(extractSummary(result.stderr).rest).toMatchSnapshot();
});

it('wait before retry with fake timers', () => {
const result = runJest('test-retries', [
'logErrorsBeforeRetriesFakeTimers.test.js',
'waitBeforeRetryFakeTimers.test.js',
]);
expect(result.exitCode).toBe(0);
expect(result.failed).toBe(false);
Expand Down
5 changes: 2 additions & 3 deletions e2e/test-retries/__tests__/logErrorsBeforeRetries.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
'use strict';

let i = 0;
const startTimeInSeconds = new Date().getTime();
jest.retryTimes(3, {logErrorsBeforeRetry: true, waitBeforeRetry: 100});
jest.retryTimes(3, {logErrorsBeforeRetry: true});
it('retryTimes set', () => {
i++;
if (i === 3) {
expect(new Date().getTime() - startTimeInSeconds).toBeGreaterThan(200);
expect(true).toBeTruthy();
} else {
expect(true).toBeFalsy();
}
Expand Down
19 changes: 19 additions & 0 deletions e2e/test-retries/__tests__/waitBeforeRetry.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';

let i = 0;
const startTimeInSeconds = new Date().getTime();
jest.retryTimes(3, {logErrorsBeforeRetry: true, waitBeforeRetry: 100});
it('retryTimes set', () => {
i++;
if (i === 3) {
expect(new Date().getTime() - startTimeInSeconds).toBeGreaterThan(200);
} else {
expect(true).toBeFalsy();
}
});

0 comments on commit 5516a56

Please sign in to comment.