headlamp 0.1.17 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,159 +1,187 @@
1
1
  # Headlamp CLI
2
2
 
3
- Coverage-first, runner-agnostic test UX for Jest/Vitest. Delegates execution to your runner, focuses on better selection and coverage insights.
3
+ Coverage-first, runner-agnostic test UX for Jest. Delegates execution to your runner, focuses on better selection and coverage insights.
4
4
 
5
5
  ## Install
6
6
 
7
- Only in /Users/david/src/headlamp/src/lib: PLACEHOLDER
8
- Only in /Users/david/src/headlamp/src/lib: \_exec.ts
9
- Files /Users/david/src/gigworx-node/scripts/cli/coverage-print.ts and /Users/david/src/headlamp/src/lib/coverage-print.ts differ
10
- Files /Users/david/src/gigworx-node/scripts/cli/discovery.ts and /Users/david/src/headlamp/src/lib/discovery.ts differ
11
- Only in /Users/david/src/headlamp/src/lib: env-utils.ts
12
- Only in /Users/david/src/headlamp/src/lib: fast-related.ts
13
- Files /Users/david/src/gigworx-node/scripts/cli/graph-distance.ts and /Users/david/src/headlamp/src/lib/graph-distance.ts differ
14
- Files /Users/david/src/gigworx-node/scripts/cli/index.ts and /Users/david/src/headlamp/src/lib/index.ts differ
15
- Files /Users/david/src/gigworx-node/scripts/cli/program.ts and /Users/david/src/headlamp/src/lib/program.ts differ
7
+ Use via npx (recommended):
16
8
 
17
- ## Usage
9
+ ```bash
10
+ npx headlamp --help
11
+ ```
18
12
 
19
- removed
20
- removed
13
+ Or install locally:
14
+
15
+ ```bash
16
+ npm i -D headlamp
17
+ ```
21
18
 
22
- - Delegates to your local Jest/Vitest install
19
+ ## Usage
20
+
21
+ - Delegates to your local Jest install
23
22
  - Renders improved coverage tables and hotspots
24
23
  - Selects tests by import-graph when you pass production paths
25
24
 
26
- ## Why
25
+ Quick examples:
27
26
 
28
- - Keep Jest/Vitest as-is. Get a better UI/UX for coverage and selection.
27
+ ```bash
28
+ # Run tests with coverage
29
+ npx headlamp --coverage
29
30
 
30
- ## Status
31
+ # Run only tests related to selected production files
32
+ npx headlamp src/services/user.ts src/components/UserCard.tsx
33
+ ```
31
34
 
32
- Alpha. API/CLI flags may change.
33
- und hotspots
35
+ ## CLI flags
34
36
 
35
- - `--coverage.mode=compact|full|auto`: compact table vs full per-file details
36
- - `--coverage.maxFiles`, `--coverage.maxHotspots`: limit rows to fit your terminal
37
- - `--coverage.pageFit=true|false`: adapt output to terminal rows
37
+ Pass your regular Jest flags (e.g. `-t`, `--testNamePattern`, paths). Headlamp forwards them, and strips/adjusts coverage-related flags when listing tests.
38
38
 
39
- Pass all your regular Jest flags (e.g. `-t`, `--testNamePattern`, paths). Headlamp strips/adjusts coverage-related flags when listing tests.
39
+ ### General
40
40
 
41
- ## Examples
41
+ - `--bootstrapCommand <cmd>`: run once before tests (npm script name or full shell command)
42
+ - `--onlyFailures[=true|false]`: show only failing tests during live output; always shows final summary
43
+ - `--showLogs[=true|false]`: include full console output under failing tests/files
42
44
 
43
- - Show coverage with detailed hotspots, auto-fit to terminal rows:
45
+ ### Concurrency
44
46
 
45
- ```bash
46
- npx headlamp --coverage
47
- ```
47
+ - `--sequential[=true|false]`: serialize execution
48
+ - Effect: adds Jest `--runInBand` and runs Headlamp’s per‑project execution with stride 1 (no parallel projects)
48
49
 
49
- - Focus on specific production files and run only directly-related tests:
50
+ ### Selection
50
51
 
51
- ```bash
52
- npx headlamp --coverage src/services/user.ts src/components/UserCard.tsx
53
- ```
52
+ - `paths...`: any file/dir paths; production paths trigger related test discovery by import graph
53
+ - `-t <pattern>` / `--testNamePattern <pattern>`: filter by test name
54
+ - `--changed[=all|staged|unstaged|branch|lastCommit]`: select tests related to changed files
55
+ - `--changed.depth=<n>`: cap transitive import scan depth for changed-file discovery (default: 5)
54
56
 
55
- ## Output flags
57
+ ### Coverage
56
58
 
