@voltro/testing 0.33.0 → 0.35.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/CHANGELOG.md +1968 -0
- package/README.md +1 -1
- package/dist/client.d.ts +49 -2
- package/dist/client.js +55 -45
- package/dist/dialect.js +192 -154
- package/dist/index.d.ts +378 -21
- package/dist/index.js +313 -113
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# @voltro/testing
|
|
4
4
|
|
|
5
|
-
**Test utilities for Voltro apps — deterministic clock,
|
|
5
|
+
**Test utilities for Voltro apps — deterministic clock, subject and row factories, a handler-level invoke and a request-level app harness, queued LLM responses, scoped subject/tenant runners, and a cross-dialect parity harness.**
|
|
6
6
|
|
|
7
7
|
[📖 Documentation](https://docs.voltro.dev/docs/testing/overview) · [voltro.dev](https://voltro.dev) · [Voltro Cloud](https://voltro.cloud)
|
|
8
8
|
|
package/dist/client.d.ts
CHANGED
|
@@ -1,9 +1,40 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import { Exit } from 'effect/Exit';
|
|
1
3
|
import { ReactElement } from 'react';
|
|
2
4
|
import { ReactNode } from 'react';
|
|
5
|
+
import { RunForkOptions } from 'effect/Runtime';
|
|
6
|
+
import { RuntimeFiber } from 'effect/Fiber';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The runtime the hooks get. EXPORTED so it can be guarded.
|
|
10
|
+
*
|
|
11
|
+
* `runPromiseExit` is required, not optional: every write hook goes through
|
|
12
|
+
* `runRpcPromise`, which reads the exit and re-throws `Cause.squash(...)` so a
|
|
13
|
+
* rejection carries its `_tag` — and it calls `runtime.runPromiseExit`, not
|
|
14
|
+
* `runPromise`. A fake missing the method makes `mutate()` throw
|
|
15
|
+
* `runtime.runPromiseExit is not a function` into a `void`ed promise: no handler
|
|
16
|
+
* runs, nothing is recorded, and the component renders perfectly. This harness
|
|
17
|
+
* kept a two-method runtime for a release after the write path moved, and the
|
|
18
|
+
* failure read as "the click did not register".
|
|
19
|
+
*
|
|
20
|
+
* It is a module constant rather than a per-instance literal for one reason:
|
|
21
|
+
* `fakeRuntimeParity.test.ts` derives the required method set from the client's
|
|
22
|
+
* own source and checks it against THIS object, so the next method the client
|
|
23
|
+
* starts calling goes red here instead of in whichever hook reaches it first.
|
|
24
|
+
*/
|
|
25
|
+
export declare const FAKE_RUNTIME: {
|
|
26
|
+
runPromise: <A, E>(effect: Effect.Effect<A, E, never>, options?: {
|
|
27
|
+
readonly signal?: AbortSignal | undefined;
|
|
28
|
+
} | undefined) => Promise<A>;
|
|
29
|
+
runPromiseExit: <A, E>(effect: Effect.Effect<A, E, never>, options?: {
|
|
30
|
+
readonly signal?: AbortSignal;
|
|
31
|
+
} | undefined) => Promise< Exit<A, E>>;
|
|
32
|
+
runFork: <A, E>(effect: Effect.Effect<A, E>, options?: RunForkOptions) => RuntimeFiber<A, E>;
|
|
33
|
+
dispose: () => Effect.Effect<void, never, never>;
|
|
34
|
+
};
|
|
3
35
|
|
|
4
36
|
declare type Handler = (input: never) => unknown;
|
|
5
37
|
|
|
6
|
-
/** Build a fake api context for tests. See the module comment. */
|
|
7
38
|
export declare const makeVoltroTestClient: (config?: VoltroTestClientConfig) => VoltroTestClient;
|
|
8
39
|
|
|
9
40
|
/** One recorded write, so a test can assert WHAT was called with WHICH input. */
|
|
@@ -13,13 +44,29 @@ export declare interface RecordedCall {
|
|
|
13
44
|
readonly input: unknown;
|
|
14
45
|
}
|
|
15
46
|
|
|
47
|
+
/**
|
|
48
|
+
* The parts of a snapshot that are NOT the data.
|
|
49
|
+
*
|
|
50
|
+
* They exist because real pages render them: the notes template greys out rows
|
|
51
|
+
* while `pendingPatches > 0` and prints the time of the last delta from
|
|
52
|
+
* `emittedAt`. The harness hardcoded both, so a page that renders either had a
|
|
53
|
+
* state no test could reach — the gap you only find by pointing the harness at
|
|
54
|
+
* an app that was written before it.
|
|
55
|
+
*/
|
|
56
|
+
export declare interface SnapshotMeta {
|
|
57
|
+
/** Optimistic patches awaiting confirmation. Drives "n pending" affordances. */
|
|
58
|
+
readonly pendingPatches?: number;
|
|
59
|
+
/** When the server emitted this delta, in ms. */
|
|
60
|
+
readonly emittedAt?: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
16
63
|
export declare interface VoltroTestClient {
|
|
17
64
|
/** Wrap the component under test. */
|
|
18
65
|
readonly Provider: (props: {
|
|
19
66
|
readonly children: ReactNode;
|
|
20
67
|
}) => ReactElement;
|
|
21
68
|
/** Push new data for a tag — components re-render, like a server delta. */
|
|
22
|
-
readonly setSubscription: (tag: string, data: unknown) => void;
|
|
69
|
+
readonly setSubscription: (tag: string, data: unknown, meta?: SnapshotMeta) => void;
|
|
23
70
|
/** Put a tag into the COLD-START error state (no snapshot + an error). */
|
|
24
71
|
readonly failSubscription: (tag: string, error: unknown) => void;
|
|
25
72
|
/** Return a tag to the loading state (no snapshot yet). */
|
package/dist/client.js
CHANGED
|
@@ -2,36 +2,45 @@ import { Effect as e } from "effect";
|
|
|
2
2
|
import { createElement as t } from "react";
|
|
3
3
|
import { FrameworkRuntimesContext as n, RpcErrorBus as r } from "@voltro/client";
|
|
4
4
|
//#region src/client.tsx
|
|
5
|
-
var i =
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
var i = {
|
|
6
|
+
runPromise: e.runPromise,
|
|
7
|
+
runPromiseExit: e.runPromiseExit,
|
|
8
|
+
runFork: e.runFork,
|
|
9
|
+
dispose: () => e.void
|
|
10
|
+
}, a = (a = {}) => {
|
|
11
|
+
let o = a.apiName ?? "app", s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), u = [];
|
|
12
|
+
for (let [e, t] of Object.entries(a.subscriptions ?? {})) s.set(e, {
|
|
8
13
|
data: t,
|
|
9
14
|
error: void 0,
|
|
10
|
-
revision: 0
|
|
15
|
+
revision: 0,
|
|
16
|
+
pendingPatches: 0,
|
|
17
|
+
emittedAt: void 0
|
|
11
18
|
});
|
|
12
|
-
let
|
|
19
|
+
let d = (e) => s.get(e) ?? {
|
|
13
20
|
data: void 0,
|
|
14
21
|
error: void 0,
|
|
15
|
-
revision: -1
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
revision: -1,
|
|
23
|
+
pendingPatches: 0,
|
|
24
|
+
emittedAt: void 0
|
|
25
|
+
}, f = (e) => {
|
|
26
|
+
l.delete(e);
|
|
27
|
+
for (let t of c.get(e) ?? []) t();
|
|
28
|
+
}, p = (e) => String(e[0] ?? ""), m = {
|
|
20
29
|
peek: (e) => {
|
|
21
|
-
let t =
|
|
30
|
+
let t = p(e), n = l.get(t);
|
|
22
31
|
if (n) return n;
|
|
23
|
-
let r =
|
|
32
|
+
let r = d(t), i = {
|
|
24
33
|
data: r.data,
|
|
25
34
|
revision: r.revision,
|
|
26
|
-
emittedAt:
|
|
35
|
+
emittedAt: r.emittedAt,
|
|
27
36
|
error: r.error,
|
|
28
|
-
pendingPatches:
|
|
37
|
+
pendingPatches: r.pendingPatches
|
|
29
38
|
};
|
|
30
|
-
return
|
|
39
|
+
return l.set(t, i), i;
|
|
31
40
|
},
|
|
32
41
|
subscribe: (e, t, n, r) => {
|
|
33
|
-
let i =
|
|
34
|
-
return a.add(r),
|
|
42
|
+
let i = p(e), a = c.get(i) ?? /* @__PURE__ */ new Set();
|
|
43
|
+
return a.add(r), c.set(i, a), { unsubscribe: () => {
|
|
35
44
|
a.delete(r);
|
|
36
45
|
} };
|
|
37
46
|
},
|
|
@@ -41,11 +50,11 @@ var i = (i = {}) => {
|
|
|
41
50
|
update: () => {},
|
|
42
51
|
forTag: () => ({ patchedCount: 0 }),
|
|
43
52
|
refreshAll: () => {}
|
|
44
|
-
},
|
|
45
|
-
let i = t.split("."), a =
|
|
53
|
+
}, h = {}, g = (t, n, r) => {
|
|
54
|
+
let i = t.split("."), a = h;
|
|
46
55
|
for (let e of i.slice(0, -1)) a[e] = a[e] ?? {}, a = a[e];
|
|
47
56
|
a[i[i.length - 1]] = (i) => e.tryPromise({
|
|
48
|
-
try: async () => (
|
|
57
|
+
try: async () => (u.push({
|
|
49
58
|
kind: n,
|
|
50
59
|
tag: t,
|
|
51
60
|
input: i
|
|
@@ -53,47 +62,48 @@ var i = (i = {}) => {
|
|
|
53
62
|
catch: (e) => e
|
|
54
63
|
});
|
|
55
64
|
};
|
|
56
|
-
for (let [e, t] of Object.entries(
|
|
57
|
-
for (let [e, t] of Object.entries(
|
|
58
|
-
let
|
|
59
|
-
runtime:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
},
|
|
63
|
-
cache: p,
|
|
64
|
-
client: m,
|
|
65
|
+
for (let [e, t] of Object.entries(a.mutations ?? {})) g(e, "mutation", t);
|
|
66
|
+
for (let [e, t] of Object.entries(a.actions ?? {})) g(e, "action", t);
|
|
67
|
+
let _ = {
|
|
68
|
+
runtime: i,
|
|
69
|
+
cache: m,
|
|
70
|
+
client: h,
|
|
65
71
|
descriptors: {},
|
|
66
72
|
inspectBaseUrl: "http://test.local",
|
|
67
73
|
errorBus: new r()
|
|
68
|
-
},
|
|
74
|
+
}, v = {
|
|
69
75
|
get: (e) => {
|
|
70
|
-
if (e !==
|
|
71
|
-
return
|
|
76
|
+
if (e !== o) throw Error(`makeVoltroTestClient: component asked for api '${e}' but the harness was built for '${o}'. Pass { apiName: '${e}' }.`);
|
|
77
|
+
return _;
|
|
72
78
|
},
|
|
73
|
-
names: [
|
|
79
|
+
names: [o]
|
|
74
80
|
};
|
|
75
81
|
return {
|
|
76
|
-
Provider: ({ children: e }) => t(n.Provider, { value:
|
|
77
|
-
setSubscription: (e, t) => {
|
|
78
|
-
let
|
|
79
|
-
|
|
82
|
+
Provider: ({ children: e }) => t(n.Provider, { value: v }, e),
|
|
83
|
+
setSubscription: (e, t, n) => {
|
|
84
|
+
let r = d(e);
|
|
85
|
+
s.set(e, {
|
|
80
86
|
data: t,
|
|
81
87
|
error: void 0,
|
|
82
|
-
revision:
|
|
83
|
-
|
|
88
|
+
revision: r.revision + 1,
|
|
89
|
+
pendingPatches: n?.pendingPatches ?? 0,
|
|
90
|
+
emittedAt: n?.emittedAt
|
|
91
|
+
}), f(e);
|
|
84
92
|
},
|
|
85
93
|
failSubscription: (e, t) => {
|
|
86
|
-
|
|
94
|
+
s.set(e, {
|
|
87
95
|
data: void 0,
|
|
88
96
|
error: t,
|
|
89
|
-
revision: -1
|
|
90
|
-
|
|
97
|
+
revision: -1,
|
|
98
|
+
pendingPatches: 0,
|
|
99
|
+
emittedAt: void 0
|
|
100
|
+
}), f(e);
|
|
91
101
|
},
|
|
92
102
|
resetSubscription: (e) => {
|
|
93
|
-
|
|
103
|
+
s.delete(e), f(e);
|
|
94
104
|
},
|
|
95
|
-
calls:
|
|
105
|
+
calls: u
|
|
96
106
|
};
|
|
97
107
|
};
|
|
98
108
|
//#endregion
|
|
99
|
-
export { i as makeVoltroTestClient };
|
|
109
|
+
export { i as FAKE_RUNTIME, a as makeVoltroTestClient };
|