60 lines
2.9 KiB
TypeScript
60 lines
2.9 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 "./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"));
|
|
const path = await packagePlugin(source, output);
|
|
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);
|
|
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 });
|
|
}
|
|
});
|