Skip to content

Commit f35b9f3

Browse files
clydinhybrist
authored andcommitted
fix(@schematics/angular): improve comment preservation in jasmine-to-vitest
This commit improves the preservation of comments during the `jasmine-to-vitest` transformation. Specifically, it fixes an issue where multi-line comments between chained spy calls were being discarded. The transformer has been updated to use a less destructive AST modification pattern, which successfully preserves this trivia. Additionally, a previously failing test case for this scenario has been re-enabled and is now passing.
1 parent 68d2baf commit f35b9f3

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ describe('Jasmine to Vitest Transformer', () => {
151151
*/
152152
.mockReturnValue(true);
153153
`,
154-
skipped: true,
155154
},
156155
{
157156
description: 'should preserve a trailing comment on a matcher line',

packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-misc.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,15 @@ export function transformFail(node: ts.Node, { sourceFile, reporter }: RefactorC
7878
reporter.reportTransformation(sourceFile, node, 'Transformed `fail()` to `throw new Error()`.');
7979
const reason = node.expression.arguments[0];
8080

81-
return ts.factory.createThrowStatement(
81+
const replacement = ts.factory.createThrowStatement(
8282
ts.factory.createNewExpression(
8383
ts.factory.createIdentifier('Error'),
8484
undefined,
8585
reason ? [reason] : [],
8686
),
8787
);
88+
89+
return ts.setOriginalNode(ts.setTextRange(replacement, node), node);
8890
}
8991

9092
return node;
@@ -119,7 +121,7 @@ export function transformDefaultTimeoutInterval(
119121
),
120122
]);
121123

122-
return ts.factory.createExpressionStatement(setConfigCall);
124+
return ts.factory.updateExpressionStatement(node, setConfigCall);
123125
}
124126
}
125127

packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-spy.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,12 @@ export function transformSpies(node: ts.Node, refactorCtx: RefactorContext): ts.
160160
node,
161161
`Transformed spy strategy \`.and.${strategyName}()\` to \`.${newMethodName}()\`.`,
162162
);
163-
const newExpression = createPropertyAccess(spyCall, newMethodName);
163+
164+
const newExpression = ts.factory.updatePropertyAccessExpression(
165+
pae,
166+
spyCall,
167+
ts.factory.createIdentifier(newMethodName),
168+
);
164169

165170
return ts.factory.updateCallExpression(
166171
node,

0 commit comments

Comments
 (0)