TemporaryVault
A temporary Obsidian vault for integration tests.
Creates a temp directory and registers it in the running Obsidian instance so that the Obsidian CLI can target it via cwd.
A handle owns the directory only when it created it. TemporaryVault.dispose deletes an owned directory and leaves a borrowed one in place — see TemporaryVaultConstructorOptions.shouldRemoveDirectoryOnDispose, which overrides that default.
Import:
import { TemporaryVault } from 'obsidian-integration-testing';Signature:
export class TemporaryVaultConstructor
new TemporaryVault(path?: string | undefined, options?: TemporaryVaultConstructorOptions | undefined)Creates a new temp vault.
Properties
| Property | Type | Description |
|---|---|---|
| #registrationTransport | ObsidianTransport | undefined | The transport TemporaryVault.register resolved, which is the one TemporaryVault.dispose unregisters through when it is handed none. |
| #shouldRemoveDirectoryOnDispose | boolean | Whether TemporaryVault.dispose removes TemporaryVault.path from disk. |
| path | string | The absolute path to the temporary vault. |
Methods
| Method | Returns | Description |
|---|---|---|
| [Symbol.asyncDispose]() | Promise<void> | Async disposable support for await using. |
| dispose(transportOverride?) | Promise<void> | Unregisters the vault from Obsidian and, when this handle owns the directory, deletes it. The directory is removed only when this instance created it, or when TemporaryVaultConstructorOptions.shouldRemoveDirectoryOnDispose said so explicitly. That is what makes a handle over a directory somebody else owns — the run's shared setup vault, say, which getTemporaryVault() wraps — safe to dispose from a consumer's afterAll.It never CREATES a transport to unregister through. A vault can only be registered in a transport that exists, so with no explicit one it uses the transport TemporaryVault.register resolved, else the worker's cached one, and skips the unregister when there is neither. Resolving the ambient transport here used to provision a whole new one for a vault whose registration had failed: on Android an Appium start and an emulator boot inside afterAll, which ran out the hook's timeout and left the emulator it was booting for the next suite to collide with. |
| populate(files) | void | Writes files and folders into the vault directory **on the host**. Parent directories are created automatically. - string values are written as UTF-8 text files. - Uint8Array values (including Buffer) are written as binary files. - Paths ending with / are treated as empty folders (value must be undefined).The write is always host-local — TemporaryVault.path is a host path, and on a mobile transport the vault the app opens lives on the device instead. TemporaryVault.register carries the directory across before it registers, so populate-then-register is all a caller needs; TemporaryVault.syncToDevice is the seam that does the carrying. |
| register(transportOverride?) | Promise<void> | Registers this vault in the running Obsidian instance so the CLI can target it. Pushes the vault directory to the target device first, via TemporaryVault.syncToDevice — a no-op on a transport whose app already reads the host filesystem. That ordering used to be the caller's to remember, and a caller who forgot got a silently **empty** vault rather than an error: every pre-registration TemporaryVault.populate write stayed on the host while the app opened the device's copy. Folding it in here makes populate-then-register correct on every transport. The transport is resolved once and handed to both steps, so a push and the registration that follows it can never land on two different transports. |
| syncToDevice(transportOverride?) | Promise<void> | Pushes all files from the local staging directory to the target device via the active transport's pushFiles().On desktop transports this is a no-op (files are already local). On mobile transports (Appium) this pushes files to the device. TemporaryVault.register calls this itself, so a populate-then-register sequence needs nothing extra. Call it directly only to carry across files written **after** registration: the host directory is not mirrored, so a later write into TemporaryVault.path stays on the host until this runs again. |
Links to this page: