Vitest: keep `@defer` dependencies as static imports, so class metadata stays synchronous

Aperta
#29 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
1-2 giorni
Idoneità per principianti
54/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
angular, typescript, vite

Direzione di ricerca

Start in ngp/preprocessor/src/processor.js and trace how canDeferDeps and deferredOnlyNames are set, then read the related JIT compatibility work in #27 for the intended test mode or shared option. Done means Vitest test mode keeps @defer dependencies eagerly loaded without relying on process.env.VITEST, and the relevant tests cover synchronous class metadata for TestBed and MockComponent().

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

feature

Part of #27.

Problem

A deferrable dependency becomes a dynamic import, so the component's class metadata is set asynchronously (ɵsetClassMetadataAsync). TestBed only resolves it in compileComponents(), and ng-mocks reads metadata synchronously. Specs that never call compileComponents(), and every MockComponent() of such a component, fail.

Proposed change

Under Vitest, canDeferDeps is false and nothing is added to deferredOnlyNames (ngp/preprocessor/src/processor.js). This matches JIT, where @defer dependencies are also loaded eagerly in tests.

Our patch gates this on process.env.VITEST, which is the wrong switch for a library. In ngp it belongs in its test mode, or behind one option shared by the JIT-compatibility changes in #27 (for example test: { jitCompat: true }).

Setup: ngp 0.3.0, @angular/compiler/compiler-cli 22.3.0-next.4, Vite 8, Vitest 5.1.0 (pool: 'forks'), a Nx monorepo with 1,035 Angular projects, one Vitest config each, specs written for TestBed under JIT (Analog).

Lingua principale
TypeScript
Stelle
7
Fork
0
Merge medio
12h 24m
PR unite (30g)
13

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di push-based/vite-plugin-ngp

Tutte le issue di push-based/vite-plugin-ngp

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.