mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 15:34:31 +00:00
refactor(test): reuse env snapshot in gateway ws harness
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { WebSocket } from "ws";
|
import { WebSocket } from "ws";
|
||||||
|
import { captureEnv } from "../test-utils/env.js";
|
||||||
import { connectOk, getFreePort, startGatewayServer } from "./test-helpers.js";
|
import { connectOk, getFreePort, startGatewayServer } from "./test-helpers.js";
|
||||||
|
|
||||||
export type GatewayWsClient = {
|
export type GatewayWsClient = {
|
||||||
@@ -14,7 +15,7 @@ export type GatewayServerHarness = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export async function startGatewayServerHarness(): Promise<GatewayServerHarness> {
|
export async function startGatewayServerHarness(): Promise<GatewayServerHarness> {
|
||||||
const previousToken = process.env.OPENCLAW_GATEWAY_TOKEN;
|
const envSnapshot = captureEnv(["OPENCLAW_GATEWAY_TOKEN"]);
|
||||||
delete process.env.OPENCLAW_GATEWAY_TOKEN;
|
delete process.env.OPENCLAW_GATEWAY_TOKEN;
|
||||||
const port = await getFreePort();
|
const port = await getFreePort();
|
||||||
const server = await startGatewayServer(port);
|
const server = await startGatewayServer(port);
|
||||||
@@ -28,11 +29,7 @@ export async function startGatewayServerHarness(): Promise<GatewayServerHarness>
|
|||||||
|
|
||||||
const close = async () => {
|
const close = async () => {
|
||||||
await server.close();
|
await server.close();
|
||||||
if (previousToken === undefined) {
|
envSnapshot.restore();
|
||||||
delete process.env.OPENCLAW_GATEWAY_TOKEN;
|
|
||||||
} else {
|
|
||||||
process.env.OPENCLAW_GATEWAY_TOKEN = previousToken;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return { port, server, openClient, close };
|
return { port, server, openClient, close };
|
||||||
|
|||||||
Reference in New Issue
Block a user