// qs-doc.test.mjs // Run: node --test bin/test/qs-doc.test.mjs import assert from "node:assert/strict"; import { spawnSync } from "node:child_process"; import { dirname, join } from "node:path"; import { test } from "node:test"; import { fileURLToPath } from "node:url"; const __dirname = dirname(fileURLToPath(import.meta.url)); const BIN = join(__dirname, "..", "qs-doc.mjs"); test("qs-doc with no args prints usage", () => { const result = spawnSync("node", [BIN], { encoding: "utf8" }); assert.notEqual(result.status, 0); assert.match(result.stderr, /usage/i); }); test("qs-doc prints the type's docs URL for the current qs version", () => { const result = spawnSync("node", [BIN, "PanelWindow"], { encoding: "utf8" }); assert.equal(result.status, 0, `stderr: ${result.stderr}`); // Must contain a quickshell.org URL matching the installed version. assert.match( result.stdout, /https?:\/\/quickshell\.org\/docs\/v\d+\.\d+\.\d+\/types\/Quickshell\/PanelWindow/, ); }); test("qs-doc accepts a namespaced type like Quickshell.Services.Pipewire.Pipewire", () => { const result = spawnSync( "node", [BIN, "Quickshell.Services.Pipewire.Pipewire"], { encoding: "utf8" }, ); assert.equal(result.status, 0, `stderr: ${result.stderr}`); assert.match( result.stdout, /https?:\/\/quickshell\.org\/docs\/v\d+\.\d+\.\d+\/types\/Quickshell\/Services\/Pipewire\/Pipewire/, ); }); test("qs-doc with --list prints type index URL", () => { const result = spawnSync("node", [BIN, "--list"], { encoding: "utf8" }); assert.equal(result.status, 0, `stderr: ${result.stderr}`); assert.match( result.stdout, /https?:\/\/quickshell\.org\/docs\/v\d+\.\d+\.\d+\/types/, ); }); test("qs-doc --open uses xdg-open (Linux) or platform equivalent", () => { // Just verify the --open flag is recognized (exit 0, no usage message). // We don't actually open a browser in the test (no display guarantee). const result = spawnSync("node", [BIN, "PanelWindow", "--print"], { encoding: "utf8", }); assert.equal(result.status, 0, `stderr: ${result.stderr}`); assert.match(result.stdout, /PanelWindow/); });