@ghostry/fabricator 0.0.5 → 0.0.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.
|
@@ -5,14 +5,14 @@ function integration(instance) {
|
|
|
5
5
|
return {
|
|
6
6
|
name: "@ghostry/fabricator",
|
|
7
7
|
provides: {
|
|
8
|
-
fabricator: ({ established })=>{
|
|
9
|
-
if (void 0 ===
|
|
10
|
-
return
|
|
8
|
+
fabricator: ({ established: instance })=>{
|
|
9
|
+
if (void 0 === instance) throw new FabricatorError.HarnessingProviderError();
|
|
10
|
+
return instance;
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
*frame ({ identity }) {
|
|
14
14
|
const salt = index_js_layer(saltFor(identity));
|
|
15
|
-
yield (body)=>instance.wrap({
|
|
15
|
+
yield (body)=>instance.context.scope().wrap({
|
|
16
16
|
salt
|
|
17
17
|
}, body);
|
|
18
18
|
}
|
|
@@ -3,9 +3,9 @@ import type { PlainObject } from "../Utility/Types";
|
|
|
3
3
|
import type { FabricatorTestContext, Integration } from "./Types";
|
|
4
4
|
/**
|
|
5
5
|
* Decorate an existing `Instance` as a `@ghostry/harness` integration. The
|
|
6
|
-
* whole of it is `
|
|
7
|
-
* of real work. Construction ordinals therefore restart per test (each
|
|
8
|
-
* re-instantiates), which is what makes `.only`, filters, shards, and
|
|
6
|
+
* whole of it is `context.scope().wrap({ salt: layer(saltFor(identity)) })` —
|
|
7
|
+
* one line of real work. Construction ordinals therefore restart per test (each
|
|
8
|
+
* `wrap` re-instantiates), which is what makes `.only`, filters, shards, and
|
|
9
9
|
* `.concurrent` unable to shift a neighbor's data. That per-test partitioning
|
|
10
10
|
* is also why the salt needs no file in it; see `saltFor`
|
|
11
11
|
* (`Harnessing/Salt.ts`).
|
|
@@ -18,10 +18,28 @@ import type { FabricatorTestContext, Integration } from "./Types";
|
|
|
18
18
|
* merely precede it. On the synchronous carrier an async body still raises
|
|
19
19
|
* `SynchronousStackError` from `wrap`.
|
|
20
20
|
*
|
|
21
|
-
* `
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
21
|
+
* `body` is handed to `wrap` directly rather than called inside a closure.
|
|
22
|
+
* `wrap(overlay, block)` already takes `(scope) => $Return`, which is exactly
|
|
23
|
+
* the wrapper's own `(established) => $Return`, so the scope `wrap` opens _is_
|
|
24
|
+
* the established value with nothing in between to adapt it.
|
|
25
|
+
*
|
|
26
|
+
* `context.scope()`, not `instance`, is the receiver. A plain `instance.wrap`
|
|
27
|
+
* lays its overlay over the instance it was called on, and that receiver is
|
|
28
|
+
* bound before any test runs — so an integration composed _inside_ another
|
|
29
|
+
* library's fabricator scope would restate from the configured instance and
|
|
30
|
+
* drop that enclosing scope entirely, silently, while still landing innermost
|
|
31
|
+
* and therefore governing every draw. `context.scope()` is the frame in effect,
|
|
32
|
+
* or the instance itself when there is none, which is this integration's
|
|
33
|
+
* contract in both cases with no branch. Called fresh here rather than hoisted:
|
|
34
|
+
* `scope` is a function so that capturing it captures the lookup, where a
|
|
35
|
+
* captured result would pin one frame.
|
|
36
|
+
*
|
|
37
|
+
* The frame that `wrap` pushes is keyed on the receiver's ancestry, so under
|
|
38
|
+
* composition the per-test frame belongs to the enclosing scope's line: a
|
|
39
|
+
* collateral `fork()` taken inside a test resolves against the outermost frame
|
|
40
|
+
* on its own line instead. That is the ordinary ancestry rule — siblings never
|
|
41
|
+
* see each other's frames, and the outward walk supplies the outer ones — not a
|
|
42
|
+
* special case here.
|
|
25
43
|
*
|
|
26
44
|
* `provides.fabricator` is then that scope — the instance `wrap` gave its
|
|
27
45
|
* block, not the base instance — so `context.fabricator.salt` is the per-test
|
|
@@ -31,13 +49,12 @@ import type { FabricatorTestContext, Integration } from "./Types";
|
|
|
31
49
|
* running providers outside the frame it opened, and raises
|
|
32
50
|
* `HarnessingProviderError` rather than quietly providing the base instance.
|
|
33
51
|
*
|
|
34
|
-
* Nothing here
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* are the request honored, not a bug to override.
|
|
52
|
+
* Nothing here sets `clock`. A pinned `Date` (the recommended setup) and the
|
|
53
|
+
* wall-clock default are already concrete numbers by the time `overlay()` sees
|
|
54
|
+
* them, so they inherit through every `wrap` — the frame in effect's included:
|
|
55
|
+
* salt varies per test, "now" does not. `clock: "derived"` is left alone on
|
|
56
|
+
* purpose — that policy's documented meaning is that the salt _is_ the
|
|
57
|
+
* reproducibility unit, so per-test clocks are the request honored, not a bug
|
|
58
|
+
* to override.
|
|
42
59
|
*/
|
|
43
60
|
export declare function integration<$Registry extends PlainObject>(instance: Instance<$Registry>): Integration<FabricatorTestContext<$Registry>, Instance<$Registry>>;
|