|
| 1 | +// Android release wrapper tests keep release args fail-closed before Fastlane work. |
| 2 | +import { execFileSync } from "node:child_process"; |
| 3 | +import path from "node:path"; |
| 4 | +import { describe, expect, it } from "vitest"; |
| 5 | + |
| 6 | +const BASH_BIN = process.platform === "win32" ? "bash" : "/bin/bash"; |
| 7 | + |
| 8 | +function runScript( |
| 9 | +scriptPath: string, |
| 10 | +args: readonly string[], |
| 11 | +): { ok: boolean; stdout: string; stderr: string } { |
| 12 | +const scriptArgs = |
| 13 | +process.platform === "win32" ? [scriptPath] : ["--noprofile", "--norc", scriptPath]; |
| 14 | +try { |
| 15 | +const stdout = execFileSync(BASH_BIN, [...scriptArgs, ...args], { |
| 16 | +cwd: process.cwd(), |
| 17 | +encoding: "utf8", |
| 18 | +stdio: ["ignore", "pipe", "pipe"], |
| 19 | +}); |
| 20 | +return { ok: true, stdout, stderr: "" }; |
| 21 | +} catch (error) { |
| 22 | +const e = error as { stdout?: unknown; stderr?: unknown }; |
| 23 | +const stdout = Buffer.isBuffer(e.stdout) ? e.stdout.toString("utf8") : String(e.stdout ?? ""); |
| 24 | +const stderr = Buffer.isBuffer(e.stderr) ? e.stderr.toString("utf8") : String(e.stderr ?? ""); |
| 25 | +return { ok: false, stdout, stderr }; |
| 26 | +} |
| 27 | +} |
| 28 | + |
| 29 | +describe("Android release shell wrapper arguments", () => { |
| 30 | +it.each(["scripts/android-release-upload.sh", "scripts/android-release.sh"])( |
| 31 | +"prints help without release work for %s", |
| 32 | +(scriptPath) => { |
| 33 | +const result = runScript(path.join(process.cwd(), scriptPath), ["--help"]); |
| 34 | + |
| 35 | +expect(result.ok).toBe(true); |
| 36 | +expect(result.stdout).toContain("Uploads Android Play metadata"); |
| 37 | +expect(result.stderr).toBe(""); |
| 38 | +}, |
| 39 | +); |
| 40 | + |
| 41 | +it.each(["scripts/android-release-upload.sh", "scripts/android-release.sh"])( |
| 42 | +"rejects unknown args before release work for %s", |
| 43 | +(scriptPath) => { |
| 44 | +const result = runScript(path.join(process.cwd(), scriptPath), ["--bogus"]); |
| 45 | + |
| 46 | +expect(result.ok).toBe(false); |
| 47 | +expect(result.stderr).toContain("Unknown argument: --bogus"); |
| 48 | +expect(result.stderr).not.toContain("fastlane"); |
| 49 | +expect(result.stdout).toContain("Uploads Android Play metadata"); |
| 50 | +}, |
| 51 | +); |
| 52 | +}); |