diff --git a/packages/vest/src/core/isolate/IsolateReconciler.ts b/packages/vest/src/core/isolate/IsolateReconciler.ts new file mode 100644 index 000000000..0c538995b --- /dev/null +++ b/packages/vest/src/core/isolate/IsolateReconciler.ts @@ -0,0 +1,11 @@ +import { TIsolate } from 'vestjs-runtime'; + +export abstract class IsolateReconciler { + static match(currentNode: TIsolate, historyNode: TIsolate): boolean { + return false; + } + + static reconcile(currentNode: TIsolate, historyNode: TIsolate): TIsolate { + return (currentNode ?? historyNode) as TIsolate; + } +} diff --git a/packages/vest/src/core/isolate/IsolateTest/IsolateTestReconciler.ts b/packages/vest/src/core/isolate/IsolateTest/IsolateTestReconciler.ts index bec0c8181..1569ca9b0 100644 --- a/packages/vest/src/core/isolate/IsolateTest/IsolateTestReconciler.ts +++ b/packages/vest/src/core/isolate/IsolateTest/IsolateTestReconciler.ts @@ -1,3 +1,4 @@ +import { IsolateReconciler } from 'IsolateReconciler'; import { Maybe, deferThrow, text } from 'vest-utils'; import { IsolateInspector, Reconciler } from 'vestjs-runtime'; import type { TIsolate } from 'vestjs-runtime'; @@ -10,20 +11,25 @@ import { castIsolateTest, isIsolateTest } from 'isIsolateTest'; import { isSameProfileTest } from 'isSameProfileTest'; import { useVerifyTestRun } from 'verifyTestRun'; -// @vx-allow use-use -export function IsolateTestReconciler( - currentNode: TIsolateTest, - historyNode: TIsolateTest -): TIsolateTest { - const reconcilerOutput = usePickNode(historyNode, currentNode); +export class IsolateTestReconciler extends IsolateReconciler { + static match(currentNode: TIsolate, historyNode: TIsolate): boolean { + return isIsolateTest(currentNode) && isIsolateTest(historyNode); + } - cancelOverriddenPendingTestOnTestReRun( - reconcilerOutput, - currentNode, - historyNode - ); + static reconcile( + currentNode: TIsolateTest, + historyNode: TIsolateTest + ): TIsolateTest { + const reconcilerOutput = usePickNode(historyNode, currentNode); - return reconcilerOutput; + cancelOverriddenPendingTestOnTestReRun( + reconcilerOutput, + currentNode, + historyNode + ); + + return reconcilerOutput; + } } function usePickNode( diff --git a/packages/vest/src/core/isolate/VestReconciler.ts b/packages/vest/src/core/isolate/VestReconciler.ts index fffd20231..1f992a8b7 100644 --- a/packages/vest/src/core/isolate/VestReconciler.ts +++ b/packages/vest/src/core/isolate/VestReconciler.ts @@ -2,15 +2,14 @@ import { Nullable } from 'vest-utils'; import { TIsolate } from 'vestjs-runtime'; import { IsolateTestReconciler } from 'IsolateTestReconciler'; -import { isIsolateTest } from 'isIsolateTest'; export function VestReconciler( currentNode: TIsolate, historyNode: TIsolate ): Nullable { - if (isIsolateTest(currentNode) && isIsolateTest(historyNode)) { - return IsolateTestReconciler(currentNode, historyNode); - } - - return null; + return ( + [IsolateTestReconciler] + .find(reconciler => reconciler.match(currentNode, historyNode)) + ?.reconcile(currentNode as any, historyNode as any) ?? null + ); } diff --git a/packages/vest/tsconfig.json b/packages/vest/tsconfig.json index 38ad4ddf8..99ca8bef4 100644 --- a/packages/vest/tsconfig.json +++ b/packages/vest/tsconfig.json @@ -88,6 +88,7 @@ "matchingFieldName": ["./src/core/test/helpers/matchingFieldName.ts"], "VestReconciler": ["./src/core/isolate/VestReconciler.ts"], "VestIsolateType": ["./src/core/isolate/VestIsolateType.ts"], + "IsolateReconciler": ["./src/core/isolate/IsolateReconciler.ts"], "isSameProfileTest": [ "./src/core/isolate/IsolateTest/isSameProfileTest.ts" ],