opencode-config/.opencode/draw-image/tests/e2e.test.ts
Sergey 56b67d2d5c
feat(draw-image): SVG template renderer for on-brand covers (#134)
* feat(draw-image): add SVG template render engine

* feat(draw-image): add opencode plugin and tool tests

* test(draw-image): add vitest unit integration e2e suite

* chore(draw-image): wire CI dependabot docs and ADR

* docs(handoff): set PR number

* docs(handoff): fix PR number placeholder in frontmatter

* fix(ci): use tempfile and trailing newline in draw-image tests

---------

Co-authored-by: opencode-agent <agent@opencode.local>
2026-07-29 23:42:50 +03:00

60 lines
No EOL
2.2 KiB
TypeScript

import { describe, test, expect, beforeAll, afterAll } from "vitest"
import { existsSync, readFileSync, rmSync, mkdirSync } from "node:fs"
import path from "node:path"
import { fileURLToPath } from "node:url"
import { spawnSync } from "node:child_process"
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const DRAW_IMAGE_DIR = path.resolve(__dirname, "..")
const TMP = "/tmp/draw-image-e2e"
beforeAll(() => {
if (existsSync(TMP)) rmSync(TMP, { recursive: true, force: true })
mkdirSync(TMP, { recursive: true })
})
function runCli(args: string[]): { status: number; stdout: string; stderr: string } {
return spawnSync("node", ["--experimental-strip-types", path.join(DRAW_IMAGE_DIR, "cli.ts"), ...args], {
encoding: "utf-8",
cwd: DRAW_IMAGE_DIR,
})
}
function assertPng1024(filePath: string) {
expect(existsSync(filePath), `PNG not found: ${filePath}`).toBe(true)
const buf = readFileSync(filePath)
expect(buf.length).toBeGreaterThan(1000)
expect(buf[0]).toBe(0x89)
expect(buf[1]).toBe(0x50)
expect(buf[2]).toBe(0x4e)
expect(buf[3]).toBe(0x47)
}
describe("e2e — full CLI render", () => {
test("render cover with title and icon", () => {
const out = path.join(TMP, "e2e.png")
const r = runCli(["render", "cover", "--title", "E2E", "--slots", "icon=mic", "--out", out])
expect(r.status, `stderr: ${r.stderr}`).toBe(0)
const result = JSON.parse(r.stdout)
expect(result.status).toBe("rendered")
assertPng1024(out)
const metaPath = out.replace(/\.png$/, ".meta.json")
expect(existsSync(metaPath)).toBe(true)
const meta = JSON.parse(readFileSync(metaPath, "utf-8"))
expect(meta.hash).toHaveLength(64)
})
test("render without icon succeeds", () => {
const out = path.join(TMP, "e2e-no-icon.png")
const r = runCli(["render", "cover", "--title", "No Icon", "--out", out])
expect(r.status, `stderr: ${r.stderr}`).toBe(0)
assertPng1024(out)
})
test("render with subtitle", () => {
const out = path.join(TMP, "e2e-sub.png")
const r = runCli(["render", "cover", "--title", "Main", "--subtitle", "Sub", "--out", out])
expect(r.status, `stderr: ${r.stderr}`).toBe(0)
assertPng1024(out)
})
})