Initial Commit
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import { SuaveplanError } from "@suaveplan/error";
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
import { LINTER_CODES, LinterError } from "./error-codes.js";
|
||||
|
||||
describe("error-codes", () => {
|
||||
it("registry exposes the full code set", { timeout: 5000 }, () => {
|
||||
const codes = Object.values(LINTER_CODES).sort();
|
||||
expect(codes).toEqual(
|
||||
[
|
||||
"LINTER.BIOME_FAILED",
|
||||
"LINTER.BIOME_UNAVAILABLE",
|
||||
"LINTER.FILE_NOT_FOUND",
|
||||
"LINTER.INVALID_OPTIONS",
|
||||
"LINTER.MARKDOWN_PARSE_FAILED",
|
||||
"LINTER.NO_TARGETS_FOUND",
|
||||
"LINTER.READ_FAILED",
|
||||
"LINTER.RUNNER_FAILED",
|
||||
"LINTER.UNKNOWN_FLAG",
|
||||
"LINTER.WRITE_FAILED",
|
||||
].sort()
|
||||
);
|
||||
});
|
||||
|
||||
it("LinterError carries code and details payload", {
|
||||
timeout: 5000,
|
||||
}, () => {
|
||||
const error = new LinterError(LINTER_CODES.INVALID_OPTIONS, "bad", {
|
||||
details: { field: "x" },
|
||||
});
|
||||
expect(error.code).toBe("LINTER.INVALID_OPTIONS");
|
||||
expect(error.details).toEqual({ field: "x" });
|
||||
expect(error).toBeInstanceOf(SuaveplanError);
|
||||
expect(error.name).toBe("LinterError");
|
||||
});
|
||||
|
||||
it("LinterError defaults details to empty record when omitted", {
|
||||
timeout: 5000,
|
||||
}, () => {
|
||||
const error = new LinterError(LINTER_CODES.READ_FAILED, "boom");
|
||||
expect(error.details).toEqual({});
|
||||
});
|
||||
|
||||
it("LinterError preserves cause when provided", { timeout: 5000 }, () => {
|
||||
const root = new Error("root");
|
||||
const error = new LinterError(LINTER_CODES.WRITE_FAILED, "boom", {
|
||||
cause: root,
|
||||
});
|
||||
expect(error.cause).toBe(root);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user