Files
renovate/lib/config/global.spec.ts
Jamie Tanna d16dc9a739 refactor(config/global): improve type restrictions for GlobalConfig.OPTIONS (#44636)
* refactor(config/global): improve type restrictions for `GlobalConfig.OPTIONS`

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>

* fixup! refactor(config/global): improve type restrictions for `GlobalConfig.OPTIONS`

---------

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>
2026-07-21 13:19:41 +00:00

25 lines
1.1 KiB
TypeScript

import { GlobalConfig } from './global.ts';
import type { InternalGlobalConfigOptions, RepoGlobalConfig } from './types.ts';
describe('config/global', () => {
it('OPTIONS contains every key of RepoGlobalConfig', () => {
// If this fails to compile, a field was added to (or removed from) `RepoGlobalConfig` without updating `GlobalConfig.OPTIONS` to match
// Unlike the forward direction (every entry in OPTIONS is a valid key of RepoGlobalConfig), which is enforced by the `satisfies` clause on OPTIONS itself, this direction can't be caught by the compiler any other way: adding an optional field to an interface doesn't require every array of its keys to be updated
//
// In more rare cases, it's been missed from InternalGlobalConfigOptions
expectTypeOf<(typeof GlobalConfig.OPTIONS)[number]>().toEqualTypeOf<
keyof RepoGlobalConfig | keyof InternalGlobalConfigOptions
>();
});
it('all values in OPTIONS are sorted', () => {
const defined = GlobalConfig.OPTIONS;
const sorted = [...defined].sort();
expect(defined, 'OPTIONS should be sorted alphabetically').toStrictEqual(
sorted,
);
});
});