bivium 0.6.1 → 0.7.0

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/docs/config.md CHANGED
@@ -1,54 +1,340 @@
1
1
  # Config
2
2
 
3
- bivium reads `bivium.config.ts` from the repository root;
4
- every key, and the comments a file can carry, are below.
3
+ The config names your test suites and tells bivium the dependencies it
4
+ can't read from your imports.
5
5
 
6
- `bivium.config.ts` (or `.mts`, `.mjs`, `.js`, `.json`) in the repository
7
- root, or `--config <file>`.
6
+ ```ts
7
+ // bivium.config.ts
8
+ import { defineConfig } from "bivium";
9
+
10
+ export default defineConfig({
11
+ suites: {
12
+ unit: {
13
+ tests: "tests/**/*.test.ts",
14
+ run: "vitest run {files}",
15
+ root: "tests", // a changed file here that no test reaches runs the suite
16
+ setup: ["tests/setup.ts"], // the runner loads it before every test
17
+ types: false, // Vitest runs code, so type-only imports select nothing
18
+ },
19
+ },
20
+ roots: ["src", "tests"], // a changed file outside them runs everything
21
+ ignore: ["docs/**"], // no test can observe these
22
+ });
23
+ ```
24
+
25
+ ## The config file
26
+
27
+ bivium reads the first of `bivium.config.ts`, `.mts`, `.mjs`,
28
+ `.js` and `.json` it finds in the repository root.
29
+ `--config <file>` names another file.
8
30
  A `.ts` config needs Bun or Node ≥ 22.18.
