@kensio/part-factory-test-data 1.9.0 → 1.10.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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://anthropic.com/claude-code/plugin.schema.json",
|
|
3
3
|
"name": "part-factory-test-data",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.10.0",
|
|
5
5
|
"description": "How to build typed test data with @kensio/part-factory factories.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Kensio Software",
|
package/README.md
CHANGED
|
@@ -33,10 +33,10 @@ to override.
|
|
|
33
33
|
an encoded form body, or front matter parts to a file as written on disk. If the map is copying
|
|
34
34
|
fields across into an object of the same shape, you wanted a `DynamicFactory`.
|
|
35
35
|
|
|
36
|
-
**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
**Call the factory directly.** `make(overrides)` already is that function, and it does the job
|
|
37
|
+
better, since its overrides are partial all the way down the nested structure where a spread
|
|
38
|
+
replaces a nested object whole. A wrapper doing more than passing overrides through is a signal that
|
|
39
|
+
the factory is the wrong shape, or that the output type is fighting you.
|
|
40
40
|
|
|
41
41
|
**Factories belong beside the type they construct.** A library defining an event or message shape
|
|
42
42
|
should export a factory for it, so consumers never hand-roll the literal. The example the skill
|
package/package.json
CHANGED
|
@@ -48,9 +48,9 @@ The type can go on saying what is actually required.
|
|
|
48
48
|
|
|
49
49
|
## Overrides are a deep partial
|
|
50
50
|
|
|
51
|
-
Overrides merge into the defaults
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
Overrides merge into the defaults, all the way down the nested structure. That is what makes "state
|
|
52
|
+
only what matters" possible. A test can set one field three levels deep and leave its siblings
|
|
53
|
+
alone.
|
|
54
54
|
|
|
55
55
|
Two consequences worth knowing:
|
|
56
56
|
|
|
@@ -84,10 +84,10 @@ export const customerFactory = new DynamicFactory<Customer>(() => ({
|
|
|
84
84
|
}));
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
##
|
|
87
|
+
## Add a variant only for a shared meaning
|
|
88
88
|
|
|
89
89
|
A variant earns its name when several tests mean the same thing by it. One test that needs an
|
|
90
|
-
unusual value should write that value down,
|
|
90
|
+
unusual value should write that value down inline, and leave the factories alone.
|
|
91
91
|
|
|
92
92
|
The failure mode is a directory of `cancelledOrderWithRefundAndNoAddressFactory` names, each used
|
|
93
93
|
once, where reading a test means going to find out what its factory actually sets. Writing the field
|
|
@@ -136,7 +136,7 @@ Keep each dependency as narrow as the factory actually needs. An `OrderStore` is
|
|
|
136
136
|
whole application never is. A wide dependency is how state starts leaking between tests that were
|
|
137
137
|
supposed to be independent.
|
|
138
138
|
|
|
139
|
-
##
|
|
139
|
+
## Call the factory directly
|
|
140
140
|
|
|
141
141
|
```typescript
|
|
142
142
|
// Anti-pattern. This is make(overrides) with extra steps.
|
|
@@ -148,7 +148,7 @@ export function makeCustomer(overrides: Partial<Customer> = {}): Customer {
|
|
|
148
148
|
`make(overrides)` already is that function, and it does the job better. Its overrides are partial
|
|
149
149
|
all the way down the nested structure, where the spread above replaces a nested object whole.
|
|
150
150
|
|
|
151
|
-
A wrapper that does anything more than pass overrides through is a signal to read
|
|
151
|
+
A wrapper that does anything more than pass overrides through is a signal to read and never to
|
|
152
152
|
write. It usually means one of two things:
|
|
153
153
|
|
|
154
154
|
- **The factory is the wrong shape.** The wrapper is computing something the defaults should be
|