75 lines
2.5 KiB
TypeScript
75 lines
2.5 KiB
TypeScript
import { readFile, stat } from "node:fs/promises";
|
|
import { fileURLToPath } from "node:url";
|
|
import { decodeWav } from "@suaveplan/audio-decode-wav";
|
|
import {
|
|
createIrRegistry,
|
|
createUriPluginCollector,
|
|
} from "@suaveplan/audio-ir-core";
|
|
import { createIrLoader } from "@suaveplan/audio-ir-loader";
|
|
import { createStorageUriResolver } from "@suaveplan/storage-uri";
|
|
import { describe, expect, it } from "@suaveplan/testing/runner";
|
|
import { register } from "../../src/register/register.js";
|
|
|
|
/**
|
|
* Minimal `file://` `FetchLike` for Node — undici's global `fetch` refuses
|
|
* `file:` URLs. Sufficient for the GET requests the bundle plugin issues.
|
|
*/
|
|
const nodeFileFetch: typeof globalThis.fetch = async (
|
|
input,
|
|
init
|
|
): Promise<Response> => {
|
|
const url =
|
|
input instanceof URL
|
|
? input
|
|
: input instanceof Request
|
|
? new URL(input.url)
|
|
: new URL(input);
|
|
if (url.protocol !== "file:") {
|
|
return globalThis.fetch(input, init);
|
|
}
|
|
const path = fileURLToPath(url);
|
|
const st = await stat(path);
|
|
if (!st.isFile()) return new Response(null, { status: 404 });
|
|
const buf = await readFile(path);
|
|
return new Response(buf, {
|
|
status: 200,
|
|
headers: {
|
|
"content-length": String(st.size),
|
|
"last-modified": st.mtime.toUTCString(),
|
|
},
|
|
});
|
|
};
|
|
|
|
describe("end-to-end", () => {
|
|
it("collector wiring loads both club IRs", {
|
|
timeout: 30000,
|
|
}, async () => {
|
|
const registry = createIrRegistry();
|
|
const collector = createUriPluginCollector();
|
|
register(registry, collector, { fetch: nodeFileFetch });
|
|
|
|
const resolver = createStorageUriResolver(collector.plugins);
|
|
|
|
const loader = createIrLoader({
|
|
registry,
|
|
resolver,
|
|
decoders: { wav: decodeWav },
|
|
});
|
|
|
|
for (const id of ["club-club1", "club-club2"] as const) {
|
|
const ir = await loader.load(id);
|
|
expect(Object.isFrozen(ir)).toBe(true);
|
|
expect(ir.id).toBe(id);
|
|
expect(ir.family).toBe("room");
|
|
expect(ir.channels).toBe(2);
|
|
expect(ir.sampleRate).toBe(44100);
|
|
expect(ir.channelData.length).toBe(2);
|
|
expect(ir.channelData[0]!.length).toBeGreaterThan(0);
|
|
expect(ir.channelData[1]!.length).toBe(ir.channelData[0]!.length);
|
|
expect(ir.lengthFrames).toBe(ir.channelData[0]!.length);
|
|
expect(ir.durationSec).toBeGreaterThan(0);
|
|
expect(ir.gainDb).toBe(0);
|
|
}
|
|
});
|
|
});
|