52 lines
2.2 KiB
JavaScript
52 lines
2.2 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { execFileSync } from "node:child_process";
|
|
import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync } from "node:fs";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import test from "node:test";
|
|
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
const script = path.join(root, "scripts/template-pack.cjs");
|
|
const templatePackages = readdirSync(path.join(root, "packages"))
|
|
.filter(
|
|
(name) =>
|
|
name.startsWith("template-") &&
|
|
existsSync(path.join(root, "packages", name, "template.json")),
|
|
)
|
|
.map((name) => {
|
|
const manifest = JSON.parse(
|
|
readFileSync(path.join(root, "packages", name, "template.json"), "utf8"),
|
|
);
|
|
return [manifest.packageKey, manifest.version];
|
|
});
|
|
|
|
for (const [packageKey, version] of templatePackages) {
|
|
test(`${packageKey} produces a stable package directory and archive`, () => {
|
|
const output = mkdtempSync(path.join("/tmp", "personal-brand-template-pack-"));
|
|
try {
|
|
const args = [script, "--template", packageKey, "--out", output];
|
|
const first = execFileSync(process.execPath, args, { cwd: root, encoding: "utf8" });
|
|
const firstChecksums = readFileSync(
|
|
path.join(output, `${packageKey}-${version}`, "checksums.json"),
|
|
"utf8",
|
|
);
|
|
const firstArchive = readFileSync(path.join(output, `${packageKey}-${version}.tar.gz`));
|
|
const second = execFileSync(process.execPath, args, { cwd: root, encoding: "utf8" });
|
|
const secondChecksums = readFileSync(
|
|
path.join(output, `${packageKey}-${version}`, "checksums.json"),
|
|
"utf8",
|
|
);
|
|
const secondArchive = readFileSync(path.join(output, `${packageKey}-${version}.tar.gz`));
|
|
assert.match(first, /content checksum: [a-f0-9]{64}/);
|
|
assert.match(second, /content checksum: [a-f0-9]{64}/);
|
|
assert.deepEqual(JSON.parse(secondChecksums), JSON.parse(firstChecksums));
|
|
assert.deepEqual(secondArchive, firstArchive);
|
|
assert.ok(
|
|
JSON.parse(firstChecksums).files.every((file) => !file.path.includes("node_modules")),
|
|
);
|
|
} finally {
|
|
rmSync(output, { recursive: true, force: true });
|
|
}
|
|
});
|
|
}
|