Initial Commit
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
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);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
import { readFileSync, statSync } from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
|
||||
const FILES_ROOT = new URL("../../files/", import.meta.url);
|
||||
|
||||
describe("file-presence", () => {
|
||||
it("club1.wav and club2.wav exist on disk and are non-empty", {
|
||||
timeout: 5000,
|
||||
}, () => {
|
||||
for (const name of ["club1.wav", "club2.wav"]) {
|
||||
const path = fileURLToPath(new URL(name, FILES_ROOT));
|
||||
const stat = statSync(path);
|
||||
expect(stat.isFile()).toBe(true);
|
||||
expect(stat.size).toBeGreaterThan(0);
|
||||
const bytes = readFileSync(path);
|
||||
expect(bytes.byteLength).toBe(stat.size);
|
||||
expect(
|
||||
String.fromCharCode(bytes[0]!, bytes[1]!, bytes[2]!, bytes[3]!)
|
||||
).toBe("RIFF");
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user