VS Code extension concept to show and run Angular unit tests in Test Explorer by executing the Angular CLI test builder (ng test) instead of plain Vitest.
Angular component tests often require Angular's build/test pipeline (resource resolution, framework-specific setup). Running plain Vitest from generic runners can fail even when ng test passes.
Provide a native Test Explorer experience for Angular workspaces while preserving the current tests and runner behavior.
- Discover
*.spec.tsin Angular workspace(s) - Map each spec to its Angular project (
customer,manage,shared, etc.) - Run tests through
ng test --project <name> - Support run at file level and single-test level (best effort)
- Parse CLI output and reflect pass/fail in VS Code Testing view
- Expose extension settings for workspace root and command template
- Replacing Angular test infrastructure
- Custom bundling pipeline
- Snapshot tooling beyond what Angular CLI already supports
- Install dependencies:
npm install
- Build the extension:
npm run build
- Run unit tests:
npm test
- Open this repository in VS Code.
- Press
F5to launch the Extension Development Host. - In the new window, open a workspace that contains
*.spec.tsfiles. - Open the Testing view.
- Run:
Kate: Refresh Teststo rediscover specsKate: Run Selected Teststo run selected items
Current behavior (implemented through prompt milestone 05):
- Discovers files using
**/*.spec.tsacross workspace folders (monorepo-safe) - Populates the Testing tree grouped by Angular project, then spec files
- Supports optional test-label trimming via setting:
angularTestExplorer.projectsBasePathTrim
- Discovers in-file test cases from
describe/it/testusing a lightweight TypeScript AST pass and adds them as child test items - Detects Angular workspace roots from
angular.jsonper spec file - Supports optional workspace root override via setting:
angularTestExplorer.workspacePathOverride
- Maps spec files to Angular projects from
angular.json(root/sourceRoot) - Executes file-level test runs through Angular CLI via npm:
npm --prefix <workspace> run test -- --project <project> --watch=false --include <specPath>
- Supports configurable command template via:
angularTestExplorer.commandTemplateOverride- placeholders:
{workspace},{project},{spec},{watch},{testNamePattern} - quote placeholders when values may include spaces, for example:
--testNamePattern "{testNamePattern}"
- Supports default watch behavior via:
angularTestExplorer.defaultWatchMode(defaultfalse)
- Attempts single-test execution with:
--testNamePattern <fullTestName>
- Falls back deterministically to file-level execution when current Angular CLI context does not support
--testNamePattern, and reports fallback in output - Streams Angular CLI stdout/stderr to test run output and marks each test item as pass/fail/error
- Normalizes streamed CLI output for cleaner Test Results rendering
- Supports optional project-aware parallelization (different projects in parallel, same project serialized)
- Supports cancellation by terminating the in-flight Angular CLI process
- Automatically refreshes discovered tests (debounced) when
*.spec.ts,angular.json, or extension settings change - Reports actionable diagnostics for missing Angular CLI/tooling context and project mapping failures
angularTestExplorer.workspacePathOverride- Type:
string(default: empty) - Optional workspace root override used to locate
angular.json. Relative paths resolve from the active workspace folder.
- Type:
angularTestExplorer.commandTemplateOverride- Type:
string(default: empty) - Optional test command template with placeholders:
{workspace},{project},{spec},{watch},{testNamePattern}. - Quote placeholders when values may contain spaces, for example:
--testNamePattern "{testNamePattern}".
- Type:
angularTestExplorer.defaultWatchMode- Type:
boolean(default:false) - Default watch value passed into Angular test execution.
- Type:
angularTestExplorer.parallelizeByProject- Type:
boolean(default:true) - When enabled, file runs are parallelized per Angular project while preserving sequential execution within each project.
- Type:
angularTestExplorer.projectsBasePathTrim- Type:
string(default: empty) - Trims a matching path prefix from discovered spec labels in the Testing view.
- Example:
apps/tableside/projectsturnsapps/tableside/projects/customer/src/...intocustomer/src/....
- Type:
- No tests appear in the Testing view:
- Ensure the opened workspace contains files matching
**/*.spec.ts. - Run
Kate: Refresh Tests.
- Ensure the opened workspace contains files matching
- Project mapping fails:
- Confirm the relevant workspace has a valid
angular.json. - If auto-detection picks the wrong root, set
angularTestExplorer.workspacePathOverride.
- Confirm the relevant workspace has a valid
- Angular CLI command fails to start:
- Verify workspace dependencies are installed and
npm run testworks for the target project. - If your workspace needs a different invocation shape, set
angularTestExplorer.commandTemplateOverride.
- Verify workspace dependencies are installed and
- Single-test run falls back to file-level:
- This occurs when the current Angular CLI context does not accept
--testNamePattern. - Check test output for the explicit fallback note.
- This occurs when the current Angular CLI context does not accept
docs/images/testing-view.png(placeholder)docs/images/single-test-run.png(placeholder)docs/images/fallback-output.png(placeholder)
Build and validate before packaging:
- Install dependencies:
npm install
- Run lint and tests:
npm run lintnpm test
- Build extension output:
npm run build
- Package VSIX:
npx @vscode/vsce package --pre-release
Expected artifact:
./kimdim-angular-test-explorer-<version>.vsix
Notes:
- CI syncs
package.jsonversion fromversion.jsonusing Nerdbank.GitVersioning before packaging. - CI currently packages as prerelease using
--pre-release.