Repository navigation
fix(@schematics/angular): preserve nested done callbacks during Vitest migration - #34787
nagahara-naoki wants to merge 2 commits into
Conversation
…t migration Keep Jasmine completion callbacks in nested functions when the migration cannot await their work. Flag the test for manual migration and report only transformations that were applied. Fixes angular#34730
There was a problem hiding this comment.
Code Review
This pull request refactors the Jasmine-to-Vitest schematic transformer to prevent incorrect automatic migration of nested done callbacks (such as those inside setTimeout or other nested functions). Instead of attempting to transform them to async/await, these nested usages are now correctly flagged for manual migration with a TODO comment, and the done parameter is preserved. The internal tracking of handled transformations in jasmine-lifecycle.ts was also updated to collect transformation messages and report them only when the migration succeeds. There are no review comments to address, so I have no feedback to provide.
| (callExpr.expression.name.text === 'then' || callExpr.expression.name.text === 'catch') | ||
| ) { | ||
| const promiseHandler = callExpr.arguments[0]; | ||
| if (promiseHandler) { |
There was a problem hiding this comment.
Could we check the argument count here? In promise.then(done, errorHandler), converting the call to await promise removes errorHandler, so any assertions or custom error handling inside it would no longer execute.
There was a problem hiding this comment.
Thanks for catching this, @ietuday!
I added the argument count check in 70f7361.
promise.then(done, errorHandler)stays intact, including the assertions in the rejection handler. The migration adds the existing TODO to flag the test for manual migration.promise.then(done)still converts toawait promise.
I added a regression test with an expect inside the rejection handler. It failed before the fix because the migration dropped the assertion, and passed afterward.
I also ran //packages/schematics/angular:test locally. All 990 active specs passed, with one existing spec skipped.
…g Vitest migration
PR Checklist
PR Type
What is the current behavior?
The Jasmine-to-Vitest migration can remove a nested
done()from a timer or subscription and mark the spec asasync. The migrated spec can finish before the callback runs, even if the expected event never arrives.Fixes #34730
What is the new behavior?
If a completion callback occurs inside a function whose work the migration cannot await, the schematic preserves the callback and adds the existing manual-migration TODO. Supported promise patterns such as
promise.then(done)still migrate toawaitwhen all uses can be handled.If a test mixes supported and unsupported uses, the verbose log reports that manual migration is required and only lists edits actually applied.
Does this PR introduce a breaking change?
Testing
Ran
pnpm bazel test //packages/schematics/angular:test --nocache_test_resultslocally. The suite reported 989 passing specs and one previously disabled spec. Coverage includes timers, custom callback names, nesteddone.fail(), and a subscription combined with.then(done)through the schematic entry point.