@shivaedev/test-story 0.27.0 → 0.28.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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.28.0 - 2026-10-31
4
+
5
+ ### Added
6
+
7
+ - Contract clients expose `clientActivity(client)`, a native Effect `Stream` with a `current` Effect reporting finite RPC calls, queued live invalidations, refreshing query atoms and received live hints.
8
+ - Screen drivers accept that activity as `pending`, wait for idle activity with their renderer before screen assertions, and expose `nextLiveHint()` for the next client delivery. Stories keep live coalescing enabled.
9
+
3
10
  ## 0.27.0 - 2026-10-31
4
11
 
5
12
  ### Added
package/README.md CHANGED
@@ -717,7 +717,7 @@ pnpm add --save-dev react react-dom @effect/atom-react @types/react @types/react
717
717
 
718
718
  ### Driving a screen
719
719
 
720
- `screenDriver(options)` supplies DOM verbs and readouts for a kit's `verbs` hook. Give it the mounted `root` (or a getter for a root that navigation replaces) and the story's `tell`. The `pending` option is needed only for `settle()`; actions, lookups and readouts work without it. Without `pending`, `settle()` fails immediately in its error channel with `MissingScreenPending`, exported from `server/screenDriver.ts`, even when the screen is idle.
720
+ `screenDriver(options)` supplies DOM verbs and readouts for a kit's `verbs` hook. Give it the mounted `root` (or a getter for a root that navigation replaces) and the story's `tell`. The `pending` option is required for `settle()`; `nextLiveHint()` requires client activity in that option. DOM actions, lookups and synchronous readouts work without it. Without `pending`, `settle()` fails immediately in its error channel with `MissingScreenPending`, exported from `server/screenDriver.ts`, even when the screen is idle.
721
721
 
722
722
  To use `settle()`, supply a `pending()` function that reads the application's own request or atom state. Settlement then keeps its `Effect<void>` type with no typed errors and waits until that signal is false; repeated identical renders never count as completion. The application must keep the signal true until its resulting screen work is ready to render.
723
723
 
@@ -732,6 +732,20 @@ verbs: ({ view, requests }, story) =>
732
732
  });
