Files
anki/tools/coverage/coverage-ts.bat
Fernando Lins f9a5b36c82 feat: add TS test coverage (#4843)
## Linked issue

Closes #4840

## Summary / motivation

Adds Vitest V8 coverage for TypeScript/Svelte tests via
`@vitest/coverage-v8`.
Introduces `just test-ts --coverage` and `just test-ts --coverage
--html`,
and wires TypeScript into the `just test --coverage` umbrella —
completing
coverage support across all three stacks (Python, Rust, TypeScript).

The threshold is set to 5% — intentionally low because the Vitest test
count is small relative to the TypeScript/Svelte source surface. It is
meant to be raised as more tests are added.

## How to test

```sh
# Existing behavior unchanged
just test-ts

# Terminal summary + enforces 5% line coverage threshold
just test-ts --coverage

# Terminal summary + HTML report under out/coverage/typescript/
just test-ts --coverage --html

# Full umbrella — all three stacks
just test --coverage
just test --coverage --html
```

### Checklist

- [x] I ran `./ninja check` or an equivalent relevant check locally.

### Details

- `@vitest/coverage-v8` pinned at `3.2.4` in `package.json`.
- Reports are written to `out/coverage/typescript/` via
`--coverage.reportsDirectory=../out/coverage/typescript` (relative to
the `ts/` working directory where vitest runs).
- V8 provider is preferred over Istanbul: faster and requires no Babel
transform for TypeScript projects.
- Coverage measures only code reachable through Vitest's module graph —
Svelte component rendering is not covered.
- The `yarn` justfile variable is added for platform-aware yarn
invocation (Windows vs Unix).

## Before / after behavior

Before: no `just test-ts`, no TypeScript coverage.
After: `just test-ts` runs Vitest via ninja; `just test-ts --coverage`
runs with V8 instrumentation.
`just test --coverage` now spans all three stacks.

---------

Co-authored-by: Abdo <abdo@abdnh.net>
2026-05-18 11:54:16 -03:00

17 lines
546 B
Batchfile

@echo off
setlocal
set "outdir=out\coverage\typescript"
set "YARN=out\extracted\node\yarn.cmd"
if not exist %outdir% mkdir %outdir%
set "COVERAGE_ARGS=--coverage.enabled true --coverage.provider=v8 --coverage.reporter=text-summary --coverage.reporter=json-summary"
if "%1"=="--html" set "COVERAGE_ARGS=%COVERAGE_ARGS% --coverage.reporter=html"
%YARN% vitest:once %COVERAGE_ARGS% --coverage.reportsDirectory=..\%outdir% --coverage.thresholds.lines=5 || exit /b 1
if "%1"=="--html" (
echo TypeScript coverage report: %outdir%\index.html
)