Skip to content

Commit 7d2185c

Browse files
committed
patch(vest): Remove isolate hooks circular dependency
1 parent fd63dd1 commit 7d2185c

File tree

7 files changed

+33
-28
lines changed

7 files changed

+33
-28
lines changed

packages/vest/src/core/isolate/isolate.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import invariant from 'invariant';
22
import isFunction from 'isFunction';
33
import * as nestedArray from 'nestedArray';
44

5-
import { IsolateCursor } from './isolateCursor';
5+
import { useCurrentPath, useCursor, useIsolate } from './isolateHooks';
66

7-
import { Isolate, IsolateTypes } from 'IsolateTypes';
7+
import { IsolateTypes } from 'IsolateTypes';
88
import VestTest from 'VestTest';
99
import ctx from 'ctx';
1010
import { generateIsolate } from 'generateIsolate';
@@ -35,31 +35,9 @@ export function isolate(
3535
return output;
3636
}
3737

38-
/**
39-
* @returns {Isolate} The current isolate layer
40-
*/
41-
export function useIsolate(): Isolate {
42-
return ctx.useX().isolate;
43-
}
44-
4538
/**
4639
* @returns {boolean} Whether or not the current isolate allows tests to be reordered
4740
*/
4841
export function shouldAllowReorder(): boolean {
4942
return useIsolate().type === IsolateTypes.EACH;
5043
}
51-
52-
/**
53-
* @returns {number[]} The current cursor path of the isolate tree
54-
*/
55-
export function useCurrentPath(): number[] {
56-
const isolate = useIsolate();
57-
return isolate.path.concat(isolate.cursor.current());
58-
}
59-
60-
/**
61-
* @returns {IsolateCursor} The cursor object for the current isolate
62-
*/
63-
export function useCursor(): IsolateCursor {
64-
return useIsolate().cursor;
65-
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Isolate } from 'IsolateTypes';
2+
import ctx from 'ctx';
3+
import { IsolateCursor } from 'isolateCursor';
4+
5+
/**
6+
* @returns {Isolate} The current isolate layer
7+
*/
8+
export function useIsolate(): Isolate {
9+
return ctx.useX().isolate;
10+
}
11+
/**
12+
* @returns {number[]} The current cursor path of the isolate tree
13+
*/
14+
export function useCurrentPath(): number[] {
15+
const isolate = useIsolate();
16+
return isolate.path.concat(isolate.cursor.current());
17+
}
18+
19+
/**
20+
* @returns {IsolateCursor} The cursor object for the current isolate
21+
*/
22+
export function useCursor(): IsolateCursor {
23+
return useIsolate().cursor;
24+
}

packages/vest/src/core/test/key.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as nestedArray from 'nestedArray';
44
import { deferThrow } from 'throwError';
55

66
import VestTest from 'VestTest';
7-
import { useCurrentPath, useIsolate } from 'isolate';
7+
import { useCurrentPath, useIsolate } from 'isolateHooks';
88
import { useTestObjects } from 'stateHooks';
99

1010
export function usePrevKeys(): Record<string, VestTest> {

packages/vest/src/core/test/lib/registerPrevRunTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import isPromise from 'isPromise';
33
import VestTest from 'VestTest';
44
import cancelOverriddenPendingTest from 'cancelOverriddenPendingTest';
55
import { isExcluded } from 'exclusive';
6-
import { useCursor } from 'isolate';
6+
import { useCursor } from 'isolateHooks';
77
import { shouldSkipBasedOnMode } from 'mode';
88
import { isOmitted } from 'omitWhen';
99
import registerTest from 'registerTest';

packages/vest/src/core/test/lib/useTestAtCursor.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import { isNullish } from 'isNullish';
44
import * as nestedArray from 'nestedArray';
55
import { deferThrow } from 'throwError';
66

7+
import { useCurrentPath, useCursor } from '../../isolate/isolateHooks';
8+
79
import VestTest from 'VestTest';
810
import { VestTests } from 'createStateRef';
911
import isSameProfileTest from 'isSameProfileTest';
10-
import { shouldAllowReorder, useCurrentPath, useCursor } from 'isolate';
12+
import { shouldAllowReorder } from 'isolate';
1113
import { usePrevTestByKey, useRetainTestKey } from 'key';
1214
import { useTestObjects, useSetTests } from 'stateHooks';
1315

packages/vest/src/core/test/test.memo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import createCache from 'cache';
33
import { isNull } from 'isNull';
44

55
import VestTest, { TestFn } from 'VestTest';
6-
import { useCursor } from 'isolate';
6+
import { useCursor } from 'isolateHooks';
77
import registerPrevRunTest from 'registerPrevRunTest';
88
import { useSuiteId } from 'stateHooks';
99
import type { TestBase } from 'test';

tsconfig.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)