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/recipes.md CHANGED
@@ -1,67 +1,137 @@
1
1
  # Recipes
2
2
 
3
- Settings for common test runners and repository shapes,
4
- each a starting point to adjust.
3
+ A recipe is a bivium config for a common test runner
4
+ or repository shape: a starting point to adjust.
5
5
 
6
- **Vitest or Jest.**
7
- Name the setup files the runner loads,
8
- mirror `resolve.alias` (a Vite key like `"@/"` works as written),
9
- give snapshots to their tests, and, for a suite that runs code,
10
- skip type-only edges:
6
+ ## Vitest or Jest
11
7
 
12
8
  ```ts
13
- suites: {
14
- unit: {
15
- tests: "src/**/*.test.{ts,tsx}",
16
- run: "vitest run {files}",
17
- root: "src",
18
- setup: ["src/setupTests.ts"], // vitest.config.ts `setupFiles`
19
- wiring: ["vitest.config.ts"],
20
- types: false,
21
- nonInputs: ["src/**/types.ts"], // types only: nothing loads them at runtime
9
+ // bivium.config.ts
10
+ import { defineConfig } from "bivium";
11
+
12
+ export default defineConfig({
13
+ suites: {
14
+ unit: {
15
+ tests: "src/**/*.test.{ts,tsx}",
16
+ run: "vitest run {files}",
17
+ root: "src",
18
+ setup: ["src/setupTests.ts"], // vitest.config.ts `setupFiles`
19
+ wiring: ["vitest.config.ts"],
20
+ types: false,
21
+ nonInputs: ["src/**/types.ts"], // types only: nothing loads them at runtime
22
+ },
22
23
  },
23
- },
24
- alias: { "@/": "src/" },
25
- reads: { "src/**/*.test.{ts,tsx}": "src/$1__snapshots__/$2.test.$3.snap" },
24
+ alias: { "@/": "src/" },
25
+ reads: { "src/**/*.test.{ts,tsx}": "src/$1__snapshots__/$2.test.$3.snap" },
26
+ });
26
27
  ```
27
28
 
28
- tsconfig `paths` (what `vite-tsconfig-paths` reads) are read without an
29
- `alias`.
29
+ Each key tells bivium how the runner loads files,
30
+ which the imports alone don't show:
31
+
32
+ - `root`: the directory the orphan rule covers.
33
+ Under it, a changed file no test reaches is wired some other way,
34
+ so the whole suite runs.
35
+ - `setup`: the setup files the runner loads before every test.
36
+ bivium doesn't read the runner's config, so name them here.
37
+ - `wiring`: the runner's config; a change to it runs the whole suite.
38
+ - `types: false`: the suite runs code,
39
+ so a change that reaches its tests only through types selects none.
40
+ - `nonInputs`: modules that hold only types,
41
+ which nothing loads at runtime.
42
+ - `alias`: the same prefixes as Vite's `resolve.alias`;
43
+ a Vite key such as `"@/"` works as written.
44
+ - `reads`: each test's snapshot, so a snapshot change selects its test.
45
+ `$1`, `$2` and `$3` are what `**/`, `*` and `{ts,tsx}` matched:
46
+ `src/a/Button.test.tsx` reads
47
+ `src/a/__snapshots__/Button.test.tsx.snap`.
48
+
49
+ For Jest, set `run` to your Jest command
50
+ and `setup` to Jest's `setupFiles`.
51
+ bivium reads tsconfig `paths` itself, as `vite-tsconfig-paths` does,
52
+ so they need no `alias`.
30
53
  An extensionless `vi.mock("@/x")` resolves as an import does.
31
- A test environment the runner loads by name (`jsdom`, `happy-dom`) goes
32
- in `loadedByName` if you set it.
33
-
34
- **pnpm workspaces.**
35
- Workspace packages resolve through their `package.json` `exports`,
36
- and a `.js` specifier into one (`@acme/ui/Button.js`) reaches its `.ts`
37
- source.
38
- A `pnpm-lock.yaml` change selects through the packages it changed.
54
+ A test environment the runner loads by name,
55
+ such as `jsdom` or `happy-dom`, goes in `loadedByName` if you set it.
56
+ That key lists the packages a test loads other than by an import.
57
+
58
+ ## pnpm workspaces
59
+
60
+ ```ts
61
+ // bivium.config.ts
62
+ import { defineConfig } from "bivium";
63
+
64
+ export default defineConfig({
65
+ suites: {
66
+ unit: { tests: "packages/*/src/**/*.test.ts", run: "vitest run {files}" },
67
+ e2e: { tests: "apps/web/e2e/**/*.spec.ts", run: "playwright test {files}" },
68
+ },
69
+ roots: ["packages", "apps"],
70
+ });
71
+ ```
72
+
73
+ Give each test runner a suite of its own.
39
74
  Set `roots` to the packages and apps whose changes the suites need to
