repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

scripts/release/version.test.ts

Raw
File outline
import { spawnSync } from "node:child_process";
import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { expect, it } from "vitest";
import { ROOT } from "../build/build.ts";

it("passes literal task arguments to the version validator without shell evaluation", () => {
	const scratch = mkdtempSync(join(tmpdir(), "pi-ext-version-task-"));
	const marker = join(scratch, "executed");
	const packagePath = join(ROOT, "package.json");
	const lockPath = join(ROOT, "package-lock.json");
	const before = [
		readFileSync(packagePath, "utf8"),
		readFileSync(lockPath, "utf8"),
	];
	try {
		const version = `1.2.3$(touch ${marker})`;
		const result = spawnSync("mise", ["run", "//:release-version", version], {
			cwd: ROOT,
			encoding: "utf8",
		});
		expect(result.status).not.toBe(0);
		expect(`${result.stdout}\n${result.stderr}`).toMatch(/valid semver/u);
		expect(existsSync(marker)).toBe(false);
		expect([
			readFileSync(packagePath, "utf8"),
			readFileSync(lockPath, "utf8"),
		]).toEqual(before);
	} finally {
		rmSync(scratch, { recursive: true, force: true });
	}
});