Skip to content

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 TemporaryVault

Constructor

new TemporaryVault(path?: string | undefined, options?: TemporaryVaultConstructorOptions | undefined)

Creates a new temp vault.

Properties

PropertyTypeDescription
#shouldRemoveDirectoryOnDisposebooleanWhether TemporaryVault.dispose removes TemporaryVault.path from disk.
pathstringThe absolute path to the temporary vault.

Methods

MethodReturnsDescription
[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.
populate(files)voidWrites 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: