Initial Commit
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* connectAdapter — integration-test helper that resolves the live SurrealDB
|
||||
* config from the fixture and returns a connected `SurrealAdapter`.
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
import type { SurrealDBConfig } from "@suaveplan/testing-integration-surrealdb";
|
||||
import { SurrealAdapter } from "../../../src/adapter/adapter/adapter.js";
|
||||
import { inject } from "../integration-setup.js";
|
||||
|
||||
export interface ConnectedAdapter {
|
||||
adapter: SurrealAdapter;
|
||||
config: SurrealDBConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the injected fixture config, instantiate `SurrealAdapter`, call
|
||||
* `connect()`, and return both. Caller is responsible for `await
|
||||
* adapter.disconnect()` in a `try/finally` so a failed assertion never leaks
|
||||
* a WebSocket.
|
||||
*
|
||||
* `namespaceOverride` and `databaseOverride` allow per-test isolation against
|
||||
* a shared container (env-bridge mode) — see `random-ns.ts`.
|
||||
*/
|
||||
export async function connectAdapter(opts?: {
|
||||
namespaceOverride?: string;
|
||||
databaseOverride?: string;
|
||||
}): Promise<ConnectedAdapter> {
|
||||
const config = inject("surrealdb");
|
||||
const adapter = new SurrealAdapter({
|
||||
url: config.url,
|
||||
namespace: opts?.namespaceOverride ?? config.namespace,
|
||||
database: opts?.databaseOverride ?? config.database,
|
||||
username: config.username,
|
||||
password: config.password,
|
||||
});
|
||||
await adapter.connect();
|
||||
return { adapter, config };
|
||||
}
|
||||
Reference in New Issue
Block a user