@shivaedev/test-story 0.23.0 → 0.24.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 +26 -0
- package/README.md +42 -9
- package/dist/server/domFetch.d.ts +6 -1
- package/dist/server/domFetch.d.ts.map +1 -1
- package/dist/server/domFetch.js +3 -3
- package/dist/server/domFetch.js.map +1 -1
- package/dist/server/forwardingProxy.d.ts +2 -0
- package/dist/server/forwardingProxy.d.ts.map +1 -1
- package/dist/server/forwardingProxy.js +27 -4
- package/dist/server/forwardingProxy.js.map +1 -1
- package/dist/server/internal/adapters/memberFetch.d.ts +3 -0
- package/dist/server/internal/adapters/memberFetch.d.ts.map +1 -0
- package/dist/server/internal/adapters/memberFetch.js +68 -0
- package/dist/server/internal/adapters/memberFetch.js.map +1 -0
- package/dist/server/memberScreens.d.ts +20 -0
- package/dist/server/memberScreens.d.ts.map +1 -0
- package/dist/server/memberScreens.js +40 -0
- package/dist/server/memberScreens.js.map +1 -0
- package/dist/server/screenDriver.d.ts +3 -2
- package/dist/server/screenDriver.d.ts.map +1 -1
- package/dist/server/screenDriver.js +14 -2
- package/dist/server/screenDriver.js.map +1 -1
- package/dist/server/seedCookies.d.ts +2 -1
- package/dist/server/seedCookies.d.ts.map +1 -1
- package/dist/server/seedCookies.js +4 -4
- package/dist/server/seedCookies.js.map +1 -1
- package/package.json +11 -11
- package/src/server/domFetch.ts +6 -3
- package/src/server/forwardingProxy.ts +47 -24
- package/src/server/internal/adapters/memberFetch.ts +67 -0
- package/src/server/memberScreens.ts +61 -0
- package/src/server/screenDriver.ts +17 -4
- package/src/server/seedCookies.ts +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.24.0 - 2026-10-30
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Scope screen-driver verbs and readouts with `within(container)`, and mount named member screens with independent cookie sessions, atom registries and scoped roots through `memberScreens`.
|
|
8
|
+
- Create password-credential test users with Identity's `passwordUser` helper for real email sign-in stories.
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Work Board file edits refresh authorized contract queries over Platform's shared WebSocket, including the Claude plugin's overview. Unrelated document reads retain their values.
|
|
13
|
+
- Forwarding proxy fixtures can disconnect and resume real client traffic at the same address.
|
|
14
|
+
- Automatic contract live connections expose a `paused` atom; resuming reconciles their mounted queries. Bindings can supply a `resumeWindow` for embedded browser lifecycle events.
|
|
15
|
+
- Live status notifications use the registry's asynchronous scheduler, so mounting a query during React rendering does not update another component.
|
|
16
|
+
- Require Effect 4.0.6 and align the Effect companion package peers and generated starter catalog to the same exact release. Install the 4.0.6 Effect stack together.
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- Register hosted RPC cache-control handling through Effect 4.0.6's request-scoped pre-response API so responses keep `private, no-store`.
|
|
21
|
+
- Accept native RPC's `application/x-ndjson` media type while preserving `application/ndjson` callers at the transport guard.
|
|
22
|
+
- Keep subscriptions open after their HTTP request body completes; closing the socket still cancels them.
|
|
23
|
+
|
|
24
|
+
### Breaking
|
|
25
|
+
|
|
26
|
+
- Work Board removes its `subscribe` RPC. Consumers bind its contract queries with Platform's default WebSocket client instead of consuming Board-specific change hints.
|
|
27
|
+
- `WorkspaceConfig.indexing` supplies a progress snapshot Effect. Replace indexing Stream overrides with an Effect that reads current progress.
|
|
28
|
+
|
|
3
29
|
## 0.23.0 - 2026-10-29
|
|
4
30
|
|
|
5
31
|
### Added
|
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ The first line is the assertion's own message. The box under it tells a reader w
|
|
|
43
43
|
|
|
44
44
|
## Using it
|
|
45
45
|
|
|
46
|
-
Before writing or reviewing
|
|
46
|
+
Before writing or reviewing stories, follow the [story-testing skill](https://github.com/ShivaeDev/platform/blob/main/packages/skills/skills/story-testing/SKILL.md), shipped by `@shivaedev/skills`. It owns the rules for how a story reads, observable evidence, boundary-driven setup, verbs and readouts, assertions, jobs, framework gaps, faked preconditions, database isolation and focused runs. The examples below explain this package's API; framework fixtures exercise this package's responsibilities, rather than prescribe application scenarios.
|
|
47
47
|
|
|
48
48
|
### How to think about it
|
|
49
49
|
|
|
@@ -496,20 +496,32 @@ accounts.it("removing Bob ends his session", [bobIsSignedIn()], function* ({ rem
|
|
|
496
496
|
|
|
497
497
|
### Pinning time
|
|
498
498
|
|
|
499
|
-
Pass a UTC `DateTime` as the story's `clock` option to pin time before its wrapper, creation, traits and hooks run. Code that uses `Clock` or `DateTime.now` reads that instant. Advance it
|
|
499
|
+
Pass a UTC `DateTime` as the story's `clock` option to pin time before its wrapper, creation, traits and hooks run. Code that uses `Clock` or `DateTime.now` reads that instant. Advance it with native `TestClock.adjust` in a kit verb, so the spec names the time that passes:
|
|
500
500
|
|
|
501
501
|
```ts
|
|
502
|
-
import { DateTime } from "effect";
|
|
503
502
|
import * as TestClock from "effect/testing/TestClock";
|
|
504
503
|
|
|
504
|
+
verbs: (engine, story) => ({
|
|
505
|
+
aDayPasses: () => {
|
|
506
|
+
story.tell("a day passes");
|
|
507
|
+
return TestClock.adjust("1 day");
|
|
508
|
+
},
|
|
509
|
+
}),
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
```ts
|
|
513
|
+
import { DateTime } from "effect";
|
|
514
|
+
|
|
505
515
|
app.it(
|
|
506
|
-
"
|
|
516
|
+
"a day later, the worker shows the next date",
|
|
507
517
|
[],
|
|
508
|
-
function* ({ click, settle, text }) {
|
|
518
|
+
function* ({ aDayPasses, click, settle, text }) {
|
|
509
519
|
yield* click("button");
|
|
510
520
|
yield* settle();
|
|
511
521
|
expect(text("#worker")).toBe("Worker: since Oct 17");
|
|
512
|
-
|
|
522
|
+
|
|
523
|
+
yield* aDayPasses();
|
|
524
|
+
|
|
513
525
|
yield* click("button");
|
|
514
526
|
yield* settle();
|
|
515
527
|
expect(text("#worker")).toBe("Worker: since Oct 18");
|
|
@@ -659,7 +671,25 @@ socialApp.it(
|
|
|
659
671
|
);
|
|
660
672
|
```
|
|
661
673
|
|
|
662
|
-
`domFetch`
|
|
674
|
+
`domFetch` defaults to the current window and its cookie jar. Run stories using that window serially, and let the application's cleanup end its sessions, restore the page location and close its host. Cookies follow hostnames, not listener ports, so a different loopback port alone does not isolate accounts.
|
|
675
|
+
|
|
676
|
+
#### Several members on one host
|
|
677
|
+
|
|
678
|
+
Use `memberScreens` from `@shivaedev/test-story/server/memberScreens.ts` inside a DOM kit's `create` hook. Supply `baseUrl`, `mount(member)` returning an Effect, and `verbs(member, tell)` returning that member's verbs and readouts. Each `MemberScreen` carries its `name`, `fetch`, `registry` and `root`. Mount the application into that root with that registry, and give its auth and HTTP clients the member's fetch. Cookie contexts are independent even when every member uses the same host.
|
|
679
|
+
|
|
680
|
+
A trait calls `yield* members.open("ada", cookies)` with a minted session's cookies. The kit's verbs hook returns `members.verbs(story.tell)`, exposing `as("ada")` to the spec. Member narration includes the name. The calling Scope closes every cookie context, disposes every registry and removes every root. Register renderer unmounting in the mount hook with `Effect.acquireRelease` so it runs before the registry and root are released.
|
|
681
|
+
|
|
682
|
+
```ts
|
|
683
|
+
sharedLists.it("grace sees ada's addition", [signedInMembers("ada", "grace")], function* ({ as }) {
|
|
684
|
+
yield* as("ada").enter("input", "Bread");
|
|
685
|
+
yield* as("ada").submit();
|
|
686
|
+
yield* as("ada").settle();
|
|
687
|
+
yield* as("grace").click({ role: "button", name: "Refresh" });
|
|
688
|
+
yield* as("grace").settle();
|
|
689
|
+
|
|
690
|
+
expect(as("grace").text("output")).toBe("grace's list: ada: Bread");
|
|
691
|
+
});
|
|
692
|
+
```
|
|
663
693
|
|
|
664
694
|
### Driving a screen
|
|
665
695
|
|
|
@@ -680,6 +710,8 @@ verbs: ({ view, requests }, story) =>
|
|
|
680
710
|
|
|
681
711
|
`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()`.
|
|
682
712
|
|
|
713
|
+
`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.
|
|
714
|
+
|
|
683
715
|
`text(selector?)` concatenates visible HTML text nodes from the selected element or the whole root, without CSS text transforms or layout line breaks. `value(selector)` returns the current input or textarea value. Both narrate what they read through `tell` and leave assertions to the spec. Entry narration omits the supplied value.
|
|
684
716
|
|
|
685
717
|
`click`, `enter`, `submit`, `text` and `value` also accept a `ScreenTarget` object such as `{ role: "button", name: "Save" }` or `{ role: "textbox", name: /email/i }`. The role and computed accessible name must match exactly when strings are used; regular expressions match the name. Like Testing Library's role queries, these targets exclude hidden elements, including `aria-hidden` ancestors. Missing or ambiguous targets fail with the requested role, name and the visible candidates on screen. Narration names the role and name instead of a selector.
|
|
@@ -702,10 +734,11 @@ Import each module with the prefix `@shivaedev/test-story/`; there is no root en
|
|
|
702
734
|
| --------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
703
735
|
| `server/storyKit.ts` | `storyKit`, `Trait`, `RunUntilOptions`, `Story`, `RunHooks`, `StoryKitDefinition`, `Told`, `StoryBody`, `StoryTest`, `StoryIt`, `StoryKit` |
|
|
704
736
|
| `server/outcomes.ts` | `outcomes(rows)` |
|
|
705
|
-
| `server/domFetch.ts` | `domFetch(baseUrl)`
|
|
706
|
-
| `server/seedCookies.ts` | `seedCookies(cookies)`, `DomCookie`
|
|
737
|
+
| `server/domFetch.ts` | `domFetch(baseUrl, target?)` |
|
|
738
|
+
| `server/seedCookies.ts` | `seedCookies(cookies, target?)`, `DomCookie` |
|
|
707
739
|
| `server/routeOutbound.ts` | `routeOutbound(routes)` |
|
|
708
740
|
| `server/screenDriver.ts` | `screenDriver(options)`, `ScreenDriverOptions`, `ScreenDriver`, `ScreenTarget`, `MissingScreenPending` |
|
|
741
|
+
| `server/memberScreens.ts` | `memberScreens(options)`, `MemberScreen` |
|
|
709
742
|
| `server/domNavigate.ts` | `domNavigate(url?)` |
|
|
710
743
|
| `server/genreTags.ts` | `genreTags(...kitNames)`, `GenreTag` |
|
|
711
744
|
| `server/domEnvironment.config.ts` | Default Vitest environment preserving Node host globals and happy-dom document transport |
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
export declare function domFetch(baseUrl: string
|
|
1
|
+
export declare function domFetch(baseUrl: string, target?: {
|
|
2
|
+
readonly fetch: typeof globalThis.fetch;
|
|
3
|
+
readonly location: {
|
|
4
|
+
href: string;
|
|
5
|
+
};
|
|
6
|
+
}): typeof globalThis.fetch;
|
|
2
7
|
//# sourceMappingURL=domFetch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domFetch.d.ts","sourceRoot":"","sources":["../../src/server/domFetch.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"domFetch.d.ts","sourceRoot":"","sources":["../../src/server/domFetch.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CACvB,OAAO,EAAE,MAAM,EACf,MAAM,GAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAW,GAC/F,OAAO,UAAU,CAAC,KAAK,CAyBzB"}
|
package/dist/server/domFetch.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export function domFetch(baseUrl) {
|
|
1
|
+
export function domFetch(baseUrl, target = window) {
|
|
2
2
|
const base = new URL(baseUrl);
|
|
3
|
-
|
|
4
|
-
const transport =
|
|
3
|
+
target.location.href = base.href;
|
|
4
|
+
const transport = target.fetch.bind(target);
|
|
5
5
|
return (input, init) => {
|
|
6
6
|
if (input instanceof Request) {
|
|
7
7
|
const request = new Request(input, init);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domFetch.js","sourceRoot":"","sources":["../../src/server/domFetch.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,QAAQ,
|
|
1
|
+
{"version":3,"file":"domFetch.js","sourceRoot":"","sources":["../../src/server/domFetch.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,QAAQ,CACvB,OAAe,EACf,MAAM,GAAqF,MAAM;IAEjG,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9B,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IACjC,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5C,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QACtB,IAAI,KAAK,YAAY,OAAO,EAAE,CAAC;YAC9B,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YACzC,OAAO,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE;gBAC7B,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,WAAW,EAAE,OAAO,CAAC,WAAW;gBAChC,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;gBAC7B,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,cAAc,EAAE,OAAO,CAAC,cAAc;gBACtC,MAAM,EAAE,OAAO,CAAC,MAAM;aACtB,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,SAAS,CACf,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAC7D,IAAI,EAAE,OAAO,YAAY,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CACjF,CAAC;IACH,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -5,6 +5,8 @@ export interface ForwardingProxyOptions {
|
|
|
5
5
|
readonly localAddress?: string;
|
|
6
6
|
}
|
|
7
7
|
export declare const forwardingProxy: (upstream: string, options?: ForwardingProxyOptions | undefined) => Effect.Effect<{
|
|
8
|
+
disconnect: () => void;
|
|
9
|
+
resume: () => void;
|
|
8
10
|
url: string;
|
|
9
11
|
}, Error, import("effect/Scope").Scope>;
|
|
10
12
|
//# sourceMappingURL=forwardingProxy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forwardingProxy.d.ts","sourceRoot":"","sources":["../../src/server/forwardingProxy.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,MAAM,WAAW,sBAAsB;IACtC,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACpD,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,eAAO,MAAM,eAAe
|
|
1
|
+
{"version":3,"file":"forwardingProxy.d.ts","sourceRoot":"","sources":["../../src/server/forwardingProxy.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,MAAM,WAAW,sBAAsB;IACtC,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACpD,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,eAAO,MAAM,eAAe;;;;uCAgG1B,CAAC"}
|
|
@@ -21,7 +21,12 @@ export const forwardingProxy = Effect.fnUntraced(function* (upstream, options =
|
|
|
21
21
|
method: incoming.method,
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
+
let offline = false;
|
|
24
25
|
const forward = (incoming, response) => {
|
|
26
|
+
if (offline) {
|
|
27
|
+
incoming.destroy();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
25
30
|
const outgoing = request(`${upstream}${incoming.url}`, requestOptions(incoming), (result) => {
|
|
26
31
|
response.writeHead(result.statusCode ?? HttpStatus.fromLiteral("BadGateway"), result.headers);
|
|
27
32
|
result.pipe(response);
|
|
@@ -39,9 +44,16 @@ export const forwardingProxy = Effect.fnUntraced(function* (upstream, options =
|
|
|
39
44
|
};
|
|
40
45
|
const sockets = new Set();
|
|
41
46
|
function server() {
|
|
42
|
-
return createServer(forward)
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
return createServer(forward)
|
|
48
|
+
.on("connection", (socket) => {
|
|
49
|
+
sockets.add(socket);
|
|
50
|
+
socket.on("close", () => sockets.delete(socket));
|
|
51
|
+
})
|
|
52
|
+
.on("upgrade", (incoming, downstream, head) => {
|
|
53
|
+
if (offline) {
|
|
54
|
+
downstream.destroy();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
45
57
|
const outgoing = request(`${upstream}${incoming.url}`, requestOptions(incoming));
|
|
46
58
|
outgoing.on("upgrade", (result, upstreamSocket, upstreamHead) => {
|
|
47
59
|
downstream.write(`HTTP/1.1 ${result.statusCode} ${result.statusMessage}\r\n`);
|
|
@@ -72,6 +84,17 @@ export const forwardingProxy = Effect.fnUntraced(function* (upstream, options =
|
|
|
72
84
|
socket.destroy();
|
|
73
85
|
}
|
|
74
86
|
}));
|
|
75
|
-
return {
|
|
87
|
+
return {
|
|
88
|
+
disconnect: () => {
|
|
89
|
+
offline = true;
|
|
90
|
+
for (const socket of sockets) {
|
|
91
|
+
socket.destroy();
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
resume: () => {
|
|
95
|
+
offline = false;
|
|
96
|
+
},
|
|
97
|
+
url,
|
|
98
|
+
};
|
|
76
99
|
});
|
|
77
100
|
//# sourceMappingURL=forwardingProxy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forwardingProxy.js","sourceRoot":"","sources":["../../src/server/forwardingProxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA8C,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9F,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAQvD,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,QAAgB,EAAE,OAAO,GAA2B,EAAE;IACjH,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QACxC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,YAAY,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC,CA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
+
function responseBody(response, release) {
|
|
2
|
+
if (response.body === null) {
|
|
3
|
+
release();
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
const reader = response.body.getReader();
|
|
7
|
+
return new ReadableStream({
|
|
8
|
+
async cancel(reason) {
|
|
9
|
+
release();
|
|
10
|
+
await reader.cancel(reason);
|
|
11
|
+
},
|
|
12
|
+
async pull(controller) {
|
|
13
|
+
try {
|
|
14
|
+
const next = await reader.read();
|
|
15
|
+
if (next.done) {
|
|
16
|
+
release();
|
|
17
|
+
controller.close();
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
controller.enqueue(next.value);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
release();
|
|
25
|
+
controller.error(error);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export function memberFetch(browser) {
|
|
31
|
+
return async (input, init) => {
|
|
32
|
+
const request = new Request(input, init);
|
|
33
|
+
const controller = new browser.AbortController();
|
|
34
|
+
function abort() {
|
|
35
|
+
controller.abort(request.signal.reason);
|
|
36
|
+
}
|
|
37
|
+
function release() {
|
|
38
|
+
request.signal.removeEventListener("abort", abort);
|
|
39
|
+
}
|
|
40
|
+
request.signal.addEventListener("abort", abort, { once: true });
|
|
41
|
+
if (request.signal.aborted) {
|
|
42
|
+
abort();
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const response = await browser.fetch(request.url, {
|
|
46
|
+
body: request.body === null ? null : await request.arrayBuffer(),
|
|
47
|
+
credentials: request.credentials,
|
|
48
|
+
headers: [...request.headers],
|
|
49
|
+
method: request.method,
|
|
50
|
+
redirect: request.redirect,
|
|
51
|
+
signal: controller.signal,
|
|
52
|
+
});
|
|
53
|
+
const result = new Response(responseBody(response, release), {
|
|
54
|
+
headers: [...response.headers],
|
|
55
|
+
status: response.status,
|
|
56
|
+
statusText: response.statusText,
|
|
57
|
+
});
|
|
58
|
+
Object.defineProperty(result, "url", { value: response.url });
|
|
59
|
+
Object.defineProperty(result, "redirected", { value: response.redirected });
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
release();
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=memberFetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memberFetch.js","sourceRoot":"","sources":["../../../../src/server/internal/adapters/memberFetch.ts"],"names":[],"mappings":"AAEA,SAAS,YAAY,CAAC,QAAyB,EAAE,OAAmB;IACnE,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QAC5B,OAAO,EAAE,CAAC;QACV,OAAO,IAAI,CAAC;IACb,CAAC;IACD,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;IACzC,OAAO,IAAI,cAAc,CAAa;QACrC,KAAK,CAAC,MAAM,CAAC,MAAM;YAClB,OAAO,EAAE,CAAC;YACV,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC7B,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,UAAU;YACpB,IAAI,CAAC;gBACJ,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;gBACjC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;oBACf,OAAO,EAAE,CAAC;oBACV,UAAU,CAAC,KAAK,EAAE,CAAC;gBACpB,CAAC;qBAAM,CAAC;oBACP,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAChC,CAAC;YACF,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,OAAO,EAAE,CAAC;gBACV,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACzB,CAAC;QACF,CAAC;KACD,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,U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AAC,MAAM;gBACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;aAC/B,CAAC,CAAC;YACH,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;YAC9D,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;YAC5E,OAAO,MAAM,CAAC;QACf,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,EAAE,CAAC;YACV,MAAM,KAAK,CAAC;QACb,CAAC;IACF,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Effect, type Scope } from "effect";
|
|
2
|
+
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
3
|
+
import { type DomCookie } from "#seedCookies.ts";
|
|
4
|
+
export interface MemberScreen {
|
|
5
|
+
readonly fetch: typeof globalThis.fetch;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly registry: AtomRegistry.AtomRegistry;
|
|
8
|
+
readonly root: HTMLDivElement;
|
|
9
|
+
}
|
|
10
|
+
export declare function memberScreens<E, R, TVerbs>(options: {
|
|
11
|
+
readonly baseUrl: string;
|
|
12
|
+
readonly mount: (member: MemberScreen) => Effect.Effect<void, E, R | Scope.Scope>;
|
|
13
|
+
readonly verbs: (member: MemberScreen, tell: (line: string) => void) => TVerbs;
|
|
14
|
+
}): {
|
|
15
|
+
open: (name: string, cookies: readonly DomCookie[]) => Effect.Effect<void, E, R | Scope.Scope>;
|
|
16
|
+
verbs: (tell: (line: string) => void) => {
|
|
17
|
+
as: (name: string) => TVerbs;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=memberScreens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memberScreens.d.ts","sourceRoot":"","sources":["../../src/server/memberScreens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AACpD,OAAO,KAAK,YAAY,MAAM,gCAAgC,CAAC;AAK/D,OAAO,EAAE,KAAK,SAAS,EAAe,MAAM,iBAAiB,CAAC;AAE9D,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC,YAAY,CAAC;IAC7C,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;CAC9B;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE;IACpD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;IAClF,QAAQ,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,KAAK,MAAM,CAAC;CAC/E;IAGC,IAAI;IA4BJ,KAAK,SAAS,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI;QACnC,EAAE,SAAS,MAAM;;EASnB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Effect, Option } from "effect";
|
|
2
|
+
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
3
|
+
import { GlobalWindow } from "happy-dom";
|
|
4
|
+
import { domFetch } from "#domFetch.ts";
|
|
5
|
+
import { memberFetch } from "#internal/adapters/memberFetch.ts";
|
|
6
|
+
import { documentTransport } from "#internal/documentTransport.ts";
|
|
7
|
+
import { seedCookies } from "#seedCookies.ts";
|
|
8
|
+
export function memberScreens(options) {
|
|
9
|
+
const members = new Map();
|
|
10
|
+
return {
|
|
11
|
+
open: Effect.fnUntraced(function* (name, cookies) {
|
|
12
|
+
const browser = yield* Effect.acquireRelease(Effect.sync(() => new GlobalWindow({ url: options.baseUrl })), (target) => Effect.promise(() => target.happyDOM.abort()).pipe(Effect.andThen(Effect.sync(() => target.close()))));
|
|
13
|
+
browser.happyDOM.settings.fetch.interceptor = documentTransport(globalThis.fetch);
|
|
14
|
+
yield* seedCookies(cookies, browser);
|
|
15
|
+
const member = yield* Effect.acquireRelease(Effect.sync(() => {
|
|
16
|
+
const root = document.createElement("div");
|
|
17
|
+
document.body.append(root);
|
|
18
|
+
return {
|
|
19
|
+
fetch: domFetch(options.baseUrl, { fetch: memberFetch(browser), location: browser.location }),
|
|
20
|
+
name,
|
|
21
|
+
registry: AtomRegistry.make(),
|
|
22
|
+
root,
|
|
23
|
+
};
|
|
24
|
+
}), ({ registry, root }) => Effect.sync(() => {
|
|
25
|
+
members.delete(name);
|
|
26
|
+
registry.dispose();
|
|
27
|
+
root.remove();
|
|
28
|
+
}));
|
|
29
|
+
yield* options.mount(member);
|
|
30
|
+
members.set(name, member);
|
|
31
|
+
}),
|
|
32
|
+
verbs: (tell) => ({
|
|
33
|
+
as: (name) => {
|
|
34
|
+
const member = Option.getOrThrowWith(Option.fromUndefinedOr(members.get(name)), () => new Error(`No screen is open for ${JSON.stringify(name)}.\nhelp: Open this member in a story trait before using as(name).`));
|
|
35
|
+
return options.verbs(member, (line) => tell(`${name}: ${line}`));
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=memberScreens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memberScreens.js","sourceRoot":"","sources":["../../src/server/memberScreens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAc,MAAM,Q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CAAC;YAClE,CAAC;SACD,CAAC;KACF,CAAC;AACH,CAAC"}
|
|
@@ -16,16 +16,17 @@ declare const MissingScreenPending_base: new <A extends Record<string, any> = {}
|
|
|
16
16
|
export declare class MissingScreenPending extends MissingScreenPending_base {
|
|
17
17
|
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
18
|
}
|
|
19
|
-
export type ScreenDriver<E = never> = Omit<ReturnType<typeof
|
|
19
|
+
export type ScreenDriver<E = never> = Omit<ReturnType<typeof makeScreenActions>, "settle"> & {
|
|
20
20
|
settle: (options?: {
|
|
21
21
|
readonly timeoutMs?: number;
|
|
22
22
|
}) => Effect.Effect<void, E>;
|
|
23
|
+
within: (container: ScreenTarget | HTMLElement) => ScreenDriver<E>;
|
|
23
24
|
};
|
|
24
25
|
export declare function screenDriver(options: ScreenDriverOptions & {
|
|
25
26
|
readonly pending: () => boolean;
|
|
26
27
|
}): ScreenDriver;
|
|
27
28
|
export declare function screenDriver(options: ScreenDriverOptions): ScreenDriver<MissingScreenPending>;
|
|
28
|
-
declare function
|
|
29
|
+
declare function makeScreenActions({ root, pending, tell, act, timeoutMs }: ScreenDriverOptions): {
|
|
29
30
|
accessible: (selector: string | Element) => {
|
|
30
31
|
name: string;
|
|
31
32
|
role: string | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"screenDriver.d.ts","sourceRoot":"","sources":["../../src/server/screenDriver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,MAAM,EAAY,MAAM,QAAQ,CAAC;AAKhD,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAE9F,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,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,OAAO,4MACiL;CAC1M;AAED,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,KAAK,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,iBAAiB,CAAC,EAAE,QAAQ,CAAC,GAAG;IAC5F,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC9E,MAAM,EAAE,CAAC,SAAS,EAAE,YAAY,GAAG,WAAW,KAAK,YAAY,CAAC,CAAC,CAAC,CAAC;CACnE,CAAC;AAEF,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,OAAO,CAAA;CAAE,GAAG,YAAY,CAAC;AAC/G,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CAAC,oBAAoB,CAAC,CAAC;AAiB/F,iBAAS,iBAAiB,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,GAA0B,EAAE,SAAgB,EAAE,EAAE,mBAAmB;2BAoD5F,MAAM,GAAG,OAAO;;;;sBASrB,YAAY;sBAOZ,YAAY,SAAS,MAAM;mBAlCxB,YAAY,YAAW;QAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;uBAzBjD;QAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE;wBA8DpC,YAAY;sBACb,YAAY;sBAKZ,YAAY;EAM/B"}
|
|
@@ -6,9 +6,21 @@ export class MissingScreenPending extends Data.TaggedError("MissingScreenPending
|
|
|
6
6
|
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
7
|
}
|
|
8
8
|
export function screenDriver(options) {
|
|
9
|
-
|
|
9
|
+
const suppliedRoot = options.root;
|
|
10
|
+
const root = typeof suppliedRoot === "function" ? suppliedRoot : () => suppliedRoot;
|
|
11
|
+
const elements = screenElements(root);
|
|
12
|
+
return {
|
|
13
|
+
...makeScreenActions(options),
|
|
14
|
+
within: (container) => {
|
|
15
|
+
function scopedRoot() {
|
|
16
|
+
return container instanceof HTMLElement ? elements.rendered(container, container.tagName.toLowerCase()) : elements.element(container);
|
|
17
|
+
}
|
|
18
|
+
scopedRoot();
|
|
19
|
+
return screenDriver({ ...options, root: scopedRoot });
|
|
20
|
+
},
|
|
21
|
+
};
|
|
10
22
|
}
|
|
11
|
-
function
|
|
23
|
+
function makeScreenActions({ root, pending, tell, act = (action) => action(), timeoutMs = 3000 }) {
|
|
12
24
|
const currentRoot = typeof root === "function" ? root : () => root;
|
|
13
25
|
const elements = screenElements(currentRoot);
|
|
14
26
|
function perform(line, action) {
|
|
@@ -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;
|
|
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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K,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,4 +1,5 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
+
import { BrowserWindow } from "happy-dom";
|
|
2
3
|
export interface DomCookie {
|
|
3
4
|
readonly domain?: string;
|
|
4
5
|
readonly expires?: number;
|
|
@@ -9,5 +10,5 @@ export interface DomCookie {
|
|
|
9
10
|
readonly secure?: boolean;
|
|
10
11
|
readonly value: string;
|
|
11
12
|
}
|
|
12
|
-
export declare const seedCookies: (cookies: readonly DomCookie[]) => Effect.Effect<undefined, never, never>;
|
|
13
|
+
export declare const seedCookies: (cookies: readonly DomCookie[], target?: Window | BrowserWindow | undefined) => Effect.Effect<undefined, never, never>;
|
|
13
14
|
//# sourceMappingURL=seedCookies.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seedCookies.d.ts","sourceRoot":"","sources":["../../src/server/seedCookies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"seedCookies.d.ts","sourceRoot":"","sources":["../../src/server/seedCookies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAsB,MAAM,WAAW,CAAC;AAG9D,MAAM,WAAW,SAAS;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC9C,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACvB;AAID,eAAO,MAAM,WAAW,wHAqBtB,CAAC"}
|
|
@@ -2,17 +2,17 @@ import { Effect } from "effect";
|
|
|
2
2
|
import { BrowserWindow, CookieSameSiteEnum } from "happy-dom";
|
|
3
3
|
import WindowBrowserContext from "happy-dom/lib/window/WindowBrowserContext.js";
|
|
4
4
|
const sameSites = { Lax: CookieSameSiteEnum.lax, None: CookieSameSiteEnum.none, Strict: CookieSameSiteEnum.strict };
|
|
5
|
-
export const seedCookies = Effect.fnUntraced(function* (cookies) {
|
|
6
|
-
if (!(
|
|
5
|
+
export const seedCookies = Effect.fnUntraced(function* (cookies, target = window) {
|
|
6
|
+
if (!(target instanceof BrowserWindow)) {
|
|
7
7
|
return yield* Effect.die("Cookie preconditions need a happy-dom window.\nhelp: Use test-story's DOM environment before seeding cookies.");
|
|
8
8
|
}
|
|
9
|
-
const context = new WindowBrowserContext(
|
|
9
|
+
const context = new WindowBrowserContext(target).getBrowserContext();
|
|
10
10
|
if (context === null) {
|
|
11
11
|
return yield* Effect.die("Cannot seed cookies after the document has closed.");
|
|
12
12
|
}
|
|
13
13
|
context.cookieContainer.addCookies(cookies.map((cookie) => ({
|
|
14
14
|
key: cookie.name,
|
|
15
|
-
"originURL": new URL(
|
|
15
|
+
"originURL": new URL(target.location.href),
|
|
16
16
|
value: cookie.value,
|
|
17
17
|
...(cookie.domain === undefined ? {} : { domain: cookie.domain }),
|
|
18
18
|
...(cookie.path === undefined ? {} : { path: cookie.path }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seedCookies.js","sourceRoot":"","sources":["../../src/server/seedCookies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,oBAAoB,MAAM,8CAA8C,CAAC;AAahF,MAAM,SAAS,GAAG,EAAE,GAAG,EAAE,kBAAkB,CAAC,GAAG,EAAE,IAAI,EAAE,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,kBAAkB,CAAC,MAAM,EAAE,CAAC;AAEpH,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,OAA6B;
|
|
1
|
+
{"version":3,"file":"seedCookies.js","sourceRoot":"","sources":["../../src/server/seedCookies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,oBAAoB,MAAM,8CAA8C,CAAC;AAahF,MAAM,SAAS,GAAG,EAAE,GAAG,EAAE,kBAAkB,CAAC,GAAG,EAAE,IAAI,EAAE,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,kBAAkB,CAAC,MAAM,EAAE,CAAC;AAEpH,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,OAA6B,EAAE,MAAM,GAA2B,MAAM;IAC7H,IAAI,CAAC,CAAC,MAAM,YAAY,aAAa,CAAC,EAAE,CAAC;QACxC,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,+GAA+G,CAAC,CAAC;IAC3I,CAAC;IACD,MAAM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,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC;KACrF,CAAC,CAAC,CACH,CAAC;AACH,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/test-story",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"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": {
|
|
@@ -41,25 +41,25 @@
|
|
|
41
41
|
"README.md"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@shivaedev/test": "0.10.
|
|
45
|
-
"@shivaedev/test-sql": "0.
|
|
44
|
+
"@shivaedev/test": "0.10.1",
|
|
45
|
+
"@shivaedev/test-sql": "0.11.0",
|
|
46
46
|
"dom-accessibility-api": "0.7.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@effect/platform-node": "4.0.
|
|
50
|
-
"@effect/vitest": "4.0.
|
|
51
|
-
"@shivaedev/quality": "0.
|
|
49
|
+
"@effect/platform-node": "4.0.6",
|
|
50
|
+
"@effect/vitest": "4.0.6",
|
|
51
|
+
"@shivaedev/quality": "0.45.0",
|
|
52
52
|
"@types/node": "24.19.2",
|
|
53
|
-
"effect": "4.0.
|
|
53
|
+
"effect": "4.0.6",
|
|
54
54
|
"happy-dom": "21.0.4",
|
|
55
55
|
"typescript": "7.0.2",
|
|
56
56
|
"vitest": "5.0.5"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@effect/platform-node": "4.0.
|
|
60
|
-
"@effect/sql-pg": "4.0.
|
|
61
|
-
"@effect/vitest": "4.0.
|
|
62
|
-
"effect": "4.0.
|
|
59
|
+
"@effect/platform-node": "4.0.6",
|
|
60
|
+
"@effect/sql-pg": "4.0.6",
|
|
61
|
+
"@effect/vitest": "4.0.6",
|
|
62
|
+
"effect": "4.0.6",
|
|
63
63
|
"happy-dom": "21.0.4",
|
|
64
64
|
"vitest": "5.0.5"
|
|
65
65
|
},
|
package/src/server/domFetch.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
export function domFetch(
|
|
1
|
+
export function domFetch(
|
|
2
|
+
baseUrl: string,
|
|
3
|
+
target: { readonly fetch: typeof globalThis.fetch; readonly location: { href: string } } = window,
|
|
4
|
+
): typeof globalThis.fetch {
|
|
2
5
|
const base = new URL(baseUrl);
|
|
3
|
-
|
|
4
|
-
const transport =
|
|
6
|
+
target.location.href = base.href;
|
|
7
|
+
const transport = target.fetch.bind(target);
|
|
5
8
|
return (input, init) => {
|
|
6
9
|
if (input instanceof Request) {
|
|
7
10
|
const request = new Request(input, init);
|
|
@@ -31,7 +31,12 @@ export const forwardingProxy = Effect.fnUntraced(function* (upstream: string, op
|
|
|
31
31
|
method: incoming.method,
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
+
let offline = false;
|
|
34
35
|
const forward: RequestListener = (incoming, response) => {
|
|
36
|
+
if (offline) {
|
|
37
|
+
incoming.destroy();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
35
40
|
const outgoing = request(`${upstream}${incoming.url}`, requestOptions(incoming), (result) => {
|
|
36
41
|
response.writeHead(result.statusCode ?? HttpStatus.fromLiteral("BadGateway"), result.headers);
|
|
37
42
|
result.pipe(response);
|
|
@@ -48,31 +53,38 @@ export const forwardingProxy = Effect.fnUntraced(function* (upstream: string, op
|
|
|
48
53
|
};
|
|
49
54
|
const sockets = new Set<Duplex>();
|
|
50
55
|
function server() {
|
|
51
|
-
return createServer(forward)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
downstream.
|
|
56
|
+
return createServer(forward)
|
|
57
|
+
.on("connection", (socket) => {
|
|
58
|
+
sockets.add(socket);
|
|
59
|
+
socket.on("close", () => sockets.delete(socket));
|
|
60
|
+
})
|
|
61
|
+
.on("upgrade", (incoming, downstream, head) => {
|
|
62
|
+
if (offline) {
|
|
63
|
+
downstream.destroy();
|
|
64
|
+
return;
|
|
59
65
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
const outgoing = request(`${upstream}${incoming.url}`, requestOptions(incoming));
|
|
67
|
+
outgoing.on("upgrade", (result, upstreamSocket, upstreamHead) => {
|
|
68
|
+
downstream.write(`HTTP/1.1 ${result.statusCode} ${result.statusMessage}\r\n`);
|
|
69
|
+
for (let index = 0; index < result.rawHeaders.length; index += 2) {
|
|
70
|
+
downstream.write(`${result.rawHeaders[index]}: ${result.rawHeaders[index + 1]}\r\n`);
|
|
71
|
+
}
|
|
72
|
+
downstream.write("\r\n");
|
|
73
|
+
downstream.write(upstreamHead);
|
|
74
|
+
upstreamSocket.write(head);
|
|
75
|
+
downstream.pipe(upstreamSocket).pipe(downstream);
|
|
76
|
+
downstream.on("close", () => upstreamSocket.destroy());
|
|
77
|
+
upstreamSocket.on("error", () => downstream.destroy());
|
|
78
|
+
});
|
|
79
|
+
outgoing.on("response", (result) => {
|
|
80
|
+
downstream.end(`HTTP/1.1 ${result.statusCode} ${result.statusMessage}\r\nConnection: close\r\n\r\n`);
|
|
81
|
+
result.resume();
|
|
82
|
+
});
|
|
83
|
+
outgoing.on("error", () => downstream.destroy());
|
|
84
|
+
downstream.on("error", () => outgoing.destroy());
|
|
85
|
+
downstream.on("close", () => outgoing.destroy());
|
|
86
|
+
outgoing.end();
|
|
66
87
|
});
|
|
67
|
-
outgoing.on("response", (result) => {
|
|
68
|
-
downstream.end(`HTTP/1.1 ${result.statusCode} ${result.statusMessage}\r\nConnection: close\r\n\r\n`);
|
|
69
|
-
result.resume();
|
|
70
|
-
});
|
|
71
|
-
outgoing.on("error", () => downstream.destroy());
|
|
72
|
-
downstream.on("error", () => outgoing.destroy());
|
|
73
|
-
downstream.on("close", () => outgoing.destroy());
|
|
74
|
-
outgoing.end();
|
|
75
|
-
});
|
|
76
88
|
}
|
|
77
89
|
const url = yield* loopbackServer(server());
|
|
78
90
|
yield* loopbackServer(server(), { host: "::1", port: Number(new URL(url).port) });
|
|
@@ -83,5 +95,16 @@ export const forwardingProxy = Effect.fnUntraced(function* (upstream: string, op
|
|
|
83
95
|
}
|
|
84
96
|
}),
|
|
85
97
|
);
|
|
86
|
-
return {
|
|
98
|
+
return {
|
|
99
|
+
disconnect: () => {
|
|
100
|
+
offline = true;
|
|
101
|
+
for (const socket of sockets) {
|
|
102
|
+
socket.destroy();
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
resume: () => {
|
|
106
|
+
offline = false;
|
|
107
|
+
},
|
|
108
|
+
url,
|
|
109
|
+
};
|
|
87
110
|
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Response as BrowserResponse, BrowserWindow } from "happy-dom";
|
|
2
|
+
|
|
3
|
+
function responseBody(response: BrowserResponse, release: () => void) {
|
|
4
|
+
if (response.body === null) {
|
|
5
|
+
release();
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
const reader = response.body.getReader();
|
|
9
|
+
return new ReadableStream<Uint8Array>({
|
|
10
|
+
async cancel(reason) {
|
|
11
|
+
release();
|
|
12
|
+
await reader.cancel(reason);
|
|
13
|
+
},
|
|
14
|
+
async pull(controller) {
|
|
15
|
+
try {
|
|
16
|
+
const next = await reader.read();
|
|
17
|
+
if (next.done) {
|
|
18
|
+
release();
|
|
19
|
+
controller.close();
|
|
20
|
+
} else {
|
|
21
|
+
controller.enqueue(next.value);
|
|
22
|
+
}
|
|
23
|
+
} catch (error) {
|
|
24
|
+
release();
|
|
25
|
+
controller.error(error);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function memberFetch(browser: BrowserWindow): typeof globalThis.fetch {
|
|
32
|
+
return async (input, init) => {
|
|
33
|
+
const request = new Request(input, init);
|
|
34
|
+
const controller = new browser.AbortController();
|
|
35
|
+
function abort() {
|
|
36
|
+
controller.abort(request.signal.reason);
|
|
37
|
+
}
|
|
38
|
+
function release() {
|
|
39
|
+
request.signal.removeEventListener("abort", abort);
|
|
40
|
+
}
|
|
41
|
+
request.signal.addEventListener("abort", abort, { once: true });
|
|
42
|
+
if (request.signal.aborted) {
|
|
43
|
+
abort();
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const response = await browser.fetch(request.url, {
|
|
47
|
+
body: request.body === null ? null : await request.arrayBuffer(),
|
|
48
|
+
credentials: request.credentials,
|
|
49
|
+
headers: [...request.headers],
|
|
50
|
+
method: request.method,
|
|
51
|
+
redirect: request.redirect,
|
|
52
|
+
signal: controller.signal,
|
|
53
|
+
});
|
|
54
|
+
const result = new Response(responseBody(response, release), {
|
|
55
|
+
headers: [...response.headers],
|
|
56
|
+
status: response.status,
|
|
57
|
+
statusText: response.statusText,
|
|
58
|
+
});
|
|
59
|
+
Object.defineProperty(result, "url", { value: response.url });
|
|
60
|
+
Object.defineProperty(result, "redirected", { value: response.redirected });
|
|
61
|
+
return result;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
release();
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Effect, Option, type Scope } from "effect";
|
|
2
|
+
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
3
|
+
import { GlobalWindow } from "happy-dom";
|
|
4
|
+
import { domFetch } from "#domFetch.ts";
|
|
5
|
+
import { memberFetch } from "#internal/adapters/memberFetch.ts";
|
|
6
|
+
import { documentTransport } from "#internal/documentTransport.ts";
|
|
7
|
+
import { type DomCookie, seedCookies } from "#seedCookies.ts";
|
|
8
|
+
|
|
9
|
+
export interface MemberScreen {
|
|
10
|
+
readonly fetch: typeof globalThis.fetch;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly registry: AtomRegistry.AtomRegistry;
|
|
13
|
+
readonly root: HTMLDivElement;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function memberScreens<E, R, TVerbs>(options: {
|
|
17
|
+
readonly baseUrl: string;
|
|
18
|
+
readonly mount: (member: MemberScreen) => Effect.Effect<void, E, R | Scope.Scope>;
|
|
19
|
+
readonly verbs: (member: MemberScreen, tell: (line: string) => void) => TVerbs;
|
|
20
|
+
}) {
|
|
21
|
+
const members = new Map<string, MemberScreen>();
|
|
22
|
+
return {
|
|
23
|
+
open: Effect.fnUntraced(function* (name: string, cookies: readonly DomCookie[]) {
|
|
24
|
+
const browser = yield* Effect.acquireRelease(
|
|
25
|
+
Effect.sync(() => new GlobalWindow({ url: options.baseUrl })),
|
|
26
|
+
(target) => Effect.promise(() => target.happyDOM.abort()).pipe(Effect.andThen(Effect.sync(() => target.close()))),
|
|
27
|
+
);
|
|
28
|
+
browser.happyDOM.settings.fetch.interceptor = documentTransport(globalThis.fetch);
|
|
29
|
+
yield* seedCookies(cookies, browser);
|
|
30
|
+
const member = yield* Effect.acquireRelease(
|
|
31
|
+
Effect.sync(() => {
|
|
32
|
+
const root = document.createElement("div");
|
|
33
|
+
document.body.append(root);
|
|
34
|
+
return {
|
|
35
|
+
fetch: domFetch(options.baseUrl, { fetch: memberFetch(browser), location: browser.location }),
|
|
36
|
+
name,
|
|
37
|
+
registry: AtomRegistry.make(),
|
|
38
|
+
root,
|
|
39
|
+
};
|
|
40
|
+
}),
|
|
41
|
+
({ registry, root }) =>
|
|
42
|
+
Effect.sync(() => {
|
|
43
|
+
members.delete(name);
|
|
44
|
+
registry.dispose();
|
|
45
|
+
root.remove();
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
48
|
+
yield* options.mount(member);
|
|
49
|
+
members.set(name, member);
|
|
50
|
+
}),
|
|
51
|
+
verbs: (tell: (line: string) => void) => ({
|
|
52
|
+
as: (name: string) => {
|
|
53
|
+
const member = Option.getOrThrowWith(
|
|
54
|
+
Option.fromUndefinedOr(members.get(name)),
|
|
55
|
+
() => new Error(`No screen is open for ${JSON.stringify(name)}.\nhelp: Open this member in a story trait before using as(name).`),
|
|
56
|
+
);
|
|
57
|
+
return options.verbs(member, (line) => tell(`${name}: ${line}`));
|
|
58
|
+
},
|
|
59
|
+
}),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -18,17 +18,30 @@ export class MissingScreenPending extends Data.TaggedError("MissingScreenPending
|
|
|
18
18
|
"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
19
|
}
|
|
20
20
|
|
|
21
|
-
export type ScreenDriver<E = never> = Omit<ReturnType<typeof
|
|
21
|
+
export type ScreenDriver<E = never> = Omit<ReturnType<typeof makeScreenActions>, "settle"> & {
|
|
22
22
|
settle: (options?: { readonly timeoutMs?: number }) => Effect.Effect<void, E>;
|
|
23
|
+
within: (container: ScreenTarget | HTMLElement) => ScreenDriver<E>;
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
export function screenDriver(options: ScreenDriverOptions & { readonly pending: () => boolean }): ScreenDriver;
|
|
26
27
|
export function screenDriver(options: ScreenDriverOptions): ScreenDriver<MissingScreenPending>;
|
|
27
|
-
export function screenDriver(options: ScreenDriverOptions) {
|
|
28
|
-
|
|
28
|
+
export function screenDriver(options: ScreenDriverOptions): ScreenDriver<MissingScreenPending> {
|
|
29
|
+
const suppliedRoot = options.root;
|
|
30
|
+
const root = typeof suppliedRoot === "function" ? suppliedRoot : () => suppliedRoot;
|
|
31
|
+
const elements = screenElements(root);
|
|
32
|
+
return {
|
|
33
|
+
...makeScreenActions(options),
|
|
34
|
+
within: (container) => {
|
|
35
|
+
function scopedRoot() {
|
|
36
|
+
return container instanceof HTMLElement ? elements.rendered(container, container.tagName.toLowerCase()) : elements.element(container);
|
|
37
|
+
}
|
|
38
|
+
scopedRoot();
|
|
39
|
+
return screenDriver({ ...options, root: scopedRoot });
|
|
40
|
+
},
|
|
41
|
+
};
|
|
29
42
|
}
|
|
30
43
|
|
|
31
|
-
function
|
|
44
|
+
function makeScreenActions({ root, pending, tell, act = (action) => action(), timeoutMs = 3000 }: ScreenDriverOptions) {
|
|
32
45
|
const currentRoot = typeof root === "function" ? root : () => root;
|
|
33
46
|
const elements = screenElements(currentRoot);
|
|
34
47
|
function perform(line: string, action: () => void) {
|
|
@@ -15,18 +15,18 @@ export interface DomCookie {
|
|
|
15
15
|
|
|
16
16
|
const sameSites = { Lax: CookieSameSiteEnum.lax, None: CookieSameSiteEnum.none, Strict: CookieSameSiteEnum.strict };
|
|
17
17
|
|
|
18
|
-
export const seedCookies = Effect.fnUntraced(function* (cookies: readonly DomCookie[]) {
|
|
19
|
-
if (!(
|
|
18
|
+
export const seedCookies = Effect.fnUntraced(function* (cookies: readonly DomCookie[], target: Window | BrowserWindow = window) {
|
|
19
|
+
if (!(target instanceof BrowserWindow)) {
|
|
20
20
|
return yield* Effect.die("Cookie preconditions need a happy-dom window.\nhelp: Use test-story's DOM environment before seeding cookies.");
|
|
21
21
|
}
|
|
22
|
-
const context = new WindowBrowserContext(
|
|
22
|
+
const context = new WindowBrowserContext(target).getBrowserContext();
|
|
23
23
|
if (context === null) {
|
|
24
24
|
return yield* Effect.die("Cannot seed cookies after the document has closed.");
|
|
25
25
|
}
|
|
26
26
|
context.cookieContainer.addCookies(
|
|
27
27
|
cookies.map((cookie) => ({
|
|
28
28
|
key: cookie.name,
|
|
29
|
-
"originURL": new URL(
|
|
29
|
+
"originURL": new URL(target.location.href),
|
|
30
30
|
value: cookie.value,
|
|
31
31
|
...(cookie.domain === undefined ? {} : { domain: cookie.domain }),
|
|
32
32
|
...(cookie.path === undefined ? {} : { path: cookie.path }),
|