mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-27 07:50:47 +00:00
df8c4051ff
* test(core): replace file snapshots with explicit assertions * test(core): replace inline snapshots with explicit assertions * test(core): assert on relevant sections instead of full bodies * test(core): drop assertions implied by full equality * test(core): address review feedback * test(core): use resolves instead of awaiting inside expect
80 lines
2.2 KiB
TypeScript
80 lines
2.2 KiB
TypeScript
import { type RenovateConfig, logger } from '~test/util.ts';
|
|
import { getConfig } from './defaults.ts';
|
|
import { migrateAndValidate } from './migrate-validate.ts';
|
|
import * as configMigration from './migration.ts';
|
|
|
|
let config: RenovateConfig;
|
|
|
|
beforeEach(() => {
|
|
config = getConfig();
|
|
});
|
|
|
|
describe('config/migrate-validate', () => {
|
|
describe('migrateAndValidate()', () => {
|
|
it('handles empty', async () => {
|
|
const res = await migrateAndValidate(config, {});
|
|
expect(res).toEqual({
|
|
errors: [],
|
|
warnings: [],
|
|
});
|
|
});
|
|
|
|
it('handles migration', async () => {
|
|
const input: RenovateConfig = { automerge: 'none' as any };
|
|
const res = await migrateAndValidate(config, input);
|
|
expect(res).toEqual({
|
|
automerge: false,
|
|
errors: [],
|
|
warnings: [],
|
|
});
|
|
});
|
|
|
|
it('handles invalid', async () => {
|
|
// @ts-expect-error -- invalid option
|
|
const input: RenovateConfig = { foo: 'none' };
|
|
const res = await migrateAndValidate(config, input);
|
|
expect(res).toEqual({
|
|
errors: [
|
|
{
|
|
message: 'Invalid configuration option: foo',
|
|
topic: 'Configuration Error',
|
|
},
|
|
],
|
|
foo: 'none',
|
|
warnings: [],
|
|
});
|
|
});
|
|
|
|
it('isOnboarded', async () => {
|
|
const input: RenovateConfig = {};
|
|
const res = await migrateAndValidate(
|
|
{ ...config, repoIsOnboarded: true },
|
|
input,
|
|
);
|
|
expect(res).toEqual({
|
|
errors: [],
|
|
});
|
|
});
|
|
|
|
it('logs errors', async () => {
|
|
vi.spyOn(configMigration, 'migrateConfig').mockImplementation(() => {
|
|
throw new Error('test error');
|
|
});
|
|
await expect(
|
|
// oxlint-disable-next-line renovate/prefer-partial-in-specs -- intentionally invalid config for error path
|
|
migrateAndValidate(config, { invalid: 'config' } as any),
|
|
).rejects.toThrow('test error');
|
|
expect(logger.logger.debug).toHaveBeenCalledTimes(2);
|
|
expect(logger.logger.debug).toHaveBeenNthCalledWith(
|
|
1,
|
|
'migrateAndValidate()',
|
|
);
|
|
expect(logger.logger.debug).toHaveBeenNthCalledWith(
|
|
2,
|
|
{ config: { invalid: 'config' } },
|
|
'migrateAndValidate error',
|
|
);
|
|
});
|
|
});
|
|
});
|