release.test.ts

2.7 KB · raw

1import { execFileSync } from "node:child_process";2import { existsSync, mkdtempSync, readFileSync } from "node:fs";3import { fileURLToPath } from "node:url";4import { dirname, join, resolve } from "node:path";5import { tmpdir } from "node:os";6import { describe, expect, it } from "vitest";78const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");9const RELEASE_SCRIPTS = ["scripts/release.ts", "scripts/release-firefox.ts"];1011function readReleaseScript(path: string): string {12  return readFileSync(join(ROOT, path), "utf8");13}1415function signCommand(script: string): string {16  const start = script.indexOf('"npx web-ext sign"');17  const end = script.indexOf('].join(" ")', start);18  return script.slice(start, end);19}2021describe("Firefox release source submission", () => {22  it("passes the generated source archive to web-ext sign in both entry points", () => {23    for (const path of RELEASE_SCRIPTS) {24      const command = signCommand(readReleaseScript(path));25      expect(command).toContain('"--upload-source-code",');26      expect(command).toContain("sourceZip");27      expect(command.match(/--upload-source-code/g)).toHaveLength(1);28    }29  });3031  it("builds an archive containing the reviewed crypto source and Noise build script", () => {32    const archive = join(mkdtempSync(join(tmpdir(), "peach-source-test-")), "source.zip");33    execFileSync(34      "zip",35      [36        "-q",37        "-r",38        archive,39        "src",40        "scripts",41        "public",42        "crypto-core",43        "manifest.json",44        "manifest.firefox.json",45        "package.json",46        "bun.lock",47        "tsconfig.json",48        "vite.config.ts",49        "--exclude",50        "node_modules/*",51        "--exclude",52        "dist-*/*",53        "--exclude",54        "crypto-core/target/*",55        "--exclude",56        "crypto-core/generated/*",57        "--exclude",58        "*.zip",59        "--exclude",60        ".DS_Store",61        "--exclude",62        "__MACOSX/*",63      ],64      { cwd: ROOT },65    );6667    const contents = execFileSync("unzip", ["-Z1", archive], { encoding: "utf8" }).split("\n");68    expect(contents).toEqual(69      expect.arrayContaining([70        "crypto-core/Cargo.toml",71        "crypto-core/Cargo.lock",72        "crypto-core/src/lib.rs",73        "scripts/build-noise-core.mjs",74      ]),75    );7677    for (const path of RELEASE_SCRIPTS) {78      const script = readReleaseScript(path);79      expect(script).toContain('"crypto-core",');80      expect(existsSync(join(ROOT, "crypto-core/Cargo.toml"))).toBe(true);81      expect(existsSync(join(ROOT, "crypto-core/Cargo.lock"))).toBe(true);82      expect(existsSync(join(ROOT, "crypto-core/src/lib.rs"))).toBe(true);83      expect(existsSync(join(ROOT, "scripts/build-noise-core.mjs"))).toBe(true);84    }85  });86});