/** * Environment detection utilities for determining runtime context * * Helps distinguish between: * - Node.js (standard tests) * - Cloudflare Workers / workerd (Workers-specific tests) * - Browser (client-side) * - Miniflare (local Workers simulation) */ /** * Runtime environment types */ export type RuntimeEnvironment = 'node' | 'workerd' | 'browser' | 'miniflare' | 'unknown'; /** * Test environment types for vitest configuration */ export type TestEnvironment = 'node' | 'workerd' | 'browser'; /** * Environment capabilities that affect test behavior */ export interface EnvironmentCapabilities { /** Whether WebSocket is natively available */ hasWebSocket: boolean; /** Whether WASM can be dynamically compiled at runtime */ hasRuntimeWasmCompile: boolean; /** Whether fetch is natively available */ hasFetch: boolean; /** Whether crypto.subtle is available */ hasCryptoSubtle: boolean; /** Whether Durable Objects stubs are available */ hasDurableObjects: boolean; /** Whether R2/KV bindings are available */ hasCloudflareBindings: boolean; /** Whether process.env is available */ hasProcessEnv: boolean; /** Whether import.meta.url is defined */ hasImportMetaUrl: boolean; } /** * Detect if running in Cloudflare Workers/workerd environment * * Detection based on: * - navigator.userAgent containing 'Cloudflare-Workers' * - Presence of caches.default (Cloudflare Cache API) * - Absence of process global */ export declare function isWorkerd(): boolean; /** * Detect if running in Node.js environment */ export declare function isNode(): boolean; /** * Detect if running in browser environment */ export declare function isBrowser(): boolean; /** * Detect if running in Miniflare (local Workers simulation) */ export declare function isMiniflare(): boolean; /** * Get the current runtime environment */ export declare function getRuntimeEnvironment(): RuntimeEnvironment; /** * Get capabilities of the current environment */ export declare function getEnvironmentCapabilities(): EnvironmentCapabilities; /** * Skip test if not in specified environment * * @example * ```ts * import { skipIfNot } from '@dotdo/postgres-shared' * * describe('Workers-only tests', () => { * skipIfNot('workerd') * * it('should work in workerd', () => { ... }) * }) * ``` */ export declare function skipIfNot(requiredEnv: TestEnvironment | TestEnvironment[]): { skip: boolean; reason: string; }; /** * Skip test if in specified environment * * @example * ```ts * import { skipIf } from '@dotdo/postgres-shared' * * describe('Non-workerd tests', () => { * skipIf('workerd') * * it('should work outside workerd', () => { ... }) * }) * ``` */ export declare function skipIf(excludedEnv: TestEnvironment | TestEnvironment[]): { skip: boolean; reason: string; }; /** * Vitest-compatible describe.skipIf helper * * @example * ```ts * import { describe, it } from 'vitest' * import { describeIf } from '@dotdo/postgres-shared' * * // Only run in Node environment * describeIf('node')('Node-only tests', () => { * it('works', () => { ... }) * }) * * // Only run in workerd/miniflare * describeIf('workerd')('Workers tests', () => { * it('works', () => { ... }) * }) * ``` */ export declare function describeIf(requiredEnv: TestEnvironment | TestEnvironment[]): (name: string, fn: () => void) => { name: string; fn: () => void; skip: boolean; }; /** * Assertion for environment at runtime * * @throws Error if not in expected environment */ export declare function assertEnvironment(expected: RuntimeEnvironment | RuntimeEnvironment[]): void; /** * Environment info for debugging and logging */ export declare function getEnvironmentInfo(): { runtime: RuntimeEnvironment; capabilities: EnvironmentCapabilities; userAgent?: string | undefined; nodeVersion?: string | undefined; }; //# sourceMappingURL=environment.d.ts.map