Skip to content

Commit ff0c48a

Browse files
clydinhybrist
authored andcommitted
refactor(@schematics/angular): clarify jasmine-to-vitest visitor behavior
The arrays of transformer functions have been reorganized into commented, logical stages. This makes the implicit, top-down execution order explicit, which is critical for the correctness of context-sensitive transformations.
1 parent f35b9f3 commit ff0c48a

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

packages/schematics/angular/refactor/jasmine-vitest/test-file-transformer.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,28 @@ export function transformJasmineToVitest(
7474
// Transform the node itself based on its type
7575
if (ts.isCallExpression(transformedNode)) {
7676
const transformations = [
77+
// **Stage 1: High-Level & Context-Sensitive Transformations**
78+
// These transformers often wrap or fundamentally change the nature of the call,
79+
// so they need to run before more specific matchers.
7780
transformWithContext,
7881
transformExpectAsync,
79-
transformSyntacticSugarMatchers,
8082
transformFocusedAndSkippedTests,
83+
transformPending,
84+
transformDoneCallback,
85+
86+
// **Stage 2: Core Matcher & Spy Transformations**
87+
// This is the bulk of the `expect(...)` and `spyOn(...)` conversions.
88+
transformSyntacticSugarMatchers,
8189
transformComplexMatchers,
8290
transformSpies,
8391
transformCreateSpyObj,
8492
transformSpyReset,
8593
transformSpyCallInspection,
86-
transformPending,
87-
transformDoneCallback,
8894
transformtoHaveBeenCalledBefore,
8995
transformToHaveClass,
96+
97+
// **Stage 3: Global Functions & Cleanup**
98+
// These handle global Jasmine functions and catch-alls for unsupported APIs.
9099
transformTimerMocks,
91100
transformGlobalFunctions,
92101
transformUnsupportedJasmineCalls,
@@ -97,6 +106,7 @@ export function transformJasmineToVitest(
97106
}
98107
} else if (ts.isPropertyAccessExpression(transformedNode)) {
99108
const transformations = [
109+
// These transformers handle `jasmine.any()` and other `jasmine.*` properties.
100110
transformAsymmetricMatchers,
101111
transformSpyCallInspection,
102112
transformUnknownJasmineProperties,
@@ -105,6 +115,8 @@ export function transformJasmineToVitest(
105115
transformedNode = transformer(transformedNode, refactorCtx);
106116
}
107117
} else if (ts.isExpressionStatement(transformedNode)) {
118+
// Statement-level transformers are mutually exclusive. The first one that
119+
// matches will be applied, and then the visitor will stop for this node.
108120
const statementTransformers = [
109121
transformCalledOnceWith,
110122
transformArrayWithExactContents,
@@ -130,7 +142,7 @@ export function transformJasmineToVitest(
130142
}
131143
};
132144

133-
return (node) => ts.visitNode(node, visitor) as ts.SourceFile;
145+
return (node) => ts.visitEachChild(node, visitor, context);
134146
};
135147

136148
const result = ts.transform(sourceFile, [transformer]);

0 commit comments

Comments
 (0)