testing/cross_backend/create_cross_backend_global_setup.ts

Generic vitest globalSetup factory for cross-backend integration suites.

Pairs with make_cross_backend_project: each cross-backend vitest project sets its own test.name, and this factory derives the backend name from that project name (vitest 4 passes the TestProject to globalSetup), picks the matching BackendConfig, spawns + bootstraps it via bootstrap_backend, and provides a serializable handle that *.cross.test.ts files read with inject_backend_handle (provided_context.ts).

A consumer's global_setup.ts collapses to:

import {create_cross_backend_global_setup} from '@fuzdev/fuz_app/testing/cross_backend/create_cross_backend_global_setup.ts'; import {node_backend_config, rust_backend_config} from './my_backend_config.ts'; export default create_cross_backend_global_setup({ configs: {node: node_backend_config, rust: rust_backend_config}, ensure_databases: true, before_spawn: {rust: () => prepare_cargo_binary(my_cargo_binary)}, });

vitest 4's provide hard-rejects non-serializable values, so the live child / teardown / keeper_transport are stripped via serialize_bootstrapped_handle; the teardown closure stays in the globalSetup process and is returned for vitest to fire after the suite.

view source

Declarations
#

3 declarations

create_cross_backend_global_setup
#

testing/cross_backend/create_cross_backend_global_setup.ts view source

({ configs, derive_name, provide_key, ensure_databases, before_spawn }: CrossBackendGlobalSetupOptions, deps?: CrossBackendGlobalSetupDeps): (project: TestProject) => Promise<...> import {create_cross_backend_global_setup} from '@fuzdev/fuz_app/testing/cross_backend/create_cross_backend_global_setup.js';

Build a vitest globalSetup default export. Returns the (project) => teardown function vitest 4 expects.

__0

deps?

the database creator and the spawn, the shipped ones by default

optional default default_cross_backend_global_setup_deps

returns

(project: TestProject) => Promise<() => Promise<void>>

throws

  • Error - when a `before_spawn` key names no config

CrossBackendGlobalSetupDeps
#

testing/cross_backend/create_cross_backend_global_setup.ts view source

CrossBackendGlobalSetupDeps import type {CrossBackendGlobalSetupDeps} from '@fuzdev/fuz_app/testing/cross_backend/create_cross_backend_global_setup.js';

What create_cross_backend_global_setup creates databases and spawns backends with — ensure_database_for_url and bootstrap_backend by default.

ensure_database_for_url

type (database_url: string): unknown

readonly

database_url

type string
returns unknown

bootstrap_backend

type (config: BackendConfig, options?: BootstrapBackendOptions | undefined): Promise<BootstrappedBackendHandle>

readonly

config

options?

optional
returns Promise<BootstrappedBackendHandle>

CrossBackendGlobalSetupOptions
#

testing/cross_backend/create_cross_backend_global_setup.ts view source

CrossBackendGlobalSetupOptions import type {CrossBackendGlobalSetupOptions} from '@fuzdev/fuz_app/testing/cross_backend/create_cross_backend_global_setup.js';

configs

Map of derived backend name → BackendConfig factory. The derived name (see derive_name) selects the factory; unknown names throw with the full supported list so a misnamed project surfaces clearly.

type Readonly<Record<string, () => BackendConfig>>

readonly

derive_name?

Derive the backend name from the vitest project name. Default strips cross_backend_(ts_)?.

type (project_name: string): string

readonly

project_name

type string
returns string

provide_key?

Key passed to project.provide (and read by inject in test files). Default 'backend_handle', which provided_context.ts declares on vitest's ProvidedContext; augment it yourself for another key.

type string

readonly

ensure_databases?

Create the database the selected config's env.DATABASE_URL names, on the server it names, when it is missing and the URL is postgres: (ensure_database_for_url — idempotent createdb; a URL like memory:// is left alone). Off by default, so a test role without CREATEDB is never required unless the setup asks.

type boolean

readonly
default false

before_spawn?

Hooks run before a backend's config is built and spawned, by backend name — the Cargo build of a Rust binary (prepare_cargo_binary), so it runs with its output shown and outside the spawn's startup window, and the config can spawn the built binary. Runs only for the selected backend; a key naming no config throws.

type Readonly<Record<string, () => unknown>>

readonly

Depends on
#