angularjs-test-coverage-inventory
Mine AngularJS test coverage signals (nearby specs, density, gaps); read-only metrics
# angularjs-test-coverage-inventory
Read-only mining codemod that correlates AngularJS app artifacts (module,
component, controller, service, directive registrations) with test signals
found in the same file, to help estimate test coverage risk before an
AngularJS → Angular migration.
Emits the `test_coverage_signal` metric. Does not modify any files.
## What it detects
For every JS/TS/TSX file scanned:
1. **`test_file`** — the filename matches a common test convention:
`*.spec.js`, `*.test.js`, `*_test.js`, `*-test.js`.
2. **`test_marker`** — a Jasmine/Mocha/`angular-mocks` call is present in the
file: `describe(`, `xdescribe(`, `fdescribe(`, `it(`, `xit(`, `fit(`,
`beforeEach(`, `afterEach(`, `beforeAll(`, `afterAll(`, `inject(`,
`module(`.
3. **`angular_artifact_without_test_markers`** — the file registers an
AngularJS `module`/`component`/`controller`/`service`/`directive` (via
`angular.module('app').<method>(...)`), the filename does **not** look
like a test file, and the file contains **no** test markers of its own.
## Cardinalities
| Field | Description |
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `file` | Relative file path |
| `line` | 1-based line number of the match |
| `snippet` | Truncated source snippet (whitespace-collapsed, 120 chars) |
| `signal_kind` | `test_file` \| `test_marker` \| `angular_artifact_without_test_markers` |
| `artifact_type` | For `test_file`: `test_file`. For `test_marker`: the marker name (e.g. `describe`, `inject`). For the missing-test signal: the AngularJS registration method (`module`, `component`, `controller`, `service`, `directive`). |
| `migration_category` | Always `testing` |
| `risk` | `low` \| `medium` \| `high` \| `critical` |
| `automation` | `full` \| `partial` \| `manual` |
| `effort_points` | Fibonacci effort estimate (`1`, `2`, `5`, ...) |
| `recommended_phase` | `phase-1` .. `phase-5` |
Risk/effort heuristics:
- Jasmine/Mocha lifecycle markers (`describe`, `it`, `beforeEach`, ...) are
low risk / fully automatable (`effort_points: 1`) — syntax carries over
almost directly to Jest/Karma+Jasmine on Angular.
- `inject(...)` and `module(...)` (from `angular-mocks`) are medium risk /
partially automatable (`effort_points: 2`) since they require a real
rewrite to `TestBed.configureTestingModule(...)`.
- AngularJS registrations with **no** test markers in the same file are
flagged high risk / manual (`effort_points: 5`, `phase-1`): write or
backfill tests **before** migrating that code, since regressions will be
invisible otherwise.
## Known limitation: file-local analysis only
JSSG codemods run per-file and cannot see sibling files. This codemod
**cannot** confirm whether a separate `*.spec.js` exists elsewhere for a
given source file — it can only tell you "this file has no test markers in
it". A source file with `describe(`/`it(` in a _different_ file will still
be flagged `angular_artifact_without_test_markers` here. Cross-reference this
metric's `file` values against your test file naming/co-location convention
(e.g. `foo.js` next to `foo.spec.js`) to filter out true negatives during
assessment.
Each AngularJS method-chain call site (e.g. every `.module('app')` in
`angular.module('app').controller(...)`) is counted independently, so a
single logical module can produce multiple `module` entries — this mirrors
how many risky call sites exist in the source, not how many distinct modules
exist.
## Installation
```bash
# Install from registry
codemod run angularjs-test-coverage-inventory
# Or run locally
codemod run -w workflow.yaml
```
## Development
```bash
# Test the transformation
pnpm test
# Validate the workflow
codemod workflow validate -w workflow.yaml
# Publish to registry
codemod login
codemod publish
```
## License
MIT