1 +// qs-scaffold.test.mjs
2 +// TDD: tests for qs-scaffold.mjs
3 +// Run: node --test bin/test/qs-scaffold.test.mjs
5 +import assert from "node:assert/strict";
6 +import { spawnSync } from "node:child_process";
16 +import { tmpdir } from "node:os";
17 +import { dirname, join } from "node:path";
18 +import { test } from "node:test";
19 +import { fileURLToPath } from "node:url";
21 +const __dirname = dirname(fileURLToPath(import.meta.url));
22 +const BIN = join(__dirname, "..", "qs-scaffold.mjs");
25 + const dir = mkdtempSync(join(tmpdir(), "qs-scaffold-test-"));
29 +test("qs-scaffold creates a config dir with shell.qml from default example", () => {
30 + const tmp = makeTmp();
32 + const result = spawnSync("node", [BIN, "mybar"], {
34 + env: { ...process.env, XDG_CONFIG_HOME: tmp },
36 + assert.equal(result.status, 0, `stderr: ${result.stderr}`);
37 + const target = join(tmp, "quickshell", "mybar");
38 + assert.ok(existsSync(target), `target dir not created: ${target}`);
39 + assert.ok(existsSync(join(target, "shell.qml")), "shell.qml missing");
40 + // The default example is 02-per-monitor-bar (canonical per-monitor shape).
41 + const content = readFileSync(join(target, "shell.qml"), "utf8");
42 + assert.match(content, /Variants/);
43 + assert.match(content, /Quickshell\.screens/);
45 + rmSync(tmp, { recursive: true, force: true });
49 +test("qs-scaffold with --from 01 uses 01-hello-bar", () => {
50 + const tmp = makeTmp();
52 + const result = spawnSync("node", [BIN, "mybar", "--from", "01-hello-bar"], {
54 + env: { ...process.env, XDG_CONFIG_HOME: tmp },
56 + assert.equal(result.status, 0, `stderr: ${result.stderr}`);
57 + const shell = readFileSync(
58 + join(tmp, "quickshell", "mybar", "shell.qml"),
61 + assert.match(shell, /hello quickshell/i);
63 + rmSync(tmp, { recursive: true, force: true });
67 +test("qs-scaffold with --from 07-composite-bar copies Bar.qml too", () => {
68 + const tmp = makeTmp();
70 + const result = spawnSync(
72 + [BIN, "mybar", "--from", "07-composite-bar"],
75 + env: { ...process.env, XDG_CONFIG_HOME: tmp },
78 + assert.equal(result.status, 0, `stderr: ${result.stderr}`);
79 + const target = join(tmp, "quickshell", "mybar");
80 + const files = readdirSync(target);
81 + assert.ok(files.includes("shell.qml"), "shell.qml missing");
83 + files.includes("Bar.qml"),
84 + "Bar.qml missing (multi-file example not fully copied)",
87 + rmSync(tmp, { recursive: true, force: true });
91 +test("qs-scaffold touches .qmlls.ini for LSP", () => {
92 + const tmp = makeTmp();
94 + const result = spawnSync("node", [BIN, "mybar"], {
96 + env: { ...process.env, XDG_CONFIG_HOME: tmp },
98 + assert.equal(result.status, 0, `stderr: ${result.stderr}`);
100 + existsSync(join(tmp, "quickshell", "mybar", ".qmlls.ini")),
101 + ".qmlls.ini missing",
104 + rmSync(tmp, { recursive: true, force: true });
108 +test("qs-scaffold without args exits non-zero with usage", () => {
109 + const result = spawnSync("node", [BIN], { encoding: "utf8" });
110 + assert.notEqual(result.status, 0);
111 + assert.match(result.stderr, /usage/i);
114 +test("qs-scaffold with bad --from exits non-zero", () => {
115 + const tmp = makeTmp();
117 + const result = spawnSync(
119 + [BIN, "mybar", "--from", "99-does-not-exist"],
122 + env: { ...process.env, XDG_CONFIG_HOME: tmp },
125 + assert.notEqual(result.status, 0);
126 + assert.match(result.stderr, /not found|does not exist/i);
128 + rmSync(tmp, { recursive: true, force: true });
132 +test("qs-scaffold with existing target dir exits non-zero (no clobber)", () => {
133 + const tmp = makeTmp();
135 + const target = join(tmp, "quickshell", "mybar");
136 + mkdirSync(target, { recursive: true });
137 + writeFileSync(join(target, "preexisting.txt"), "do not clobber");
138 + const result = spawnSync("node", [BIN, "mybar"], {
140 + env: { ...process.env, XDG_CONFIG_HOME: tmp },
142 + assert.notEqual(result.status, 0);
143 + // Preexisting file must still exist with original content.
144 + const still = readFileSync(join(target, "preexisting.txt"), "utf8");
145 + assert.equal(still, "do not clobber");
147 + rmSync(tmp, { recursive: true, force: true });