52 lines
1.9 KiB
TypeScript
52 lines
1.9 KiB
TypeScript
import { describe, expect, it } from "@suaveplan/testing/runner";
|
|
import {
|
|
AUDIO_CODEC_FFMPEG_WASM_CODES,
|
|
AUDIO_CODEC_FFMPEG_WASM_ERROR_METADATA,
|
|
AudioCodecFfmpegWasmError,
|
|
registerAudioCodecFfmpegWasmErrorCodes,
|
|
} from "./error-codes.js";
|
|
|
|
describe("error-codes", () => {
|
|
it("every code has metadata with description and severity", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
for (const code of Object.values(AUDIO_CODEC_FFMPEG_WASM_CODES)) {
|
|
const meta = AUDIO_CODEC_FFMPEG_WASM_ERROR_METADATA[code];
|
|
expect(typeof meta.description).toBe("string");
|
|
expect(meta.description.length).toBeGreaterThan(0);
|
|
expect(["warning", "error"]).toContain(meta.severity);
|
|
}
|
|
});
|
|
|
|
it("AudioCodecFfmpegWasmError constructs with code, context, cause", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
const cause = new Error("boom");
|
|
const err = new AudioCodecFfmpegWasmError(
|
|
AUDIO_CODEC_FFMPEG_WASM_CODES.DECODE_FAILED,
|
|
"audio-codec-ffmpeg-wasm.test.message",
|
|
{ cause, context: { foo: 1 } }
|
|
);
|
|
expect(err.code).toBe(AUDIO_CODEC_FFMPEG_WASM_CODES.DECODE_FAILED);
|
|
expect(err.cause).toBe(cause);
|
|
expect(err.context).toEqual({ foo: 1 });
|
|
expect(err.name).toBe("AudioCodecFfmpegWasmError");
|
|
expect(err.category).toBe("audio-codec-ffmpeg-wasm");
|
|
});
|
|
|
|
it("registerAudioCodecFfmpegWasmErrorCodes is idempotent", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
expect(() => registerAudioCodecFfmpegWasmErrorCodes()).not.toThrow();
|
|
expect(() => registerAudioCodecFfmpegWasmErrorCodes()).not.toThrow();
|
|
});
|
|
|
|
it("constructor accepts default options", { timeout: 5000 }, () => {
|
|
const err = new AudioCodecFfmpegWasmError(
|
|
AUDIO_CODEC_FFMPEG_WASM_CODES.ABORTED,
|
|
"msg"
|
|
);
|
|
expect(err.context).toBeUndefined();
|
|
});
|
|
});
|