40
- see, and a suite per test runner.
75
+ see; a changed file outside them that isn't ignored runs everything.
76
+
77
+ Workspace packages resolve through their `package.json` `exports`.
78
+ A `.js` specifier into one (`@acme/ui/Button.js`) reaches its
79
+ `.ts` source.
80
+ A `pnpm-lock.yaml` change selects through the packages it changed
81
+ (see [Lockfiles](how-it-works.md#lockfiles)).
41
82
 
42
- **Playwright.**
43
- Map `page.goto()` URLs to the pages they open with `urls`,
44
- list pages only a `goto()` opens in `pages`,
45
- and name `playwright.config.ts` in `wiring`:
83
+ ## Playwright
46
84
 
47
85
  ```ts
48
- e2e: {
49
- tests: "e2e/**/*.spec.ts",
50
- root: "e2e",
51
- urls: { "/*": "e2e/fixtures/*.html" },
52
- wiring: ["playwright.config.ts"],
53
- },
86
+ // bivium.config.ts
87
+ import { defineConfig } from "bivium";
88
+
89
+ export default defineConfig({
90
+ suites: {
91
+ e2e: {
92
+ tests: "e2e/**/*.spec.ts",
93
+ root: "e2e",
94
+ urls: { "/*": "e2e/fixtures/*.html" },
95
+ wiring: ["playwright.config.ts"],
96
+ },
97
+ },
98
+ });
99
+ ```
100
+
101
+ A test reaches a page through the URL it opens, not an import:
102
+
103
+ - `urls`: maps each `page.goto()` URL to the page it opens.
104
+ Each `*` in the value is what the key's `*` matched,
105
+ so `page.goto("/accordion")` opens `e2e/fixtures/accordion.html`.
106
+ - `wiring`: `playwright.config.ts`; a change to it runs the whole suite.
107
+
108
+ List the pages only a `goto()` opens in the suite's `pages`.
109
+
110
+ ## Generated code
111
+
112
+ ```ts
113
+ // bivium.config.ts
114
+ import { defineConfig } from "bivium";
115
+
116
+ export default defineConfig({
117
+ suites: {
118
+ unit: { tests: "src/**/*.test.ts", run: "vitest run {files}" },
119
+ },
120
+ edges: { ".velite/*": ["content/**", "velite.config.ts"] },
121
+ });
54
122
  ```
55
123
 
56
- **Generated code.**
57
- A content or type generator that writes into a gitignored directory
58
- (`.velite`, `.contentlayer/generated`) is an `edges` entry from what it
59
- writes to what it reads:
60
- `{ ".velite/*": ["content/**", "velite.config.ts"] }`.
61
- An import of `#velite` or `../.velite` then reaches the content,
62
- and not every change.
124
+ A content or type generator writes into a gitignored directory,
125
+ such as `.velite` or `.contentlayer/generated`.
126
+ Without an entry, an import of a file there is unknown:
127
+ it counts as depending on every change.
128
+ An `edges` entry goes from what the generator writes to what it reads.
129
+ An import of `#velite` or `../.velite` then reaches the content
130
+ and the generator's config, and not every change.
63
131
 
64
132
  ## Related
65
133
 
66
134
  - [Config](config.md): every key
67
135
  - [Tuning a plan](tuning.md): when a plan still runs too much
136
+ - [Not supported](how-it-works.md#not-supported): what bivium leaves to
137
+ other tools
package/docs/tuning.md CHANGED
@@ -1,18 +1,77 @@
1
1
  # Tuning a plan
2
2
 
3
- A plan that runs more than a change needs has a cause bivium can name;
4
- `bivium check` lists each one with its fix.
3
+ Tuning a plan is telling bivium how your files are wired,
4
+ so a change runs only the tests it can reach.
5
+ When a plan runs more than that, bivium can name the cause,
6
+ and `bivium check` lists each cause with its fix.
7
+
8
+ With a suite's default `root`, an edit to `README.md`
9
+ or `vitest.config.ts` runs the whole suite:
10
+
11
+ ```console
12
+ $ bunx bivium plan
13
+ all 4 tests run: README.md: no unit test imports it
14
+ since origin/main (merge base 9236bd3) · config bivium.config.ts
15
+ full run: vitest.config.ts: no unit test imports it
16
+
17
+ ✓ Planned 4 tests · 256 ms
18
+ ```
19
+
20
+ `bivium check` lists those files before they change, each with a fix:
21
+
22
+ ```console
23
+ $ bunx bivium check --all
24
+ bivium can follow every file a test reaches
25
+ 2 files no test reaches
26
+
27
+ no test reaches: a change runs the whole suite · 2 files in suite unit
28
+ ├ README.md
29
+ fix if a test reads or runs it, say so with `reads` or `@depends-on` in that
30
+ test or what loads it; if none can observe it, list it in the suite's
31
+ `nonInputs`, or delete it if it's dead
32
+ └ vitest.config.ts
33
+ fix if the runner loads it, name it in the suite's `wiring` (or `setup`, if
34
+ it runs before every test), which makes the full run deliberate
35
+
36
+ ✓ Check passes · checked in 254 ms
37
+ ```
5
38
 
6
39
  ## A change no test reaches
7
40
 
8
- A changed file under a suite's `root` that no test of the suite reaches
9
- is wired some other way (a runner config, a setup file),
10
- so the whole suite runs: the orphan rule.
11
- With the default `root`, the whole repository,
12
- any file bivium can't trace to a test runs the suite,
13
- which is sound and coarse.
41
+ To stop a change to a file no test reaches from running a whole suite,
42
+ set the suite's `root` and say what the other files are.
43
+
44
+ The orphan rule is why it runs.
45
+ It applies to a changed file under a suite's `root` that no test of the
46
+ suite reaches.
47
+ bivium takes such a file to be wired some other way,
48
+ such as a runner config or a setup file, so the whole suite runs.
49
+ The default `root` is the whole repository,
50
+ so any file bivium can't trace to a test runs the suite.
51
+ That misses no test, and it runs the suite for a README edit.
52
+
14
53
  Set `root` on every suite to the directories its tests
15
- and sources live in, and say what the rest is:
54
+ and sources live in:
55
+
56
+ ```ts
57
+ // bivium.config.ts
58
+ import { defineConfig } from "bivium";
59
+
60
+ export default defineConfig({
61
+ suites: {
62
+ unit: {
63
+ tests: "tests/**/*.test.ts",
64
+ run: "vitest run {files}",
65
+ root: "tests",
66
+ wiring: ["vitest.config.ts"],
67
+ },
68
+ },
69
+ roots: ["src", "tests"],
70
+ ignore: ["README.md"],
71
+ });
72
+ ```
73
+
74
+ Then say what each remaining file is:
16
75
 
17
76
  | You changed… | and want… | Use |
18
77
  |:---|:---|:---|
@@ -26,61 +85,107 @@ and sources live in, and say what the rest is:
26
85
  | a file a test lists but doesn't read (a route, a story) | the test, when one is added or deleted | `// @lists <glob>` in the test |
27
86
  | a file a build turns into what tests load | the tests that load the output | `edges` from the output to its inputs |
28
87
 
29
- A file outside `roots` that isn't ignored runs everything:
30
- it's the backstop for wiring the graph can't see, such as a CI workflow.
88
+ `roots` is the backstop.
89
+ A file outside `roots` that isn't ignored runs everything,
90
+ for wiring the graph can't see, such as a CI workflow.
91
+
92
+ ### What `check` lists
31
93
 
32
94
  `bivium check` lists every file under a suite's `root` that no test
33
- reaches and the config doesn't exempt,
34
- with a fix for each by what it looks like: a test's snapshot,
95
+ reaches and the config doesn't exempt.
96
+ Each gets a fix chosen by what the file looks like: a test's snapshot,
35
97
  a runner's config, or anything else.
36
- It's the list to work through when adopting bivium,
37
- and a new entry is a gap someone added.
38
-
39
- A file's own disk reads make it unknown,
40
- but a test that hands a path to the code under test
41
- (`typecheck({ workspace: "tests/fixtures" })`),
42
- or a `hermetic` one that reads it, reads nothing the graph can see.
43
- So `check` also reads the string literals in each test,
44
- and in what the tests reach under a suite's `root`,
45
- for repository paths: relative to the root when they have a slash,
46
- as `join(root, "tests/fixtures")` spells one, and relative to the file,
47
- as `new URL("fixtures", import.meta.url)` does.
48
- It fails on one a change to which wouldn't select the tests that reach
49
- the file, with the `reads`, `edges` or annotation that declares it.
50
- A path whose change runs the suite anyway, as `wiring`,
51
- `self` or by the orphan rule, doesn't fail,
52
- and an unreached file's fix names where it's spelled.
53
- Strings inside brackets are skipped as data
54
- (`["src/a.ts", …]`, `map["key"]`), as are the directories a file is in
55
- and paths outside the graph.
98
+ Work through the list when adopting bivium.
99
+ After that, an entry that appears is a gap someone added.
100
+
101
+ ### Paths a test spells
102
+
103
+ A test can depend on a file without bivium seeing it.
104
+ A file that reads the disk itself is unknown:
105
+ bivium counts it as depending on every change.
106
+ But a test that hands a path to the code under test reads nothing the
107
+ graph can see, as in `typecheck({ workspace: "tests/fixtures" })`.
108
+ Neither does a `hermetic` file that reads the path.
109
+
110
+ So `check` reads the string literals in each test,
111
+ and in the files the tests reach under a suite's `root`,
112
+ for repository paths.
113
+ A string with a slash is tried relative to the repository root,
114
+ as `join(root, "tests/fixtures")` spells one, and relative to the file.
115
+ A bare name is tried relative to the file,
116
+ as `new URL("fixtures", import.meta.url)` spells one.
117
+
118
+ `check` fails on a path whose change wouldn't select the tests that
119
+ reach the file.
120
+ The report names the `reads`, `edges` or annotation that declares it.
121
+ A path whose change runs the suite anyway doesn't fail:
122
+ one that `wiring` or `self` names, or one the orphan rule covers.
123
+ For that last kind, the unreached file's fix names where it's spelled.
124
+
125
+ `check` skips three kinds of string:
126
+
127
+ - strings inside brackets, as data: `["src/a.ts", …]`, `map["key"]`;
128
+ - the directories the file itself is in;
129
+ - paths outside the graph.
130
+
56
131
  A path a test only names, such as an expected output,
57
132
  takes `// @lists <path>`.
58
133
 
59
134
  ## Dead globs
60
135
 
61
- A typo'd `@depends-on`, or one pointing only at files the planner skips,
62
- looks fine and never selects its file.
63
- `check` evaluates every `@depends-on`, `@reads`,
64
- `@lists` and `import.meta.glob` pattern,
65
- every `edges` and `reads` value, and every suite's `setup`,
66
- against every file git lists
67
- (tracked and untracked, inside the roots or not) and reports one that:
136
+ A dead glob is a pattern that looks fine and never selects its file,
137
+ such as a typo'd `@depends-on`, or one that points only at files
138
+ bivium skips.
139
+ `check` looks for them.
140
+ It tests these patterns against every file git lists,
141
+ tracked or untracked, inside the roots or not:
142
+
143
+ - every `@depends-on`, `@reads`, `@lists`
144
+ and `import.meta.glob` pattern;
145
+ - every `edges` and `reads` value;
146
+ - every suite's `setup`.
147
+
148
+ It reports a pattern with one of these problems:
68
149
 
69
150
  | Problem | Means |
70
151
  |:---|:---|
71
152
  | matches nothing | No file matches: a typo or a stale path |
72
- | matches only ignored files, partly ignored | Some matches are ignored and not in the graph, so a change to one selects nothing |
153
+ | matches only ignored files | Every match is ignored and outside the graph, so a change to one selects nothing |
154
+ | partly ignored | Some matches are ignored and outside the graph, and a change to those selects nothing |
155
+
156
+ ```console
157
+ $ bunx bivium check
158
+ bivium can follow every file a test reaches
159
+ 2 dead globs
160
+
161
+ dead glob: a change to what it matches selects nothing · 2 globs in 1 file
162
+ ├ tests/a.test.ts:1 depends-on docs/**: matches only ignored files (1…
163
+ fix point it at files the selector reads, or allowlist it in `deadGlobs`…
164
+ └ tests/a.test.ts:2 reads src/tokns.css: matches nothing
165
+ fix fix the path
166
+
167
+ ✗ 2 dead globs · checked in 241 ms · --all for every file
168
+ ```
169
+
170
+ A config value with captures (`$1`) is dead only when it matches nothing
171
+ for every file its key matches.
172
+ A key that matches no file the graph reads is reported too,
173
+ under the config's file.
174
+
175
+ Two cases aren't dead.
176
+ An ignored file the graph reads still starts a walk to the tests that
177
+ reach it.
178
+ A change outside the roots runs everything.
73
179
 
74
- A config value with captures is dead only when it matches nothing for
75
- every file its key matches, and a key that matches no file the graph
76
- reads is reported too, under the config's file.
77
- An ignored file the graph reads still seeds a walk,
78
- and a change outside the roots runs everything, so neither is dead.
79
180
  A glob that's dead on purpose goes in `deadGlobs` with a reason:
80
181
 
81
182
  ```ts
82
183
  deadGlobs: [
83
- { file: "tests/css/tokens.test.ts", glob: "docs/src/**", reason: "docs-only changes skip CI" },
184
+ {
185
+ file: "tests/css/tokens.test.ts",
186
+ glob: "docs/src/**",
187
+ reason: "docs-only changes skip CI",
188
+ },
84
189
  ],
85
190
  ```
86
191
 
@@ -89,3 +194,5 @@ deadGlobs: [
89
194
  - [Config](config.md): every key named here
90
195
  - [CLI](cli.md): `check`, `why` and `graph`
91
196
  - [Recipes](recipes.md): settings for common runners
197
+ - [Not supported](how-it-works.md#not-supported): what bivium leaves to
198
+ other tools