The plugin's default-exported activate function.
Where the plugin lives and how to start it.
Optionaldirectory?: string | URLThe plugin's package directory, as a path or a file: URL (e.g.
new URL("..", import.meta.url) from tests/). Relative .slint
files resolve against it. Default: the current working directory.
Optionalid?: stringThe plugin's id; then manifest.json is not read. Default: the
manifest's id, or "test.plugin" without directory.
Optionalbuiltin?: booleanRun the plugin as one built into the player
(TestHost.builtin): only then do commands.run and
palette.lead work. Default false.
Optionalhost?: TestHostA host to use (to preset data before activation). Default: a new one.
OptionaldataDirectory?: stringUse an existing directory as plugin.dataDirectory (to test a restart).
OptionalsessionStorage?: ReadonlyMap<string, Json>Start with these plugin.storage.session values (to test a restart
within one player session): pass the previous run's
host.sessionStorage. They are copied into the new host's
TestHost.sessionStorage.
Optionallocale?: LocaleThe interface language to play (TestHost.locale): the plugin's
locales/<locale>.po (or .json) in directory is loaded and its
menus, messages and titles show translated. Default: the host's.
host: the TestHost; plugin: the object passed to
activate (call the plugin API on it directly); stop(): dispose the plugin
like the player stopping it (scopes released, stores flushed), wait until the
host is idle and remove the host's temporary files; stop({ reason }):
reason is the StopReason the player sends; disconnect() stops it as
when the player is lost (host-lost, requests refused with disabled).
Removing the temporary files never fails a test.
The test turns on the 10-step option, stops the plugin, starts it again
on the same data directory and checks the option is still on. Both runs
get a directory the test made (dataDirectory): stop() disposes the
plugin like the player, which writes its pending stores there, and only
removes the host's own temporary directory, so the second run reads what
the first one saved.
import assert from "node:assert/strict";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
import { startPlugin } from "@vestra-player/sdk/testing";
import activate from "../main.ts";
test("remembers the step across restarts", async () => {
const directory = new URL("..", import.meta.url);
const data = mkdtempSync(join(tmpdir(), "data-"));
try {
const first = await startPlugin(activate, { directory, dataDirectory: data });
try {
await first.host.command("step-10").run();
} finally {
await first.stop(); // flushes the plugin's stores into `data`
}
// A restart: a new host and a new plugin instance on the same data.
const second = await startPlugin(activate, { directory, dataDirectory: data });
try {
assert.equal(second.host.command("step-10").state.checked, true);
} finally {
await second.stop();
}
} finally {
rmSync(data, { recursive: true, force: true });
}
});
Activate a plugin against a test host, the way the player's runner does: build the
pluginobject, callactivate(plugin), wait for every registration started during activation (commands, panels, resolvers, ...), then wait until the host is idle.The manifest id comes from
directory/manifest.jsonunlessidis given; then no manifest is read (and withoutdirectorynone is read either: the id is"test.plugin"). Nothing in the manifest changes how the plugin runs: the start-up read is the plugin's own call (plugin.player.read()), and an event reaches it from its first listener, as in the player.Rejects when
manifest.jsoncannot be read or parsed, whenactivatethrows, or when a registration made during activation fails (for examplelimit,conflict,invalid). Stricter than the player's runner for commands: there the SDK logs a command declaration the player refuses during activation, skips it and activates the rest of the plugin (onErrorhears it);startPluginfails, so a test shows the bad declaration.