Skip to content

Commit 839b8a9

Browse files
committed
test: test both websockets & sse in drivers
1 parent fc53189 commit 839b8a9

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

packages/misc/driver-test-suite/src/mod.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { createNodeWebSocket, type NodeWebSocket } from "@hono/node-ws";
1717
import invariant from "invariant";
1818
import { bundleRequire } from "bundle-require";
1919
import { getPort } from "actor-core/test";
20+
import { Transport } from "actor-core/client";
2021

2122
export interface DriverTestConfig {
2223
/** Deploys an app and returns the connection endpoint. */
@@ -32,6 +33,10 @@ export interface DriverTestConfig {
3233
HACK_skipCleanupNet?: boolean;
3334
}
3435

36+
export interface DriverTestConfigWithTransport extends DriverTestConfig {
37+
transport: Transport;
38+
}
39+
3540
export interface DriverDeployOutput {
3641
endpoint: string;
3742

@@ -41,10 +46,18 @@ export interface DriverDeployOutput {
4146

4247
/** Runs all Vitest tests against the provided drivers. */
4348
export function runDriverTests(driverTestConfig: DriverTestConfig) {
44-
describe("driver tests", () => {
45-
runActorDriverTests(driverTestConfig);
46-
runManagerDriverTests(driverTestConfig);
47-
});
49+
for (const transport of ["websocket", "sse"] as Transport[]) {
50+
describe(`driver tests (${transport})`, () => {
51+
runActorDriverTests({
52+
...driverTestConfig,
53+
transport,
54+
});
55+
runManagerDriverTests({
56+
...driverTestConfig,
57+
transport,
58+
});
59+
});
60+
}
4861
}
4962

5063
/**

packages/misc/driver-test-suite/src/tests/actor-driver.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, test, expect, vi } from "vitest";
2-
import type { DriverTestConfig } from "@/mod";
2+
import type { DriverTestConfig, DriverTestConfigWithTransport } from "@/mod";
33
import { setupDriverTest } from "@/utils";
44
import { resolve } from "node:path";
55
import type { App as CounterApp } from "../../fixtures/apps/counter";
@@ -20,7 +20,7 @@ export async function waitFor(
2020
return Promise.resolve();
2121
}
2222
}
23-
export function runActorDriverTests(driverTestConfig: DriverTestConfig) {
23+
export function runActorDriverTests(driverTestConfig: DriverTestConfigWithTransport) {
2424
describe("Actor Driver Tests", () => {
2525
describe("State Persistence", () => {
2626
test("persists state between actor instances", async (c) => {
@@ -110,4 +110,4 @@ export function runActorDriverTests(driverTestConfig: DriverTestConfig) {
110110
});
111111
});
112112
});
113-
}
113+
}

packages/misc/driver-test-suite/src/tests/manager-driver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { describe, test, expect, vi } from "vitest";
2-
import { waitFor, type DriverTestConfig } from "@/mod";
2+
import { DriverTestConfigWithTransport, waitFor, type DriverTestConfig } from "@/mod";
33
import { setupDriverTest } from "@/utils";
44
import { resolve } from "node:path";
55
import type { App as CounterApp } from "../../fixtures/apps/counter";
66
import { ConnectionError } from "actor-core/client";
77

8-
export function runManagerDriverTests(driverTestConfig: DriverTestConfig) {
8+
export function runManagerDriverTests(driverTestConfig: DriverTestConfigWithTransport) {
99
describe("Manager Driver Tests", () => {
1010
describe("Client Connection Methods", () => {
1111
test("connect() - finds or creates an actor", async (c) => {

packages/misc/driver-test-suite/src/utils.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import type { ActorCoreApp } from "actor-core";
22
import { type TestContext, vi } from "vitest";
3-
import { createClient, type Client } from "actor-core/client";
4-
import type { DriverTestConfig } from "./mod";
3+
import { createClient, Transport, type Client } from "actor-core/client";
4+
import type { DriverTestConfig, DriverTestConfigWithTransport } from "./mod";
55

66
// Must use `TestContext` since global hooks do not work when running concurrently
77
export async function setupDriverTest<A extends ActorCoreApp<any>>(
88
c: TestContext,
9-
driverTestConfig: DriverTestConfig,
9+
driverTestConfig: DriverTestConfigWithTransport,
1010
appPath: string,
1111
): Promise<{
1212
client: Client<A>;
@@ -20,7 +20,9 @@ export async function setupDriverTest<A extends ActorCoreApp<any>>(
2020
c.onTestFinished(cleanup);
2121

2222
// Create client
23-
const client = createClient<A>(endpoint);
23+
const client = createClient<A>(endpoint, {
24+
transport: driverTestConfig.transport,
25+
});
2426
if (!driverTestConfig.HACK_skipCleanupNet) {
2527
c.onTestFinished(async () => await client.dispose());
2628
}

0 commit comments

Comments
 (0)