refactor-jasmine-vitest removes done() from asynchronous callbacks, so migrated tests no longer wait for them
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 74/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- angular, typescript
Rechercherichtung
Read packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle.ts and the first relevant case in transformers/jasmine-lifecycle_spec.ts. Trace how transformDoneCallback handles done() inside nested functions, then run the focused transformer spec. Done means migrated tests still await nested asynchronous callbacks or the schematic leaves those cases unchanged with a TODO.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Command
e2e, generate
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
When a spec uses Jasmine's done callback inside an asynchronous callback — subscribe(...),
setTimeout(...), an event listener — the refactor-jasmine-vitest schematic deletes the done()
call and converts the test to a plain async function. The migrated test then resolves immediately,
before the callback ever runs, so it no longer waits for — or asserts anything about — the
asynchronous work:
// before (fails under Jasmine if the observable never emits: done timeout;
// fails if the assertion inside the callback throws)
it('emits the loaded data', (done) => {
service.getData().subscribe((data) => {
expect(data).toEqual(expected);
done();
});
});
// after migration (passes unconditionally if the emission is not synchronous)
it('emits the loaded data', async () => {
service.getData().subscribe((data) => {
expect(data).toEqual(expected);
});
});
Two guarantees are lost at once:
- The completion guarantee. In Jasmine, a test whose
doneis never called fails with a
timeout. The migrated test passes instantly, so "the event/emission never happened" bugs are no
longer caught. - Failure attribution. If the callback does fire later, an assertion failure inside it throws
outside any test. Depending on timing it surfaces as an unattributed unhandled error or not at
all (when the run ends first) — instead of failing this test.
The transformation is correct for done() at the top level of the test body and for the explicitly
handled promise forms (.then(done), .then(() => done()), .catch(done.fail)), which are
rewritten to await. The problem is only done() inside a nested function that the transformer
cannot await. The existing safety check (unhandled-done-usage) does not catch this, because
removing the nested done() counts as a handled usage.
Since Vitest has no done callback, a faithful migration for the nested case would wrap the body in
an awaited promise whose resolver takes done's place:
it('emits the loaded data', () =>
new Promise<void>((done) => {
service.getData().subscribe((data) => {
expect(data).toEqual(expected);
done();
});
}));
Alternatively, the schematic could leave the test unchanged with a TODO (like
unhandled-done-usage) whenever done is referenced inside a nested function. Happy to send a PR
for whichever direction you prefer.
Minimal Reproduction
-
ng new repro --defaults && cd repro -
Replace the body of
src/app/app.spec.ts(or any spec) with a test whose callback never fires:import { Subject } from 'rxjs'; describe('done in async callback', () => { it('fails when the data never arrives', (done) => { const data$ = new Subject<number>(); data$.subscribe(() => done()); // nothing ever emits — under Jasmine this test fails with a done timeout }); }); -
Run it with Karma/Jasmine (
ng testwith the Karma builder): the test fails after the timeout —
Async function did not complete within 5000ms. -
ng generate @schematics/angular:refactor-jasmine-vitest -
The spec becomes
it('fails when the data never arrives', async () => { data$.subscribe(() => {}); });
andng test(Vitest runner) reports it as passing.
Exception or Error
Your Environment
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI : 22.3.0-next.5
Node.js : 24.15.0
Package Manager : yarn 1.22.22
Operating System : darwin arm64
┌──────────────┬───────────────────┬───────────────────┐
│ Package │ Installed Version │ Requested Version │
├──────────────┼───────────────────┼───────────────────┤
│ @angular/cli │ 22.3.0-next.5 │ ^22.3.0-next.5 │
Anything else relevant?
packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-lifecycle.ts—
transformDoneCallback: the body visitor recurses into nested functions and replaces any
done()statement with an empty statement, then marks the testasync.- The current output is asserted by the first case in
transformers/jasmine-lifecycle_spec.ts(setTimeoutwithdone()→asyncwithdone()
removed), so I wanted to raise this before proposing a behavior change. - Not OS- or browser-specific.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 27k
- Forks
- 11.8k
- Ø Merge
- 1 T. 2 Std.
- Gemergte PRs (30 T.)
- 225
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus angular/angular-cli
-
`@angular/[email protected]` depends on vulnerable Vite 7.3.7 - GHSA-p4f5-76q4-ffq7 (Critical RCE)Offenarea: @angular/build
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
angular/angular-cli#34764 ·
Maintainer antworten meist innerhalb von 1 Tag
-
ng add @angular/ssr fails with TypeError when an NgModule in the app module file has no bootstrap arrayEvtl. vergeben @0z5a hat das heute übernommen. Offenarea: @schematics/angular
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 90/100
angular/angular-cli#34761 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 72/100
angular/angular-cli#34760 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Angular SSR can crash `AngularAppEngine` servers with a single aborted request (22.2.6 regression)Evtl. vergeben @SkyZeroZx hat das vor 1 Tag übernommen. Offenarea: @angular/ssr
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 20/100
angular/angular-cli#34754 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area: @angular/build
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
angular/angular-cli#34728 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in angular/angular-cli
Ähnliche Issues
-
status/need-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
google-gemini/gemini-cli#30384 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
P2
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 84/100
Maintainer antworten meist innerhalb von 1 Tag
-
bug ready-for-human
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 60/100
LucasSantana-Dev/Lucky#3150 ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement good first issue priority: low size: XS
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
vercel-labs/scriptc#3979 ·
Maintainer antworten meist innerhalb von 1 Tag