Unit tests go to tests/unit/<area>/, browser smoke tests to tests/smoke/<area>/, and tests against a running desktop app to tests/native/. Files named after dates, work passes, or Kanban cards get feature names, for example editorOctober12 -> editor/footnotes. scripts/ keeps the build, release, and package tools. Plugin repositories import scripts/packagePlugin.mjs, and the Terminal smoke test imports scripts/pluginMocks.mjs, which now re-exports the harness copy. The unit tests get their own type check (tests/tsconfig.json) with Node types. pnpm check runs it after the app check. Add @types/node and fix the three test mocks that it reported.
65 lines
3.3 KiB
TypeScript
65 lines
3.3 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { mkdtemp, mkdir, readFile, writeFile, rm, realpath } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
// @ts-ignore The build tool is a JavaScript module.
|
|
import { packagePlugin } from "../../../scripts/packagePlugin.mjs";
|
|
|
|
test("plugin packaging rejects invalid release inputs before writing an archive", async () => {
|
|
const root = await mkdtemp(join(tmpdir(), "runestone-packaging-"));
|
|
const source = join(root, "plugin"), output = join(root, "releases");
|
|
await mkdir(source);
|
|
const manifest = {
|
|
schemaVersion: 1, apiVersion: 1, id: "org.test.demo", name: "Demo", author: "Test",
|
|
description: "Test plugin", version: "1.0.0", entry: "main.js", access: "full-app",
|
|
};
|
|
const save = async (changes = {}) => writeFile(join(source, "plugin.json"), JSON.stringify({ ...manifest, ...changes }));
|
|
try {
|
|
await assert.rejects(packagePlugin(source, output), /plugin.json at its root/);
|
|
await save();
|
|
await assert.rejects(packagePlugin(source, output), /entry module is missing/);
|
|
await writeFile(join(source, "main.js"), "export function activate() {}");
|
|
for (const [changes, message] of [
|
|
[{ id: "../escape" }, /ID is invalid/],
|
|
[{ version: "1.0" }, /version such as/],
|
|
[{ version: "1.0.0A" }, /version such as/],
|
|
[{ version: "1.0.0a1" }, /version such as/],
|
|
[{ version: "1.0.0-beta" }, /version such as/],
|
|
[{ version: "1.0.0+build" }, /version such as/],
|
|
[{ entry: "../main.js" }, /compiled JavaScript/],
|
|
[{ apiVersion: 99 }, /Unsupported/],
|
|
[{ author: "" }, /valid author/],
|
|
] as const) {
|
|
await save(changes);
|
|
await assert.rejects(packagePlugin(source, output), message);
|
|
}
|
|
await save();
|
|
await assert.rejects(packagePlugin(source, source), /outside the plugin folder/);
|
|
await writeFile(join(source, "invalid file.txt"), "test");
|
|
await assert.rejects(packagePlugin(source, output), /Invalid package path/);
|
|
await rm(join(source, "invalid file.txt"));
|
|
await writeFile(join(root, "package.json"), JSON.stringify({ name: "test-plugin" }));
|
|
const path = await packagePlugin(source);
|
|
assert.equal(path, join(await realpath(output), "org.test.demo-1.0.0.zip"));
|
|
const first = await readFile(path);
|
|
await packagePlugin(source, output);
|
|
assert.deepEqual(await readFile(path), first);
|
|
await writeFile(join(source, "main.js"), "export function activate() { return 1; }");
|
|
await assert.rejects(packagePlugin(source), /different contents/);
|
|
assert.deepEqual(await readFile(path), first);
|
|
await writeFile(join(source, "main.js"), "export function activate() {}");
|
|
for (const version of ["0.2.28a", "0.2.28b", "0.2.28aa"]) {
|
|
await save({ version });
|
|
const hotfix = await packagePlugin(source, output);
|
|
assert.equal(hotfix, join(await realpath(output), `org.test.demo-${version}.zip`));
|
|
assert.ok((await readFile(hotfix)).length > 0);
|
|
assert.deepEqual(await readFile(path), first);
|
|
}
|
|
} finally {
|
|
// mkdtemp returns this test's unique directory under the operating system temp folder.
|
|
assert.equal(root.startsWith(join(tmpdir(), "runestone-packaging-")), true);
|
|
await rm(root, { recursive: true, force: true });
|
|
}
|
|
});
|