42 lines
1.6 KiB
TypeScript
42 lines
1.6 KiB
TypeScript
import { afterEach, describe, expect, it } from "bun:test";
|
|
import * as fs from "node:fs/promises";
|
|
import * as os from "node:os";
|
|
import * as path from "node:path";
|
|
import { $ } from "bun";
|
|
import { inspectPackedTarball, isVersionAlreadyPublished } from "./ci-release-publish.ts";
|
|
|
|
const temporaryDirectories: string[] = [];
|
|
|
|
afterEach(async () => {
|
|
await Promise.all(temporaryDirectories.splice(0).map(dir => fs.rm(dir, { recursive: true, force: true })));
|
|
});
|
|
|
|
describe("release publish", () => {
|
|
it("uses the packed manifest identity for an exact-version registry preflight", async () => {
|
|
const root = await fs.mkdtemp(path.join(os.tmpdir(), "omp-release-publish-test-"));
|
|
temporaryDirectories.push(root);
|
|
const packageDir = path.join(root, "package");
|
|
await fs.mkdir(packageDir);
|
|
await Bun.write(
|
|
path.join(packageDir, "package.json"),
|
|
JSON.stringify({ name: "@oh-my-pi/pi-test", version: "1.2.3" }),
|
|
);
|
|
const tarball = path.join(root, "test.tgz");
|
|
await $`tar -czf ${tarball} -C ${root} package`.quiet();
|
|
|
|
await expect(inspectPackedTarball(tarball)).resolves.toEqual({
|
|
name: "@oh-my-pi/pi-test",
|
|
version: "1.2.3",
|
|
path: tarball,
|
|
});
|
|
});
|
|
|
|
it("recognizes npm's existing-version machine codes without matching registry prose", () => {
|
|
expect(isVersionAlreadyPublished("npm error code E409\nnpm error Cannot publish over existing version")).toBe(
|
|
true,
|
|
);
|
|
expect(isVersionAlreadyPublished("npm error code EPUBLISHCONFLICT")).toBe(true);
|
|
expect(isVersionAlreadyPublished("cannot publish over the previously published version")).toBe(false);
|
|
});
|
|
});
|