733
733
  ```
734
734
 
735
+ For a real contract client, use its activity instead of maintaining request counters or reading loading markup:
736
+
737
+ ```ts
738
+ import { clientActivity } from "@shivaedev/contract/clientActivity.ts";
739
+ import { screenDriver } from "@shivaedev/test-story/server/screenDriver.ts";
740
+
741
+ const screen = screenDriver({ act, pending: clientActivity(client), root, tell });
742
+ yield* screen.click({ role: "button", name: "Save" });
743
+ yield* screen.settle();
744
+ expect(screen.text("output")).toBe("Saved title");
745
+ ```
746
+
747
+ This form of `settle()` observes client activity changes and flushes the renderer before returning. Finite RPC calls, coalesced invalidations and refreshing query atoms all keep it waiting; subscription streams themselves do not. With client activity, `find()` settles before looking up its target once. Keep live coalescing enabled. `nextLiveHint()` waits for the next subscription update received after the verb starts, including initial or resync updates; it does not wait for a refresh. Start the wait before another viewer writes, then settle before reading the resulting screen. It needs client activity; a callback-only driver fails with `MissingClientActivity`.
748
+
735
749
  `click(selector)`, `enter(selector, value)` and `submit(selector = "form")` return Effects. Selectors identify exactly one descendant of the root; missing or ambiguous controls fail. Hidden targets and targets inside hidden ancestors refuse actions and readouts. Text entry focuses an input or textarea and dispatches input and change events. Disabled controls refuse clicks and entry, inert ancestors also prevent form submission, and read-only fields refuse entry. Actions do not wait for settlement, so a story can release a held request before calling `settle()`.
736
750
 
737
751
  `within(container)` returns the same driver scoped to that container, including nested `within` calls. Pass a selector, a role/name target or an `HTMLElement`. Selector and role containers must resolve to one rendered descendant and use the usual missing or ambiguous target diagnostics. For example, `within({ role: "region", name: "Billing" }).click({ role: "button", name: "Save" })` can address a Save button when Delivery has an identical button. Settlement keeps the original pending signal and error type.
@@ -0,0 +1,5 @@
1
+ import { Effect } from "effect";
2
+ import { type ClientActivity } from "@shivaedev/contract/clientActivity.ts";
3
+ export declare function waitForClient(activity: ClientActivity): Effect.Effect<void, never, never>;
4
+ export declare const nextClientHint: (activity: ClientActivity) => Effect.Effect<void, never, never>;
5
+ //# sourceMappingURL=screenActivity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screenActivity.d.ts","sourceRoot":"","sources":["../../../src/server/internal/screenActivity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,KAAK,cAAc,EAAgB,MAAM,uCAAuC,CAAC;AAE1F,wBAAgB,aAAa,CAAC,QAAQ,EAAE,cAAc,qCAErD;AAED,eAAO,MAAM,cAAc,iEAOzB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { Effect, Stream } from "effect";
2
+ import { isClientIdle } from "@shivaedev/contract/clientActivity.ts";
3
+ export function waitForClient(activity) {
4
+ return activity.pipe(Stream.filter(isClientIdle), Stream.take(1), Stream.runDrain);
5
+ }
6
+ export const nextClientHint = Effect.fnUntraced(function* (activity) {
7
+ const before = (yield* activity.current).liveHints;
8
+ return yield* activity.pipe(Stream.filter((state) => state.liveHints > before), Stream.take(1), Stream.runDrain);
9
+ });
10
+ //# sourceMappingURL=screenActivity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screenActivity.js","sourceRoot":"","sources":["../../../src/server/internal/screenActivity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAuB,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAE1F,MAAM,UAAU,aAAa,CAAC,QAAwB;IACrD,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;AACpF,CAAC;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,QAAwB;IAClF,MAAM,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC;IACnD,OAAO,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,CAC1B,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,GAAG,MAAM,CAAC,EAClD,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EACd,MAAM,CAAC,QAAQ,CACf,CAAC;AACH,CAAC,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { ScreenTarget } from "#screenDriver.ts";
2
+ export declare function screenReadouts(currentRoot: () => HTMLElement, tell: (line: string) => void): {
3
+ accessible: (selector: string | Element) => {
4
+ name: string;
5
+ role: string | null;
6
+ };
7
+ text: (selector?: ScreenTarget) => string;
8
+ value: (selector: ScreenTarget) => string;
9
+ };
10
+ //# sourceMappingURL=screenReadouts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screenReadouts.d.ts","sourceRoot":"","sources":["../../../src/server/internal/screenReadouts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIrD,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,WAAW,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI;IAGzF,UAAU,aAAa,MAAM,GAAG,OAAO;;;;IASvC,IAAI,cAAc,YAAY;IAK9B,KAAK,aAAa,YAAY;EAM/B"}
@@ -0,0 +1,27 @@
1
+ import { accessibility, targetName } from "./screenAccessibility.js";
2
+ import { screenElements } from "./screenElements.js";
3
+ export function screenReadouts(currentRoot, tell) {
4
+ const elements = screenElements(currentRoot);
5
+ return {
6
+ accessible: (selector) => {
7
+ if (typeof selector !== "string") {
8
+ return accessibility(selector);
9
+ }
10
+ const element = elements.element(selector);
11
+ const accessible = accessibility(element);
12
+ tell(`read the accessibility of ${selector}: ${JSON.stringify(accessible)}`);
13
+ return accessible;
14
+ },
15
+ text: (selector) => {
16
+ const text = elements.text(selector === undefined ? elements.rendered(currentRoot(), "root") : elements.element(selector));
17
+ tell(`read ${selector === undefined ? "the screen" : targetName(selector)}: ${JSON.stringify(text)}`);
18
+ return text;
19
+ },
20
+ value: (selector) => {
21
+ const value = elements.input(selector).value;
22
+ tell(`read the value in ${targetName(selector)}: ${JSON.stringify(value)}`);
23
+ return value;
24
+ },
25
+ };
26
+ }
27
+ //# sourceMappingURL=screenReadouts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screenReadouts.js","sourceRoot":"","sources":["../../../src/server/internal/screenReadouts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,MAAM,UAAU,cAAc,CAAC,WAA8B,EAAE,IAA4B;IAC1F,MAAM,QAAQ,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;IAC7C,OAAO;QACN,UAAU,EAAE,CAAC,QAA0B,EAAE,EAAE;YAC1C,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;gBAClC,OAAO,aAAa,CAAC,QAAQ,CAAC,CAAC;YAChC,CAAC;YACD,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAC3C,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;YAC1C,IAAI,CAAC,6BAA6B,QAAQ,KAAK,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YAC7E,OAAO,UAAU,CAAC;QACnB,CAAC;QACD,IAAI,EAAE,CAAC,QAAuB,EAAE,EAAE;YACjC,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC3H,IAAI,CAAC,QAAQ,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACtG,OAAO,IAAI,CAAC;QACb,CAAC;QACD,KAAK,EAAE,CAAC,QAAsB,EAAE,EAAE;YACjC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC;YAC7C,IAAI,CAAC,qBAAqB,UAAU,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC5E,OAAO,KAAK,CAAC;QACd,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -1,11 +1,12 @@
1
1
  import { Effect } from "effect";
2
+ import { type ClientActivity } from "@shivaedev/contract/clientActivity.ts";
2
3
  export type ScreenTarget = string | {
3
4
  readonly role: string;
4
5
  readonly name: string | RegExp;
5
6
  };
6
7
  export interface ScreenDriverOptions {
7
8
  readonly act?: (action: () => Promise<void>) => PromiseLike<void>;
8
- readonly pending?: () => boolean;
9
+ readonly pending?: (() => boolean) | ClientActivity;
9
10
  readonly root: HTMLElement | (() => HTMLElement);
10
11
  readonly tell: (line: string) => void;
11
12
  readonly timeoutMs?: number;
@@ -16,12 +17,22 @@ declare const MissingScreenPending_base: new <A extends Record<string, any> = {}
16
17
  export declare class MissingScreenPending extends MissingScreenPending_base {
17
18
  readonly message = "Cannot settle the screen without the pending option.\nhelp: Supply pending: () => boolean that reads the application's pending work and stays true until its resulting screen work is ready to render.";
18
19
  }
19
- export type ScreenDriver<E = never> = Omit<ReturnType<typeof makeScreenActions>, "settle"> & {
20
+ declare const MissingClientActivity_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
21
+ readonly _tag: "MissingClientActivity";
22
+ } & Readonly<A>;
23
+ export declare class MissingClientActivity extends MissingClientActivity_base {
24
+ readonly message = "Cannot wait for a live hint without client activity.\nhelp: Supply pending: clientActivity(client) from @shivaedev/contract/clientActivity.ts.";
25
+ }
26
+ export type ScreenDriver<E = never, THintError = MissingClientActivity> = Omit<ReturnType<typeof makeScreenActions>, "settle" | "nextLiveHint"> & {
27
+ nextLiveHint: () => Effect.Effect<void, THintError>;
20
28
  settle: (options?: {
21
29
  readonly timeoutMs?: number;
22
30
  }) => Effect.Effect<void, E>;
23
- within: (container: ScreenTarget | HTMLElement) => ScreenDriver<E>;
31
+ within: (container: ScreenTarget | HTMLElement) => ScreenDriver<E, THintError>;
24
32
  };
33
+ export declare function screenDriver(options: ScreenDriverOptions & {
34
+ readonly pending: ClientActivity;
35
+ }): ScreenDriver<never, never>;
25
36
  export declare function screenDriver(options: ScreenDriverOptions & {
26
37
  readonly pending: () => boolean;
27
38
  }): ScreenDriver;
@@ -31,17 +42,18 @@ declare function makeScreenActions({ root, pending, tell, act, timeoutMs }: Scre
31
42
  name: string;
32
43
  role: string | null;
33
44
  };
45
+ text: (selector?: ScreenTarget) => string;
46
+ value: (selector: ScreenTarget) => string;
34
47
  click: (selector: ScreenTarget) => Effect.Effect<void, never, never>;
35
48
  enter: (selector: ScreenTarget, value: string) => Effect.Effect<void, never, never>;
36
49
  find: (target: ScreenTarget, options?: {
37
50
  readonly timeout?: number;
38
51
  }) => Effect.Effect<HTMLElement, import("effect/Cause").UnknownError, never>;
52
+ nextLiveHint: () => Effect.Effect<void, never, never> | Effect.Effect<never, MissingClientActivity, never>;
39
53
  settle: (options?: {
40
54
  readonly timeoutMs?: number;
41
55
  }) => Effect.Effect<void, never, never> | Effect.Effect<never, MissingScreenPending, never>;
42
56
  submit: (selector?: ScreenTarget) => Effect.Effect<void, never, never>;
43
- text: (selector?: ScreenTarget) => string;
44
- value: (selector: ScreenTarget) => string;
45
57
  };
46
58
  export {};
47
59
  //# sourceMappingURL=screenDriver.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"screenDriver.d.ts","sourceRoot":"","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AC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;;uBA/BjD;QAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE;wBAgFpC,YAAY;EAEhC"}
@@ -1,10 +1,16 @@
1
1
  import { Data, Effect, Schedule } from "effect";
2
+ import { isClientIdle } from "@shivaedev/contract/clientActivity.ts";
2
3
  import { withLive } from "@shivaedev/test/withLive.ts";
3
- import { accessibility, targetName } from "#internal/screenAccessibility.ts";
4
+ import { targetName } from "#internal/screenAccessibility.ts";
5
+ import { nextClientHint, waitForClient } from "#internal/screenActivity.ts";
4
6
  import { screenElements } from "#internal/screenElements.ts";
7
+ import { screenReadouts } from "#internal/screenReadouts.ts";
5
8
  export class MissingScreenPending extends Data.TaggedError("MissingScreenPending") {
6
9
  message = "Cannot settle the screen without the pending option.\nhelp: Supply pending: () => boolean that reads the application's pending work and stays true until its resulting screen work is ready to render.";
7
10
  }
11
+ export class MissingClientActivity extends Data.TaggedError("MissingClientActivity") {
12
+ message = "Cannot wait for a live hint without client activity.\nhelp: Supply pending: clientActivity(client) from @shivaedev/contract/clientActivity.ts.";
13
+ }
8
14
  export function screenDriver(options) {
9
15
  const suppliedRoot = options.root;
10
16
  const root = typeof suppliedRoot === "function" ? suppliedRoot : () => suppliedRoot;
@@ -33,16 +39,22 @@ function makeScreenActions({ root, pending, tell, act = (action) => action(), ti
33
39
  if (pending === undefined) {
34
40
  return Effect.fail(new MissingScreenPending());
35
41
  }
42
+ return settleWork(pending, options);
43
+ }
44
+ function settleWork(work, options) {
36
45
  const limit = options.timeoutMs ?? timeoutMs;
46
+ const isIdle = typeof work === "function" ? Effect.sync(() => !work()) : Effect.map(work.current, isClientIdle);
37
47
  const wait = Effect.gen(function* () {
38
48
  tell("wait for the screen's pending work");
39
49
  do {
40
50
  yield* Effect.promise(() => act(async () => undefined));
41
- if (!pending()) {
51
+ if (yield* isIdle) {
42
52
  tell("the screen has no pending work");
43
53
  return;
44
54
  }
45
- yield* Effect.promise(() => act(() => new Promise((resolve) => setTimeout(resolve, 10))));
55
+ yield* typeof work === "function"
56
+ ? Effect.promise(() => act(() => new Promise((resolve) => setTimeout(resolve, 10))))
57
+ : Effect.promise((signal) => act(() => Effect.runPromise(waitForClient(work), { signal })));
46
58
  } while (true);
47
59
  });
48
60
  function timedOut() {
@@ -51,6 +63,12 @@ function makeScreenActions({ root, pending, tell, act = (action) => action(), ti
51
63
  return withLive(wait.pipe(Effect.timeoutOrElse({ duration: limit, orElse: timedOut })));
52
64
  }
53
65
  function find(target, options = {}) {
66
+ if (pending !== undefined && typeof pending !== "function") {
67
+ return settleWork(pending, { timeoutMs: options.timeout ?? timeoutMs }).pipe(Effect.andThen(Effect.sync(() => {
68
+ tell(`find ${targetName(target)}`);
69
+ return elements.element(target);
70
+ })));
71
+ }
54
72
  return withLive(Effect.gen(function* () {
55
73
  tell(`find ${targetName(target)}`);
56
74
  return yield* Effect.tryPromise(async () => {
@@ -63,15 +81,7 @@ function makeScreenActions({ root, pending, tell, act = (action) => action(), ti
63
81
  }));
64
82
  }
65
83
  return {
66
- accessible: (selector) => {
67
- if (typeof selector !== "string") {
68
- return accessibility(selector);
69
- }
70
- const element = elements.element(selector);
71
- const accessible = accessibility(element);
72
- tell(`read the accessibility of ${selector}: ${JSON.stringify(accessible)}`);
73
- return accessible;
74
- },
84
+ ...screenReadouts(currentRoot, tell),
75
85
  click: (selector) => perform(`click ${targetName(selector)}`, () => {
76
86
  const element = elements.element(selector);
77
87
  elements.enabled(element, selector);
@@ -80,18 +90,14 @@ function makeScreenActions({ root, pending, tell, act = (action) => action(), ti
80
90
  }),
81
91
  enter: (selector, value) => perform(`enter a value in ${targetName(selector)}`, () => elements.enter(selector, value)),
82
92
  find,
93
+ nextLiveHint: () => {
94
+ if (pending === undefined || typeof pending === "function") {
95
+ return Effect.fail(new MissingClientActivity());
96
+ }
97
+ return withLive(Effect.sync(() => tell("wait for the next live hint")).pipe(Effect.andThen(Effect.promise((signal) => act(() => Effect.runPromise(nextClientHint(pending), { signal }))))));
98
+ },
83
99
  settle,
84
100
  submit: (selector = "form") => perform(`submit ${targetName(selector)}`, () => elements.form(selector).requestSubmit()),
85
- text: (selector) => {
86
- const text = elements.text(selector === undefined ? elements.rendered(currentRoot(), "root") : elements.element(selector));
87
- tell(`read ${selector === undefined ? "the screen" : targetName(selector)}: ${JSON.stringify(text)}`);
88
- return text;
89
- },
90
- value: (selector) => {
91
- const value = elements.input(selector).value;
92
- tell(`read the value in ${targetName(selector)}: ${JSON.stringify(value)}`);
93
- return value;
94
- },
95
101
  };
96
102
  }
97
103
  //# sourceMappingURL=screenDriver.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"screenDriver.js","sourceRoot":"","sources":["../../src/server/screenDriver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAY7D,MAAM,OAAO,oBAAqB,SAAQ,IAAI,CAAC,WAAW,CAAC,sBAAsB,CAAC;IAC/D,OAAO,GACxB,wMAAwM,CAAC;CAC1M;AASD,MAAM,UAAU,YAAY,CAAC,OAA4B;IACxD,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAClC,MAAM,IAAI,GAAG,OAAO,YAAY,KAAK,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC;IACpF,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IACtC,OAAO;QACN,GAAG,iBAAiB,CAAC,OAAO,CAAC;QAC7B,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE;YACrB,SAAS,UAAU;gBAClB,OAAO,SAAS,YAAY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description": "Tests that read like stories over the real engine: a story kit per engine with its own it, traits per feature, and a failure that prints the story, where it stopped and the engine's state",
5
5
  "homepage": "https://github.com/ShivaeDev/platform/tree/main/packages/test-story#readme",
6
6
  "bugs": {
@@ -42,7 +42,7 @@
42
42
  "README.md"
43
43
  ],
44
44
  "dependencies": {
45
- "@shivaedev/contract": "0.26.0",
45
+ "@shivaedev/contract": "0.27.0",
46
46
  "@shivaedev/test": "0.12.0",
47
47
  "@shivaedev/test-sql": "0.15.0",
48
48
  "dom-accessibility-api": "0.7.1"
@@ -51,7 +51,7 @@
51
51
  "@effect/atom-react": "4.0.6",
52
52
  "@effect/platform-node": "4.0.6",
53
53
  "@effect/vitest": "4.0.6",
54
- "@shivaedev/quality": "0.48.1",
54
+ "@shivaedev/quality": "0.48.2",
55
55
  "@types/node": "24.19.2",
56
56
  "@types/react": "19.3.0",
57
57
  "@types/react-dom": "19.3.0",
@@ -0,0 +1,15 @@
1
+ import { Effect, Stream } from "effect";
2
+ import { type ClientActivity, isClientIdle } from "@shivaedev/contract/clientActivity.ts";
3
+
4
+ export function waitForClient(activity: ClientActivity) {
5
+ return activity.pipe(Stream.filter(isClientIdle), Stream.take(1), Stream.runDrain);
6
+ }
7
+
8
+ export const nextClientHint = Effect.fnUntraced(function* (activity: ClientActivity) {
9
+ const before = (yield* activity.current).liveHints;
10
+ return yield* activity.pipe(
11
+ Stream.filter((state) => state.liveHints > before),
12
+ Stream.take(1),
13
+ Stream.runDrain,
14
+ );
15
+ });
@@ -0,0 +1,28 @@
1
+ import type { ScreenTarget } from "#screenDriver.ts";
2
+ import { accessibility, targetName } from "./screenAccessibility.ts";
3
+ import { screenElements } from "./screenElements.ts";
4
+
5
+ export function screenReadouts(currentRoot: () => HTMLElement, tell: (line: string) => void) {
6
+ const elements = screenElements(currentRoot);
7
+ return {
8
+ accessible: (selector: string | Element) => {
9
+ if (typeof selector !== "string") {
10
+ return accessibility(selector);
11
+ }
12
+ const element = elements.element(selector);
13
+ const accessible = accessibility(element);
14
+ tell(`read the accessibility of ${selector}: ${JSON.stringify(accessible)}`);
15
+ return accessible;
16
+ },
17
+ text: (selector?: ScreenTarget) => {
18
+ const text = elements.text(selector === undefined ? elements.rendered(currentRoot(), "root") : elements.element(selector));
19
+ tell(`read ${selector === undefined ? "the screen" : targetName(selector)}: ${JSON.stringify(text)}`);
20
+ return text;
21
+ },
22
+ value: (selector: ScreenTarget) => {
23
+ const value = elements.input(selector).value;
24
+ tell(`read the value in ${targetName(selector)}: ${JSON.stringify(value)}`);
25
+ return value;
26
+ },
27
+ };
28
+ }
@@ -1,13 +1,16 @@
1
1
  import { Data, Effect, Schedule } from "effect";
2
+ import { type ClientActivity, isClientIdle } from "@shivaedev/contract/clientActivity.ts";
2
3
  import { withLive } from "@shivaedev/test/withLive.ts";
3
- import { accessibility, targetName } from "#internal/screenAccessibility.ts";
4
+ import { targetName } from "#internal/screenAccessibility.ts";
5
+ import { nextClientHint, waitForClient } from "#internal/screenActivity.ts";
4
6
  import { screenElements } from "#internal/screenElements.ts";
7
+ import { screenReadouts } from "#internal/screenReadouts.ts";
5
8
 
6
9
  export type ScreenTarget = string | { readonly role: string; readonly name: string | RegExp };
7
10
 
8
11
  export interface ScreenDriverOptions {
9
12
  readonly act?: (action: () => Promise<void>) => PromiseLike<void>;
10
- readonly pending?: () => boolean;
13
+ readonly pending?: (() => boolean) | ClientActivity;
11
14
  readonly root: HTMLElement | (() => HTMLElement);
12
15
  readonly tell: (line: string) => void;
13
16
  readonly timeoutMs?: number;
@@ -18,11 +21,18 @@ export class MissingScreenPending extends Data.TaggedError("MissingScreenPending
18
21
  "Cannot settle the screen without the pending option.\nhelp: Supply pending: () => boolean that reads the application's pending work and stays true until its resulting screen work is ready to render.";
19
22
  }
20
23
 
21
- export type ScreenDriver<E = never> = Omit<ReturnType<typeof makeScreenActions>, "settle"> & {
24
+ export class MissingClientActivity extends Data.TaggedError("MissingClientActivity") {
25
+ override readonly message =
26
+ "Cannot wait for a live hint without client activity.\nhelp: Supply pending: clientActivity(client) from @shivaedev/contract/clientActivity.ts.";
27
+ }
28
+
29
+ export type ScreenDriver<E = never, THintError = MissingClientActivity> = Omit<ReturnType<typeof makeScreenActions>, "settle" | "nextLiveHint"> & {
30
+ nextLiveHint: () => Effect.Effect<void, THintError>;
22
31
  settle: (options?: { readonly timeoutMs?: number }) => Effect.Effect<void, E>;
23
- within: (container: ScreenTarget | HTMLElement) => ScreenDriver<E>;
32
+ within: (container: ScreenTarget | HTMLElement) => ScreenDriver<E, THintError>;
24
33
  };
25
34
 
35
+ export function screenDriver(options: ScreenDriverOptions & { readonly pending: ClientActivity }): ScreenDriver<never, never>;
26
36
  export function screenDriver(options: ScreenDriverOptions & { readonly pending: () => boolean }): ScreenDriver;
27
37
  export function screenDriver(options: ScreenDriverOptions): ScreenDriver<MissingScreenPending>;
28
38
  export function screenDriver(options: ScreenDriverOptions): ScreenDriver<MissingScreenPending> {
@@ -54,16 +64,22 @@ function makeScreenActions({ root, pending, tell, act = (action) => action(), ti
54
64
  if (pending === undefined) {
55
65
  return Effect.fail(new MissingScreenPending());
56
66
  }
67
+ return settleWork(pending, options);
68
+ }
69
+ function settleWork(work: NonNullable<ScreenDriverOptions["pending"]>, options: { readonly timeoutMs?: number }) {
57
70
  const limit = options.timeoutMs ?? timeoutMs;
71
+ const isIdle = typeof work === "function" ? Effect.sync(() => !work()) : Effect.map(work.current, isClientIdle);
58
72
  const wait = Effect.gen(function* () {
59
73
  tell("wait for the screen's pending work");
60
74
  do {
61
75
  yield* Effect.promise(() => act(async () => undefined));
62
- if (!pending()) {
76
+ if (yield* isIdle) {
63
77
  tell("the screen has no pending work");
64
78
  return;
65
79
  }
66
- yield* Effect.promise(() => act(() => new Promise<void>((resolve) => setTimeout(resolve, 10))));
80
+ yield* typeof work === "function"
81
+ ? Effect.promise(() => act(() => new Promise<void>((resolve) => setTimeout(resolve, 10))))
82
+ : Effect.promise((signal) => act(() => Effect.runPromise(waitForClient(work), { signal })));
67
83
  } while (true);
68
84
  });
69
85
  function timedOut() {
@@ -76,6 +92,16 @@ function makeScreenActions({ root, pending, tell, act = (action) => action(), ti
76
92
  return withLive(wait.pipe(Effect.timeoutOrElse({ duration: limit, orElse: timedOut })));
77
93
  }
78
94
  function find(target: ScreenTarget, options: { readonly timeout?: number } = {}) {
95
+ if (pending !== undefined && typeof pending !== "function") {
96
+ return settleWork(pending, { timeoutMs: options.timeout ?? timeoutMs }).pipe(
97
+ Effect.andThen(
98
+ Effect.sync(() => {
99
+ tell(`find ${targetName(target)}`);
100
+ return elements.element(target);
101
+ }),
102
+ ),
103
+ );
104
+ }
79
105
  return withLive(
80
106
  Effect.gen(function* () {
81
107
  tell(`find ${targetName(target)}`);
@@ -93,15 +119,7 @@ function makeScreenActions({ root, pending, tell, act = (action) => action(), ti
93
119
  );
94
120
  }
95
121
  return {
96
- accessible: (selector: string | Element) => {
97
- if (typeof selector !== "string") {
98
- return accessibility(selector);
99
- }
100
- const element = elements.element(selector);
101
- const accessible = accessibility(element);
102
- tell(`read the accessibility of ${selector}: ${JSON.stringify(accessible)}`);
103
- return accessible;
104
- },
122
+ ...screenReadouts(currentRoot, tell),
105
123
  click: (selector: ScreenTarget) =>
106
124
  perform(`click ${targetName(selector)}`, () => {
107
125
  const element = elements.element(selector);
@@ -111,17 +129,17 @@ function makeScreenActions({ root, pending, tell, act = (action) => action(), ti
111
129
  }),
112
130
  enter: (selector: ScreenTarget, value: string) => perform(`enter a value in ${targetName(selector)}`, () => elements.enter(selector, value)),
113
131
  find,
132
+ nextLiveHint: () => {
133
+ if (pending === undefined || typeof pending === "function") {
134
+ return Effect.fail(new MissingClientActivity());
135
+ }
136
+ return withLive(
137
+ Effect.sync(() => tell("wait for the next live hint")).pipe(
138
+ Effect.andThen(Effect.promise((signal) => act(() => Effect.runPromise(nextClientHint(pending), { signal })))),
139
+ ),
140
+ );
141
+ },
114
142
  settle,
115
143
  submit: (selector: ScreenTarget = "form") => perform(`submit ${targetName(selector)}`, () => elements.form(selector).requestSubmit()),
116
- text: (selector?: ScreenTarget) => {
117
- const text = elements.text(selector === undefined ? elements.rendered(currentRoot(), "root") : elements.element(selector));
118
- tell(`read ${selector === undefined ? "the screen" : targetName(selector)}: ${JSON.stringify(text)}`);
119
- return text;
120
- },
121
- value: (selector: ScreenTarget) => {
122
- const value = elements.input(selector).value;
123
- tell(`read the value in ${targetName(selector)}: ${JSON.stringify(value)}`);
124
- return value;
125
- },
126
144
  };
127
145
  }