@vestra-player/sdk - v1.11.3
    Preparing search index...
    • Activate a plugin against a test host, the way the player's runner does: build the plugin object, call activate(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.json unless id is given; then no manifest is read (and without directory none 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.json cannot be read or parsed, when activate throws, or when a registration made during activation fails (for example limit, 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 (onError hears it); startPlugin fails, so a test shows the bad declaration.

      Parameters

      • activate: (plugin: Plugin) => unknown

        The plugin's default-exported activate function.

      • options: {
            directory?: string | URL;
            id?: string;
            builtin?: boolean;
            host?: TestHost;
            dataDirectory?: string;
            sessionStorage?: ReadonlyMap<string, Json>;
            locale?: Locale;
        } = {}

        Where the plugin lives and how to start it.

        • Optionaldirectory?: string | URL

          The 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?: string

          The plugin's id; then manifest.json is not read. Default: the manifest's id, or "test.plugin" without directory.

        • Optionalbuiltin?: boolean

          Run the plugin as one built into the player (TestHost.builtin): only then do commands.run and palette.lead work. Default false.

          1.7.9

        • Optionalhost?: TestHost

          A host to use (to preset data before activation). Default: a new one.

        • OptionaldataDirectory?: string

          Use 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.

          1.5.25

        • Optionallocale?: Locale

          The 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.

          1.5.9

      Returns Promise<
          {
              host: TestHost;
              plugin: Plugin;
              stop: {
                  (): Promise<void>;
                  (options: { reason?: StopReason }): Promise<void>;
              };
              disconnect(): Promise<void>;
          },
      >

      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 });
      }
      });

      The way into a plugin's tests: one call starts the plugin the way the player's runner does and returns the host to drive, the plugin object to call directly, and stop to end it like the player.

      1.0.0