stack/packages/stack-shared/src/config-authoring.test.ts
2026-05-06 12:03:06 -07:00

53 lines
1.3 KiB
TypeScript

import { expect, it } from "vitest";
import { typeAssertExtends } from "./utils/types";
import { defineStackConfig, type StackConfig } from "./config-authoring";
const validConfig = defineStackConfig({
payments: {
items: {
todos: {
displayName: "Todo Slots",
customerType: "user",
},
},
},
});
const showOnboardingConfig = defineStackConfig("show-onboarding");
typeAssertExtends<typeof validConfig, StackConfig>()();
typeAssertExtends<typeof showOnboardingConfig, StackConfig>()();
it("returns its input unchanged", () => {
expect(defineStackConfig(validConfig)).toBe(validConfig);
expect(defineStackConfig(showOnboardingConfig)).toBe(showOnboardingConfig);
});
defineStackConfig({
// @ts-expect-error Top-level dot notation should not be accepted in typed config files.
"payments.items": {
todos: {
displayName: "Todo Slots",
customerType: "user",
},
},
});
defineStackConfig({
payments: {
// @ts-expect-error Unknown keys should not be accepted in typed config files.
missingField: true,
},
});
defineStackConfig({
payments: {
items: {
todos: {
displayName: "Todo Slots",
// @ts-expect-error Invalid enum values should fail type-checking.
customerType: "workspace",
},
},
},
});