Skip to content

Commit 7b85c12

Browse files
committed
feat: only leave code matchers and chai-retry-plugin
delete all other mocha hooking functionality, as it appears to hurt our ability to parallelize tests in Dazl
1 parent e10288a commit 7b85c12

14 files changed

Lines changed: 8 additions & 649 deletions

packages/testing/README.md

Lines changed: 6 additions & 58 deletions
Large diffs are not rendered by default.

packages/testing/src/chai-retry-plugin/chai-retry-plugin.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import * as chai from 'chai';
2-
import { isAdjustedTimeout } from '../timeouts.helpers.js';
3-
import { scaleTimeout } from '../timeouts.js';
42
import type { PromiseLikeAssertion } from '../types.js';
53
import { retryFunctionAndAssertions } from './helpers.js';
64
import type { Assertion, AssertionMethod, AssertionStackItem, FunctionToRetry, RetryOptions } from './types.js';
@@ -44,16 +42,9 @@ export const chaiRetryPlugin = function (_: Chai.ChaiStatic, utils: Chai.ChaiUti
4442
`Please pass function to \`expect\` in order to use \`chaiRetryPlugin\`. ${utils.inspect(functionToRetry)} is not a function.`,
4543
);
4644
}
47-
if (isAdjustedTimeout(retryOptions)) {
48-
throw new Error(
49-
`retry is debug safe, don't use it with debugSafeTimeout, use { timeout: X, ... } instead.`,
50-
);
51-
}
5245

5346
const defaultRetryOptions: Required<RetryOptions> = { timeout: 8_000, retries: Infinity, delay: 0 };
5447
const options: Required<RetryOptions> = { ...defaultRetryOptions, ...retryOptions };
55-
options.delay = scaleTimeout(options.delay);
56-
options.timeout = scaleTimeout(options.timeout);
5748

5849
const assertionStack: AssertionStackItem[] = [];
5950
// Fake assertion object for catching calls of chained methods

packages/testing/src/chai-retry-plugin/helpers.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as chai from 'chai';
22
import { deferred, timeout } from 'promise-assist';
3-
import { adjustCurrentTestTimeout, isDebugMode } from '../timeouts.js';
43
import { chaiMethodsThatHandleFunction } from './constants.js';
54
import type { AssertionMethod, RetryAndAssertArguments } from './types.js';
65

@@ -33,8 +32,7 @@ export const retryFunctionAndAssertions = async (retryParams: RetryAndAssertArgu
3332
const performRetries = async () => {
3433
let delay: Promise<void>;
3534

36-
for (let retriesCount = 0; (retriesCount < options.retries && !didTimeout) || isDebugMode(); retriesCount++) {
37-
const time = Date.now();
35+
for (let retriesCount = 0; retriesCount < options.retries && !didTimeout; retriesCount++) {
3836
try {
3937
/**
4038
* If assertion chain includes such method as `change`, `decrease` or `increase` that means function passed to
@@ -50,7 +48,6 @@ export const retryFunctionAndAssertions = async (retryParams: RetryAndAssertArgu
5048
} catch (error: any) {
5149
if (!didTimeout) {
5250
assertionError = error as Error;
53-
adjustTest(time, options.delay);
5451
({ cancel, delay } = sleep(options.delay));
5552
await delay;
5653
}
@@ -62,7 +59,7 @@ export const retryFunctionAndAssertions = async (retryParams: RetryAndAssertArgu
6259

6360
const getTimeoutError = () => `Timed out after ${options.timeout}ms.`;
6461

65-
if (isDebugMode() || !options.timeout) {
62+
if (!options.timeout) {
6663
return performRetries();
6764
} else {
6865
return timeout(performRetries(), options.timeout, getTimeoutError).catch((err) => {
@@ -96,14 +93,6 @@ const updateAssertion = async (
9693
propertyName: keyof Chai.Assertion,
9794
) => (method && args ? await method.apply(assertion, args) : (assertion[propertyName] as Chai.Assertion));
9895

99-
const adjustTest = (time: number, delay: number): number => {
100-
const now = Date.now();
101-
const diff = now - time;
102-
103-
adjustCurrentTestTimeout(diff + delay);
104-
return now + delay;
105-
};
106-
10796
const sleep = (ms: number) => {
10897
const { promise, resolve, reject } = deferred();
10998
const timeoutId = setTimeout(resolve, ms);

packages/testing/src/dispose.ts

Lines changed: 0 additions & 88 deletions
This file was deleted.

packages/testing/src/index.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,6 @@
11
/**
22
* @packageDocumentation
33
* Utils for making mocha + chai testing easy and fun
4-
*
5-
* @remarks
6-
* [[[h 3 Env variables]]]
7-
* - DEBUG=true/positive number env variable will set test timeouts and time scale to infinity so tests (that don't explicitly override timeout) will not time out on breakpoints
8-
*
9-
* - TIMEOUT_MULTIPLIER=number env variable will multiply all test timeouts by the given number
10-
*
11-
* [[[h 3 Test timeout manipulation]]]
12-
*
13-
* - {@link scaleTimeout} multiplies timeouts when debugging or running on slow CI machines, based on TIMEOUT_MULTIPLIER and DEBUG env variables
14-
*
15-
* - {@link adjustTestTime} adjusts current test timeout (for use in non step async actions)
16-
*
17-
* - {@link locatorTimeout} creates a locator timeout and adjust the current test
18-
*
194
*/
20-
export * from './safe-fake-timer.js';
21-
export * from './dispose.js';
22-
export * from './randomize-tests-order.js';
23-
export * from './mocha-ctx.js';
245
export * from './chai-retry-plugin/index.js';
256
export * from './code-matchers/index.js';
26-
export * from './timeouts.js';

packages/testing/src/mocha-ctx.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

packages/testing/src/mocha-helpers.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

packages/testing/src/randomize-tests-order.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

packages/testing/src/safe-fake-timer.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)