headlamp 0.1.16 → 0.1.18

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
@@ -38,6 +38,140 @@ und hotspots
38
38
 
39
39
  Pass all your regular Jest flags (e.g. `-t`, `--testNamePattern`, paths). Headlamp strips/adjusts coverage-related flags when listing tests.
40
40
 
41
+ ## Configuration
42
+
43
+ Headlamp supports a project-level config file. The config is explicit and contextual:
44
+
45
+ - Base defaults: always applied (safe, non-surprising)
46
+ - Coverage-context defaults: only applied if coverage is active (i.e., you passed `--coverage` or you set `coverage: true` in config)
47
+ - Changed-context defaults: only applied if changed selection is active (i.e., you passed `--changed=…` or set a default mode in config)
48
+
49
+ CLI always overrides config. No environment variables or hidden presets are used.
50
+
51
+ ### Supported filenames (repo root)
52
+
53
+ - `headlamp.config.ts`
54
+ - `headlamp.config.js` / `headlamp.config.mjs` / `headlamp.config.cjs`
55
+ - `headlamp.config.json` / `headlamp.config.yaml` / `headlamp.config.yml`
56
+
57
+ ### Base defaults (always applied)
58
+
59
+ These are applied to every run and should be non-controversial project choices:
60
+
61
+ - `bootstrapCommand: string` – command or npm script to run before tests
62
+ - `jestArgs: string[]` – extra args passed to Jest (e.g., `['--runInBand']`)
63
+
64
+ Example:
65
+
66
+ ```ts
67
+ // headlamp.config.ts
68
+ export default {
69
+ bootstrapCommand: 'test:jest:bootstrap',
70
+ jestArgs: ['--runInBand'],
71
+ };
72
+ ```
73
+
74
+ ### Coverage-context defaults
75
+
76
+ Applied only when coverage is active (triggered by `--coverage` on the CLI or `coverage: true` in config). Prefer the nested `coverage` section:
77
+
78
+ ```ts
79
+ export default {
80
+ coverage: {
81
+ abortOnFailure: true, // -> --coverage.abortOnFailure
82
+ mode: 'auto', // -> --coverage.mode=auto
83
+ pageFit: true, // -> --coverage.pageFit=true
84
+ },
85
+ };
86
+ ```
87
+
88
+ Optional extras (honored when coverage is active):
89
+
90
+ - `editorCmd` -> `--coverage.editor`
91
+ - `include: string[]` -> `--coverage.include=a,b,c`
92
+ - `exclude: string[]` -> `--coverage.exclude=a,b,c`
93
+ - `coverageDetail: number | 'all' | 'auto'` -> `--coverage.detail`
94
+ - `coverageShowCode: boolean` -> `--coverage.showCode`
95
+ - `coverageMaxFiles: number` -> `--coverage.maxFiles`
96
+ - `coverageMaxHotspots: number` -> `--coverage.maxHotspots`
97
+
98
+ Back-compat: legacy top-level fields (`coverageAbortOnFailure`, `coverageMode`, `coveragePageFit`, etc.) are still recognized, but the nested `coverage` section is preferred.
99
+
100
+ ### Changed-context defaults
101
+
102
+ Applied only when changed selection is active (triggered by `--changed=…` on the CLI, or by specifying a default mode in config). Prefer the nested `changed` section:
103
+
104
+ ```ts
105
+ export default {
106
+ changed: {
107
+ depth: 20, // default depth for all modes -> --changed.depth=20
108
+ branch: {
109
+ depth: 10, // per-mode override when --changed=branch
110
+ },
111
+ staged: {
112
+ depth: 8,
113
+ },
114
+ unstaged: {
115
+ depth: 6,
116
+ },
117
+ all: {
118
+ depth: 12,
119
+ },
120
+ },
121
+ };
122
+ ```
123
+
124
+ If you also want to enforce a default mode for everyone, you can set a string at the legacy top-level: `changed: 'branch'`. Headlamp will emit `--changed=branch` unless the CLI already specified a mode. Otherwise, prefer to let scripts opt-in on the CLI and keep config focused on depth/details.
125
+
126
+ ### Precedence and gating rules
127
+
128
+ - CLI always wins. If you pass `--coverage.mode=full`, it overrides the config’s `coverage.mode`.
129
+ - Coverage extras only apply when coverage is active.
130
+ - Changed depth only applies when changed selection is active. If a per‑mode depth exists, it’s used; otherwise we fall back to the default `changed.depth`.
131
+
132
+ ### Example configs and scripts
133
+
134
+ Config (headlamp.config.ts):
135
+
136
+ ```ts
137
+ export default {
138
+ // Base
139
+ bootstrapCommand: 'test:jest:bootstrap',
140
+ jestArgs: ['--runInBand'],
141
+
142
+ // Coverage-context
143
+ coverage: {
144
+ abortOnFailure: true,
145
+ mode: 'auto',
146
+ pageFit: true,
147
+ },
148
+
149
+ // Changed-context
150
+ changed: {
151
+ depth: 20,
152
+ branch: { depth: 10 },
153
+ },
154
+ };
155
+ ```
156
+
157
+ Scripts:
158
+
159
+ ```json
160
+ {
161
+ "scripts": {
162
+ "test": "headlamp --runInBand",
163
+ "test:coverage": "headlamp --coverage --runInBand",
164
+ "test:dev": "npm run test -- --changed=branch --coverage --onlyFailures"
165
+ }
166
+ }
167
+ ```
168
+
169
+ Resulting behavior:
170
+
171
+ - `headlamp --runInBand`: base defaults only; no coverage/changed extras.
172
+ - `headlamp --coverage --runInBand`: applies coverage abortOnFailure/mode/pageFit; changed depth is not applied.
173
+ - `headlamp --changed=branch --coverage --onlyFailures`: applies per‑mode changed depth (10) and coverage group; `onlyFailures` is opt‑in via CLI.
174
+
41
175
  ## Examples