57
- - `--onlyFailures[=true|false]`:
58
- - When enabled, the CLI prints only failing tests during execution across all views, while still printing the final test summary (files/tests/time) at the end.
59
- - Supported forms: `--onlyFailures`, `--onlyFailures=true`, `--onlyFailures=false`.
60
- - Works with other selection flags (e.g., `-t`, `--changed`).
59
+ - `--coverage`: enable coverage collection and merged reporting
60
+ - `--coverage.ui=jest|both` (alias: `--coverage-ui`): output mode for Istanbul text reports (default: `both`)
61
+ - `--coverage.abortOnFailure`: exit immediately with test code and skip coverage print on failures
62
+ - Display/detail options:
63
+ - `--coverage.mode=compact|full|auto` (default: `auto`)
64
+ - `--coverage.detail=<n>|all|auto` (default: `auto`)
65
+ - `--coverage.showCode=true|false` (default: `true` on TTY)
66
+ - `--coverage.maxFiles=<n>`
67
+ - `--coverage.maxHotspots=<n>`
68
+ - `--coverage.pageFit=true|false` (default: `true` on TTY)
69
+ - Globbing filters: `--coverage.include=a,b,c`, `--coverage.exclude=a,b,c`
61
70
 
62
- Examples:
71
+ ## Configuration
63
72
 
64
- ```bash
65
- # Show only failures during the run, but still print the final summary
66
- npx headlamp --onlyFailures
73
+ Project-level file at repo root. CLI always overrides config. No env vars or hidden presets.
67
74
 
68
- # Combine with changed-file selection
69
- npx headlamp --changed --onlyFailures
70
- ```
75
+ ### Supported filenames
71
76
 
72
- - `--showLogs[=true|false]`:
73
- - When enabled, Headlamp prints a dedicated "Logs" section under each failing test and failing file with the full console output captured by the runner.
74
- - By default (without this flag), Headlamp shows a condensed "Console errors" snippet with only the most relevant error messages. `--showLogs` includes all console entries (log/info/warn/error).
75
- - Supported forms: `--showLogs`, `--showLogs=true`, `--showLogs=false`.
76
- - Works alongside `--onlyFailures`, coverage flags, and selection flags.
77
+ - `headlamp.config.ts`
78
+ - `headlamp.config.js` / `headlamp.config.mjs` / `headlamp.config.cjs`
79
+ - `headlamp.config.json` / `headlamp.config.yaml` / `headlamp.config.yml`
77
80
 
78
- Examples:
81
+ ### Base defaults (always applied)
79
82
 
80
- ```bash
81
- # Always include the full console output for each failure
82
- npx headlamp --showLogs
83
+ - `bootstrapCommand: string`
84
+ - `jestArgs: string[]`
85
+ - `sequential?: boolean` – serialize tests across Jest and Headlamp
83
86
 
84
- # Combine with only failures visible during the run
85
- npx headlamp --onlyFailures --showLogs
86
- ```
87
+ ### Coverage-context defaults (applied only when coverage is active)
87
88
 
88
- ## Changed-file selection
89
-
90
- - `--changed[=mode]` selects tests by files changed in your working tree or branch.
91
- - Modes:
92
- - `all` (default when `--changed` is passed without a value): includes staged + unstaged + untracked files.
93
- - `staged`: only staged changes.
94
- - `unstaged`: only unstaged + untracked files.
95
- - `branch`: union of
96
- - files changed on the current branch relative to the default branch (via merge-base), and
97
- - your current uncommitted changes (staged, unstaged tracked, and untracked files).
98
- - Default branch is resolved via `origin/HEAD` when available, falling back to `origin/main` or `origin/master`.
99
- - Effects:
100
- - Uses changed production files as seeds to discover related tests by import-graph.
101
- - Coverage tables prioritize and annotate files related to selection/changed files.
102
- - Additional flags:
103
- - `--changed.depth=<n>`: cap the transitive import scan depth when refining related tests from changed production files. Default: 5. Increase to include more indirectly-related tests (slower), decrease for speed.
89
+ Prefer the nested `coverage` section:
104
90
 
105
- Examples:
91
+ ```ts
92
+ export default {
93
+ coverage: {
94
+ abortOnFailure: true, // -> --coverage.abortOnFailure
95
+ mode: 'auto', // -> --coverage.mode=auto
96
+ pageFit: true, // -> --coverage.pageFit=true
97
+ },
98
+ };
99
+ ```
106
100
 
107
- ```bash
108
- # Staged changes only
109
- npx headlamp --changed=staged
101
+ Additional recognized fields when coverage is active:
110
102
 
111
- # All working tree changes
112
- npx headlamp --changed
103
+ - `editorCmd` -> `--coverage.editor`
104
+ - `include`, `exclude` -> `--coverage.include`, `--coverage.exclude`
105
+ - `coverageDetail`, `coverageShowCode`, `coverageMaxFiles`, `coverageMaxHotspots`
113
106
 
114
- # Diff current branch against default branch (merge-base)
115
- npx headlamp --changed=branch
107
+ ### Changed-context defaults (applied only when changed selection is active)
116
108
 
117
- # Combine with coverage
118
- npx headlamp --coverage --changed=branch
109
+ ```ts
110
+ export default {
111
+ changed: {
112
+ depth: 20, // default for all modes -> --changed.depth=20
113
+ branch: { depth: 10 },
114
+ staged: { depth: 8 },
115
+ unstaged: { depth: 6 },
116
+ all: { depth: 12 },
117
+ },
118
+ };
119
119
  ```
120
120
 
121
- Depth examples:
121
+ You may also set a top‑level default mode (e.g., `changed: 'branch'`); CLI still wins.
122
122
 
123
- ```bash
124
- # Scan imports up to 10 levels deep when resolving related tests for changed files
125
- npx headlamp --changed=all --changed.depth=10
123
+ ### Full example
126
124
 
