52 lines
2.9 KiB
TypeScript
52 lines
2.9 KiB
TypeScript
// The prompt module's shape (novox/hq ADR 0204, ADR 0205): the vendored release is pinned, carries
|
|
// its licence in the archive, and is loaded with its configuration from the normal slot.
|
|
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
|
|
const at = (p: string) => new URL(`../${p}`, import.meta.url);
|
|
const m = JSON.parse(readFileSync(at("module.json"), "utf8"));
|
|
const artifact = (name: string) => m.build.artifacts.find((a: { name: string }) => a.name === name);
|
|
|
|
test("the theme archive is built from the vendored release and carries its licence", () => {
|
|
assert.deepEqual(artifact("theme"), { name: "theme", kind: "archive", from: "theme" });
|
|
assert.match(readFileSync(at("theme/LICENSE"), "utf8"), /Permission is hereby granted, free of charge/);
|
|
assert.ok(existsSync(at("theme/powerlevel10k.zsh-theme")));
|
|
assert.ok(existsSync(at("theme/gitstatus/LICENSE")));
|
|
});
|
|
|
|
test("the configuration archive holds the prompt's configuration and nothing else", () => {
|
|
assert.deepEqual(artifact("configuration"), { name: "configuration", kind: "archive", from: "config" });
|
|
assert.ok(statSync(at("config/p10k.zsh")).size > 0);
|
|
});
|
|
|
|
test("both are unpacked under the account's home, owned by the account", () => {
|
|
const byId = Object.fromEntries(m.resources.map((r: { id: string }) => [r.id, r]));
|
|
assert.deepEqual(byId.theme, { id: "theme", type: "archive", path: "${machine:account-home}/.local/share/powerlevel10k", owner: "${machine:account}", artifact: "theme" });
|
|
assert.deepEqual(byId.configuration, { id: "configuration", type: "archive", path: "${machine:account-home}/.config/powerlevel10k", owner: "${machine:account}", artifact: "configuration" });
|
|
});
|
|
|
|
// The zsh code is an item of the collection shell:zsh:normal, its text a template in files/ (ADR 0348, 0349).
|
|
const shellCode = (): string => {
|
|
const items = m.items.filter((i: { collection: string }) => i.collection.startsWith("shell:"));
|
|
assert.equal(items.length, 1);
|
|
assert.equal(items[0].collection, "shell:zsh:normal", "for zsh, in the normal slot");
|
|
return readFileSync(at(items[0].template), "utf8");
|
|
};
|
|
|
|
test("the zsh code in the normal slot sources the theme, then the configuration, and turns on no instant prompt", () => {
|
|
assert.equal(m.shell, undefined);
|
|
const code = shellCode();
|
|
const sourced = [...code.matchAll(/\|\| source (\S+)/g)].map((x) => x[1]);
|
|
assert.deepEqual(sourced, ["~/.local/share/powerlevel10k/powerlevel10k.zsh-theme", "~/.config/powerlevel10k/p10k.zsh"]);
|
|
assert.doesNotMatch(code, /instant/);
|
|
});
|
|
|
|
test("the README names the upstream, the version and the licence", () => {
|
|
const readme = readFileSync(at("README.md"), "utf8");
|
|
assert.match(readme, /github\.com\/romkatv\/powerlevel10k/);
|
|
assert.match(readme, /v1\.20\.0/);
|
|
assert.match(readme, /MIT/);
|
|
assert.match(shellCode(), /v1\.20\.0/, "the version in the shell code's comment matches");
|
|
});
|