45 lines
1.9 KiB
JavaScript
45 lines
1.9 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { execFileSync } from "node:child_process";
|
|
import { mkdtempSync, readFileSync, 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 = [
|
|
["acheng-campus-food", "1.0.0"],
|
|
["atelier-solopreneur", "1.1.0"],
|
|
["linjing-editorial", "1.0.0"],
|
|
];
|
|
|
|
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 });
|
|
}
|
|
});
|
|
}
|