From 50abb5f2e0b4d0687ef4df71dee411f5951b50d4 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Mon, 16 Nov 2026 11:22:09 -0500 Subject: [PATCH 1/2] fix(@schematics/angular): handle done callbacks in focused and skipped tests Similar to `transformPending`, `transformDoneCallback` previously only matched calls whose expression was the bare `it` identifier (or lifecycle hooks). Because `transformFocusedAndSkippedTests` runs earlier in the pipeline and rewrites `fit` to `it.only` and `xit` to `it.skip`, focused and skipped specs using a `done` callback were skipped by `transformDoneCallback`, leaving the `done` parameter and `done()`/`done.fail()` calls unmigrated. Extract a shared `isItCallExpression` helper that matches `it`, `it.only`, and `it.skip`, and use it in both `transformPending` and `transformDoneCallback`. Added unit tests covering `fit` and `xit` specs with `done` callbacks and verified with `pnpm bazel test //packages/schematics/angular:test`. --- .../transformers/jasmine-lifecycle.ts | 46 +++++++++++-------- .../transformers/jasmine-lifecycle_spec.ts | 26 +++++++++++ 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle.ts b/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle.ts index 9608a5e931f5..1037a59fc076 100644 --- a/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle.ts +++ b/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle.ts @@ -50,23 +50,30 @@ export function transformFocusedAndSkippedTests( return node; } +/** + * Checks whether a call expression target is `it`, `it.only`, or `it.skip`. + * `fit`/`xit` have already become `it.only`/`it.skip` when `transformPending` + * and `transformDoneCallback` run, as `transformFocusedAndSkippedTests` is + * applied earlier in the pipeline. + */ +function isItCallExpression(expression: ts.Expression): boolean { + if (ts.isIdentifier(expression) && expression.text === 'it') { + return true; + } + + return ( + ts.isPropertyAccessExpression(expression) && + ts.isIdentifier(expression.expression) && + expression.expression.text === 'it' && + (expression.name.text === 'only' || expression.name.text === 'skip') + ); +} + export function transformPending( node: ts.Node, { sourceFile, reporter, tsContext }: RefactorContext, ): ts.Node { - if (!ts.isCallExpression(node)) { - return node; - } - - // `fit`/`xit` have already become `it.only`/`it.skip` when this transformer runs, - // as `transformFocusedAndSkippedTests` is applied earlier in the pipeline. - const isBareIt = ts.isIdentifier(node.expression) && node.expression.text === 'it'; - const isFocusedOrSkippedIt = - ts.isPropertyAccessExpression(node.expression) && - ts.isIdentifier(node.expression.expression) && - node.expression.expression.text === 'it' && - (node.expression.name.text === 'only' || node.expression.name.text === 'skip'); - if (!isBareIt && !isFocusedOrSkippedIt) { + if (!ts.isCallExpression(node) || !isItCallExpression(node.expression)) { return node; } @@ -301,11 +308,14 @@ function countDoneUsages(node: ts.Node, doneIdentifier: ts.Identifier): number { export function transformDoneCallback(node: ts.Node, refactorCtx: RefactorContext): ts.Node { const { sourceFile, reporter, tsContext } = refactorCtx; - if ( - !ts.isCallExpression(node) || - !ts.isIdentifier(node.expression) || - !['it', 'beforeEach', 'afterEach', 'beforeAll', 'afterAll'].includes(node.expression.text) - ) { + if (!ts.isCallExpression(node)) { + return node; + } + + const isLifecycleHook = + ts.isIdentifier(node.expression) && + ['beforeEach', 'afterEach', 'beforeAll', 'afterAll'].includes(node.expression.text); + if (!isItCallExpression(node.expression) && !isLifecycleHook) { return node; } diff --git a/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle_spec.ts b/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle_spec.ts index d8fb576948ce..8fcaf40fc9c9 100644 --- a/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle_spec.ts +++ b/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle_spec.ts @@ -171,6 +171,32 @@ describe('Jasmine to Vitest Transformer - transformDoneCallback', () => { }); `, }, + { + description: 'should transform a focused test (fit) with a done callback', + input: ` + fit('should do something async', (done) => { + service.init().then(() => done()); + }); + `, + expected: ` + it.only('should do something async', async () => { + await service.init().then(() => {}); + }); + `, + }, + { + description: 'should transform a skipped test (xit) with a done callback', + input: ` + xit('should do something async', (done) => { + done.fail('it failed'); + }); + `, + expected: ` + it.skip('should do something async', async () => { + throw new Error('it failed'); + }); + `, + }, ]; testCases.forEach(({ description, input, expected }) => { From 13bdd61d9cd9421948b93d42e52b6bf35cdd1261 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Mon, 16 Nov 2026 11:52:15 -0500 Subject: [PATCH 2/2] fixup! fix(@schematics/angular): handle done callbacks in focused and skipped tests --- .../jasmine-vitest/transformers/jasmine-lifecycle.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle.ts b/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle.ts index 1037a59fc076..f71e55eeef46 100644 --- a/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle.ts +++ b/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle.ts @@ -314,7 +314,10 @@ export function transformDoneCallback(node: ts.Node, refactorCtx: RefactorContex const isLifecycleHook = ts.isIdentifier(node.expression) && - ['beforeEach', 'afterEach', 'beforeAll', 'afterAll'].includes(node.expression.text); + (node.expression.text === 'beforeEach' || + node.expression.text === 'afterEach' || + node.expression.text === 'beforeAll' || + node.expression.text === 'afterAll'); if (!isItCallExpression(node.expression) && !isLifecycleHook) { return node; }