Files
renovate/lib/config/migrations/custom/host-rules-migration.spec.ts
Sebastian Poxhofer 4add67e86e test: add linter for as any in test files (#44658)
* ci(linter): add prefer-partial-in-specs oxlint rule

Flags object literals cast to `any` (`{...} as any`) in spec/test files and steers toward `partial<T>()` from `test/util`. Enabled at error in the spec-files override so CI blocks new occurrences.

Closes #44646

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* test: drop unnecessary object-literal `as any` casts

The casts masked values already assignable to the expected type (migration configs accepted as Record<string, unknown>, all-optional param types, etc.); removing them restores real type checking.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* test: replace object-literal `as any` casts with partial<T>()

Uses partial<T>() from test/util so incomplete mock/config objects keep proper typing. Azure API mocks switch to mockResolvedValue(partial<T>()) and their inner method mocks to mockResolvedValue(), matching the sibling-file idiom.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* test: suppress prefer-partial-in-specs for intentionally-invalid inputs

Some tests deliberately pass malformed or legacy data to exercise validation/error paths, where no real type fits; keep the cast with a reasoned oxlint-disable-next-line.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 10:47:30 +00:00

92 lines
2.8 KiB
TypeScript

import { CONFIG_VALIDATION } from '../../../constants/error-messages.ts';
import { HostRulesMigration } from './host-rules-migration.ts';
describe('config/migrations/custom/host-rules-migration', () => {
it('should migrate array', async () => {
await expect(HostRulesMigration).toMigrate(
{
hostRules: [
{
hostType: 'dotnet',
baseUrl: 'https://some.domain.com',
token: '123test',
},
{
hostType: 'dotnet',
baseUrl: 'https://some.domain.com',
matchHost: 'https://some.domain.com',
token: '123test',
},
{
hostType: 'adoptium-java',
domainName: 'domain.com',
token: '123test',
},
{ domainName: 'domain.com/', token: '123test' },
{ hostType: 'docker', matchHost: 'domain.com/', token: '123test' },
{ hostName: 'some.domain.com', token: '123test' },
{ endpoint: 'domain.com/', token: '123test' },
{ host: 'some.domain.com', token: '123test' },
{ matchHost: 'some.domain.com:8080', token: '123test' },
],
},
{
hostRules: [
{
hostType: 'dotnet-version',
matchHost: 'https://some.domain.com',
token: '123test',
},
{
hostType: 'dotnet-version',
matchHost: 'https://some.domain.com',
token: '123test',
},
{
hostType: 'java-version',
matchHost: 'domain.com',
token: '123test',
},
{
matchHost: 'https://domain.com/',
token: '123test',
},
{
hostType: 'docker',
matchHost: 'https://domain.com/',
token: '123test',
},
{ matchHost: 'some.domain.com', token: '123test' },
{ matchHost: 'https://domain.com/', token: '123test' },
{ matchHost: 'some.domain.com', token: '123test' },
{ matchHost: 'https://some.domain.com:8080', token: '123test' },
],
},
);
});
it('throws when multiple hosts are present', () => {
expect(() =>
new HostRulesMigration(
// oxlint-disable-next-line renovate/prefer-partial-in-specs -- legacy baseUrl hostRule field is intentionally invalid for this migration test
{
hostRules: [
{
matchHost: 'https://some-diff.domain.com',
baseUrl: 'https://some.domain.com',
token: '123test',
},
],
} as any,
{},
).run([
{
matchHost: 'https://some-diff.domain.com',
baseUrl: 'https://some.domain.com',
token: '123test',
},
]),
).toThrow(CONFIG_VALIDATION);
});
});