Vitest: drop template scope errors (NG8001–NG8004) that TestBed resolves at runtime

Open
#30 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
angular, typescript

Research direction

Read ngp/preprocessor/src/tcb.js, especially dropRuntimeScopedDiagnostics, and trace how diagnostics are filtered for non-standalone and spec-declared components. Check the existing test mode and the JIT compatibility work referenced in #27 to see how the option should be shared. Done means the specified diagnostics are dropped in the relevant test mode while TestBed can still report genuinely missing items at runtime.

Written by the indexing model from the issue text.

Description

feature

Part of #27.

Problem

Per-file analysis can't see two scopes that only exist at runtime:

  • a non-standalone component gets its scope from its NgModule, or from TestBed.configureTestingModule({ declarations });
  • a component declared in a spec file often gets its imports from TestBed.overrideComponent.

ngp reports NG8001–NG8004 (unknown element, property, exportAs, pipe) for both, and the spec file fails to compile. It also reports NG8008 (missing required input) for spec-declared test hosts, a check JIT never ran.

Proposed change

Under Vitest, drop NG8001–NG8004 for non-standalone and spec-declared components, and NG8008 for spec-declared ones (dropRuntimeScopedDiagnostics in ngp/preprocessor/src/tcb.js). TestBed still throws at runtime for anything really missing.

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).

Dominant language
TypeScript
Stars
7
Forks
1
Avg merge
12h 24m
Merged PRs (30d)
13

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from push-based/vite-plugin-ngp

All issues in push-based/vite-plugin-ngp

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.