@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
|
@@ -2,17 +2,127 @@
|
|
|
2
2
|
|
|
3
3
|
```json
|
|
4
4
|
{
|
|
5
|
-
"serves":
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"serves": [
|
|
6
|
+
{
|
|
7
|
+
"rule": "straight-through-tests"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"rule": "declared-not-asserted"
|
|
11
|
+
}
|
|
12
|
+
],
|
|
8
13
|
"standing": "accepted",
|
|
9
14
|
"reason": {
|
|
10
15
|
"text": "\"use vi assert to validate it's existence first to narrow the type to exclude the need for optional chain\".",
|
|
11
16
|
"standing": "accepted"
|
|
12
|
-
}
|
|
17
|
+
},
|
|
18
|
+
"examples": [
|
|
19
|
+
{
|
|
20
|
+
"anchor": "a-short-circuit",
|
|
21
|
+
"answers": [
|
|
22
|
+
{
|
|
23
|
+
"check": "branch-in-a-test#test-body",
|
|
24
|
+
"form": "a-short-circuit"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"anchor": "an-optional-chain-after-an-index",
|
|
30
|
+
"answers": [
|
|
31
|
+
{
|
|
32
|
+
"check": "branch-in-a-test#test-body",
|
|
33
|
+
"form": "an-optional-chain-after-an-index"
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"anchor": "an-optional-chain-on-a-property",
|
|
39
|
+
"answers": [
|
|
40
|
+
{
|
|
41
|
+
"check": "branch-in-a-test#test-body",
|
|
42
|
+
"form": "an-optional-chain-on-a-property"
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"anchor": "an-optional-call",
|
|
48
|
+
"answers": [
|
|
49
|
+
{
|
|
50
|
+
"check": "branch-in-a-test#test-body",
|
|
51
|
+
"form": "an-optional-call"
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
]
|
|
13
56
|
}
|
|
14
57
|
```
|
|
15
58
|
|
|
16
59
|
- **Method:** A value that may be absent or one of several outcomes is narrowed with the framework's `assert` first. After that, plain `expect` reads it.
|
|
17
60
|
- **You can tell because:** No `?.`, `&&`, `if` or ternary in the test.
|
|
18
61
|
- **Industry name:** Guard Assertion (Meszaros).
|
|
62
|
+
|
|
63
|
+
The framework's assertion is not a claim of ours.
|
|
64
|
+
|
|
65
|
+
## Examples
|
|
66
|
+
|
|
67
|
+
### A short-circuit
|
|
68
|
+
```ts
|
|
69
|
+
declare const lookup: (id: string) => { readonly name: string } | undefined;
|
|
70
|
+
const found = lookup("a");
|
|
71
|
+
expect(found !== undefined && found.name === "Ada").toBe(true);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Assert the value is defined, then read it:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
declare const lookup: (id: string) => { readonly name: string } | undefined;
|
|
78
|
+
const found = lookup("a");
|
|
79
|
+
assert.isDefined(found);
|
|
80
|
+
expect(found.name).toBe("Ada");
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### An optional chain after an index
|
|
84
|
+
```ts
|
|
85
|
+
declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
|
|
86
|
+
expect(listTasks()[0]?.id).toBe("a");
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Destructure the element and assert it is defined, then read it:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
declare const listTasks: () => readonly { readonly id: string; readonly status: "open" | "done" }[];
|
|
93
|
+
const [first] = listTasks();
|
|
94
|
+
assert.isDefined(first);
|
|
95
|
+
expect(first.id).toBe("a");
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### An optional chain on a property
|
|
99
|
+
```ts
|
|
100
|
+
declare const findUser: (id: string) => { readonly name: string } | undefined;
|
|
101
|
+
expect(findUser("a")?.name).toBe("Ada");
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Assert the value is defined, then read it:
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
declare const findUser: (id: string) => { readonly name: string } | undefined;
|
|
108
|
+
const user = findUser("a");
|
|
109
|
+
assert.isDefined(user);
|
|
110
|
+
expect(user.name).toBe("Ada");
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### An optional call
|
|
114
|
+
```ts
|
|
115
|
+
declare const observers: { readonly enter?: (node: string) => string };
|
|
116
|
+
expect(observers.enter?.("a")).toBe("entered a");
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Destructure the function and assert it is defined, then call it:
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
declare const observers: { readonly enter?: (node: string) => string };
|
|
123
|
+
const { enter } = observers;
|
|
124
|
+
assert.isDefined(enter);
|
|
125
|
+
expect(enter("a")).toBe("entered a");
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
A method that reads `this` loses it once taken off its object, so assert it is defined where it is and call it there.
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
```json
|
|
4
4
|
{
|
|
5
|
-
"serves":
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"serves": [
|
|
6
|
+
{
|
|
7
|
+
"principle": "no-hidden-effects"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
8
10
|
"standing": "accepted",
|
|
9
11
|
"reason": {
|
|
10
12
|
"text": "\"this is a bunch of nullable and state management mess\". Proposed: Once a method travels as a value, its `this` is a fact the checker does not prove.",
|
|
@@ -16,5 +18,3 @@
|
|
|
16
18
|
- **Method:** Settings and changing state live in a factory, `createX({ settings })`. It returns an object of functions that close over private bindings. We author no `class`. A library's class is built only in its adapter.
|
|
17
19
|
- **You can tell because:** No `class` keyword in our code. No unit reads `this`.
|
|
18
20
|
- **Industry name:** Private Members (Crockford).
|
|
19
|
-
|
|
20
|
-
[Functional iteration](functional-iteration.md) also serves this principle.
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
```json
|
|
4
4
|
{
|
|
5
|
-
"serves":
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"serves": [
|
|
6
|
+
{
|
|
7
|
+
"rule": "tested-where-its-owned"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
8
10
|
"standing": "accepted",
|
|
9
11
|
"reason": {
|
|
10
12
|
"text": "\"if its a unit test it covers the unit it is the companion file to\".",
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
```json
|
|
4
4
|
{
|
|
5
|
-
"serves":
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"serves": [
|
|
6
|
+
{
|
|
7
|
+
"rule": "doer-or-orchestrator"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
8
10
|
"standing": "accepted",
|
|
9
11
|
"reason": {
|
|
10
12
|
"text": "\"If it's long it's doing too many things inline. I hold to functions are doers or are orchestrator a teaching.\"",
|
|
@@ -15,4 +17,4 @@
|
|
|
15
17
|
|
|
16
18
|
- **Method:** An orchestrator's body is a sequence of named calls to our units. Each failed result returns at once, unchanged. Any computing or branching between calls moves into a named doer.
|
|
17
19
|
- **You can tell because:** The orchestrator holds calls, early returns of failures, and a final return.
|
|
18
|
-
- **Industry name:** the Integration Operation Segregation Principle (Westphal)
|
|
20
|
+
- **Industry name:** the Integration Operation Segregation Principle (Westphal).
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
```json
|
|
4
4
|
{
|
|
5
|
-
"serves":
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"serves": [
|
|
6
|
+
{
|
|
7
|
+
"rule": "ports-declared-inside"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
8
10
|
"standing": "accepted",
|
|
9
11
|
"reason": {
|
|
10
12
|
"text": "If a unit builds its own adapter, it imports it, so the port is not passed in and the test cannot stub it.",
|
package/rules/typescript/recipes/{bounded-context-generic.md → constrained-context-generic.md}
RENAMED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Constrained context generic
|
|
2
2
|
|
|
3
3
|
```json
|
|
4
4
|
{
|
|
5
|
-
"serves":
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"serves": [
|
|
6
|
+
{
|
|
7
|
+
"rule": "declared-not-asserted"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
8
10
|
"standing": "accepted",
|
|
9
11
|
"reason": {
|
|
10
12
|
"text": "A field read from an open context is either cast or defaulted. Both hide a missing capability until run time.",
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
```json
|
|
4
4
|
{
|
|
5
|
-
"serves":
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"serves": [
|
|
6
|
+
{
|
|
7
|
+
"principle": "no-hidden-effects"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
8
10
|
"standing": "accepted",
|
|
9
11
|
"reason": {
|
|
10
12
|
"text": "\"this is giving mutation of input args vibes, not okay\"; \"pure functions are required\".",
|
|
@@ -15,4 +17,4 @@
|
|
|
15
17
|
|
|
16
18
|
- **Method:** A changed value is a new one: `{ ...order, total }` or `[...items].sort()`. Nothing writes to, deletes from, or rebinds a parameter.
|
|
17
19
|
- **You can tell because:** No assignment to a parameter or its fields.
|
|
18
|
-
- **Industry name:** immutability; Value Object (Fowler)
|
|
20
|
+
- **Industry name:** immutability; Value Object (Fowler).
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
```json
|
|
4
4
|
{
|
|
5
|
-
"serves":
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"serves": [
|
|
6
|
+
{
|
|
7
|
+
"rule": "shipped-risk-declared"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
8
10
|
"standing": "proposed",
|
|
9
11
|
"reason": {
|
|
10
12
|
"text": "\"Do we still bundle Zod which means a Zod cve won't show up accurately?\"; \"Otherwise we ship as a peer dependency declaration only.\"",
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
```json
|
|
4
4
|
{
|
|
5
|
-
"serves":
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"serves": [
|
|
6
|
+
{
|
|
7
|
+
"rule": "outside-dependencies-justified"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
8
10
|
"standing": "accepted",
|
|
9
11
|
"reason": {
|
|
10
12
|
"text": "\"Packages need a justification for the maintenance they add.\"",
|
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
```json
|
|
4
4
|
{
|
|
5
|
-
"serves":
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"serves": [
|
|
6
|
+
{
|
|
7
|
+
"rule": "handed-what-it-uses"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"rule": "one-reason-per-module"
|
|
11
|
+
}
|
|
12
|
+
],
|
|
8
13
|
"standing": "accepted",
|
|
9
14
|
"reason": {
|
|
10
15
|
"text": "\"The anaemic concern there is that by writing types with no logic you are failing coupling/cohesion and single responsibility principles.\"",
|
|
@@ -16,5 +21,3 @@
|
|
|
16
21
|
- **Method:** An entity's type and its logic share one module. Its functions take the entity.
|
|
17
22
|
- **You can tell because:** No file holds only types, except port declarations.
|
|
18
23
|
- **Industry name:** DDD entity (Evans).
|
|
19
|
-
|
|
20
|
-
Entity module also serves One reason per module.
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
```json
|
|
4
4
|
{
|
|
5
|
-
"serves":
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"serves": [
|
|
6
|
+
{
|
|
7
|
+
"rule": "fixed-versions"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
8
10
|
"standing": "accepted",
|
|
9
11
|
"reason": {
|
|
10
12
|
"text": "\"dependencies must be pinned\"; \"If we ship with dependencies we need lock files.\"",
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
```json
|
|
4
4
|
{
|
|
5
|
-
"serves":
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"serves": [
|
|
6
|
+
{
|
|
7
|
+
"rule": "upstream-stays-untouched"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
8
10
|
"standing": "accepted",
|
|
9
11
|
"reason": {
|
|
10
12
|
"text": "\"this must be justified as additional drift as impossible to apply as an extension instead\".",
|
|
@@ -2,17 +2,57 @@
|
|
|
2
2
|
|
|
3
3
|
```json
|
|
4
4
|
{
|
|
5
|
-
"serves":
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"serves": [
|
|
6
|
+
{
|
|
7
|
+
"rule": "straight-through-tests"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
8
10
|
"standing": "accepted",
|
|
9
11
|
"reason": {
|
|
10
12
|
"text": "\"more error throwing, not allowed\". A `try` or `catch` in a test is a branch that decides whether the test passes.",
|
|
11
13
|
"standing": "proposed"
|
|
12
|
-
}
|
|
14
|
+
},
|
|
15
|
+
"examples": [
|
|
16
|
+
{
|
|
17
|
+
"anchor": "a-try-block",
|
|
18
|
+
"answers": [
|
|
19
|
+
{
|
|
20
|
+
"check": "throw-or-catch-in-a-test#try-block",
|
|
21
|
+
"form": "a-try-block"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
]
|
|
13
26
|
}
|
|
14
27
|
```
|
|
15
28
|
|
|
16
29
|
- **Method:** A failure is checked as the returned variant: `expect(result).toEqual({ outcome: "failure", ... })`. An adapter whose caller's contract is a throw is checked with `expect(call).toThrow(...)`.
|
|
17
30
|
- **You can tell because:** No `try`, `catch` or `throw` in any test.
|
|
18
31
|
- **Industry name:** none; it follows from Failures are values.
|
|
32
|
+
|
|
33
|
+
## Examples
|
|
34
|
+
|
|
35
|
+
### A try block
|
|
36
|
+
```ts
|
|
37
|
+
declare const load: (path: string) => string;
|
|
38
|
+
try {
|
|
39
|
+
load("missing.json");
|
|
40
|
+
} catch (error) {
|
|
41
|
+
expect(error).toBeInstanceOf(Error);
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Assert the returned variant:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
declare const load: (path: string) => { readonly outcome: "ok"; readonly value: string } | { readonly outcome: "failure"; readonly kind: "missing" };
|
|
49
|
+
expect(load("missing.json")).toEqual({ outcome: "failure", kind: "missing" });
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
For an adapter whose caller's contract is a throw, assert the throw:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
declare const load: (path: string) => string;
|
|
56
|
+
const call = () => load("missing.json");
|
|
57
|
+
expect(call).toThrow(Error);
|
|
58
|
+
```
|
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
```json
|
|
4
4
|
{
|
|
5
|
-
"serves":
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"serves": [
|
|
6
|
+
{
|
|
7
|
+
"principle": "no-leak-across-a-boundary"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"rule": "failures-are-values"
|
|
11
|
+
}
|
|
12
|
+
],
|
|
8
13
|
"standing": "accepted",
|
|
9
14
|
"reason": {
|
|
10
15
|
"text": "\"They are about speaking the language of the caller at the boundary.\"",
|
|
@@ -16,5 +21,3 @@
|
|
|
16
21
|
- **Method:** The adapter turns a library's throw into a failure variant of ours. At the program's edge, it turns our failure into the caller's form: an exit code, a status, or a throw where that caller's contract is exceptions.
|
|
17
22
|
- **You can tell because:** No `throw` except at an adapter whose caller expects one.
|
|
18
23
|
- **Industry name:** anticorruption layer (Evans), applied to failures.
|
|
19
|
-
|
|
20
|
-
Failure mapping at the adapter also serves Failures are values.
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
```json
|
|
4
4
|
{
|
|
5
|
-
"serves":
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"serves": [
|
|
6
|
+
{
|
|
7
|
+
"rule": "declared-not-asserted"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
8
10
|
"standing": "accepted",
|
|
9
11
|
"reason": {
|
|
10
12
|
"text": "\"the correct amount of casting is **0**\"; \"this feels like its hiding a problem with out modelling\".",
|
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
```json
|
|
4
4
|
{
|
|
5
|
-
"serves":
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"serves": [
|
|
6
|
+
{
|
|
7
|
+
"rule": "doer-or-orchestrator"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"principle": "no-hidden-effects"
|
|
11
|
+
}
|
|
12
|
+
],
|
|
8
13
|
"standing": "accepted",
|
|
9
14
|
"reason": {
|
|
10
15
|
"text": "\"For of mutates by its nature. It doesn't return. It's state holding required or side effect based.\"",
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
```json
|
|
4
4
|
{
|
|
5
|
-
"serves":
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"serves": [
|
|
6
|
+
{
|
|
7
|
+
"rule": "tested-where-its-owned"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
8
10
|
"standing": "accepted",
|
|
9
11
|
"reason": {
|
|
10
12
|
"text": "An ambient setting broke the shared checkout three times; each fix to one instance left the class open.",
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
```json
|
|
4
4
|
{
|
|
5
|
-
"serves":
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"serves": [
|
|
6
|
+
{
|
|
7
|
+
"rule": "tested-where-its-owned"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
8
10
|
"standing": "accepted",
|
|
9
11
|
"reason": {
|
|
10
12
|
"text": "\"a useful pattern to ensure boundaries are clear when to maintain and keep pyramid checkable.\"",
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# it.each over typed rows
|
|
2
|
+
|
|
3
|
+
```json
|
|
4
|
+
{
|
|
5
|
+
"serves": [
|
|
6
|
+
{
|
|
7
|
+
"rule": "straight-through-tests"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
10
|
+
"standing": "accepted",
|
|
11
|
+
"reason": {
|
|
12
|
+
"text": "\"It's just boilerplate for cases being tested.\"",
|
|
13
|
+
"standing": "accepted"
|
|
14
|
+
},
|
|
15
|
+
"examples": [
|
|
16
|
+
{
|
|
17
|
+
"anchor": "branching-with-if",
|
|
18
|
+
"answers": [
|
|
19
|
+
{
|
|
20
|
+
"check": "branch-in-a-test#test-body",
|
|
21
|
+
"form": "branching-with-if"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"anchor": "a-ternary",
|
|
27
|
+
"answers": [
|
|
28
|
+
{
|
|
29
|
+
"check": "branch-in-a-test#test-body",
|
|
30
|
+
"form": "a-ternary"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"anchor": "a-switch",
|
|
36
|
+
"answers": [
|
|
37
|
+
{
|
|
38
|
+
"check": "branch-in-a-test#test-body",
|
|
39
|
+
"form": "a-switch"
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
- **Method:** Several cases of one behaviour are one `it.each<Row>([...])`. `Row` is a declared type whose members are primitives, types imported from non-test modules, or readonly lists of imported types. Each row writes out its input and its expected output.
|
|
48
|
+
- **You can tell because:** Every row is a literal. No row is built, mapped or picked.
|
|
49
|
+
- **Industry name:** Parameterized Test (Meszaros), with rows typed and written out.
|
|
50
|
+
|
|
51
|
+
## Examples
|
|
52
|
+
|
|
53
|
+
### Branching with if
|
|
54
|
+
```ts
|
|
55
|
+
declare const gradeFor: (score: number) => string;
|
|
56
|
+
const score = 60;
|
|
57
|
+
const grade = gradeFor(score);
|
|
58
|
+
if (score >= 50) {
|
|
59
|
+
expect(grade).toBe("pass");
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Write one typed row per case:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
declare const gradeFor: (score: number) => string;
|
|
67
|
+
type Row = { readonly score: number; readonly expected: string };
|
|
68
|
+
it.each<Row>([
|
|
69
|
+
{ score: 60, expected: "pass" },
|
|
70
|
+
{ score: 40, expected: "fail" },
|
|
71
|
+
])("grades $score as $expected", ({ score, expected }) => {
|
|
72
|
+
expect(gradeFor(score)).toBe(expected);
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### A ternary
|
|
77
|
+
```ts
|
|
78
|
+
declare const discountFor: (order: { readonly quantity: number }) => number;
|
|
79
|
+
const quantity = 10;
|
|
80
|
+
expect(discountFor({ quantity })).toBe(quantity >= 10 ? 5 : 0);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Write one typed row per case:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
declare const discountFor: (order: { readonly quantity: number }) => number;
|
|
87
|
+
type Row = { readonly quantity: number; readonly expected: number };
|
|
88
|
+
it.each<Row>([
|
|
89
|
+
{ quantity: 10, expected: 5 },
|
|
90
|
+
{ quantity: 9, expected: 0 },
|
|
91
|
+
])("gives $expected off an order of $quantity", ({ quantity, expected }) => {
|
|
92
|
+
expect(discountFor({ quantity })).toBe(expected);
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### A switch
|
|
97
|
+
```ts
|
|
98
|
+
declare const labelFor: (basket: { readonly count: number }) => string;
|
|
99
|
+
const basket = { count: 1 } as const;
|
|
100
|
+
switch (basket.count) {
|
|
101
|
+
case 1:
|
|
102
|
+
expect(labelFor(basket)).toBe("1 item");
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Write one typed row per case:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
declare const labelFor: (basket: { readonly count: number }) => string;
|
|
110
|
+
type Row = { readonly count: number; readonly expected: string };
|
|
111
|
+
it.each<Row>([
|
|
112
|
+
{ count: 1, expected: "1 item" },
|
|
113
|
+
{ count: 2, expected: "2 items" },
|
|
114
|
+
])("labels a basket of $count", ({ count, expected }) => {
|
|
115
|
+
expect(labelFor({ count })).toBe(expected);
|
|
116
|
+
});
|
|
117
|
+
```
|