/** * @file * * Jest global setup and teardown adapter. * * Delegates to the framework-agnostic core and bridges context * to test workers via `globalThis.__obsidianIntegrationTesting`. */ import type { PopulateFilesParams } from '../temporary-vault.cjs'; import type { ObsidianTransportOptions } from '../transport-options.cjs'; import { TemporaryVault } from '../temporary-vault.cjs'; /** * Shape of `globalThis.__obsidianIntegrationTesting`. * * Consumers may pre-populate `transportOptions` before the global setup runs * (e.g., via Jest config `globals`). The setup then adds `temporaryVaultPath`. */ interface ObsidianIntegrationTestingGlobal { /** Temp vault path, set by the global setup for test workers. */ temporaryVaultPath?: string | undefined; /** Transport options. Set by the consumer before setup, or by the setup itself. */ transportOptions?: ObsidianTransportOptions | undefined; } declare global { /** * Namespace for all `obsidian-integration-testing` global state. * Consumers configure transport options here; the setup populates the rest. */ var __obsidianIntegrationTesting: ObsidianIntegrationTestingGlobal | undefined; } /** * Options for {@link createSetup}. */ export interface CreateSetupOptions { /** * Community-plugin ids to enable in the vault in addition to the plugin-under-test, * after it is enabled (see {@link CoreSetupOptions.enableCommunityPlugins}). Seed each * plugin's built files via {@link CreateSetupOptions.populate} (e.g. with `buildDemoVaultPopulate`) * so the enable finds them on disk. */ readonly enableCommunityPlugins?: readonly string[]; /** * Whether to install and enable the built plugin in the temp vault. Defaults * to `true`. Set to `false` for a **non-plugin** consumer that only needs a * registered, empty vault to `evalInObsidian` against — the owned instance is * still launched and its endpoint published to workers, so re-exporting * `createSetup({ installPlugin: false })` reuses the same attach wiring with no * plugin copy/enable. See {@link CoreSetupOptions.installPlugin}. */ readonly installPlugin?: boolean; /** * Returns files/folders to write into the vault before Obsidian opens it (see * {@link CoreSetupOptions.populate}). A thunk so large fixtures are built lazily, * once, in the setup process. * * May return a promise, so the map can be built by something that needs the network — notably * `buildDemoVaultPopulateAsync`, which installs a demo vault's missing community plugins before * reading them. A synchronous thunk (e.g. `buildDemoVaultPopulate`) is unchanged. */ readonly populate?: (this: void) => PopulateFilesParams | Promise; } /** * A Jest `globalSetup` / `globalTeardown` module's `setup` / `teardown` pair. */ export interface JestGlobalSetup { setup: (this: void) => Promise; teardown: (this: void) => Promise; } /** * Creates a Jest global setup/teardown pair, optionally pre-populating the vault * before Obsidian opens it — use this for a dedicated large-vault/performance * setup. The plain {@link setup} / {@link teardown} exports are the no-populate * case (`createSetup()`). Pass `{ installPlugin: false }` for a non-plugin consumer * that only needs a registered, empty vault (see {@link CreateSetupOptions.installPlugin}). * * @param options - Setup options. * @returns The `setup` and `teardown` functions to re-export from a `globalSetup` module. */ export declare function createSetup(options?: CreateSetupOptions): JestGlobalSetup; /** * Returns the temporary vault provided by the global setup. * * Reads the vault path from `globalThis.__obsidianIntegrationTesting.temporaryVaultPath`, * which is set by the Jest global setup. * * @returns The temporary vault. */ export declare function getTemporaryVault(): TemporaryVault; /** * Returns the transport options provided by the global setup. * * @returns The transport options, or `undefined` if not configured. */ export declare function getTransportOptions(): ObsidianTransportOptions | undefined; /** * Jest global setup function (no pre-population). * * Copies the built plugin into a temporary vault, enables it via a renderer eval * over the transport, and populates `globalThis.__obsidianIntegrationTesting` for tests. * * Transport options are read from `globalThis.__obsidianIntegrationTesting.transportOptions`. * Set this in your Jest config via the `globals` option. * * @returns A promise that resolves when setup completes. */ export declare const setup: (this: void) => Promise; /** * Jest global teardown function. * * Removes the temporary vault created during setup. * * @returns A promise that resolves when teardown completes. */ export declare const teardown: (this: void) => Promise; export default setup;