127
- # With branch mode
128
- npx headlamp --changed=branch --changed.depth=12
125
+ ```ts
126
+ // headlamp.config.ts
127
+ export default {
128
+ // Base
129
+ bootstrapCommand: 'test:jest:bootstrap',
130
+ sequential: true, // serialize tests (maps to Jest --runInBand and single-project stride)
131
+ jestArgs: ['--runInBand'], // optional: redundant when sequential is true
132
+
133
+ // Coverage-context
134
+ coverage: {
135
+ abortOnFailure: true,
136
+ mode: 'auto',
137
+ pageFit: true,
138
+ },
139
+
140
+ // Changed-context
141
+ changed: {
142
+ depth: 20,
143
+ branch: { depth: 10 },
144
+ },
145
+ };
129
146
  ```
130
147
 
131
- ## Coverage flags
132
-
133
- - `--coverage`: enables coverage collection and prints merged coverage output after test execution. Uses your project's Jest/Vitest setup and reads coverage JSON from Jest.
134
- - Prints a compact per-file table with hotspots and optionally detailed per-file breakdowns.
135
- - Honors file selection and include/exclude globs when rendering coverage tables.
136
- - When `--changed` is specified, coverage views factor in those changed files as selection seeds, influencing relevancy ordering and the “changed-related” highlighting.
137
- - `--coverage.abortOnFailure`: if tests fail, exit immediately with the test exit code and skip coverage printing. Useful in CI when failures should short-circuit.
138
- - `--coverage.ui=jest|both`:
139
- - `jest`: write Istanbul text report to `coverage/merged/coverage.txt` only.
140
- - `both` (default): write both `coverage.txt` and `coverage-summary.txt`.
141
- - Display and filtering options:
142
- - `--coverage.mode=compact|full|auto` (default: `auto`): choose compact table-only or full per-file details.
143
- - `--coverage.detail=<n>|all|auto` (default: `auto`): number of uncovered lines per file to show; `all` shows everything.
144
- - `--coverage.showCode=true|false` (default: `true` when TTY): show code snippets for uncovered lines in full mode.
145
- - `--coverage.maxFiles=<n>`: limit number of files in printed tables.
146
- - `--coverage.maxHotspots=<n>`: limit hotspots per file in compact mode.
147
- - `--coverage.pageFit=true|false` (default: `true` when TTY): fit output to terminal rows.
148
+ ## Scripts
149
+
150
+ ```json
151
+ {
152
+ "scripts": {
153
+ "test": "headlamp --sequential",
154
+ "test:coverage": "headlamp --coverage --sequential",
155
+ "test:dev": "npm run test -- --changed=branch --coverage --onlyFailures"
156
+ }
157
+ }
158
+ ```
159
+
160
+ ## Bootstrap command
161
+
162
+ Use `--bootstrapCommand` to run setup work before tests (e.g., database migrations/seeding). If omitted, no bootstrap runs.
163
+
164
+ - Single token: treated as an npm script name and run as `npm run -s <name>`
165
+ - With spaces: treated as a full command and executed via the system shell
148
166
 
149
167
  Examples:
150
168
 
169
+ ```bash
170
+ npx headlamp --bootstrapCommand test:jest:bootstrap
171
+ npx headlamp --bootstrapCommand "sequelize db:migrate --env test"
172
+ ```
173
+
174
+ ## Examples
175
+
151
176
  ```bash
152
177
  # Abort on failing tests without printing coverage
153
178
  npx headlamp --coverage --coverage.abortOnFailure
154
179
 
155
180
  # Show compact coverage limited to 50 files and 5 hotspots per file
156
181
  npx headlamp --coverage --coverage.mode=compact --coverage.maxFiles=50 --coverage.maxHotspots=5
182
+
183
+ # Sequential run to avoid DB deadlocks
184
+ npx headlamp --sequential
157
185
  ```
158
186
 
159
187
  ## Editor links
@@ -162,7 +190,7 @@ Headlamp prints clickable links (OSC 8) to open files at hotspots. Set `--covera
162
190
 
163
191
  ## API
164
192
 
165
- You can import pieces programmatically:
193
+ Programmatic use:
166
194
 
167
195
  ```ts
168
196
  import { printCompactCoverage, resolveImportWithRoot } from 'headlamp';