Initial Commit
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Shared integration-setup module — exposes the typed `inject` helper and a
|
||||
* `surrealUnavailable` boolean for `describe.skipIf(...)` skip-when-down
|
||||
* behaviour. Fixture registration happens in the sibling `global-setup.ts`
|
||||
* file because vitest runs `globalSetup` in a separate process from the
|
||||
* worker pool.
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
import { inject as vitestInject } from "@suaveplan/testing/runner";
|
||||
import type { SurrealDBConfig } from "@suaveplan/testing-integration-surrealdb";
|
||||
|
||||
interface IntegrationConfigs {
|
||||
surrealdb: SurrealDBConfig;
|
||||
}
|
||||
|
||||
export function inject<K extends keyof IntegrationConfigs>(
|
||||
key: K
|
||||
): IntegrationConfigs[K] {
|
||||
const all = (vitestInject as (k: string) => IntegrationConfigs)(
|
||||
"__integration_configs__"
|
||||
);
|
||||
return all[key];
|
||||
}
|
||||
|
||||
/**
|
||||
* `true` when the SurrealDB fixture failed to start (no Docker, env-bridge
|
||||
* incomplete) or when the test runs outside the integration config (no
|
||||
* globalSetup at all). Test files use this with `describe.skipIf(...)` so
|
||||
* the suite SKIPS rather than FAILS.
|
||||
*/
|
||||
export const surrealUnavailable: boolean = (() => {
|
||||
try {
|
||||
const failed = (vitestInject as (k: string) => string[] | undefined)(
|
||||
"__integration_failed__"
|
||||
);
|
||||
if (failed === undefined) return true;
|
||||
if (failed.includes("surrealdb")) return true;
|
||||
const configs = (
|
||||
vitestInject as (
|
||||
k: string
|
||||
) => Record<string, Record<string, unknown>> | undefined
|
||||
)("__integration_configs__");
|
||||
return configs === undefined || configs.surrealdb === undefined;
|
||||
} catch {
|
||||
return true;
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user