42
176
 
43
177
  - Show coverage with detailed hotspots, auto-fit to terminal rows:
@@ -52,6 +186,31 @@ npx headlamp --coverage
52
186
  npx headlamp --coverage src/services/user.ts src/components/UserCard.tsx
53
187
  ```
54
188
 
189
+ ## Bootstrap command
190
+
191
+ Use `--bootstrapCommand` to run setup work before tests (e.g., database migrations/seeding). If omitted, no bootstrap runs.
192
+
193
+ - Single token value is treated as an npm script name and run as `npm run -s <name>`.
194
+ - Values containing whitespace are treated as full commands and executed via the system shell.
195
+
196
+ Examples:
197
+
198
+ ```bash
199
+ # 1) Run an npm script before tests
200
+ npx headlamp --bootstrapCommand test:jest:bootstrap
201
+
202
+ # 2) Run an npm script with its own args
203
+ npx headlamp --bootstrapCommand "db:migrate -- --reset"
204
+
205
+ # 3) Run an arbitrary command (e.g., sequelize migrations for test env)
206
+ npx headlamp --bootstrapCommand "sequelize db:migrate --env test"
207
+
208
+ # 4) Seed a test database via a node script
209
+ npx headlamp --bootstrapCommand "node scripts/seed-test-db.js"
210
+ ```
211
+
212
+ This bootstrap step executes once before Jest is started. If the bootstrap exits non‑zero, the run aborts with an error.
213
+
55
214
  ## Output flags
56
215
 
57
216
  - `--onlyFailures[=true|false]`:
@@ -69,20 +228,20 @@ npx headlamp --onlyFailures
69
228
  npx headlamp --changed --onlyFailures
70
229
  ```
71
230
 
72
- - `--showConsole[=true|false]`:
231
+ - `--showLogs[=true|false]`:
73
232
  - 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. `--showConsole` includes all console entries (log/info/warn/error).
75
- - Supported forms: `--showConsole`, `--showConsole=true`, `--showConsole=false`.
233
+ - 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).
234
+ - Supported forms: `--showLogs`, `--showLogs=true`, `--showLogs=false`.
76
235
  - Works alongside `--onlyFailures`, coverage flags, and selection flags.
77
236
 
78
237
  Examples:
79
238
 
80
239
  ```bash
81
240
  # Always include the full console output for each failure
82
- npx headlamp --showConsole
241
+ npx headlamp --showLogs
83
242
 
84
243
  # Combine with only failures visible during the run
85
- npx headlamp --onlyFailures --showConsole
244
+ npx headlamp --onlyFailures --showLogs
86
245
  ```
87
246
 
88
247
  ## Changed-file selection
@@ -96,6 +255,7 @@ npx headlamp --onlyFailures --showConsole
96
255
  - files changed on the current branch relative to the default branch (via merge-base), and
97
256
  - your current uncommitted changes (staged, unstaged tracked, and untracked files).
98
257
  - Default branch is resolved via `origin/HEAD` when available, falling back to `origin/main` or `origin/master`.
258
+ - `lastCommit`: files changed in the last commit (`git diff --name-only HEAD^ HEAD`). Useful on main to scope to the most recent change.
99
259
  - Effects:
100
260
  - Uses changed production files as seeds to discover related tests by import-graph.
101
261
  - Coverage tables prioritize and annotate files related to selection/changed files.