@geekmidas/constructs 10.0.0-alpha.153 → 10.0.0-alpha.155
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/dist/adaptors/testing.cjs +206 -0
- package/dist/adaptors/testing.cjs.map +1 -1
- package/dist/adaptors/testing.d.cts +81 -2
- package/dist/adaptors/testing.d.cts.map +1 -1
- package/dist/adaptors/testing.d.mts +81 -2
- package/dist/adaptors/testing.d.mts.map +1 -1
- package/dist/adaptors/testing.mjs +201 -2
- package/dist/adaptors/testing.mjs.map +1 -1
- package/dist/site.cjs +19 -0
- package/dist/site.cjs.map +1 -1
- package/dist/site.d.cts +34 -0
- package/dist/site.d.cts.map +1 -1
- package/dist/site.d.mts +34 -0
- package/dist/site.d.mts.map +1 -1
- package/dist/site.mjs +19 -1
- package/dist/site.mjs.map +1 -1
- package/dist/websocket-api-9bXfgrqd.cjs +1439 -0
- package/dist/websocket-api-9bXfgrqd.cjs.map +1 -0
- package/dist/websocket-api-CLnV_7CB.d.cts +908 -0
- package/dist/websocket-api-CLnV_7CB.d.cts.map +1 -0
- package/dist/websocket-api-DSWDhZph.d.mts +908 -0
- package/dist/websocket-api-DSWDhZph.d.mts.map +1 -0
- package/dist/websocket-api-Dn_3Y2fI.mjs +1302 -0
- package/dist/websocket-api-Dn_3Y2fI.mjs.map +1 -0
- package/dist/websocket-api.cjs +24 -1121
- package/dist/websocket-api.d.cts +2 -699
- package/dist/websocket-api.d.mts +2 -699
- package/dist/websocket-api.mjs +2 -1102
- package/package.json +31 -31
- package/dist/websocket-api.cjs.map +0 -1
- package/dist/websocket-api.d.cts.map +0 -1
- package/dist/websocket-api.d.mts.map +0 -1
- package/dist/websocket-api.mjs.map +0 -1
|
@@ -8,7 +8,9 @@ import { t as Subscriber } from "../Subscriber-5rCX1Nph.cjs";
|
|
|
8
8
|
import { t as KyselyDatabase } from "../kysely-CebjCWTl.cjs";
|
|
9
9
|
import { t as Fake } from "../fake-DqieDYYA.cjs";
|
|
10
10
|
import { o as TestStage } from "../stages-DaTaoQei.cjs";
|
|
11
|
+
import { L as Connection, Q as WebSocketPublisher, T as TestWebSocketPublisher, Y as NoMessages, Z as WebSocketMessages, g as RecordedClose, h as RecordedBroadcast, m as InvalidWebSocketRequest, n as WebSocketApi, v as RecordedSend } from "../websocket-api-CLnV_7CB.cjs";
|
|
11
12
|
import { p as Verdicts } from "../inbox-CR3L1fOI.cjs";
|
|
13
|
+
import { EnvironmentParser } from "@geekmidas/envkit";
|
|
12
14
|
import { Logger } from "@geekmidas/logger";
|
|
13
15
|
import { ComposableStandardSchema, InferComposableStandardSchema, InferStandardSchema } from "@geekmidas/schema";
|
|
14
16
|
import { Service, ServiceDiscovery, ServiceRecord } from "@geekmidas/services";
|
|
@@ -16,7 +18,7 @@ import { AuditStorage, AuditableAction, Auditor } from "@geekmidas/audit";
|
|
|
16
18
|
import { EventPublisher, ExtractPublisherMessage } from "@geekmidas/events";
|
|
17
19
|
import { InboxAddressing } from "@geekmidas/manifest";
|
|
18
20
|
import { TEST_CONTEXT_HEADER } from "@geekmidas/testkit/context";
|
|
19
|
-
import { HttpHandler } from "msw";
|
|
21
|
+
import { HttpHandler, WebSocketHandler } from "msw";
|
|
20
22
|
import { Browser, BrowserOptions } from "@geekmidas/testkit/browser";
|
|
21
23
|
import { FakerFactory } from "@geekmidas/testkit/faker";
|
|
22
24
|
import { Mailbox } from "@geekmidas/testkit/mailbox";
|
|
@@ -404,6 +406,16 @@ interface FeatureContext<TBrowser extends Browser, TDatabases extends DatabaseSc
|
|
|
404
406
|
published: (channel: {
|
|
405
407
|
id: string;
|
|
406
408
|
}) => PublishedMessage[];
|
|
409
|
+
/**
|
|
410
|
+
* What this test sent to a `WebSocketApi`'s sockets — through
|
|
411
|
+
* `services.<surface>` in an endpoint, a subscriber, a consumer — recorded
|
|
412
|
+
* rather than delivered: `sockets(realtime).sent`, `.broadcasts`,
|
|
413
|
+
* `.closed`. Each send is checked by the surface's declared messages, as
|
|
414
|
+
* deployed.
|
|
415
|
+
*
|
|
416
|
+
* @throws {UnknownWebSocketApi} when the manifest declares no such surface.
|
|
417
|
+
*/
|
|
418
|
+
sockets: <S extends WebSocketApi<string, any>>(surface: S) => TestWebSocketPublisher<MessagesOf<S>>;
|
|
407
419
|
/**
|
|
408
420
|
* A subscriber, run on its own — handed events rather than delivered them —
|
|
409
421
|
* with this test's services: its databases resolve to this test's
|
|
@@ -455,6 +467,8 @@ interface EmittedObjectEvent {
|
|
|
455
467
|
}
|
|
456
468
|
type SubscriberAdaptorOf<S> = S extends Subscriber<infer TServices, infer TLogger, infer OutSchema, infer TEventPublisher, infer TSubscribedEvents, infer TDatabase, infer TDatabaseServiceName> ? TestSubscriberAdaptor<TServices, TLogger, OutSchema, TEventPublisher, TSubscribedEvents, TDatabase, TDatabaseServiceName> : never;
|
|
457
469
|
type QueueAdaptorOf<Q> = Q extends Queue<infer TName, infer TMessage, infer TServices, infer TLogger, infer TDatabase, infer TDatabaseServiceName> ? TestQueueAdaptor<TName, TMessage, TServices, TLogger, TDatabase, TDatabaseServiceName> : never;
|
|
470
|
+
/** The messages a WebSocket surface declares — what its recorder is typed by. */
|
|
471
|
+
type MessagesOf<S> = S extends WebSocketApi<string, infer TMessages extends WebSocketMessages> ? TMessages : never;
|
|
458
472
|
/** The schema a database construct was declared with — what `db` is typed by. */
|
|
459
473
|
type DatabaseOf<C> = C extends KyselyDatabase<infer DB, any> ? DB : unknown;
|
|
460
474
|
/** One message as it was published: its type and its payload. */
|
|
@@ -469,6 +483,13 @@ interface FeatureIt<TBrowser extends Browser, TDatabases extends DatabaseSchemas
|
|
|
469
483
|
skip(name: string, fn: FeatureFn<TBrowser, TDatabases, TFactories, TServices>, timeout?: number): void;
|
|
470
484
|
}
|
|
471
485
|
export declare function featureTest<TBrowser extends Browser = Browser, TDatabases extends DatabaseSchemas = {}, TFactories extends FactoryBuilders = {}, TServices extends ServiceClients = {}>(options?: FeatureTestOptions<TBrowser, TFactories>): FeatureIt<TBrowser, TDatabases, TFactories, TServices>;
|
|
486
|
+
/** `objects(bucket)` named a bucket no subscriber in the app is bound to. */
|
|
487
|
+
/** `sockets(surface)` for a surface the test manifest does not declare. */
|
|
488
|
+
export declare class UnknownWebSocketApi extends Error {
|
|
489
|
+
readonly surface: string;
|
|
490
|
+
readonly declared: readonly string[];
|
|
491
|
+
constructor(surface: string, declared: readonly string[]);
|
|
492
|
+
}
|
|
472
493
|
/** What `signInWithMagicLink` uses of a better-auth client. */
|
|
473
494
|
interface MagicLinkAuthClient<TSession> {
|
|
474
495
|
signIn: {
|
|
@@ -585,5 +606,63 @@ interface InProcessBindings {
|
|
|
585
606
|
/** Bindings for `app.fetch(request, bindings)` from inside this process. */
|
|
586
607
|
export declare function inProcessBindings(): InProcessBindings;
|
|
587
608
|
//#endregion
|
|
588
|
-
|
|
609
|
+
//#region src/websocket/msw.d.ts
|
|
610
|
+
/**
|
|
611
|
+
* The query parameter that names a connection's test context. Read and
|
|
612
|
+
* removed before `connect()` sees `query`, so the handler never does.
|
|
613
|
+
*/
|
|
614
|
+
export declare const TEST_CONTEXT_PARAM = "__gkm_test_context";
|
|
615
|
+
/**
|
|
616
|
+
* The close code a refused connection gets: `4000 + status`, so a 401 is
|
|
617
|
+
* 4401. MSW cannot answer an upgrade with a status line, as a server does.
|
|
618
|
+
*/
|
|
619
|
+
export declare const REFUSED_CLOSE_BASE = 4000;
|
|
620
|
+
/** What one test's connections run with. */
|
|
621
|
+
interface MswWebSocketContext {
|
|
622
|
+
/** Instances for the routes' dependencies — the test's transaction. */
|
|
623
|
+
services?: Record<string, unknown>;
|
|
624
|
+
/** Whose connection it is, as `.auth()` would have resolved it. */
|
|
625
|
+
session?: unknown;
|
|
626
|
+
}
|
|
627
|
+
interface CreateMswWebSocketHandlersOptions {
|
|
628
|
+
/** The URL the client opens — what `ws.link()` matches. */
|
|
629
|
+
url: string | RegExp;
|
|
630
|
+
/** What unregistered services are registered with. Default the surface's. */
|
|
631
|
+
envParser?: EnvironmentParser<{}>;
|
|
632
|
+
/**
|
|
633
|
+
* The `memory://` channel sends reach the connections on. Default one of
|
|
634
|
+
* its own, so two adaptors in one process never share sockets.
|
|
635
|
+
*/
|
|
636
|
+
channel?: string;
|
|
637
|
+
}
|
|
638
|
+
interface MswWebSocketHandlers<TMessages extends WebSocketMessages = NoMessages> {
|
|
639
|
+
/** For `setupServer(...)` or `server.use(...)`. */
|
|
640
|
+
handlers: WebSocketHandler[];
|
|
641
|
+
/** Give a test's connections their services and session. */
|
|
642
|
+
registerContext(id: string, context: MswWebSocketContext): void;
|
|
643
|
+
removeContext(id: string): void;
|
|
644
|
+
/**
|
|
645
|
+
* A publisher whose sends reach these connections — hand it to an
|
|
646
|
+
* endpoint as `services.<surface>`.
|
|
647
|
+
*/
|
|
648
|
+
publisher: WebSocketPublisher<TMessages>;
|
|
649
|
+
/**
|
|
650
|
+
* The same channel as a connection string — what
|
|
651
|
+
* `<ID>_PUBLISHER_CONNECTION_STRING` would be for `services.<surface>` to
|
|
652
|
+
* register onto it.
|
|
653
|
+
*/
|
|
654
|
+
connectionString: string;
|
|
655
|
+
/** Every connection open now, in the order they opened. */
|
|
656
|
+
readonly connections: readonly Connection[];
|
|
657
|
+
/** Stop receiving sends on the channel. */
|
|
658
|
+
close(): Promise<void>;
|
|
659
|
+
}
|
|
660
|
+
/** A connection whose query names a context no test registered. */
|
|
661
|
+
export declare class UnknownWebSocketTestContext extends Error {
|
|
662
|
+
readonly id: string;
|
|
663
|
+
constructor(id: string);
|
|
664
|
+
}
|
|
665
|
+
export declare function createMswWebSocketHandlers<TMessages extends WebSocketMessages = NoMessages>(surface: WebSocketApi<string, TMessages>, modules: readonly object[], options: CreateMswWebSocketHandlersOptions): MswWebSocketHandlers<TMessages>;
|
|
666
|
+
//#endregion
|
|
667
|
+
export { type ClientOf, type CreateMswHandlersOptions, type CreateMswHandlersResult, type CreateMswWebSocketHandlersOptions, type DatabaseOf, type DatabaseSchemas, type FactoryBuilders, type FeatureContext, type FeatureIt, type FeatureMailbox, type FeatureTestOptions, type InProcessBindings, InvalidWebSocketRequest, type MagicLinkAuthClient, type MailToReceive, type MswWebSocketContext, type MswWebSocketHandlers, type RecordedBroadcast, type RecordedClose, type RecordedSend, type RegisterContextOptions, type ServiceClients, TEST_CONTEXT_HEADER, type TestDatabases, type TestFactories, type TestManifest, type TestManifestSource, type TestServices, TestWebSocketPublisher };
|
|
589
668
|
//# sourceMappingURL=testing.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.cts","names":["TestBrowser"],"sources":["../../src/endpoints/MswEndpointAdaptor.ts","../../src/endpoints/TestEndpointAdaptor.ts","../../src/functions/TestFunctionAdaptor.ts","../../src/queue/TestQueueAdaptor.ts","../../src/subscribers/TestSubscriberAdaptor.ts","../../src/testing/manifest.ts","../../src/testing/receive.ts","../../src/testing/featureTest.ts","../../src/testing/peer.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"testing.d.cts","names":["TestBrowser"],"sources":["../../src/endpoints/MswEndpointAdaptor.ts","../../src/endpoints/TestEndpointAdaptor.ts","../../src/functions/TestFunctionAdaptor.ts","../../src/queue/TestQueueAdaptor.ts","../../src/subscribers/TestSubscriberAdaptor.ts","../../src/testing/manifest.ts","../../src/testing/receive.ts","../../src/testing/featureTest.ts","../../src/testing/peer.ts","../../src/websocket/msw.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA0DiB;;EAEhB;;;;;;;;;UAUgB;;EAEhB,WAAW;;EAEX;;EAEA;;;;;UAiBgB;;EAEhB,UAAU;;EAEV,kBAAkB,YAAY,SAAS;;;;;;;;;;;;;;;;;wBAkBxB,kBACf,WAAW,0CACX,SAAS,2BACP;;;KC5ES,iBAAiB;EAC5B,MAAM;EACN;EACA,SAAS;;qBAwCG,oBACZ,uBACA,gBAAgB,YAChB,eAAe,sBACf,mBAAmB,0CACnB,kB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QAAQ;;qBAkDE,qBAAqB;WAEvB;WACA;EAFV,YACU,eACA;;;qBAQE,2BAA2B;WAE7B;WACA;EAFV,YACU,aACA;;;qBAcE,gBAAgB;EAC5B;;;qBAWY,wBAAwB;WAE1B;WACA;EAFV,YACU,kBACA;;;qBAeE,uBAAuB;WAEzB;WACA;EAFV,YACU,iBACA;;;qBAeE,wBAAwB;WAE1B;WACA,WAAW;WACX,QAAQ,cAAc,iBAAiB;EAHjD,YACU,kBACA,WAAW,kBACX,QAAQ,cAAc,iBAAiB;;;qBAarC,uBAAuB;WAEzB;WACA,mBAAmB;WACV;EAHnB,YACU,kBACA,mBAAmB,oBACV;;;qBAcP,6BAA6B;WAE/B;WACA;EAFV,YACU,gBACA;;;qBAYE,uBAAuB;WAEzB;WACA;EAFV,YACU,qBACA;;;;;;;;;;;;;;;;;;;;;;;;;;;qBCx+CE;;UAGI;EAChB;IAAY;MAAU;;;;;wBAIP,qBAAqB;;;;;;;qBCcxB;;;;;qBAMA;;UAGI;;EAEhB,WAAW;;EAEX;;UAGgB;;EAEhB,cAAc;;EAEd,YAAY;;;;;EAKZ;;UAGgB,qBAChB,kBAAkB,oBAAoB;;EAGtC,UAAU;;EAEV,gBAAgB,YAAY,SAAS;EACrC,cAAc;;;;;EAKd,WAAW,mBAAmB;;;;;;EAM9B;;WAES,sBAAsB;;EAE/B,SAAS;;;qBAgBG,oCAAoC;WAC3B;EAArB,YAAqB;;wBAWN,2BACf,kBAAkB,oBAAoB,YAEtC,SAAS,qBAAqB,YAC9B,4BACA,SAAS,oCACP,qBAAqB"}
|
|
@@ -8,15 +8,17 @@ import { t as Subscriber } from "../Subscriber-CW_Dl-YR.mjs";
|
|
|
8
8
|
import { t as KyselyDatabase } from "../kysely-DE4kADWD.mjs";
|
|
9
9
|
import { t as Fake } from "../fake-BqhP8RRQ.mjs";
|
|
10
10
|
import { o as TestStage } from "../stages-DaTaoQei.mjs";
|
|
11
|
+
import { L as Connection, Q as WebSocketPublisher, T as TestWebSocketPublisher, Y as NoMessages, Z as WebSocketMessages, g as RecordedClose, h as RecordedBroadcast, m as InvalidWebSocketRequest, n as WebSocketApi, v as RecordedSend } from "../websocket-api-DSWDhZph.mjs";
|
|
11
12
|
import { p as Verdicts } from "../inbox-CjxpLVkH.mjs";
|
|
12
13
|
import { InboxAddressing } from "@geekmidas/manifest";
|
|
13
14
|
import { EventPublisher, ExtractPublisherMessage } from "@geekmidas/events";
|
|
14
15
|
import { Service, ServiceDiscovery, ServiceRecord } from "@geekmidas/services";
|
|
16
|
+
import { EnvironmentParser } from "@geekmidas/envkit";
|
|
15
17
|
import { ComposedAttachment } from "@geekmidas/emailkit/inbound";
|
|
16
18
|
import { Kysely } from "kysely";
|
|
17
19
|
import { AuditStorage, AuditableAction, Auditor } from "@geekmidas/audit";
|
|
18
20
|
import { TEST_CONTEXT_HEADER } from "@geekmidas/testkit/context";
|
|
19
|
-
import { HttpHandler } from "msw";
|
|
21
|
+
import { HttpHandler, WebSocketHandler } from "msw";
|
|
20
22
|
import { Browser, BrowserOptions } from "@geekmidas/testkit/browser";
|
|
21
23
|
import { FakerFactory } from "@geekmidas/testkit/faker";
|
|
22
24
|
import { Mailbox } from "@geekmidas/testkit/mailbox";
|
|
@@ -404,6 +406,16 @@ interface FeatureContext<TBrowser extends Browser, TDatabases extends DatabaseSc
|
|
|
404
406
|
published: (channel: {
|
|
405
407
|
id: string;
|
|
406
408
|
}) => PublishedMessage[];
|
|
409
|
+
/**
|
|
410
|
+
* What this test sent to a `WebSocketApi`'s sockets — through
|
|
411
|
+
* `services.<surface>` in an endpoint, a subscriber, a consumer — recorded
|
|
412
|
+
* rather than delivered: `sockets(realtime).sent`, `.broadcasts`,
|
|
413
|
+
* `.closed`. Each send is checked by the surface's declared messages, as
|
|
414
|
+
* deployed.
|
|
415
|
+
*
|
|
416
|
+
* @throws {UnknownWebSocketApi} when the manifest declares no such surface.
|
|
417
|
+
*/
|
|
418
|
+
sockets: <S extends WebSocketApi<string, any>>(surface: S) => TestWebSocketPublisher<MessagesOf<S>>;
|
|
407
419
|
/**
|
|
408
420
|
* A subscriber, run on its own — handed events rather than delivered them —
|
|
409
421
|
* with this test's services: its databases resolve to this test's
|
|
@@ -455,6 +467,8 @@ interface EmittedObjectEvent {
|
|
|
455
467
|
}
|
|
456
468
|
type SubscriberAdaptorOf<S> = S extends Subscriber<infer TServices, infer TLogger, infer OutSchema, infer TEventPublisher, infer TSubscribedEvents, infer TDatabase, infer TDatabaseServiceName> ? TestSubscriberAdaptor<TServices, TLogger, OutSchema, TEventPublisher, TSubscribedEvents, TDatabase, TDatabaseServiceName> : never;
|
|
457
469
|
type QueueAdaptorOf<Q> = Q extends Queue<infer TName, infer TMessage, infer TServices, infer TLogger, infer TDatabase, infer TDatabaseServiceName> ? TestQueueAdaptor<TName, TMessage, TServices, TLogger, TDatabase, TDatabaseServiceName> : never;
|
|
470
|
+
/** The messages a WebSocket surface declares — what its recorder is typed by. */
|
|
471
|
+
type MessagesOf<S> = S extends WebSocketApi<string, infer TMessages extends WebSocketMessages> ? TMessages : never;
|
|
458
472
|
/** The schema a database construct was declared with — what `db` is typed by. */
|
|
459
473
|
type DatabaseOf<C> = C extends KyselyDatabase<infer DB, any> ? DB : unknown;
|
|
460
474
|
/** One message as it was published: its type and its payload. */
|
|
@@ -469,6 +483,13 @@ interface FeatureIt<TBrowser extends Browser, TDatabases extends DatabaseSchemas
|
|
|
469
483
|
skip(name: string, fn: FeatureFn<TBrowser, TDatabases, TFactories, TServices>, timeout?: number): void;
|
|
470
484
|
}
|
|
471
485
|
export declare function featureTest<TBrowser extends Browser = Browser, TDatabases extends DatabaseSchemas = {}, TFactories extends FactoryBuilders = {}, TServices extends ServiceClients = {}>(options?: FeatureTestOptions<TBrowser, TFactories>): FeatureIt<TBrowser, TDatabases, TFactories, TServices>;
|
|
486
|
+
/** `objects(bucket)` named a bucket no subscriber in the app is bound to. */
|
|
487
|
+
/** `sockets(surface)` for a surface the test manifest does not declare. */
|
|
488
|
+
export declare class UnknownWebSocketApi extends Error {
|
|
489
|
+
readonly surface: string;
|
|
490
|
+
readonly declared: readonly string[];
|
|
491
|
+
constructor(surface: string, declared: readonly string[]);
|
|
492
|
+
}
|
|
472
493
|
/** What `signInWithMagicLink` uses of a better-auth client. */
|
|
473
494
|
interface MagicLinkAuthClient<TSession> {
|
|
474
495
|
signIn: {
|
|
@@ -585,5 +606,63 @@ interface InProcessBindings {
|
|
|
585
606
|
/** Bindings for `app.fetch(request, bindings)` from inside this process. */
|
|
586
607
|
export declare function inProcessBindings(): InProcessBindings;
|
|
587
608
|
//#endregion
|
|
588
|
-
|
|
609
|
+
//#region src/websocket/msw.d.ts
|
|
610
|
+
/**
|
|
611
|
+
* The query parameter that names a connection's test context. Read and
|
|
612
|
+
* removed before `connect()` sees `query`, so the handler never does.
|
|
613
|
+
*/
|
|
614
|
+
export declare const TEST_CONTEXT_PARAM = "__gkm_test_context";
|
|
615
|
+
/**
|
|
616
|
+
* The close code a refused connection gets: `4000 + status`, so a 401 is
|
|
617
|
+
* 4401. MSW cannot answer an upgrade with a status line, as a server does.
|
|
618
|
+
*/
|
|
619
|
+
export declare const REFUSED_CLOSE_BASE = 4000;
|
|
620
|
+
/** What one test's connections run with. */
|
|
621
|
+
interface MswWebSocketContext {
|
|
622
|
+
/** Instances for the routes' dependencies — the test's transaction. */
|
|
623
|
+
services?: Record<string, unknown>;
|
|
624
|
+
/** Whose connection it is, as `.auth()` would have resolved it. */
|
|
625
|
+
session?: unknown;
|
|
626
|
+
}
|
|
627
|
+
interface CreateMswWebSocketHandlersOptions {
|
|
628
|
+
/** The URL the client opens — what `ws.link()` matches. */
|
|
629
|
+
url: string | RegExp;
|
|
630
|
+
/** What unregistered services are registered with. Default the surface's. */
|
|
631
|
+
envParser?: EnvironmentParser<{}>;
|
|
632
|
+
/**
|
|
633
|
+
* The `memory://` channel sends reach the connections on. Default one of
|
|
634
|
+
* its own, so two adaptors in one process never share sockets.
|
|
635
|
+
*/
|
|
636
|
+
channel?: string;
|
|
637
|
+
}
|
|
638
|
+
interface MswWebSocketHandlers<TMessages extends WebSocketMessages = NoMessages> {
|
|
639
|
+
/** For `setupServer(...)` or `server.use(...)`. */
|
|
640
|
+
handlers: WebSocketHandler[];
|
|
641
|
+
/** Give a test's connections their services and session. */
|
|
642
|
+
registerContext(id: string, context: MswWebSocketContext): void;
|
|
643
|
+
removeContext(id: string): void;
|
|
644
|
+
/**
|
|
645
|
+
* A publisher whose sends reach these connections — hand it to an
|
|
646
|
+
* endpoint as `services.<surface>`.
|
|
647
|
+
*/
|
|
648
|
+
publisher: WebSocketPublisher<TMessages>;
|
|
649
|
+
/**
|
|
650
|
+
* The same channel as a connection string — what
|
|
651
|
+
* `<ID>_PUBLISHER_CONNECTION_STRING` would be for `services.<surface>` to
|
|
652
|
+
* register onto it.
|
|
653
|
+
*/
|
|
654
|
+
connectionString: string;
|
|
655
|
+
/** Every connection open now, in the order they opened. */
|
|
656
|
+
readonly connections: readonly Connection[];
|
|
657
|
+
/** Stop receiving sends on the channel. */
|
|
658
|
+
close(): Promise<void>;
|
|
659
|
+
}
|
|
660
|
+
/** A connection whose query names a context no test registered. */
|
|
661
|
+
export declare class UnknownWebSocketTestContext extends Error {
|
|
662
|
+
readonly id: string;
|
|
663
|
+
constructor(id: string);
|
|
664
|
+
}
|
|
665
|
+
export declare function createMswWebSocketHandlers<TMessages extends WebSocketMessages = NoMessages>(surface: WebSocketApi<string, TMessages>, modules: readonly object[], options: CreateMswWebSocketHandlersOptions): MswWebSocketHandlers<TMessages>;
|
|
666
|
+
//#endregion
|
|
667
|
+
export { type ClientOf, type CreateMswHandlersOptions, type CreateMswHandlersResult, type CreateMswWebSocketHandlersOptions, type DatabaseOf, type DatabaseSchemas, type FactoryBuilders, type FeatureContext, type FeatureIt, type FeatureMailbox, type FeatureTestOptions, type InProcessBindings, InvalidWebSocketRequest, type MagicLinkAuthClient, type MailToReceive, type MswWebSocketContext, type MswWebSocketHandlers, type RecordedBroadcast, type RecordedClose, type RecordedSend, type RegisterContextOptions, type ServiceClients, TEST_CONTEXT_HEADER, type TestDatabases, type TestFactories, type TestManifest, type TestManifestSource, type TestServices, TestWebSocketPublisher };
|
|
589
668
|
//# sourceMappingURL=testing.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.mts","names":["TestBrowser"],"sources":["../../src/endpoints/MswEndpointAdaptor.ts","../../src/endpoints/TestEndpointAdaptor.ts","../../src/functions/TestFunctionAdaptor.ts","../../src/queue/TestQueueAdaptor.ts","../../src/subscribers/TestSubscriberAdaptor.ts","../../src/testing/manifest.ts","../../src/testing/receive.ts","../../src/testing/featureTest.ts","../../src/testing/peer.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"testing.d.mts","names":["TestBrowser"],"sources":["../../src/endpoints/MswEndpointAdaptor.ts","../../src/endpoints/TestEndpointAdaptor.ts","../../src/functions/TestFunctionAdaptor.ts","../../src/queue/TestQueueAdaptor.ts","../../src/subscribers/TestSubscriberAdaptor.ts","../../src/testing/manifest.ts","../../src/testing/receive.ts","../../src/testing/featureTest.ts","../../src/testing/peer.ts","../../src/websocket/msw.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA0DiB;;EAEhB;;;;;;;;;UAUgB;;EAEhB,WAAW;;EAEX;;EAEA;;;;;UAiBgB;;EAEhB,UAAU;;EAEV,kBAAkB,YAAY,SAAS;;;;;;;;;;;;;;;;;wBAkBxB,kBACf,WAAW,0CACX,SAAS,2BACP;;;KC5ES,iBAAiB;EAC5B,MAAM;EACN;EACA,SAAS;;qBAwCG,oBACZ,uBACA,gBAAgB,YAChB,eAAe,sBACf,mBAAmB,0CACnB,kBAAkB,gBAClB,gBAAgB,SAAS,QACzB,oBACA,sBAAsB,sCACtB,kDACA,qBAAqB,mCAAmC,kCAIxD,uBACA;mBAqCkB;UAcT;SAjDF,0BACN,uBACA,gBAAgB,YAChB,e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AE1B;WACA;EAFV,YACU,kBACA;;;qBAeE,uBAAuB;WAEzB;WACA;EAFV,YACU,iBACA;;;qBAeE,wBAAwB;WAE1B;WACA,WAAW;WACX,QAAQ,cAAc,iBAAiB;EAHjD,YACU,kBACA,WAAW,kBACX,QAAQ,cAAc,iBAAiB;;;qBAarC,uBAAuB;WAEzB;WACA,mBAAmB;WACV;EAHnB,YACU,kBACA,mBAAmB,oBACV;;;qBAcP,6BAA6B;WAE/B;WACA;EAFV,YACU,gBACA;;;qBAYE,uBAAuB;WAEzB;WACA;EAFV,YACU,qBACA;;;;;;;;;;;;;;;;;;;;;;;;;;;qBCx+CE;;UAGI;EAChB;IAAY;MAAU;;;;;wBAIP,qBAAqB;;;;;;;qBCcxB;;;;;qBAMA;;UAGI;;EAEhB,WAAW;;EAEX;;UAGgB;;EAEhB,cAAc;;EAEd,YAAY;;;;;EAKZ;;UAGgB,qBAChB,kBAAkB,oBAAoB;;EAGtC,UAAU;;EAEV,gBAAgB,YAAY,SAAS;EACrC,cAAc;;;;;EAKd,WAAW,mBAAmB;;;;;;EAM9B;;WAES,sBAAsB;;EAE/B,SAAS;;;qBAgBG,oCAAoC;WAC3B;EAArB,YAAqB;;wBAWN,2BACf,kBAAkB,oBAAoB,YAEtC,SAAS,qBAAqB,YAC9B,4BACA,SAAS,oCACP,qBAAqB"}
|
|
@@ -2,6 +2,7 @@ import { isConsumable } from "../construct-interface.mjs";
|
|
|
2
2
|
import { BetterAuth } from "../auth.mjs";
|
|
3
3
|
import { a as publishEvents, i as publishConstructEvents, t as FunctionBuilder } from "../functions-BvIDQKAA.mjs";
|
|
4
4
|
import { r as ResponseBuilder, t as Endpoint } from "../Endpoint-sUOU7uLx.mjs";
|
|
5
|
+
import { a as MemoryTransport, f as InvalidWebSocketRequest, m as TestWebSocketPublisher, n as WebSocketApi, s as TransportSink } from "../websocket-api-Dn_3Y2fI.mjs";
|
|
5
6
|
import { t as Queue } from "../Queue-u8w8_HpE.mjs";
|
|
6
7
|
import { Email } from "../email.mjs";
|
|
7
8
|
import { t as Topic } from "../Topic-DN2gYJ-p.mjs";
|
|
@@ -17,7 +18,7 @@ import { EnvironmentParser } from "@geekmidas/envkit";
|
|
|
17
18
|
import { Hono } from "hono";
|
|
18
19
|
import { DefaultAuditor } from "@geekmidas/audit";
|
|
19
20
|
import { TEST_CONTEXT_HEADER, currentTestContext, installContextFetch, runAsServer, runInTestContext, testContextOf } from "@geekmidas/testkit/context";
|
|
20
|
-
import { http } from "msw";
|
|
21
|
+
import { http, ws } from "msw";
|
|
21
22
|
import { Browser } from "@geekmidas/testkit/browser";
|
|
22
23
|
import { faker } from "@geekmidas/testkit/faker";
|
|
23
24
|
import { createMailbox } from "@geekmidas/testkit/mailbox";
|
|
@@ -707,6 +708,7 @@ function featureTest(options = {}) {
|
|
|
707
708
|
auth: /* @__PURE__ */ new Map(),
|
|
708
709
|
addresses: /* @__PURE__ */ new Set(),
|
|
709
710
|
published: /* @__PURE__ */ new Map(),
|
|
711
|
+
sockets: /* @__PURE__ */ new Map(),
|
|
710
712
|
pending: [],
|
|
711
713
|
delivering: false
|
|
712
714
|
};
|
|
@@ -717,6 +719,7 @@ function featureTest(options = {}) {
|
|
|
717
719
|
};
|
|
718
720
|
contexts.set(id, state);
|
|
719
721
|
await state.discovery.register(recorders(app.channels, state));
|
|
722
|
+
await state.discovery.register(socketRecorders(app.surfaces, state));
|
|
720
723
|
await state.discovery.register(watchers(app, state));
|
|
721
724
|
try {
|
|
722
725
|
await runInTestContext(id, async () => {
|
|
@@ -760,6 +763,11 @@ function featureTest(options = {}) {
|
|
|
760
763
|
await deliver(app, state, id);
|
|
761
764
|
} }),
|
|
762
765
|
published: (channel) => [...state.published.get(channel.id) ?? []],
|
|
766
|
+
sockets: (surface) => {
|
|
767
|
+
const recorder = state.sockets.get(surface.id);
|
|
768
|
+
if (!recorder) throw new UnknownWebSocketApi(surface.id, [...state.sockets.keys()]);
|
|
769
|
+
return recorder;
|
|
770
|
+
},
|
|
763
771
|
services: { get: (name) => resolveService(app, state, name) },
|
|
764
772
|
subscriber: (subscriber) => thenDeliver(new TestSubscriberAdaptor(subscriber, state.discovery), () => deliver(app, state, id)),
|
|
765
773
|
queue: (queue) => thenDeliver(new TestQueueAdaptor(queue, state.discovery), () => deliver(app, state, id)),
|
|
@@ -826,6 +834,7 @@ async function load(manifest, modules) {
|
|
|
826
834
|
const channels = unique(constructs.filter((value) => value instanceof Topic || value instanceof Queue));
|
|
827
835
|
const watched = unique(constructs.filter((value) => isBucket(value) && subscribers.some(({ subscriber }) => subscriber.bucketName === value.id)));
|
|
828
836
|
const inboxes = unique(constructs.filter(isInboxConstruct));
|
|
837
|
+
const surfaces = unique(constructs.filter((value) => value instanceof WebSocketApi));
|
|
829
838
|
const inbox = emails.map((email) => manifest.env[provideKey(email.id, "inboxUrl")]).find(Boolean);
|
|
830
839
|
return {
|
|
831
840
|
envParser,
|
|
@@ -836,6 +845,7 @@ async function load(manifest, modules) {
|
|
|
836
845
|
channels,
|
|
837
846
|
watched,
|
|
838
847
|
inboxes,
|
|
848
|
+
surfaces,
|
|
839
849
|
env: manifest.env,
|
|
840
850
|
consumables,
|
|
841
851
|
subscribers,
|
|
@@ -867,6 +877,20 @@ function recorders(channels, state) {
|
|
|
867
877
|
});
|
|
868
878
|
}
|
|
869
879
|
/**
|
|
880
|
+
* A WebSocket surface's publisher that records rather than sends, under the
|
|
881
|
+
* name `.dependsOn([realtime])` injects it by — one per surface per test.
|
|
882
|
+
*/
|
|
883
|
+
function socketRecorders(surfaces, state) {
|
|
884
|
+
return surfaces.map((surface) => {
|
|
885
|
+
const recorder = surface.testPublisher();
|
|
886
|
+
state.sockets.set(surface.id, recorder);
|
|
887
|
+
return {
|
|
888
|
+
serviceName: surface.service.serviceName,
|
|
889
|
+
register: () => recorder
|
|
890
|
+
};
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
870
894
|
* The databases a test is handed: the app's own. A schema tenant an auth server
|
|
871
895
|
* owns is reached through that server, as the app reaches it, and a reader is
|
|
872
896
|
* the same database through a read-only role — neither is another database to
|
|
@@ -1029,6 +1053,17 @@ function isBucket(value) {
|
|
|
1029
1053
|
return typeof declare === "function" && declare.call(value)[0]?.kind === "objects";
|
|
1030
1054
|
}
|
|
1031
1055
|
/** `objects(bucket)` named a bucket no subscriber in the app is bound to. */
|
|
1056
|
+
/** `sockets(surface)` for a surface the test manifest does not declare. */
|
|
1057
|
+
var UnknownWebSocketApi = class extends Error {
|
|
1058
|
+
surface;
|
|
1059
|
+
declared;
|
|
1060
|
+
constructor(surface, declared) {
|
|
1061
|
+
super(`The test manifest declares no WebSocketApi '${surface}'` + (declared.length ? ` — it declares ${declared.map((id) => `'${id}'`).join(", ")}.` : ", and no WebSocketApi at all.") + " Export the surface from the app so `gkm test` records it.");
|
|
1062
|
+
this.surface = surface;
|
|
1063
|
+
this.declared = declared;
|
|
1064
|
+
this.name = "UnknownWebSocketApi";
|
|
1065
|
+
}
|
|
1066
|
+
};
|
|
1032
1067
|
var BucketNotWatched = class extends Error {
|
|
1033
1068
|
bucket;
|
|
1034
1069
|
constructor(bucket) {
|
|
@@ -1305,6 +1340,170 @@ var UnknownService = class extends Error {
|
|
|
1305
1340
|
}
|
|
1306
1341
|
};
|
|
1307
1342
|
//#endregion
|
|
1308
|
-
|
|
1343
|
+
//#region src/websocket/msw.ts
|
|
1344
|
+
/**
|
|
1345
|
+
* The MSW adaptor: a surface's real routes behind MSW's `ws.link()`, so code
|
|
1346
|
+
* that holds a `WebSocket` — a client, its reconnects, its decoding — runs
|
|
1347
|
+
* unchanged against them, in one process, with no server.
|
|
1348
|
+
*
|
|
1349
|
+
* MSW intercepts the client's `WebSocket` and hands each connection here.
|
|
1350
|
+
* The adaptor gives it an id, runs `connect()`, then each frame the client
|
|
1351
|
+
* sends through `message()`, and `disconnect()` when either side closes.
|
|
1352
|
+
* What reaches a socket from elsewhere — an endpoint's `services.<surface>` —
|
|
1353
|
+
* goes over an in-process `memory://` channel, as it does between a route
|
|
1354
|
+
* and the Node adaptor in one dev process, and is written to MSW's `client`.
|
|
1355
|
+
*
|
|
1356
|
+
* ```ts
|
|
1357
|
+
* const realtime = createMswWebSocketHandlers(surface, [routes], {
|
|
1358
|
+
* url: 'wss://realtime.test',
|
|
1359
|
+
* });
|
|
1360
|
+
* server.use(...realtime.handlers);
|
|
1361
|
+
*
|
|
1362
|
+
* realtime.registerContext(id, { session, services: { database: trx } });
|
|
1363
|
+
* const socket = new WebSocket(`wss://realtime.test/?${TEST_CONTEXT_PARAM}=${id}`);
|
|
1364
|
+
* await sendMessage.request({ services: { realtime: realtime.publisher }, … });
|
|
1365
|
+
* ```
|
|
1366
|
+
*
|
|
1367
|
+
* There is no handshake to see: a browser-style `WebSocket` sends no headers
|
|
1368
|
+
* a test can set, so the session comes from the registered context (no
|
|
1369
|
+
* context is no session). The Origin check, the heartbeat and close codes
|
|
1370
|
+
* on a real upgrade stay the Node adaptor's.
|
|
1371
|
+
*/
|
|
1372
|
+
/**
|
|
1373
|
+
* The query parameter that names a connection's test context. Read and
|
|
1374
|
+
* removed before `connect()` sees `query`, so the handler never does.
|
|
1375
|
+
*/
|
|
1376
|
+
const TEST_CONTEXT_PARAM = "__gkm_test_context";
|
|
1377
|
+
/**
|
|
1378
|
+
* The close code a refused connection gets: `4000 + status`, so a 401 is
|
|
1379
|
+
* 4401. MSW cannot answer an upgrade with a status line, as a server does.
|
|
1380
|
+
*/
|
|
1381
|
+
const REFUSED_CLOSE_BASE = 4e3;
|
|
1382
|
+
/** A connection whose query names a context no test registered. */
|
|
1383
|
+
var UnknownWebSocketTestContext = class extends Error {
|
|
1384
|
+
id;
|
|
1385
|
+
constructor(id) {
|
|
1386
|
+
super(`No test registered the WebSocket context '${id}'. Call registerContext('${id}', …) before opening the socket, and keep it until it closes.`);
|
|
1387
|
+
this.id = id;
|
|
1388
|
+
this.name = "UnknownWebSocketTestContext";
|
|
1389
|
+
}
|
|
1390
|
+
};
|
|
1391
|
+
/** The close code a connection with an unknown context is closed with. */
|
|
1392
|
+
const UNKNOWN_CONTEXT_CLOSE = 1011;
|
|
1393
|
+
function createMswWebSocketHandlers(surface, modules, options) {
|
|
1394
|
+
const instance = `msw${randomUUID().slice(0, 8)}`;
|
|
1395
|
+
const channel = options.channel ?? `gkm:ws:${surface.id}:${instance}`;
|
|
1396
|
+
const transport = new MemoryTransport(channel);
|
|
1397
|
+
const contexts = /* @__PURE__ */ new Map();
|
|
1398
|
+
const open = /* @__PURE__ */ new Map();
|
|
1399
|
+
const deliver = (delivery) => {
|
|
1400
|
+
if (delivery.kind === "broadcast") {
|
|
1401
|
+
const except = new Set(delivery.except ?? []);
|
|
1402
|
+
for (const [id, { client }] of open) if (!except.has(id)) client.send(delivery.payload);
|
|
1403
|
+
return;
|
|
1404
|
+
}
|
|
1405
|
+
for (const id of delivery.ids) {
|
|
1406
|
+
const client = open.get(id)?.client;
|
|
1407
|
+
if (!client) continue;
|
|
1408
|
+
if (delivery.kind === "send") client.send(delivery.payload);
|
|
1409
|
+
else client.close(delivery.code, delivery.reason);
|
|
1410
|
+
}
|
|
1411
|
+
};
|
|
1412
|
+
const subscribed = transport.subscribe(instance, deliver);
|
|
1413
|
+
const sink = new TransportSink(transport, {
|
|
1414
|
+
instance,
|
|
1415
|
+
deliver
|
|
1416
|
+
});
|
|
1417
|
+
const core = surface.core({
|
|
1418
|
+
envParser: options.envParser ?? surface.envParser,
|
|
1419
|
+
sink,
|
|
1420
|
+
modules
|
|
1421
|
+
});
|
|
1422
|
+
let issued = 0;
|
|
1423
|
+
async function accept(client) {
|
|
1424
|
+
const query = new URLSearchParams(client.url.searchParams);
|
|
1425
|
+
const contextId = query.get(TEST_CONTEXT_PARAM);
|
|
1426
|
+
query.delete(TEST_CONTEXT_PARAM);
|
|
1427
|
+
const context = contextId ? contexts.get(contextId) : {};
|
|
1428
|
+
issued += 1;
|
|
1429
|
+
const connectionId = `${instance}.${issued}`;
|
|
1430
|
+
let accepted = Promise.resolve(void 0);
|
|
1431
|
+
let queue = Promise.resolve();
|
|
1432
|
+
let closed = false;
|
|
1433
|
+
const call = context?.services ? { services: context.services } : {};
|
|
1434
|
+
client.addEventListener("message", (event) => {
|
|
1435
|
+
queue = queue.then(async () => {
|
|
1436
|
+
const connection = await accepted;
|
|
1437
|
+
if (!connection) return;
|
|
1438
|
+
await core.message(connection, await textOrBytes(event.data), (payload) => client.send(payload), call);
|
|
1439
|
+
});
|
|
1440
|
+
});
|
|
1441
|
+
client.addEventListener("close", (event) => {
|
|
1442
|
+
if (closed) return;
|
|
1443
|
+
closed = true;
|
|
1444
|
+
queue = queue.then(async () => {
|
|
1445
|
+
const connection = await accepted;
|
|
1446
|
+
if (!connection) return;
|
|
1447
|
+
open.delete(connection.id);
|
|
1448
|
+
await core.disconnect(connection, {
|
|
1449
|
+
code: event.code,
|
|
1450
|
+
reason: event.reason
|
|
1451
|
+
}, call);
|
|
1452
|
+
});
|
|
1453
|
+
});
|
|
1454
|
+
if (!context) {
|
|
1455
|
+
const error = new UnknownWebSocketTestContext(contextId);
|
|
1456
|
+
client.close(UNKNOWN_CONTEXT_CLOSE, error.message.slice(0, 123));
|
|
1457
|
+
return;
|
|
1458
|
+
}
|
|
1459
|
+
accepted = (async () => {
|
|
1460
|
+
await subscribed;
|
|
1461
|
+
const outcome = await core.connect({
|
|
1462
|
+
connectionId,
|
|
1463
|
+
headers: new Headers(),
|
|
1464
|
+
query,
|
|
1465
|
+
session: context.session ?? null
|
|
1466
|
+
}, call);
|
|
1467
|
+
if (!outcome.accepted) {
|
|
1468
|
+
client.close(REFUSED_CLOSE_BASE + outcome.status, outcome.statusText);
|
|
1469
|
+
return;
|
|
1470
|
+
}
|
|
1471
|
+
if (closed) return void 0;
|
|
1472
|
+
open.set(connectionId, {
|
|
1473
|
+
connection: outcome.connection,
|
|
1474
|
+
client
|
|
1475
|
+
});
|
|
1476
|
+
return outcome.connection;
|
|
1477
|
+
})();
|
|
1478
|
+
await accepted;
|
|
1479
|
+
}
|
|
1480
|
+
return {
|
|
1481
|
+
handlers: [ws.link(options.url).addEventListener("connection", ({ client }) => {
|
|
1482
|
+
accept(client);
|
|
1483
|
+
})],
|
|
1484
|
+
registerContext: (id, context) => {
|
|
1485
|
+
contexts.set(id, context);
|
|
1486
|
+
},
|
|
1487
|
+
removeContext: (id) => {
|
|
1488
|
+
contexts.delete(id);
|
|
1489
|
+
},
|
|
1490
|
+
publisher: surface.publisher(new TransportSink(new MemoryTransport(channel))),
|
|
1491
|
+
connectionString: `memory://${channel}`,
|
|
1492
|
+
get connections() {
|
|
1493
|
+
return [...open.values()].map(({ connection }) => connection);
|
|
1494
|
+
},
|
|
1495
|
+
close: () => transport.close()
|
|
1496
|
+
};
|
|
1497
|
+
}
|
|
1498
|
+
/** A frame as the core takes it: text, or the bytes it refuses. */
|
|
1499
|
+
async function textOrBytes(data) {
|
|
1500
|
+
if (typeof data === "string") return data;
|
|
1501
|
+
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
1502
|
+
if (ArrayBuffer.isView(data)) return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
1503
|
+
if (data instanceof Blob) return new Uint8Array(await data.arrayBuffer());
|
|
1504
|
+
return String(data);
|
|
1505
|
+
}
|
|
1506
|
+
//#endregion
|
|
1507
|
+
export { DeliveryDidNotSettle, DeliveryFailed, IN_PROCESS_PEER_ADDRESS, InboxNotLocal, InvalidWebSocketRequest, MessageRejected, NoInbox, NoInboxForAddress, NoTestManifest, REFUSED_CLOSE_BASE, ReceiveFieldsOrRaw, ReceiveNeedsRecipient, SignInFailed, TEST_CONTEXT_HEADER, TEST_CONTEXT_PARAM, TEST_MANIFEST_ENV, TestEndpointAdaptor, TestFunctionAdaptor, TestQueueAdaptor, TestSubscriberAdaptor, TestWebSocketPublisher, UnknownDatabase, UnknownFactory, UnknownService, UnknownTestContext, UnknownWebSocketApi, UnknownWebSocketTestContext, createMswHandlers, createMswWebSocketHandlers, featureTest, inProcessBindings, loadTestManifest, signInWithMagicLink };
|
|
1309
1508
|
|
|
1310
1509
|
//# sourceMappingURL=testing.mjs.map
|