Files
suaveplan/packages/media/audio/audio-cli/tests/integration.test.ts
2026-05-27 23:47:53 +01:00

74 lines
2.0 KiB
TypeScript

import { mkdtemp, rm, stat } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import {
afterEach,
beforeEach,
describe,
expect,
it,
} from "@suaveplan/testing/runner";
import { AudioCLI } from "../src/cli/cli.js";
import { writeWav } from "./helpers.js";
describe("audio-cli integration", () => {
let dir: string;
let cli: AudioCLI;
beforeEach(async () => {
dir = await mkdtemp(join(tmpdir(), "audio-cli-int-"));
cli = new AudioCLI();
});
afterEach(async () => {
await rm(dir, { recursive: true, force: true });
});
it("process → analyze → convert round-trip via dispatch", {
timeout: 30_000,
}, async () => {
const a = join(dir, "in.wav");
await writeWav(a, 256);
// process
expect(
await cli.dispatch([
"process",
a,
join(dir, "out.wav"),
"--pipeline",
"normalize",
])
).toBe(0);
expect((await stat(join(dir, "out.wav"))).size).toBeGreaterThan(0);
// analyze with --output
const report = join(dir, "report.json");
expect(await cli.dispatch(["analyze", a, "--output", report])).toBe(0);
expect((await stat(report)).size).toBeGreaterThan(0);
// convert
expect(await cli.dispatch(["convert", a, join(dir, "conv.wav")])).toBe(
0
);
});
it("batch dispatch over a comma list returns a JSON report", {
timeout: 30_000,
}, async () => {
const a = join(dir, "a.wav");
const b = join(dir, "b.wav");
await writeWav(a, 32);
await writeWav(b, 32);
expect(
await cli.dispatch([
"batch",
"--input",
`${a},${b}`,
"--output",
dir,
"--pipeline",
"",
])
).toBe(0);
});
});