9
- Every glob key takes one glob or a list.
10
- An unknown key is an error, since a misspelled one would quietly select
11
- less.
31
+ `defineConfig` returns the config unchanged, with its types checked.
32
+
33
+ Every glob key takes one glob or a list of globs.
34
+ An unknown key is an error: a misspelled key would otherwise select
35
+ fewer tests without saying so.
36
+
37
+ ## Suites
38
+
39
+ Each entry under `suites` is one suite:
40
+ a set of test files and the command that runs them.
41
+ `plan` reports a selection per suite, and `run --suite <name>` runs one.
42
+
43
+ | Key | Sets | Default |
44
+ |:---|:---|:---|
45
+ | `tests` | The suite's test files | required |
46
+ | `run` | The command `bivium run` runs | none; `bivium run` needs one |
47
+ | `root` | Where the orphan rule applies | the whole repository |
48
+ | `urls` | URL pattern → the page a `page.goto()` opens | none |
49
+ | `pages` | Pages only a `goto()` opens | none |
50
+ | `setup` | Files the runner loads before every test | none |
51
+ | `wiring` | Files whose change runs the whole suite: another harness, a runner config | none |
52
+ | `nonInputs` | Files under `root` the runner never reads, such as type-check inputs | none |
53
+ | `types` | Whether the suite's tests can observe types | `true` |
54
+ | `output` | The step output `plan --github` writes | `<name>-tests` |
55
+
56
+ ### `run`
57
+
58
+ `bivium run` puts the selected files where `{files}` is:
59
+ `vitest run {files}` runs `vitest run tests/a.test.ts tests/b.test.ts`.
60
+ When the whole suite is selected, `{files}` becomes nothing,
61
+ and the command runs with no files.
62
+ Without `{files}`, the files go at the end of the command.
63
+
64
+ ### `root` and the orphan rule
65
+
66
+ The orphan rule runs a whole suite when a file under its `root` changes
67
+ and no test of the suite reaches it.
68
+ bivium takes such a file to be wired some other way,
69
+ such as a setup file or a runner config.
70
+ `root` is also where bivium reads `page.goto()` calls.
71
+
72
+ `root` takes paths, not globs: `e2e`, not `e2e/**`.
73
+ A glob is an error.
74
+ To keep the rule from running a suite for files that aren't test inputs,
75
+ see [A change no test reaches](tuning.md#a-change-no-test-reaches).
76
+
77
+ ### `urls` and `pages`
78
+
79
+ For a browser suite, `urls` turns each `page.goto()` call under `root`
80
+ into an edge, a dependency the graph follows, to the page it opens.
81
+ A list value names the page first, then what else it loads that no
82
+ import says, such as a router's layouts:
83
+
84
+ ```ts
85
+ urls: {
86
+ "/*": ["app/(site)/*/page.tsx", "app/(site)/layout.tsx", "app/layout.tsx"],
87
+ },
88
+ ```
89
+
90
+ The page must exist, or the `goto()` is unknown.
91
+ The rest become edges where their files exist.
92
+
93
+ `pages` lists the pages only a `goto()` opens.
94
+ A listed page that no test opens is wired to no test,
95
+ and so are the files only such pages load.
96
+ A change to one selects nothing, and doesn't run the suite by the
97
+ orphan rule.
98
+
99
+ ### `setup` and `wiring`
12
100
 
13
- | Key | Meaning |
101
+ bivium doesn't read the runner's config,
102
+ so name the files the runner loads on its own.
103
+ `setup` is for the files it loads before every test:
104
+ Vitest and Jest `setupFiles`, Mocha `--require`,
105
+ Playwright `globalSetup`.
106
+ Every test of the suite depends on them and on what they import.
107
+
108
+ `wiring` is for files whose change runs the whole suite,
109
+ such as a second harness or a runner config.
110
+
111
+ ### `types`
112
+
113
+ Set `types: false` on a suite that runs code and can't observe types:
114
+ Vitest, Jest, Playwright, `bun test`.
115
+ A change that reaches its tests only through type-only edges
116
+ then selects none of them.
117
+ Type-only edges are `import type`, `export type … from`, JSDoc types,
118
+ and declaration files.
119
+ The default, `true`, is what a type-checking suite needs,
120
+ such as `tsc` or `vitest --typecheck`.
121
+
122
+ An inline `import { type A }` is always an edge:
123
+ under `verbatimModuleSyntax`, it still loads the module.
124
+
125
+ With `types: false`, the orphan rule counts a type-only reach only for a
126
+ declaration file, since the runner may load any other file by name.
127
+ List a types-only module under `root` in `nonInputs`.
128
+
129
+ ## What the graph reads
130
+
131
+ The graph is bivium's map of which file depends on which.
132
+ These keys set which files it reads and how it resolves imports.
133
+
134
+ | Key | Sets | Default |
135
+ |:---|:---|:---|
136
+ | `roots` | Paths the graph reads | the whole repository |
137
+ | `alias` | Specifier prefix → path, as the bundler aliases it | none |
138
+ | `extensions` | Suffixes tried after a specifier | the list below |
139
+ | `barrels` | Modules that may bind named imports | every module made only of re-exports |
140
+ | `external` | Packages a dependency installs that your code imports without declaring | none |
141
+
142
+ `roots` takes paths, directories or files, not globs.
143
+ A changed file outside the roots that isn't ignored runs everything.
144
+ That is the backstop for wiring the graph can't see,
145
+ such as a CI workflow.
146
+
147
+ `alias` is tried before tsconfig `paths` and `package.json` `exports`.
148
+ A key ending in `/` is a prefix, as Vite reads it:
149
+ `{ "@/": "src/" }` maps `@/x` to `src/x`.
150
+
151
+ `extensions` defaults to `.ts`, `.tsx`, `.mts`, `.cts`, `.js`, `.jsx`,
152
+ `.mjs`, `.cjs`, `.d.ts`, `.svelte`, `.vue` and `.json`, in that order.
153
+ A list you set replaces it.
154
+
155
+ A barrel is a module made only of re-exports, such as an `index.ts`.
156
+ bivium can trace a named import from one to the single file that exports
157
+ the name, as [What it reads](how-it-works.md#what-it-reads) describes.
158
+ `barrels` limits which modules get that treatment.
159
+
160
+ `external` is for packages a dependency installs that your code imports
161
+ without declaring.
162
+ An import of any other package no `package.json` declares is unknown:
163
+ bivium counts the importing file as depending on every change.
164
+
165
+ ## Files with a fixed effect
166
+
167
+ These keys mark files that need a rule of their own.
168
+
169
+ | Key | Names |
14
170
  |:---|:---|
15
- | `suites.<name>.tests` | The suite's test files |
16
- | `suites.<name>.run` | The command `bivium run` runs. `{files}` is replaced by the selection (nothing for `all`); without it, the files are appended |
17
- | `suites.<name>.root` | Where the orphan rule applies: a changed file here that no test of the suite reaches is wired some other way (a setup file, a runner config), so the whole suite runs. Paths, not globs (`e2e`, not `e2e/**`): a glob is an error. Default: the whole repository |
18
- | `suites.<name>.urls` | URL pattern → file pattern, for `page.goto()` calls under `root`. A list names the page first, then what else it loads that no import says, such as a router's layouts: `{ "/*": ["app/(site)/*/page.tsx", "app/(site)/layout.tsx", "app/layout.tsx"] }`. The page must exist; the rest are edges where they do |
19
- | `suites.<name>.pages` | Pages only a `goto()` opens; files only they load are wired to no test |
20
- | `suites.<name>.setup` | Files the runner loads before every test (Vitest and Jest `setupFiles`, Mocha `--require`, Playwright `globalSetup`): every test of the suite depends on them and what they import. bivium doesn't read the runner's config, so name them here |
21
- | `suites.<name>.wiring` | Files whose change runs the whole suite: another harness, a runner config |
22
- | `suites.<name>.nonInputs` | Files under `root` the runner never reads, such as type-check inputs |
23
- | `suites.<name>.types` | `false` when the suite runs code and can't observe types (Vitest, Jest, Playwright, `bun test`): a change that reaches its tests only through `import type`, `export type … from`, JSDoc types or a declaration file selects none of them. For the orphan rule a type-only reach counts only for a declaration file, since the runner may load any other file by name: list a types-only module under `root` in `nonInputs`. Default: `true`, which a type-checking suite (`tsc`, `vitest --typecheck`) needs. An inline `import { type A }` is always an edge: under `verbatimModuleSyntax` it still loads the module |
24
- | `suites.<name>.output` | The step output `plan --github` writes. Default: `<name>-tests` |
25
- | `roots` | Paths (not globs) the graph reads. A changed file outside them that isn't ignored runs everything. Default: the whole repository |
26
- | `ignore` | Files no test can observe except through an edge (docs, stories). A change to one selects only the tests that reach it, never runs a suite by the orphan rule, and doesn't select the tests whose dependencies are unknown |
27
- | `alias` | Specifier prefix → path, as the bundler aliases it. Tried before tsconfig `paths` and `package.json` `exports`. A key ending in `/` is the prefix, as Vite reads it: `{ "@/": "src/" }` maps `@/x` to `src/x` |
28
- | `edges` | Generated file glob → its inputs, which it depends on transitively, as with `@depends-on`: `{ "dist/*.css": "styles/**" }`. A key may name files git doesn't list, such as a gitignored generator output (`{ ".velite/*": "content/**" }`): an import that resolves under it, by extension or as an index, lands on that file instead of being unresolved. In a value, `$1`, `$2`… are what the key's wildcards matched, counted from the left: `{ "examples/*/package.json": "examples/$1/**" }` |
29
- | `reads` | File glob → the files it reads as text, as with `@reads`: only a direct change to one counts, so their imports and unknowns don't spread to it. An `edges` or `reads` key that names one file (no wildcard) declares what it reads, as its own `@depends-on` or `@reads` would, so its disk reads aren't unknown. Values take `$1`… as in `edges`: `{ "tests/*.test.ts": "tests/__snapshots__/$1.test.ts.snap" }` |
30
- | `self` | The selector's own files: a change to one runs everything. The config file is always one |
31
- | `importOnly` | Files only an import reaches: deleting one never orphans a suite |
32
- | `hermetic` | Files whose disk reads and non-literal imports reach no file of the repository: a library's `fs` calls on its caller's paths, a test that reads only the temporary files it writes. They add no unknown, and `check` still flags a repository path one spells that nothing declares |
33
- | `barrels` | Modules that may bind named imports. Default: every module made only of re-exports |
34
- | `external` | Packages a dependency installs that your code imports without declaring |
35
- | `inert` | Packages no test uses except by importing them: linters, formatters, type packages (`["@biomejs/biome", "knip", "@types/*"]`). A [lockfile change](how-it-works.md#lockfiles) that only they reach selects nothing. With `loadedByName` set, only packages with a `bin` need listing. bivium itself always is |
36
- | `loadedByName` | Packages a test may load other than by an import: a test environment or a plugin a config names by string (`["jsdom", "ts-jest"]`). Setting it, even to `[]`, says every other package without a `bin` is loaded only by imports, so a [lockfile change](how-it-works.md#lockfiles) that reaches one no test imports selects only its importers. A package with a `bin` always counts as one a test may run |
37
- | `extensions` | Suffixes tried after a specifier |
38
- | `deadGlobs` | Dead globs `check` allows, each `{ file, glob, reason }`, the glob as `file` spells it |
39
- | `knownUnknowns` | Nodes `check` allows to have unknown dependencies, each `{ file, reason }`. With it set, even to `[]` (which is `--max-unknown 0`), `check` fails on an unknown node some test reaches that it doesn't list, and on an entry that's no longer unknown, so a new unknown can't replace one that went away |
40
- | `narrowers` | See [Narrowers](api.md#narrowers) |
41
- | `base` | The default base ref. Otherwise the upstream default branch (`origin/HEAD`, then `origin/main`, `origin/master`, `main`, `master`) |
42
- | `cache` | The cache's directory, or `false`. Default: `node_modules/.cache/bivium`, or `.bivium/cache` |
171
+ | `ignore` | Files no test can observe except through an edge, such as docs and stories |
172
+ | `self` | The selector's own files |
173
+ | `importOnly` | Files only an import reaches |
43
174
 
44
- ## Annotations
175
+ A change to an ignored file selects only the tests that reach it.
176
+ It never runs a suite by the orphan rule,
177
+ and doesn't select the tests whose dependencies are unknown.
178
+
179
+ A change to a `self` file runs everything,
180
+ since the selector can't be trusted to select itself.
181
+ The config file is always one.
45
182
 
46
- | Comment | Meaning |
183
+ Deleting an `importOnly` file never runs a suite by the orphan rule.
184
+ An importer still pointing at it can't resolve it,
185
+ so the importer's tests run anyway.
186
+
187
+ ## Inputs imports don't show
188
+
189
+ A file is unknown when bivium can't read all of its dependencies,
190
+ such as a file that reads the disk.
191
+ bivium counts an unknown file as depending on every change,
192
+ so the tests that reach it run every time.
193
+ These keys declare what such files read,
194
+ or vouch that they read nothing in the repository.
195
+
196
+ | Key | Maps or names |
47
197
  |:---|:---|
48
- | `// @depends-on <glob> [glob…]` | Inputs that aren't imports: files a script reads, a tool it spawns, the pages a `goto()` the graph can't read opens (a loop over a list of URLs). Transitive. A file that reads the disk without one (or `@reads`, or `@lists`), or calls `goto()` with a URL it can't read, is unknown, unless it's `hermetic` |
49
- | `// @reads <glob> [glob…]` | Files read as text. Only a direct change to one counts, not a change to what it imports. The config's `reads` says the same for files that can't hold a comment |
50
- | `// @lists <glob> [glob…]` | Files whose names it lists, not their contents: a convention test that checks every route has a handler. Only adding, deleting or renaming one counts; an edit doesn't select it, and doesn't run its suite by the orphan rule either |
51
- | `// @glob-registry` | This file's `import.meta.glob` is a lookup table and adds no edges: whatever loads an entry names it itself |
198
+ | `edges` | Generated file glob → its inputs |
199
+ | `reads` | File glob → the files it reads as text |
200
+ | `hermetic` | Files whose disk reads reach no file of the repository |
201
+
202
+ ### `edges`
203
+
204
+ `edges` maps a generated file to the inputs a build makes it
205
+ from: `{ "dist/*.css": "styles/**" }`.
206
+ The generated file depends on its inputs transitively,
207
+ as with `@depends-on`.
208
+
209
+ A key may name files git doesn't list,
210
+ such as a gitignored generator output: `{ ".velite/*": "content/**" }`.
211
+ An import that resolves under the key, by extension or as an index,
212
+ then lands on that file instead of being unresolved.
213
+
214
+ In a value, `$1`, `$2`… stand for what the key's wildcards matched,
215
+ counted from the
216
+ left: `{ "examples/*/package.json": "examples/$1/**" }`.
217
+
218
+ ### `reads`
219
+
220
+ `reads` maps a file to the files it reads as text,
221
+ as `@reads`
222
+ does: `{ "tests/*.test.ts": "tests/__snapshots__/$1.test.ts.snap" }`.
223
+ Only a direct change to a read file counts:
224
+ its imports and unknowns don't spread to the reader.
225
+ Values take `$1`… as in `edges`.
226
+
227
+ ### A key that names one file
228
+
229
+ An `edges` or `reads` key with no wildcard names one file.
230
+ It declares what that file reads, as the file's own `@depends-on`
231
+ or `@reads` would, so the file's disk reads aren't unknown.
232
+
233
+ ### `hermetic`
234
+
235
+ `hermetic` names files whose disk reads and non-literal imports reach no
236
+ file of the repository.
237
+ Examples are a library's `fs` calls on the paths its caller passes,
238
+ and a test that reads only the temporary files it writes.
239
+ These files add no unknown.
240
+ `check` still flags a repository path one of them spells that nothing
241
+ declares (see [Paths a test spells](tuning.md#paths-a-test-spells)).
242
+
243
+ ## Packages and lockfiles
244
+
245
+ When a lockfile changes, bivium selects the tests that import each
246
+ changed package.
247
+ A changed package no test imports runs everything,
248
+ since a test may use it another way, such as a CLI it spawns.
249
+ These keys say which packages need that caution;
250
+ [Lockfiles](how-it-works.md#lockfiles) has the full rule.
251
+
252
+ | Key | Names | Example |
253
+ |:---|:---|:---|
254
+ | `inert` | Packages no test uses except by importing them | `["@biomejs/biome", "knip", "@types/*"]` |
255
+ | `loadedByName` | Packages a test may load other than by an import | `["jsdom", "ts-jest"]` |
256
+
257
+ `inert` is for linters, formatters and type packages.
258
+ A lockfile change that only they reach selects nothing.
259
+ With `loadedByName` set, only packages with a `bin` need listing.
260
+ bivium itself is always inert.
261
+
262
+ `loadedByName` is for a test environment,
263
+ or a plugin a config names by string.
264
+ Setting it, even to `[]`, says every other package without a `bin` is
265
+ loaded only by imports.
266
+ A lockfile change that reaches one no test imports
267
+ then selects only its importers.
268
+ A package with a `bin` always counts as one a test may run.
269
+
270
+ ## What `check` allows
271
+
272
+ These keys list what `bivium check` accepts, each entry with a reason.
273
+
274
+ | Key | Each entry | Allows |
275
+ |:---|:---|:---|
276
+ | `deadGlobs` | `{ file, glob, reason }` | A [dead glob](tuning.md#dead-globs): one that matches no file, or only files bivium skips |
277
+ | `knownUnknowns` | `{ file, reason }` | A file with unknown dependencies |
278
+
279
+ In `deadGlobs`, `glob` is the glob as `file` spells it.
280
+
281
+ With `knownUnknowns` set, `check` fails on an unknown file some test
282
+ reaches that the list doesn't name.
283
+ Setting it to `[]` does what `--max-unknown 0` does.
284
+ `check` also fails on an entry whose dependencies are known,
285
+ so an unknown that appears can't take the place of one that went away.
286
+
287
+ ## Plans and the cache
288
+
289
+ These keys set what a plan compares with, how it narrows,
290
+ and where it caches what it reads.
291
+
292
+ | Key | Sets | Default |
293
+ |:---|:---|:---|
294
+ | `narrowers` | Plugins that narrow what a change to some files selects | none |
295
+ | `base` | The base ref when a command names none | the upstream default branch |
296
+ | `cache` | The cache's directory, or `false` for none | `node_modules/.cache/bivium` |
297
+
298
+ The upstream default branch is `origin/HEAD`,
299
+ or else the first of `origin/main`, `origin/master`,
300
+ `main` and `master` that exists.
301
+ Without `node_modules`, the cache is `.bivium/cache`.
302
+ [Narrowers](api.md#narrowers) covers writing one.
303
+
304
+ ## Annotations
305
+
306
+ An annotation is a comment in a source file that declares a dependency
307
+ its imports don't show.
308
+
309
+ ```ts
310
+ // tests/tokens.test.ts
311
+ // @reads src/tokens.css
312
+ import { readFileSync } from "node:fs";
313
+
314
+ const css = readFileSync("src/tokens.css", "utf-8");
315
+ ```
316
+
317
+ | Comment | Declares | A change that counts |
318
+ |:---|:---|:---|
319
+ | `// @depends-on <glob> [glob…]` | Inputs that aren't imports: files a script reads, a tool it spawns, pages a `goto()` opens | One to an input, or to what it depends on |
320
+ | `// @reads <glob> [glob…]` | Files read as text | A direct change to one, not to what it imports |
321
+ | `// @lists <glob> [glob…]` | Files whose names it lists, not their contents | Adding, deleting or renaming one |
322
+ | `// @glob-registry` | This file's `import.meta.glob` is a lookup table | None: it adds no edges |
323
+
324
+ A file that reads the disk without `@depends-on`,
325
+ `@reads` or `@lists` is unknown, unless it's `hermetic`.
326
+ So is a file that calls `goto()` with a URL the graph can't read,
327
+ such as one from a loop over a list of URLs.
328
+ An `@depends-on` in that file names the pages it opens.
329
+ The config's `edges` and `reads` say the same for files that can't hold
330
+ a comment.
331
+
332
+ `@lists` fits a convention test that checks every route has a handler.
333
+ An edit to a listed file doesn't select the test,
334
+ and doesn't run its suite by the orphan rule either.
335
+
336
+ `@glob-registry` is for an `import.meta.glob` used as a lookup table:
337
+ whatever loads an entry names it itself.
52
338
 
53
339
  ## Related
54
340
 
@@ -57,3 +343,5 @@ less.
57
343
  - [Recipes](recipes.md): Vitest, Jest, Playwright, pnpm workspaces,
58
344
  generated code
59
345
  - [How it works](how-it-works.md): what the graph follows
346
+ - [Not supported](how-it-works.md#not-supported): what bivium leaves to
347
+ other tools
@@ -1,106 +1,180 @@
1
1
  # How it works
2
2
 
3
- bivium builds a static, file-level dependency graph
4
- and walks it backwards from the files a change touches to the tests that
5
- reach them; what it can't read counts as depending on everything.
3
+ bivium builds a static, file-level dependency graph: which file imports,
4
+ loads, or reads which.
5
+ It walks that graph backwards, from the files a change touches to the
6
+ tests that reach them.
7
+ It fails closed: a file it can't read is unknown,
8
+ and an unknown counts as depending on every change.
9
+
10
+ `why` prints one such walk, from the test down to the changed file:
11
+
12
+ ```console
13
+ $ bunx bivium why e2e/accordion.test.ts
14
+ e2e/accordion.test.ts
15
+ └─ goto e2e/fixtures/accordion.html e2e/accordion.test.ts:13
16
+ └─ html e2e/fixtures/accordion.ts e2e/fixtures/accordion.html:10
17
+ └─ import e2e/fixtures/Fixture.svelte e2e/fixtures/accordion.ts:1
18
+ └─ name src/index.js#AccordionItem e2e/fixtures/Fixture.svelte:2
19
+ └─ export src/AccordionItem.svelte src/index.js:2
20
+ ● changed
21
+ ```
6
22
 
7
23
  ## What it reads
8
24
 
9
- A one-pass lexer reads JavaScript and TypeScript
10
- (`.js`, `.ts`, `.jsx`, `.tsx`, and their `m`/`c` variants),
11
- the scripts and markup expressions of `.svelte`, the scripts of `.vue`,
12
- `.astro` and `.html`, and the `script[src]`,
13
- `link[href]` and `iframe[src]` of `.html`.
25
+ A one-pass lexer reads the code in these files:
26
+
27
+ - JavaScript and TypeScript: `.js`, `.ts`, `.jsx`, `.tsx`,
28
+ and their `m` and `c` variants;
29
+ - `.svelte`: the scripts and the markup expressions;
30
+ - `.vue` and `.astro`: the scripts;
31
+ - `.html`: the scripts, and the `script[src]`,
32
+ `link[href]` and `iframe[src]`.
33
+
14
34
  Only code counts: an import spelled in a string
15
35
  or a comment adds no edge.
36
+ Each reference it follows becomes edges to files, a `pkg:`
37
+ node for a package, or an unknown:
16
38
 
17
39
  | It follows | As |
18
40
  |:---|:---|
19
- | Static, side-effect and dynamic imports, `export … from`, `require()` | Edges to every file the specifier can load: each extension that exists, each `exports` condition. A missing `x.js` (`.jsx`, `.mjs`, `.cjs`) is its TypeScript source, as TypeScript reads it: `x.ts`, `x.tsx` or `x.d.ts`, through any path, alias or `exports` target. A value import that finds only `x.d.ts` is unknown: what runs isn't in the graph |
41
+ | Static, side-effect and dynamic imports, `export … from`, `require()` | Edges to every file the specifier can load: each extension that exists, each `exports` condition |
42
+ | A missing `x.js` or `x.jsx` | Its TypeScript source, as TypeScript reads it: `x.ts`, `x.tsx` or `x.d.ts`, through any path, alias or `exports` target |
43
+ | A missing `x.mjs` or `x.cjs` | `x.mts` or `x.d.mts`; `x.cts` or `x.d.cts` |
44
+ | A value import that finds only a declaration file (`x.d.ts`) | Unknown: what runs isn't in the graph |
20
45
  | `vi.mock()`, `vi.importActual()` and the rest of the family | Edges |
21
- | `import.meta.glob()` | Every matching file, now and later |
22
- | JSDoc `@type {import("x")}` and `@import` | Edges (TypeScript reads them) |
23
- | `%sveltekit.assets%/x` in a SvelteKit `app.html` | An edge to `static/x` in the project, the nearest directory with a `svelte.config.*` or a `package.json`. `%sveltekit.head%`, `%sveltekit.body%` and the rest aren't references |
46
+ | `import.meta.glob()` | Edges to every matching file, including one a change adds |
47
+ | JSDoc `@type {import("x")}` and `@import` | Edges, since TypeScript reads them |
48
+ | `%sveltekit.assets%/x` in a SvelteKit `app.html` | An edge to `static/x` in the project: the nearest directory with a `svelte.config.*` or a `package.json`. `%sveltekit.head%`, `%sveltekit.body%` and the rest aren't references |
24
49
  | `page.goto("/x.html")` in a suite with `urls` | An edge to the page |
25
- | `compilerOptions.paths` and `baseUrl` of the nearest `tsconfig.json`, with its relative `extends` | Edges to every target that exists, tried after `alias` and before `package.json` `exports`. A `tsconfig.json` that doesn't parse maps nothing, and `check` lists it |
50
+ | `compilerOptions.paths` of the nearest `tsconfig.json`, with its relative `extends` | Edges to every target that exists, tried after `alias` and before the `exports` of a package in the repository. A `tsconfig.json` that doesn't parse maps nothing, and `check` lists it |
51
+ | `compilerOptions.baseUrl` of that `tsconfig.json` | An edge to the file under it, tried after the `exports` of a package in the repository |
26
52
  | `#name` subpath imports, through the `imports` of the importing file's own `package.json` | Edges to every condition's target that exists; an unmatched `#name` is unknown |
27
- | Named imports from a module made only of re-exports | An edge to the one file that exports each name, when the package declares `sideEffects` |
28
- | A file's own package and its ancestors' `package.json` dependencies, and builtins | `pkg:` nodes |
53
+ | Named imports from a barrel: a module made only of re-exports | An edge to the one file that exports each name, when the package's `sideEffects` is `false` or a list without the barrel |
54
+ | A package in the dependencies of the file's own `package.json` or an ancestor's, a package in `external`, and a builtin | A `pkg:` node |
29
55
  | Anything else | Unknown: the file depends on every change |
30
56
 
31
- A root `bun.lock`, `package-lock.json` or `pnpm-lock.yaml` isn't a
32
- source file: a change to one seeds the packages it changed
57
+ Some files change how others resolve or run, and no import says so.
58
+ bivium seeds the walk from them instead:
59
+ seeds are the nodes a walk starts from.
60
+
61
+ A root lockfile (`bun.lock`, `package-lock.json`, `pnpm-lock.yaml`)
62
+ isn't a source file.
63
+ A change to one seeds the packages it changed
33
64
  (see [Lockfiles](#lockfiles)).
34
65
 
35
- Nor is a `tsconfig.json` (or a file one `extends`)
36
- or a `package.json` under `roots`: their options, `paths`,
37
- `type` or `exports` change how the files under them resolve or run,
38
- which no import says.
39
- A change to one seeds the files it governs,
66
+ Nor is a `tsconfig.json`, a file one `extends`,
67
+ or a `package.json` under `roots` (the paths the graph reads).
68
+ Their options, `paths`, `type` or `exports` change how the files under
69
+ them resolve or run.
70
+ A change to one seeds the files it governs:
40
71
  those it's the nearest of its kind to.
41
- A change the parsed file doesn't show, such as formatting or comments,
42
- seeds nothing; so does one to a `package.json`'s metadata alone
43
- (`version`, `description`, `repository` and the like),
44
- and a dependency change is the lockfile's.
45
72
 
46
- A file it can't lex cleanly is read by a regex extractor instead,
47
- which over-approximates.
48
- CSS isn't scanned: generated stylesheets reach their inputs through
49
- `edges`, and a [narrower](api.md#narrowers) can do better.
73
+ Three kinds of change to these files seed nothing:
50
74
 
51
- ## Lockfiles
75
+ - a change the parsed file doesn't show, such as formatting or comments;
76
+ - a change to a `package.json`'s metadata alone:
77
+ `version`, `description`, `repository` and the like;
78
+ - a change to a `package.json`'s dependencies,
79
+ which goes through the lockfile instead.
52
80
 
53
- A dependency bump changes a lockfile, which no file imports.
54
- When a root `bun.lock`, `package-lock.json` (v2 or v3),
55
- or `pnpm-lock.yaml` v6 or v9 changes,
56
- bivium diffs it against the merge base and seeds the walk with the
57
- `pkg:` nodes of the packages whose entries changed,
58
- and of every package that depends on one,
59
- so a `svelte` bump selects what imports `svelte`,
60
- or a package built on it.
61
- A `package.json` whose only change is to dependencies the lockfile
62
- records the same way counts as those packages changing.
81
+ A file the lexer can't read cleanly goes to a regex extractor instead.
82
+ The regex over-approximates: it errs toward extra edges,
83
+ and an extra edge only selects more tests.
63
84
 
64
- A changed package can also be used in ways the graph can't see:
65
- a CLI a test spawns, a runner, a type package.
66
- So when a change reaches a package that a `package.json` declares,
67
- or that some file imports, and that no test imports, everything runs,
68
- with the reason
69
- (`bun.lock: playwright 1.63.0 → 1.64.0, and no test imports it`),
70
- unless the package is `inert`.
71
- bivium itself always is: a bump changes which tests later plans pick,
72
- not what a test does.
73
- With `loadedByName` set, only a package with a `bin` in the lockfile,
74
- or one it lists, counts as used that way:
75
- a bump that reaches a library only a CMS config imports selects nothing.
76
- Everything also runs for a lockfile bivium can't parse,
77
- one whose settings other than its packages changed
78
- (`overrides`, patches, pnpm's `settings`, `catalogs`, or the version of
79
- pnpm itself), and a `package.json` change the lockfile doesn't record.
80
- Other lockfiles (`yarn.lock`, `bun.lockb`) are files like any other:
81
- outside the roots, a change to one runs everything.
85
+ CSS isn't scanned.
86
+ A generated stylesheet reaches its inputs through `edges`,
87
+ and a [narrower](api.md#narrowers) can do better.
88
+
89
+ ## Lockfiles
90
+
91
+ A dependency bump changes a lockfile, and no file imports a lockfile,
92
+ so bivium reads it:
82
93
 
83
94
  ```console
84
95
  $ bunx bivium plan
96
+ 4 of 12 tests run for 1 changed file
97
+ since origin/main (merge base 1c0ffee) · config bivium.config.ts
85
98
  bun.lock: @biomejs/biome 2.5.14 → 2.6.3, inert
86
99
  bun.lock: svelte 5.57.1 → 5.57.2
87
- unit tests: 4 of 12 files
88
100
  …
89
101
  ```
90
102
 
103
+ bivium reads these lockfiles at the repository root:
104
+
105
+ - `bun.lock`;
106
+ - `package-lock.json`, v2 or v3;
107
+ - `pnpm-lock.yaml`, v6 or v9.
108
+
109
+ When one changes, bivium diffs it against the merge base.
110
+ It seeds the walk with the `pkg:` nodes of the packages whose entries
111
+ changed, and of every package that depends on one.
112
+ So a `svelte` bump selects what imports `svelte`,
113
+ or a package built on it.
114
+ A `package.json` whose only change is to its dependencies,
115
+ when the lockfile records them the same way,
116
+ counts as those packages changing.
117
+
118
+ A changed package can also be used in ways the graph can't see:
119
+ a CLI a test spawns, a runner, a type package.
120
+ So when a change reaches a package that a `package.json` declares
121
+ or some file imports, and no test imports it, everything runs.
122
+ The plan names the
123
+ reason (`bun.lock: playwright 1.63.0 → 1.64.0, and no test imports it`).
124
+ A package in `inert` is the exception:
125
+ `inert` lists packages no test uses except by importing them,
126
+ such as linters and formatters.
127
+ bivium itself is always inert: a bump changes which tests later plans
128
+ pick, not what a test does.
129
+
130
+ `loadedByName` lists the packages a test loads other than by an import,
131
+ such as a test environment.
132
+ With it set, only a package with a `bin` in the lockfile,
133
+ or one it lists, counts as used that way.
134
+ A bump that reaches a library only a CMS config imports
135
+ then selects nothing.
136
+
137
+ Everything also runs for:
138
+
139
+ - a lockfile bivium can't parse;
140
+ - a lockfile whose settings other than its packages changed:
141
+ `overrides`, patches, pnpm's `settings`, `catalogs`,
142
+ or the version of pnpm itself;
143
+ - a `package.json` change the lockfile doesn't record.
144
+
145
+ Other lockfiles (`yarn.lock`, `bun.lockb`, `npm-shrinkwrap.json`) are
146
+ files like any other.
147
+ Outside the roots, a change to one runs everything.
148
+
149
+ ## Not supported
150
+
151
+ What bivium leaves to other tools, and what to use instead:
152
+
153
+ | bivium doesn't | Instead |
154
+ | --- | --- |
155
+ | run your tests | `bivium run` hands the selection to your runner's command |
156
+ | read your runner's config | name its setup files in a suite's `setup` |
157
+ | scan CSS | `edges` from a stylesheet to its sources, or a [narrower](api.md#narrowers) |
158
+ | parse `yarn.lock` or `bun.lockb` | they're files like any other, so a change to one doesn't seed packages |
159
+ | select below the file | a test file is selected whole, every case in it |
160
+ | follow an import it can't read | the file counts as depending on every change, so its tests always run |
161
+ | build or cache outputs | Nx, Turborepo, or Bazel, which skip whole projects |
162
+
91
163
  ## Compared with
92
164
 
93
- Where bivium sits among the tools that select or skip tests:
165
+ Tools that select or skip tests differ in what they select
166
+ and what they miss:
94
167
 
95
168
  | | Selects | Misses |
96
169
  |:---|:---|:---|
97
170
  | `vitest --changed`, `jest --changedSince` | Tests whose module graph reaches a changed file, from the runner's own resolver | Disk reads, fixtures, pages a test visits, config and setup wiring |
98
- | Playwright `--only-changed` | Test files whose imports changed | The pages a test opens and what they load |
99
- | Nx, Turborepo | Whole projects whose inputs changed | Nothing within a project's declared inputs, at project granularity |
100
- | Bazel | Targets whose declared inputs changed | Nothing, if every input is declared |
101
- | bivium | Test files, across runners and file types, from one graph | Nothing it can see; what it can't, it runs |
171
+ | Playwright `--only-changed` | Test files whose imports changed | The pages a test opens, and what they load |
172
+ | Nx, Turborepo | Whole projects whose inputs changed | Nothing within a project's declared inputs, but it selects whole projects |
173
+ | Bazel | Targets whose declared inputs changed | Nothing, when every input is declared |
174
+ | bivium | Test files, across runners and file types, from one graph | Nothing it can see; what it can't see, it runs |
102
175
 
103
176
  ## Related
104
177
 
105
- - [Tuning a plan](tuning.md): the orphan rule and `check`
106
- - [Config](config.md): telling it what it can't see
178
+ - [Tuning a plan](tuning.md): a change no test reaches, and `check`
179
+ - [Config](config.md): telling bivium what it can't see
180
+ - [CI](ci.md): the checkout and cache a plan needs