From 4233d572230fdceddd96bce0a0214e4e82bdbd81 Mon Sep 17 00:00:00 2001 From: Shuaib Hasan Akib Date: Thu, 12 Nov 2026 02:49:35 +0600 Subject: [PATCH] fix(@schematics/angular): handle pending() in focused and skipped tests in refactor-jasmine-vitest `transformPending` only matches calls whose expression is the bare `it` identifier, but `transformFocusedAndSkippedTests` runs earlier in the pipeline and has already renamed `fit` to `it.only` and `xit` to `it.skip`. A focused test containing `pending()` is therefore migrated to `it.only` with the `pending()` call left in place, which throws a ReferenceError at runtime since Vitest has no `pending` global; a skipped test keeps a dangling `pending()` call that no longer compiles once the Jasmine types are removed. Also match the renamed `it.only` and `it.skip` forms and convert both to `it.skip` with the usual TODO comment. A pending spec never runs its body in Jasmine, even when focused, so `it.skip` preserves the observed behavior. Verified with two new `transformPending` cases that run the full transform pipeline on `fit` and `xit` inputs; both fail without this change and `//packages/schematics/angular:test` passes with it. --- .../transformers/jasmine-lifecycle.ts | 22 +++++++++++---- .../transformers/jasmine-lifecycle_spec.ts | 28 +++++++++++++++++++ 2 files changed, 44 insertions(+), 6 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 eb58a7f9d5b9..9608a5e931f5 100644 --- a/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle.ts +++ b/packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle.ts @@ -54,11 +54,19 @@ export function transformPending( node: ts.Node, { sourceFile, reporter, tsContext }: RefactorContext, ): ts.Node { - if ( - !ts.isCallExpression(node) || - !ts.isIdentifier(node.expression) || - node.expression.text !== 'it' - ) { + 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) { return node; } @@ -100,7 +108,9 @@ export function transformPending( return node; } - const newExpression = createPropertyAccess(node.expression, 'skip'); + // A pending spec never runs its body in Jasmine, even when focused, so `it.only` + // also becomes `it.skip`. + const newExpression = createPropertyAccess('it', 'skip'); const newTestFn = ts.isArrowFunction(testFn) ? ts.factory.updateArrowFunction( testFn, 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 611bb2330cd3..d8fb576948ce 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 @@ -210,6 +210,34 @@ describe('transformPending', () => { }); `, }, + { + description: 'should transform a focused test (fit) with pending() to it.skip()', + input: ` + fit('is a work in progress', () => { + pending('Not yet implemented'); + }); + `, + expected: ` + it.skip('is a work in progress', () => { + // TODO: vitest-migration: The pending() function was converted to a skipped test (\`it.skip\`). See: https://vitest.dev/api/vi.html#it-skip + // pending('Not yet implemented'); + }); + `, + }, + { + description: 'should comment out pending() in a skipped test (xit)', + input: ` + xit('is a work in progress', () => { + pending('Not yet implemented'); + }); + `, + expected: ` + it.skip('is a work in progress', () => { + // TODO: vitest-migration: The pending() function was converted to a skipped test (\`it.skip\`). See: https://vitest.dev/api/vi.html#it-skip + // pending('Not yet implemented'); + }); + `, + }, ]; testCases.forEach(({ description, input, expected }) => {