@hailstails/hone 2.0.0-pre.4 → 2.0.0-pre.6
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/ADOPTING.md +10 -19
- package/CHANGELOG.md +46 -0
- package/MIGRATING.md +25 -14
- package/README.md +3 -4
- package/chunks/chunk-2U5EKYGS.js +14348 -0
- package/chunks/{chunk-FPIP7JEC.js → chunk-4AJQHZ7I.js} +1 -1
- package/chunks/chunk-4PHKVNM3.js +2377 -0
- package/chunks/{chunk-CXM5KBZX.js → chunk-6LTJRJOE.js} +1 -1
- package/chunks/{chunk-PVSC4SE3.js → chunk-BISP2JOL.js} +4 -6
- package/chunks/{chunk-BRANVR7K.js → chunk-FRE5IA3C.js} +1 -1
- package/chunks/{chunk-E4D5WDRX.js → chunk-GMLT3MHO.js} +252 -254
- package/chunks/chunk-M4VSJ27S.js +139 -0
- package/chunks/{chunk-YGMO5Z6U.js → chunk-P2VHWLK4.js} +182 -193
- package/chunks/{chunk-LD766VWU.js → chunk-U6W65ZOF.js} +31 -2
- package/chunks/{chunk-BKQ3K766.js → chunk-WPEOCLTP.js} +39 -33
- package/chunks/{chunk-A3RL4O5V.js → chunk-XNIXPQQ5.js} +35 -2
- package/docs/extending.md +2 -2
- package/methods/lenses/function-first.md +2 -2
- package/package.json +1 -1
- package/rules/README.md +5 -3
- package/rules/SPIRIT.md +1 -1
- package/rules/numbers.md +4 -4
- package/rules/principles/no-leak-across-a-boundary.md +1 -1
- package/rules/principles.md +1 -1
- package/rules/record-kinds/authorised-location.md +1 -1
- package/rules/records.md +11 -19
- package/rules/rules.md +5 -5
- package/rules/sources.md +6 -7
- package/rules/typescript/checks.md +55 -387
- package/rules/typescript/recipes/adapter-per-outside-party.md +10 -5
- package/rules/typescript/recipes/assert-to-narrow.md +114 -4
- package/rules/typescript/recipes/closure-factory.md +5 -5
- package/rules/typescript/recipes/companion-test-file.md +5 -3
- package/rules/typescript/recipes/composed-orchestrator.md +6 -4
- package/rules/typescript/recipes/composition-root.md +5 -3
- package/rules/typescript/recipes/{bounded-context-generic.md → constrained-context-generic.md} +6 -4
- package/rules/typescript/recipes/copy-never-write-in.md +6 -4
- package/rules/typescript/recipes/declared-not-bundled.md +5 -3
- package/rules/typescript/recipes/dependency-record.md +5 -3
- package/rules/typescript/recipes/domain-vocabulary-list.md +5 -3
- package/rules/typescript/recipes/entity-module.md +8 -5
- package/rules/typescript/recipes/exact-pins-and-a-lock-file.md +5 -3
- package/rules/typescript/recipes/extension-outside-the-vendored-code.md +5 -3
- package/rules/typescript/recipes/failure-asserted-as-a-value.md +44 -4
- package/rules/typescript/recipes/failure-mapping-at-the-adapter.md +8 -5
- package/rules/typescript/recipes/fix-the-declaration-not-the-value.md +5 -3
- package/rules/typescript/recipes/functional-iteration.md +8 -3
- package/rules/typescript/recipes/guard-clauses.md +5 -3
- package/rules/typescript/recipes/integration-test-owns-its-scratch.md +5 -3
- package/rules/typescript/recipes/integration-test-suffix.md +5 -3
- package/rules/typescript/recipes/it-each-over-typed-rows.md +117 -0
- package/rules/typescript/recipes/map-out-at-the-adapter.md +36 -4
- package/rules/typescript/recipes/meaning-in-names-not-comments.md +5 -5
- package/rules/typescript/recipes/named-exported-type.md +5 -3
- package/rules/typescript/recipes/narrow-ports.md +5 -3
- package/rules/typescript/recipes/one-argument-object.md +8 -3
- package/rules/typescript/recipes/{port-in-the-domain.md → port-in-a-module-of-its-own.md} +7 -5
- package/rules/typescript/recipes/ports-in-the-argument.md +5 -3
- package/rules/typescript/recipes/repo-scripts-only.md +5 -3
- package/rules/typescript/recipes/result-union.md +5 -5
- package/rules/typescript/recipes/screaming-folders.md +5 -5
- package/rules/typescript/recipes/shared-strict-base-config.md +5 -5
- package/rules/typescript/recipes/stub-with-vi-fn.md +130 -0
- package/rules/typescript/recipes/tagged-union-and-exhaustive-switch.md +5 -3
- package/rules/typescript/recipes/whole-words.md +5 -3
- package/rules/typescript/recipes/whole-written-out-expectation.md +284 -4
- package/rules/typescript/recipes/world-values-through-a-port.md +5 -3
- package/rules/typescript/recipes/zod-at-the-producers-adapter.md +8 -3
- package/rules/typescript/recipes.md +567 -21
- package/rules/typescript/symptoms/ambient-randomness.md +1 -1
- package/rules/typescript/symptoms/answer-set-in-a-hook.md +1 -1
- package/rules/typescript/symptoms/{assertion-outside-a-test → assertion-outside-a-test-body}/assertion-site.md +1 -1
- package/rules/typescript/symptoms/{assertion-outside-a-test.md → assertion-outside-a-test-body.md} +1 -1
- package/rules/typescript/symptoms/branch-in-a-test/test-body.md +10 -184
- package/rules/typescript/symptoms/branch-in-a-test.md +11 -1
- package/rules/typescript/symptoms/claimed-type/non-null-assertions.md +1 -1
- package/rules/typescript/symptoms/{code-or-prose-read-as-text.md → code-or-prose-read-as-text-in-a-test.md} +2 -2
- package/rules/typescript/symptoms/computed-value-in-a-test/test-body.md +26 -117
- package/rules/typescript/symptoms/computed-value-in-a-test.md +1 -1
- package/rules/typescript/symptoms/date-used-directly.md +1 -1
- package/rules/typescript/symptoms/default-for-a-required-value.md +1 -1
- package/rules/typescript/symptoms/double-with-a-body/logic-in-a-passed-function.md +1 -18
- package/rules/typescript/symptoms/double-with-a-body.md +1 -1
- package/rules/typescript/symptoms/{export-from-a-test-file.md → export-from-a-test.md} +1 -1
- package/rules/typescript/symptoms/failure-shaped-as-success.md +1 -1
- package/rules/typescript/symptoms/inherited-environment-in-a-subprocess/git-spawn-environment.md +1 -1
- package/rules/typescript/symptoms/inner-layer-imports-outer.md +1 -1
- package/rules/typescript/symptoms/library-class-built-in-place.md +1 -1
- package/rules/typescript/symptoms/loop-keyword/loop-statement.md +1 -1
- package/rules/typescript/symptoms/outside-import-past-a-boundary/import-or-require.md +1 -0
- package/rules/typescript/symptoms/outside-import-past-a-boundary.md +5 -4
- package/rules/typescript/symptoms/outside-type-in-a-signature.md +2 -2
- package/rules/typescript/symptoms/{port-outside-the-domain.md → port-beside-its-adapter.md} +2 -2
- package/rules/typescript/symptoms/port-named-for-a-mechanism.md +1 -1
- package/rules/typescript/symptoms/process-global-used-in-place.md +1 -1
- package/rules/typescript/symptoms/rebinding/test-body.md +1 -18
- package/rules/typescript/symptoms/rebinding.md +11 -1
- package/rules/typescript/symptoms/schema-past-its-adapter.md +2 -2
- package/rules/typescript/symptoms/text-past-its-reader/test-body.md +2 -17
- package/rules/typescript/symptoms/text-past-its-reader.md +1 -1
- package/rules/typescript/symptoms/throw-or-catch-in-a-test/try-block.md +1 -25
- package/rules/typescript/symptoms/type-declared-in-a-test/test-type-declaration.md +1 -1
- package/rules/typescript/symptoms/unasserted-call.md +1 -1
- package/rules/typescript/symptoms.md +35 -35
- package/src/application/conformance/conformance-testing-types.d.ts +2 -0
- package/src/domain/language-layer/authored-item-types.d.ts +21 -5
- package/src/domain/runner/runner-result-types.d.ts +1 -2
- package/src/eslint-plugin.js +40 -38
- package/src/hone.js +15 -13638
- package/src/infrastructure/disciplines-file/version-one-names.json +4 -5
- package/src/infrastructure/engines/eslint/runner/runner.js +56 -70
- package/src/infrastructure/engines/walker/{assertion-outside-a-test → assertion-outside-a-test-body}/assertion-site/assertion-site.js +1 -1
- package/src/infrastructure/engines/walker/branch-in-a-test/test-body/test-body-logic.js +39 -65
- package/src/infrastructure/engines/walker/{code-or-prose-read-as-text → code-or-prose-read-as-text-in-a-test}/raw-read/raw-read.js +1 -1
- package/src/infrastructure/engines/walker/{export-from-a-test-file → export-from-a-test}/test-file-export/test-file-export.js +1 -1
- package/src/infrastructure/engines/walker/runner/runner.js +10 -10
- package/src/infrastructure/engines/walker/strictness-weakened/strict/compiler-overrides.js +3 -3
- package/src/infrastructure/engines/walker/type-declared-in-a-test/test-type-declaration/test-type-declaration.examples.json +15 -3
- package/src/infrastructure/engines/walker/type-declared-in-a-test/test-type-declaration/test-type-declaration.js +118 -4
- package/src/measure-engines.process.js +80 -0
- package/src/testing.d.ts +1 -0
- package/src/testing.js +111 -26
- package/chunks/chunk-7FVSZ2VL.js +0 -1304
- package/chunks/chunk-BIDD2YWP.js +0 -398
- package/rules/record-kinds/boundary-record.md +0 -9
- package/rules/typescript/recipes/iteach-over-typed-rows.md +0 -18
- package/rules/typescript/recipes/stub-with-vifn.md +0 -20
- /package/rules/typescript/symptoms/{code-or-prose-read-as-text → code-or-prose-read-as-text-in-a-test}/raw-read.md +0 -0
- /package/rules/typescript/symptoms/{export-from-a-test-file → export-from-a-test}/test-file-export.md +0 -0
- /package/src/infrastructure/engines/walker/{assertion-outside-a-test → assertion-outside-a-test-body}/assertion-site/assertion-site.examples.json +0 -0
- /package/src/infrastructure/engines/walker/{assertion-outside-a-test → assertion-outside-a-test-body}/assertion-site/piece.json +0 -0
- /package/src/infrastructure/engines/walker/{code-or-prose-read-as-text → code-or-prose-read-as-text-in-a-test}/raw-read/piece.json +0 -0
- /package/src/infrastructure/engines/walker/{code-or-prose-read-as-text → code-or-prose-read-as-text-in-a-test}/raw-read/raw-read.examples.json +0 -0
- /package/src/infrastructure/engines/walker/{export-from-a-test-file → export-from-a-test}/test-file-export/piece.json +0 -0
- /package/src/infrastructure/engines/walker/{export-from-a-test-file → export-from-a-test}/test-file-export/test-file-export.examples.json +0 -0
|
@@ -20,7 +20,7 @@ Direct calls to `Math.random`, `crypto.randomUUID` and `crypto.getRandomValues`.
|
|
|
20
20
|
|
|
21
21
|
Stub answers set in inline test lifecycle callbacks.
|
|
22
22
|
|
|
23
|
-
## Assertion outside a test
|
|
23
|
+
## Assertion outside a test body
|
|
24
24
|
|
|
25
25
|
### assertion-site
|
|
26
26
|
|
|
@@ -28,7 +28,7 @@ Stub answers set in inline test lifecycle callbacks.
|
|
|
28
28
|
- **Misses:** Assertions called through another wrapper or a Vitest namespace import. A test registered through a shared fixture module or a mutable alias may be reported as outside a test. Asymmetric matchers and extension registration do not assert.
|
|
29
29
|
- **Settings traced to:** None.
|
|
30
30
|
|
|
31
|
-
An assertion in a hook, suite body or helper is detached from the test whose result it should determine. Put it in the
|
|
31
|
+
An assertion in a hook, suite body or helper is detached from the test whose result it should determine. Put it in the test body that exercises the behaviour.
|
|
32
32
|
|
|
33
33
|
## Authored class or this
|
|
34
34
|
|
|
@@ -111,213 +111,40 @@ Name each state in the type.
|
|
|
111
111
|
### test-body
|
|
112
112
|
|
|
113
113
|
- **Engines:** `walker`
|
|
114
|
+
- **Forms:** `branching-with-if`, `a-ternary`, `a-short-circuit`, `an-optional-chain-after-an-index`, `an-optional-chain-on-a-mock-call`, `an-optional-chain-on-a-mock-result`, `an-optional-chain-on-a-property`, `an-optional-call`, `a-switch`
|
|
114
115
|
- **Flags beyond the symptom:** unit's own API (edition 1).
|
|
115
116
|
- **Settings traced to:** the edition: backwards compatibility for adopters since the npm release.
|
|
116
117
|
|
|
117
|
-
|
|
118
|
+
Branches in a test file. These run with the other [test-body checks](../README.md#checks-the-test-body-checks), which share their scope, editions and settings.
|
|
118
119
|
|
|
119
120
|
## Flags
|
|
120
|
-
Edition 1:
|
|
121
|
-
- `if` statements and ternary expressions.
|
|
122
|
-
|
|
123
|
-
Edition 2 also flags:
|
|
124
|
-
- `??`, `||` and `&&`, and their assignment forms `??=`, `||=` and `&&=`.
|
|
125
|
-
- Optional chaining: `a?.b`, `a?.[key]` and `f?.()`.
|
|
126
|
-
- `switch` statements.
|
|
127
|
-
|
|
128
|
-
## Allowed forms in a test
|
|
129
121
|
|
|
130
122
|
### Branching with if
|
|
131
|
-
|
|
132
|
-
declare const parse: (text: string) => { readonly outcome: "ok"; readonly value: string } | { readonly outcome: "failed" };
|
|
133
|
-
const parsed = parse("a");
|
|
134
|
-
if (parsed.outcome === "ok") {
|
|
135
|
-
expect(parsed.value).toBe("a");
|
|
136
|
-
}
|
|
137
|
-
```
|
|
138
|
-
Compare the whole result:
|
|
139
|
-
|
|
140
|
-
```ts
|
|
141
|
-
declare const parse: (text: string) => { readonly outcome: "ok"; readonly value: string } | { readonly outcome: "failed" };
|
|
142
|
-
expect(parse("a")).toEqual({ outcome: "ok", value: "a" });
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
Or write one test per case, or one table:
|
|
146
|
-
|
|
147
|
-
```ts
|
|
148
|
-
declare const parse: (text: string) => { readonly outcome: "ok"; readonly value: string } | { readonly outcome: "failed" };
|
|
149
|
-
it.each([
|
|
150
|
-
{ text: "a", expected: { outcome: "ok", value: "a" } },
|
|
151
|
-
{ text: "", expected: { outcome: "failed" } },
|
|
152
|
-
])("parses $text", ({ text, expected }) => {
|
|
153
|
-
expect(parse(text)).toEqual(expected);
|
|
154
|
-
});
|
|
155
|
-
```
|
|
123
|
+
An `if` statement. Edition 1.
|
|
156
124
|
|
|
157
125
|
### A ternary
|
|
158
|
-
|
|
159
|
-
declare const discountFor: (customer: { readonly tier: "premium" | "standard" }) => number;
|
|
160
|
-
const tier = "premium";
|
|
161
|
-
expect(discountFor({ tier })).toBe(tier === "premium" ? 10 : 0);
|
|
162
|
-
```
|
|
163
|
-
Write the value out, with one table row per case:
|
|
164
|
-
|
|
165
|
-
```ts
|
|
166
|
-
declare const discountFor: (customer: { readonly tier: "premium" | "standard" }) => number;
|
|
167
|
-
it.each([
|
|
168
|
-
{ tier: "premium", expected: 10 },
|
|
169
|
-
{ tier: "standard", expected: 0 },
|
|
170
|
-
] as const)("gives $expected off to a $tier customer", ({ tier, expected }) => {
|
|
171
|
-
expect(discountFor({ tier })).toBe(expected);
|
|
172
|
-
});
|
|
173
|
-
```
|
|
126
|
+
A ternary expression. Edition 1.
|
|
174
127
|
|
|
175
128
|
### A short-circuit
|
|
176
|
-
|
|
177
|
-
declare const lookup: (id: string) => { readonly name: string } | undefined;
|
|
178
|
-
const found = lookup("a");
|
|
179
|
-
expect(found !== undefined && found.name === "Ada").toBe(true);
|
|
180
|
-
```
|
|
181
|
-
Write the value a fallback gives. To narrow a value that may be missing, assert it is defined, then read it:
|
|
182
|
-
|
|
183
|
-
```ts
|
|
184
|
-
declare const lookup: (id: string) => { readonly name: string } | undefined;
|
|
185
|
-
const found = lookup("a");
|
|
186
|
-
assert.isDefined(found);
|
|
187
|
-
expect(found.name).toBe("Ada");
|
|
188
|
-
```
|
|
129
|
+
`??`, `||` or `&&`, or an assignment form `??=`, `||=` or `&&=`. Edition 2 adds it.
|
|
189
130
|
|
|
190
131
|
### An optional chain after an index
|
|
191
|
-
|
|
192
|
-
declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
|
|
193
|
-
expect(listTasks()[0]?.id).toBe("a");
|
|
194
|
-
```
|
|
195
|
-
Compare the whole element:
|
|
196
|
-
|
|
197
|
-
```ts
|
|
198
|
-
declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
|
|
199
|
-
expect(listTasks()[0]).toMatchObject({ id: "a" });
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
Or destructure it and assert it is defined before reading it:
|
|
203
|
-
|
|
204
|
-
```ts
|
|
205
|
-
declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
|
|
206
|
-
const [first] = listTasks();
|
|
207
|
-
assert.isDefined(first);
|
|
208
|
-
expect(first.id).toBe("a");
|
|
209
|
-
```
|
|
132
|
+
Optional chaining straight after an index, as in `rows[0]?.id`, `mock.instances` and `mock.contexts` included. Edition 2 adds it.
|
|
210
133
|
|
|
211
134
|
### An optional chain on a mock call
|
|
212
|
-
|
|
213
|
-
declare const start: (run: (task: { readonly id: string }) => void) => void;
|
|
214
|
-
const run = vi.fn<(task: { readonly id: string }) => void>();
|
|
215
|
-
start(run);
|
|
216
|
-
expect(run.mock.calls[0]?.[0].id).toBe("a");
|
|
217
|
-
```
|
|
218
|
-
Assert that call by its position:
|
|
219
|
-
|
|
220
|
-
```ts
|
|
221
|
-
declare const start: (run: (task: { readonly id: string }) => void) => void;
|
|
222
|
-
const run = vi.fn<(task: { readonly id: string }) => void>();
|
|
223
|
-
start(run);
|
|
224
|
-
expect(run).toHaveBeenNthCalledWith(1, expect.objectContaining({ id: "a" }));
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
Reading `run.mock.lastCall?.[0]` names this section too. Assert the last call:
|
|
228
|
-
|
|
229
|
-
```ts
|
|
230
|
-
declare const start: (run: (task: { readonly id: string }) => void) => void;
|
|
231
|
-
const run = vi.fn<(task: { readonly id: string }) => void>();
|
|
232
|
-
start(run);
|
|
233
|
-
expect(run).toHaveBeenLastCalledWith({ id: "a" });
|
|
234
|
-
```
|
|
135
|
+
Optional chaining after an index into `mock.calls`, or on `mock.lastCall`. Edition 2 adds it.
|
|
235
136
|
|
|
236
137
|
### An optional chain on a mock result
|
|
237
|
-
|
|
238
|
-
declare const pricing: { readonly priceOf: (amount: number) => number };
|
|
239
|
-
declare const settle: (prices: { readonly priceOf: (amount: number) => number }) => void;
|
|
240
|
-
const priceOf = vi.spyOn(pricing, "priceOf");
|
|
241
|
-
settle(pricing);
|
|
242
|
-
expect(priceOf.mock.results[0]?.value).toBe(4);
|
|
243
|
-
```
|
|
244
|
-
Assert what that call returned, by its position:
|
|
245
|
-
|
|
246
|
-
```ts
|
|
247
|
-
declare const pricing: { readonly priceOf: (amount: number) => number };
|
|
248
|
-
declare const settle: (prices: { readonly priceOf: (amount: number) => number }) => void;
|
|
249
|
-
const priceOf = vi.spyOn(pricing, "priceOf");
|
|
250
|
-
settle(pricing);
|
|
251
|
-
expect(priceOf).toHaveNthReturnedWith(1, 4);
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
`toHaveLastReturnedWith` asserts what the last call returned.
|
|
255
|
-
|
|
256
|
-
An optional chain on `mock.instances` or `mock.contexts` names [An optional chain after an index](#an-optional-chain-after-an-index).
|
|
138
|
+
Optional chaining after an index into `mock.results`. Edition 2 adds it.
|
|
257
139
|
|
|
258
140
|
### An optional chain on a property
|
|
259
|
-
|
|
260
|
-
declare const findUser: (id: string) => { readonly name: string } | undefined;
|
|
261
|
-
expect(findUser("a")?.name).toBe("Ada");
|
|
262
|
-
```
|
|
263
|
-
Compare the whole value:
|
|
264
|
-
|
|
265
|
-
```ts
|
|
266
|
-
declare const findUser: (id: string) => { readonly name: string } | undefined;
|
|
267
|
-
expect(findUser("a")).toMatchObject({ name: "Ada" });
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
Or assert it is defined before reading it:
|
|
271
|
-
|
|
272
|
-
```ts
|
|
273
|
-
declare const findUser: (id: string) => { readonly name: string } | undefined;
|
|
274
|
-
const user = findUser("a");
|
|
275
|
-
assert.isDefined(user);
|
|
276
|
-
expect(user.name).toBe("Ada");
|
|
277
|
-
```
|
|
141
|
+
Any other optional property or index, `a?.b` or `a?.[key]`. Edition 2 adds it.
|
|
278
142
|
|
|
279
143
|
### An optional call
|
|
280
|
-
|
|
281
|
-
declare const observers: { readonly enter?: (node: string) => void };
|
|
282
|
-
observers.enter?.("a");
|
|
283
|
-
```
|
|
284
|
-
Destructure the function, assert it is defined, then call it:
|
|
285
|
-
|
|
286
|
-
```ts
|
|
287
|
-
declare const observers: { readonly enter?: (node: string) => void };
|
|
288
|
-
const { enter } = observers;
|
|
289
|
-
assert.isDefined(enter);
|
|
290
|
-
enter("a");
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
A method that reads `this` loses it once taken off its object, so assert it is defined where it is and call it there:
|
|
294
|
-
|
|
295
|
-
```ts
|
|
296
|
-
declare const tracker: { readonly entered: readonly string[]; enter?(node: string): void };
|
|
297
|
-
assert.isDefined(tracker.enter);
|
|
298
|
-
tracker.enter("a");
|
|
299
|
-
```
|
|
144
|
+
An optional call, `f?.()`. Edition 2 adds it.
|
|
300
145
|
|
|
301
146
|
### A switch
|
|
302
|
-
|
|
303
|
-
declare const areaOf: (shape: { readonly kind: "square"; readonly side: number } | { readonly kind: "circle"; readonly radius: number }) => number;
|
|
304
|
-
const shape = { kind: "square", side: 2 } as const;
|
|
305
|
-
switch (shape.kind) {
|
|
306
|
-
case "square":
|
|
307
|
-
expect(areaOf(shape)).toBe(4);
|
|
308
|
-
}
|
|
309
|
-
```
|
|
310
|
-
Write one test per case, or one table:
|
|
311
|
-
|
|
312
|
-
```ts
|
|
313
|
-
declare const areaOf: (shape: { readonly kind: "square"; readonly side: number } | { readonly kind: "circle"; readonly radius: number }) => number;
|
|
314
|
-
it.each([
|
|
315
|
-
{ shape: { kind: "square", side: 2 } as const, expected: 4 },
|
|
316
|
-
{ shape: { kind: "circle", radius: 0 } as const, expected: 0 },
|
|
317
|
-
])("measures a $shape.kind", ({ shape, expected }) => {
|
|
318
|
-
expect(areaOf(shape)).toBe(expected);
|
|
319
|
-
});
|
|
320
|
-
```
|
|
147
|
+
A `switch` statement. Edition 2 adds it.
|
|
321
148
|
|
|
322
149
|
## Built unit called in place
|
|
323
150
|
|
|
@@ -388,7 +215,7 @@ const name = user.name;
|
|
|
388
215
|
```
|
|
389
216
|
Parse or narrow the value so the type follows from a check rather than from an assertion. For a value that may be absent, handle the absent case with a check or an early return; for a binding assigned later, initialise it where it is declared or make it a `const` built from what it needs.
|
|
390
217
|
|
|
391
|
-
In a test file, [the test-body check](symptoms/branch-in-a-test/test-body.md) flags an `if` check at either edition, and its edition 2 flags the `??` fallback:
|
|
218
|
+
In a test file, [the test-body check](symptoms/branch-in-a-test/test-body.md) flags an `if` check at either edition, and its edition 2 flags the `??` fallback: read [Branch in a test](symptoms/branch-in-a-test.md) there.
|
|
392
219
|
|
|
393
220
|
### unlisted-cast-site
|
|
394
221
|
|
|
@@ -422,7 +249,7 @@ Parse or narrow the value so the type follows from a check rather than from an a
|
|
|
422
249
|
|
|
423
250
|
When handing a value across a boundary truly forces a cast, such as a library that types its schemas loosely or a database driver that returns unparsed rows, put the cast in the one adapter file at that boundary and record that file as an `authorised-location` with a why-chain. With clean boundaries that is one file and one record; casts scattered across many files are the sign the boundary is missing.
|
|
424
251
|
|
|
425
|
-
## Code or prose read as text
|
|
252
|
+
## Code or prose read as text in a test
|
|
426
253
|
|
|
427
254
|
### raw-read
|
|
428
255
|
|
|
@@ -437,144 +264,54 @@ The test reads source or prose as text. Assert what the code returns or does. A
|
|
|
437
264
|
### test-body
|
|
438
265
|
|
|
439
266
|
- **Engines:** `walker`
|
|
267
|
+
- **Forms:** `a-method-that-picks-or-tests-an-element`, `a-method-that-computes-a-value`, `a-method-that-mutates`, `merging-objects`, `building-an-object-from-entries`, `building-an-array-from-a-length`, `a-math-call`
|
|
440
268
|
- **Flags beyond the symptom:** unit's own API (edition 1).
|
|
441
269
|
- **Settings traced to:** the edition: backwards compatibility for adopters since the npm release.
|
|
442
270
|
|
|
443
|
-
|
|
271
|
+
Values computed, mutated or picked in a test file. These run with the other [test-body checks](../README.md#checks-the-test-body-checks), which share their scope, editions and settings.
|
|
444
272
|
|
|
445
273
|
## Flags
|
|
446
|
-
Edition 1:
|
|
447
|
-
- A method call with a computing or mutating name, wherever it could be the string or array method of that name: `map`, `filter`, `reduce`, `find`, `forEach`, `join`, `slice`, `split`, `replace`, `includes`, `sort`, `trim`, `keys`, `values`, `push`, `pop`, `splice`, `fill` and similar string and array methods.
|
|
448
|
-
- Not flagged: a call with one of those names whose arguments no string or array method of that name accepts, which makes it the unit's own API. Either it passes an object literal where none of them takes an object, such as `paths.join({ segments: ["a", "b"] })`, or it passes more arguments than any of them takes, such as `screen.keys("x", true, true)`.
|
|
449
|
-
- Still flagged, though they look like that:
|
|
450
|
-
- a call whose receiver traces back to a built-in namespace such as `Object` or `Math`, a package or `node:` module (imported, required or loaded with `import()`) other than a `#` import or a package some `package.json` in the repository names, or a string or array literal. The trace follows variables declared in the test file, including names destructured from a traced module or namespace, such as `posix` after `const { posix } = path`, and a property read directly off an object literal declared there, such as `deps.path` after `const deps = { path }`;
|
|
451
|
-
- a call that spreads its arguments;
|
|
452
|
-
- an object at a position where a string or array method takes one, such as `rows.includes({ id: "a" })`, `rows.push({ id: "a" })`, `rows.reduce(sum, { total: 0 })`, `rows.find(isA, {})` or `text.split({ [Symbol.split]: splitter })`.
|
|
453
|
-
- What this check cannot know: it reads names and syntax, not types, so it cannot tell what a receiver is.
|
|
454
|
-
- It flags the unit's own method given a variable, such as `repository.find(query)`.
|
|
455
|
-
- It misses a string or array method taken off its receiver before the call.
|
|
456
|
-
- It does not trace a receiver that is a function parameter, an `it.each` row, a value from another module (even a relative module that re-exports a package), a name destructured from an object literal, or a property nested deeper in one, such as `deps.nested.path`; it reads these as the unit's own.
|
|
457
|
-
- It releases a method of another built-in or library type that shares a name, such as a stream's `values` or `reduce`, when that call passes an object or more arguments than the string or array method takes.
|
|
458
|
-
Only a check that reads types knows a receiver's identity, and Hone does not have one yet.
|
|
459
|
-
|
|
460
|
-
Edition 2 also flags:
|
|
461
|
-
- Computing calls on a built-in namespace: `Object.assign`, `Object.fromEntries`, `Array.from` and any `Math` method. `JSON.stringify` and `JSON.parse` are [text-past-its-reader#test-body](symptoms/text-past-its-reader/test-body.md).
|
|
462
|
-
|
|
463
|
-
## Allowed forms in a test
|
|
464
274
|
|
|
465
275
|
### A method that picks or tests an element
|
|
466
|
-
|
|
467
|
-
declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
|
|
468
|
-
expect(listTasks().find((task) => task.id === "a")).toEqual({ id: "a", status: "open" });
|
|
469
|
-
```
|
|
470
|
-
Assert on the whole array:
|
|
471
|
-
|
|
472
|
-
```ts
|
|
473
|
-
declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
|
|
474
|
-
expect(listTasks()).toContainEqual({ id: "a", status: "open" });
|
|
475
|
-
```
|
|
476
|
-
|
|
477
|
-
```ts
|
|
478
|
-
declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
|
|
479
|
-
expect(listTasks()).toEqual(expect.arrayContaining([expect.objectContaining({ id: "a" })]));
|
|
480
|
-
```
|
|
481
|
-
|
|
482
|
-
The check cannot tell the unit's own method with one of these names from an array method when it is given a variable, such as `repository.find(query)`. That is a limit of the check, described under [What the check flags](#flags).
|
|
276
|
+
A call named `at`, `every`, `filter`, `find`, `findIndex`, `findLast`, `findLastIndex`, `includes`, `indexOf`, `lastIndexOf` or `some`. Edition 1.
|
|
483
277
|
|
|
484
278
|
### A method that computes a value
|
|
485
|
-
|
|
486
|
-
declare const idsOf: (rows: readonly { readonly id: string }[]) => readonly string[];
|
|
487
|
-
const rows = [{ id: "a1" }, { id: "b2" }];
|
|
488
|
-
expect(idsOf(rows)).toEqual(rows.map((row) => row.id));
|
|
489
|
-
```
|
|
490
|
-
Write the expected value out:
|
|
491
|
-
|
|
492
|
-
```ts
|
|
493
|
-
declare const idsOf: (rows: readonly { readonly id: string }[]) => readonly string[];
|
|
494
|
-
expect(idsOf([{ id: "a1" }, { id: "b2" }])).toEqual(["a1", "b2"]);
|
|
495
|
-
```
|
|
496
|
-
|
|
497
|
-
Or match the part that matters:
|
|
498
|
-
|
|
499
|
-
```ts
|
|
500
|
-
declare const receiptOf: (order: { readonly total: number }) => { readonly total: number; readonly label: string };
|
|
501
|
-
expect(receiptOf({ total: 30 })).toMatchObject({ label: expect.stringContaining("30") });
|
|
502
|
-
```
|
|
279
|
+
A call named after a string or array method that gives back a new value or walks the list: `map`, `reduce`, `forEach`, `join`, `slice`, `split`, `replace`, `sort`, `trim`, `keys`, `values` and similar. Edition 1.
|
|
503
280
|
|
|
504
281
|
### A method that mutates
|
|
505
|
-
|
|
506
|
-
declare const namesOf: (team: string) => readonly string[];
|
|
507
|
-
const expected = ["Ada"];
|
|
508
|
-
expected.push("Grace");
|
|
509
|
-
expect(namesOf("core")).toEqual(expected);
|
|
510
|
-
```
|
|
511
|
-
Write the finished array out:
|
|
512
|
-
|
|
513
|
-
```ts
|
|
514
|
-
declare const namesOf: (team: string) => readonly string[];
|
|
515
|
-
expect(namesOf("core")).toEqual(["Ada", "Grace"]);
|
|
516
|
-
```
|
|
282
|
+
A call named `copyWithin`, `fill`, `pop`, `push`, `reverse`, `shift`, `splice` or `unshift`. Edition 1.
|
|
517
283
|
|
|
518
284
|
### Merging objects
|
|
519
|
-
|
|
520
|
-
const base = { method: "POST", path: "/tasks" } as const;
|
|
521
|
-
const request = Object.assign({}, base, { body: "a" });
|
|
522
|
-
expect(request.body).toBe("a");
|
|
523
|
-
```
|
|
524
|
-
Write the object out, spreading what it copies:
|
|
525
|
-
|
|
526
|
-
```ts
|
|
527
|
-
const base = { method: "POST", path: "/tasks" } as const;
|
|
528
|
-
const request = { ...base, body: "a" };
|
|
529
|
-
expect(request.body).toBe("a");
|
|
530
|
-
```
|
|
531
|
-
|
|
532
|
-
A spread copies an `Error`'s own properties into a plain object, which is not an `Error`. To give an `Error` a property, assign it:
|
|
533
|
-
|
|
534
|
-
```ts
|
|
535
|
-
declare const reasonOf: (error: Error & { readonly code?: string }) => string;
|
|
536
|
-
const missing: Error & { code?: string } = new Error("ENOENT");
|
|
537
|
-
missing.code = "ENOENT";
|
|
538
|
-
expect(reasonOf(missing)).toBe("missing");
|
|
539
|
-
```
|
|
285
|
+
`Object.assign`. Edition 2 adds it.
|
|
540
286
|
|
|
541
287
|
### Building an object from entries
|
|
542
|
-
|
|
543
|
-
declare const countsOf: (words: readonly string[]) => Readonly<Record<string, number>>;
|
|
544
|
-
expect(countsOf(["a"])).toEqual(Object.fromEntries([["a", 1]]));
|
|
545
|
-
```
|
|
546
|
-
Write the object out:
|
|
547
|
-
|
|
548
|
-
```ts
|
|
549
|
-
declare const countsOf: (words: readonly string[]) => Readonly<Record<string, number>>;
|
|
550
|
-
expect(countsOf(["a"])).toEqual({ a: 1 });
|
|
551
|
-
```
|
|
288
|
+
`Object.fromEntries`. Edition 2 adds it.
|
|
552
289
|
|
|
553
290
|
### Building an array from a length
|
|
554
|
-
|
|
555
|
-
declare const pageOf: (rows: readonly { readonly id: number }[]) => readonly { readonly id: number }[];
|
|
556
|
-
expect(pageOf(Array.from({ length: 3 }, (_, index) => ({ id: index })))).toHaveLength(3);
|
|
557
|
-
```
|
|
558
|
-
Write a short array out:
|
|
291
|
+
`Array.from`. Edition 2 adds it.
|
|
559
292
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
expect(pageOf([{ id: 0 }, { id: 1 }, { id: 2 }])).toHaveLength(3);
|
|
563
|
-
```
|
|
293
|
+
### A Math call
|
|
294
|
+
Any `Math` method. Edition 2 adds it.
|
|
564
295
|
|
|
565
|
-
|
|
296
|
+
## Margin
|
|
566
297
|
|
|
567
|
-
|
|
568
|
-
```ts
|
|
569
|
-
declare const roundedOf: (amount: number) => number;
|
|
570
|
-
expect(roundedOf(2.5)).toBe(Math.round(2.5));
|
|
571
|
-
```
|
|
572
|
-
Write the number out:
|
|
298
|
+
A method call is flagged wherever it could be the string or array method of that name.
|
|
573
299
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
300
|
+
- Not flagged: a call with one of those names whose arguments no string or array method of that name accepts, which makes it the unit's own API. Either it passes an object literal where none of them takes an object, such as `paths.join({ segments: ["a", "b"] })`, or it passes more arguments than any of them takes, such as `screen.keys("x", true, true)`.
|
|
301
|
+
- Still flagged, though they look like that:
|
|
302
|
+
- a call whose receiver traces back to a built-in namespace such as `Object` or `Math`, a package or `node:` module (imported, required or loaded with `import()`) other than a `#` import or a package some `package.json` in the repository names, or a string or array literal. The trace follows variables declared in the test file, including names destructured from a traced module or namespace, such as `posix` after `const { posix } = path`, and a property read directly off an object literal declared there, such as `deps.path` after `const deps = { path }`;
|
|
303
|
+
- a call that spreads its arguments;
|
|
304
|
+
- an object at a position where a string or array method takes one, such as `rows.includes({ id: "a" })`, `rows.push({ id: "a" })`, `rows.reduce(sum, { total: 0 })`, `rows.find(isA, {})` or `text.split({ [Symbol.split]: splitter })`.
|
|
305
|
+
- What this check cannot know: it reads names and syntax, not types, so it cannot tell what a receiver is.
|
|
306
|
+
- It flags the unit's own method given a variable, such as `repository.find(query)`.
|
|
307
|
+
- It misses a string or array method taken off its receiver before the call.
|
|
308
|
+
- It does not trace a receiver that is a function parameter, an `it.each` row, a value from another module (even a relative module that re-exports a package), a name destructured from an object literal, or a property nested deeper in one, such as `deps.nested.path`; it reads these as the unit's own.
|
|
309
|
+
- It releases a method of another built-in or library type that shares a name, such as a stream's `values` or `reduce`, when that call passes an object or more arguments than the string or array method takes.
|
|
310
|
+
Only a check that reads types knows a receiver's identity, and Hone does not have one yet.
|
|
311
|
+
|
|
312
|
+
An array too long to read written out, such as one row past a page size of 1,000, is flagged too. A record at the site answers it.
|
|
313
|
+
|
|
314
|
+
`JSON.stringify` and `JSON.parse` are [text-past-its-reader#test-body](symptoms/text-past-its-reader/test-body.md).
|
|
578
315
|
|
|
579
316
|
## Date used directly
|
|
580
317
|
|
|
@@ -644,32 +381,16 @@ Name each remaining variant so the compiler checks exhaustiveness.
|
|
|
644
381
|
### logic-in-a-passed-function
|
|
645
382
|
|
|
646
383
|
- **Engines:** `walker`
|
|
384
|
+
- **Forms:** `logic-inside-a-function-the-test-passes-on`
|
|
647
385
|
- **Misses:** hand-written doubles.
|
|
648
386
|
- **Settings traced to:** test files are what `testFiles` declares: the adopter's convention.
|
|
649
387
|
|
|
650
388
|
A construct any other test-body check flags, inside a function a test passes on. These run with the other [test-body checks](../README.md#checks-the-test-body-checks), which share their scope, editions and settings.
|
|
651
389
|
|
|
652
390
|
## Flags
|
|
653
|
-
- A function a test writes as a property or method of an object literal, or gives to `vi.fn` or `mockImplementation`, holding a construct another test-body check flags at the edition that runs.
|
|
654
|
-
|
|
655
|
-
## Allowed forms in a test
|
|
656
391
|
|
|
657
392
|
### Logic inside a function the test passes on
|
|
658
|
-
|
|
659
|
-
declare const isInstalled: (fileKind: { readonly kindOf: (path: string) => "file" | "missing" }) => "installed" | "missing";
|
|
660
|
-
const installedFiles = ["bin/hone.js"];
|
|
661
|
-
expect(isInstalled({ kindOf: (path) => (installedFiles.includes(path) ? "file" : "missing") })).toBe("installed");
|
|
662
|
-
```
|
|
663
|
-
A function a test writes as a property or method of an object literal, or gives to `vi.fn` or `mockImplementation`, is passed on: to the unit, to a table row, or to a double. Any flagged construct inside it names this section. Make it a `vi.fn` spy with a written-out return, and write out what it was asked:
|
|
664
|
-
|
|
665
|
-
```ts
|
|
666
|
-
declare const isInstalled: (fileKind: { readonly kindOf: (path: string) => "file" | "missing" }) => "installed" | "missing";
|
|
667
|
-
const kindOf = vi.fn<(path: string) => "file" | "missing">().mockReturnValue("file");
|
|
668
|
-
expect(isInstalled({ kindOf })).toBe("installed");
|
|
669
|
-
expect(kindOf).toHaveBeenCalledExactlyOnceWith("bin/hone.js");
|
|
670
|
-
```
|
|
671
|
-
|
|
672
|
-
The recipe is [Stub with vi.fn](recipes/stub-with-vifn.md).
|
|
393
|
+
A function a test writes as a property or method of an object literal, gives to `vi.fn`, `mockImplementation` or `mockImplementationOnce`, or passes straight to a function it calls in its own body, holding a construct another test-body check flags. The edition is that construct's.
|
|
673
394
|
|
|
674
395
|
### stub-implementation
|
|
675
396
|
|
|
@@ -728,7 +449,7 @@ src/price-formatting.ts
|
|
|
728
449
|
```
|
|
729
450
|
Rename the file or folder for what it contains, or split it into files that each hold one thing.
|
|
730
451
|
|
|
731
|
-
## Export from a test
|
|
452
|
+
## Export from a test
|
|
732
453
|
|
|
733
454
|
### test-file-export
|
|
734
455
|
|
|
@@ -766,7 +487,7 @@ Floating versions the repository runs, including development dependencies, priva
|
|
|
766
487
|
- **Misses:** `env` built from `process.env` under an accepted name.
|
|
767
488
|
- **Settings traced to:** accepted helper names: **nothing**; `.spec`, `.js`, `.mjs` test files: **nothing**.
|
|
768
489
|
|
|
769
|
-
A git spawn in a test
|
|
490
|
+
A git spawn in a test whose `env` is inherited.
|
|
770
491
|
|
|
771
492
|
## Flags
|
|
772
493
|
|
|
@@ -867,7 +588,7 @@ const totals = orders.map((order) => order.total);
|
|
|
867
588
|
```
|
|
868
589
|
Replace a counted loop with `Array.from({ length }, (_, position) => ...)`.
|
|
869
590
|
|
|
870
|
-
In a test file, the [computed-value-in-a-test check](symptoms/computed-value-in-a-test/test-body.md) flags `map` at either edition, and its edition 2 flags `Array.from`:
|
|
591
|
+
In a test file, the [computed-value-in-a-test check](symptoms/computed-value-in-a-test/test-body.md) flags `map` at either edition, and its edition 2 flags `Array.from`: read [Computed value in a test](symptoms/computed-value-in-a-test.md) there.
|
|
871
592
|
|
|
872
593
|
## Many spellings of one concept
|
|
873
594
|
|
|
@@ -1083,32 +804,16 @@ Needs ESLint adopted through the projection; see the ESLint piece.
|
|
|
1083
804
|
### test-body
|
|
1084
805
|
|
|
1085
806
|
- **Engines:** `walker`
|
|
807
|
+
- **Forms:** `a-let`
|
|
1086
808
|
- **Misses:** a local `let` in production.
|
|
1087
809
|
- **Settings traced to:** none.
|
|
1088
810
|
|
|
1089
811
|
`let` declarations in a test file. These run with the other [test-body checks](../README.md#checks-the-test-body-checks), which share their scope, editions and settings.
|
|
1090
812
|
|
|
1091
813
|
## Flags
|
|
1092
|
-
Edition 1:
|
|
1093
|
-
- `let` declarations.
|
|
1094
|
-
|
|
1095
|
-
## Allowed forms in a test
|
|
1096
814
|
|
|
1097
815
|
### A let
|
|
1098
|
-
|
|
1099
|
-
declare const record: (store: { readonly save: (text: string) => void }) => void;
|
|
1100
|
-
let saved = "";
|
|
1101
|
-
record({ save: (text) => { saved = text; } });
|
|
1102
|
-
expect(saved).toBe("a");
|
|
1103
|
-
```
|
|
1104
|
-
Record the calls with `vi.fn` and assert them:
|
|
1105
|
-
|
|
1106
|
-
```ts
|
|
1107
|
-
declare const record: (store: { readonly save: (text: string) => void }) => void;
|
|
1108
|
-
const save = vi.fn<(text: string) => void>();
|
|
1109
|
-
record({ save });
|
|
1110
|
-
expect(save).toHaveBeenCalledWith("a");
|
|
1111
|
-
```
|
|
816
|
+
A `let` declaration. Edition 1.
|
|
1112
817
|
|
|
1113
818
|
## Shorthand name
|
|
1114
819
|
|
|
@@ -1556,30 +1261,16 @@ Needs ESLint adopted through the projection.
|
|
|
1556
1261
|
### test-body
|
|
1557
1262
|
|
|
1558
1263
|
- **Engines:** `walker`
|
|
1264
|
+
- **Forms:** `serialising-or-parsing-json`
|
|
1559
1265
|
- **Misses:** production sites.
|
|
1560
1266
|
- **Settings traced to:** the edition: backwards compatibility for adopters since the npm release.
|
|
1561
1267
|
|
|
1562
|
-
|
|
1268
|
+
JSON text made or read in a test file. These run with the other [test-body checks](../README.md#checks-the-test-body-checks), which share their scope, editions and settings.
|
|
1563
1269
|
|
|
1564
1270
|
## Flags
|
|
1565
|
-
Edition 2:
|
|
1566
|
-
- `JSON.stringify` and `JSON.parse`. A finding names [Serialising or parsing JSON](#serialising-or-parsing-json).
|
|
1567
|
-
|
|
1568
|
-
## Allowed forms in a test
|
|
1569
1271
|
|
|
1570
1272
|
### Serialising or parsing JSON
|
|
1571
|
-
|
|
1572
|
-
declare const render: (row: { readonly id: string }) => string;
|
|
1573
|
-
expect(JSON.parse(render({ id: "a" }))).toEqual({ id: "a" });
|
|
1574
|
-
```
|
|
1575
|
-
A finding on `JSON.stringify` or `JSON.parse` names this section. Assert the object the unit gives back, written out:
|
|
1576
|
-
|
|
1577
|
-
```ts
|
|
1578
|
-
declare const rowOf: (row: { readonly id: string }) => { readonly id: string };
|
|
1579
|
-
expect(rowOf({ id: "a" })).toEqual({ id: "a" });
|
|
1580
|
-
```
|
|
1581
|
-
|
|
1582
|
-
A unit that gives back only text should hand over an object, leaving the text to the adapter at its edge.
|
|
1273
|
+
`JSON.stringify` or `JSON.parse`. Edition 2 adds it.
|
|
1583
1274
|
|
|
1584
1275
|
## Throw between our units
|
|
1585
1276
|
|
|
@@ -1626,39 +1317,16 @@ Assert on the whole result. Branching in tests is also reported by [the branch-i
|
|
|
1626
1317
|
### try-block
|
|
1627
1318
|
|
|
1628
1319
|
- **Engines:** `walker`
|
|
1320
|
+
- **Forms:** `a-try-block`
|
|
1629
1321
|
- **Misses:** `catch`.
|
|
1630
1322
|
- **Settings traced to:** none.
|
|
1631
1323
|
|
|
1632
1324
|
`try` statements in a test file. These run with the other [test-body checks](../README.md#checks-the-test-body-checks), which share their scope, editions and settings.
|
|
1633
1325
|
|
|
1634
1326
|
## Flags
|
|
1635
|
-
Edition 1:
|
|
1636
|
-
- `try` statements.
|
|
1637
|
-
|
|
1638
|
-
## Allowed forms in a test
|
|
1639
1327
|
|
|
1640
1328
|
### A try block
|
|
1641
|
-
|
|
1642
|
-
declare const load: (path: string) => string;
|
|
1643
|
-
try {
|
|
1644
|
-
load("missing.json");
|
|
1645
|
-
} catch (error) {
|
|
1646
|
-
expect(error).toBeInstanceOf(Error);
|
|
1647
|
-
}
|
|
1648
|
-
```
|
|
1649
|
-
Assert the throw:
|
|
1650
|
-
|
|
1651
|
-
```ts
|
|
1652
|
-
declare const load: (path: string) => string;
|
|
1653
|
-
expect(() => load("missing.json")).toThrow(Error);
|
|
1654
|
-
```
|
|
1655
|
-
|
|
1656
|
-
```ts
|
|
1657
|
-
declare const loadLater: (path: string) => Promise<string>;
|
|
1658
|
-
it("refuses a missing file", async () => {
|
|
1659
|
-
await expect(loadLater("missing.json")).rejects.toThrow(Error);
|
|
1660
|
-
});
|
|
1661
|
-
```
|
|
1329
|
+
A `try` statement. Edition 1.
|
|
1662
1330
|
|
|
1663
1331
|
## Thrown non-error
|
|
1664
1332
|
|
|
@@ -1693,7 +1361,7 @@ Direct fetch-and-run commands in package scripts, CI workflows, and shell script
|
|
|
1693
1361
|
- **Misses:** Inline type literals and declarations in ordinary source files imported only by tests.
|
|
1694
1362
|
- **Settings traced to:** None.
|
|
1695
1363
|
|
|
1696
|
-
A test declares a type, interface or enum of its own. Import the contract owned by the unit or its boundary so the test and the unit rely on the same type. Module and global augmentations are allowed.
|
|
1364
|
+
A test declares a type, interface or enum of its own. Import the contract owned by the unit or its boundary so the test and the unit rely on the same type. Module and global augmentations are allowed. So is a top-level `type`, not exported, used only as the `it.each` or `describe.each` row type: one flat object or tuple, readonly or not, whose members are primitives, types imported by name, or readonly lists of imported types.
|
|
1697
1365
|
|
|
1698
1366
|
## Type derived from code
|
|
1699
1367
|
|
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
```json
|
|
4
4
|
{
|
|
5
|
-
"serves":
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"serves": [
|
|
6
|
+
{
|
|
7
|
+
"rule": "outside-dependencies-stay-at-boundaries"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"principle": "no-leak-across-a-boundary"
|
|
11
|
+
}
|
|
12
|
+
],
|
|
8
13
|
"standing": "accepted",
|
|
9
14
|
"reason": {
|
|
10
15
|
"text": "\"I didn't want a json parse wrapper. I wanted a boundary on whoever made json\"; \"Json parse has no contract… Http fetch library for example has complexity to bind\".",
|
|
@@ -14,5 +19,5 @@
|
|
|
14
19
|
```
|
|
15
20
|
|
|
16
21
|
- **Method:** An outside dependency or runtime module is imported only in the adapter file for the party it reaches. That adapter fulfils a port and returns our types. Nothing re-exports the outside dependency. `JSON.parse` is called inside the adapter for whoever produced the JSON.
|
|
17
|
-
- **You can tell because:** Each package import sits in a file with
|
|
18
|
-
- **Industry name:** Adapter; Gateway;
|
|
22
|
+
- **You can tell because:** Each package import sits in a file with an authorised location bound to that party.
|
|
23
|
+
- **Industry name:** Adapter; Gateway; anticorruption layer; Hexagonal Architecture (Cockburn).
|