feat(FN-4621): complete Step 3 — add worktrunk resolver and validator
Fusion-Task-Id: FN-4621 Fusion-Task-Lineage: fc1b0b13-9052-4378-86e3-3634d6c9db4e
This commit is contained in:
56
packages/core/src/__tests__/worktrunk-settings.test.ts
Normal file
56
packages/core/src/__tests__/worktrunk-settings.test.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
resolveWorktrunkSettings,
|
||||
validateWorktrunkSettings,
|
||||
} from "../worktrunk-settings.js";
|
||||
|
||||
describe("worktrunk-settings", () => {
|
||||
it("returns defaults when settings are empty", () => {
|
||||
expect(resolveWorktrunkSettings({}, {})).toEqual({
|
||||
enabled: false,
|
||||
onFailure: "fail",
|
||||
});
|
||||
});
|
||||
|
||||
it("lets project enabled override global enabled", () => {
|
||||
expect(resolveWorktrunkSettings({ enabled: false }, { enabled: true })).toEqual({
|
||||
enabled: true,
|
||||
onFailure: "fail",
|
||||
});
|
||||
});
|
||||
|
||||
it("retains global binaryPath when project only sets enabled", () => {
|
||||
expect(
|
||||
resolveWorktrunkSettings(
|
||||
{ enabled: false, binaryPath: "/x", onFailure: "fail" },
|
||||
{ enabled: true },
|
||||
),
|
||||
).toEqual({
|
||||
enabled: true,
|
||||
binaryPath: "/x",
|
||||
onFailure: "fail",
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to defaults when both scopes are undefined", () => {
|
||||
expect(resolveWorktrunkSettings(undefined, undefined)).toEqual({
|
||||
enabled: false,
|
||||
onFailure: "fail",
|
||||
});
|
||||
});
|
||||
|
||||
it("validator rejects invalid values", () => {
|
||||
expect(() => validateWorktrunkSettings({ onFailure: "ignore" })).toThrow(
|
||||
"worktrunk.onFailure must be one of",
|
||||
);
|
||||
expect(() => validateWorktrunkSettings({ binaryPath: 123 })).toThrow(
|
||||
"worktrunk.binaryPath must be a string when set",
|
||||
);
|
||||
expect(() => validateWorktrunkSettings("oops")).toThrow("worktrunk settings must be an object");
|
||||
});
|
||||
|
||||
it("validator drops unknown keys", () => {
|
||||
expect(validateWorktrunkSettings({ enabled: true, unknown: "x" })).toEqual({ enabled: true });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user