import { mkdtemp, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { WavCodec } from "@suaveplan/audio-codecs"; import { afterEach, beforeEach, describe, expect, it, } from "@suaveplan/testing/runner"; import { FileSinkAdapter, FileSourceAdapter } from "../src/index.js"; describe("integration", () => { let dir: string; beforeEach(async () => { dir = await mkdtemp(join(tmpdir(), "aes-int-")); }); afterEach(async () => { await rm(dir, { recursive: true, force: true }); }); it("load then save round-trips through a real node:fs.mkdtemp tmpdir", { timeout: 30_000, }, async () => { const inPath = join(dir, "in.wav"); const outPath = join(dir, "out.wav"); const wav = await WavCodec.encode([new Float32Array(256)], { sampleRate: 44_100, bitDepth: 16, format: "pcm", }); await writeFile(inPath, wav); const source = new FileSourceAdapter(); const sink = new FileSinkAdapter(); const doc = await source.load(inPath); await sink.save(doc, outPath, "wav"); const back = await source.load(outPath); expect(back.sourceLength).toBe(doc.sourceLength); expect(back.channels).toBe(doc.channels); }); });