mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-27 07:50:47 +00:00
a67a96eab5
* refactor(lint): Switch to Oxlint * Update .oxlintrc.json * Fix CI --------- Co-authored-by: Jamie Tanna <jamie.tanna@mend.io>
68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
import type {
|
|
MigratableConfig,
|
|
Migration,
|
|
MigrationConstructor,
|
|
} from '../lib/config/migrations/types.ts';
|
|
import type { RenovateConfig } from '../lib/config/types.ts';
|
|
|
|
declare global {
|
|
// oxlint-disable-next-line typescript/no-namespace
|
|
namespace jest {
|
|
interface Matchers<R> {
|
|
toMigrate(
|
|
originalConfig: MigratableConfig | Record<string, unknown>,
|
|
expectedConfig: MigratableConfig | Record<string, unknown>,
|
|
isMigrated?: boolean,
|
|
): Promise<R>;
|
|
}
|
|
}
|
|
}
|
|
|
|
expect.extend({
|
|
async toMigrate(
|
|
CustomMigration: MigrationConstructor,
|
|
originalConfig: RenovateConfig,
|
|
expectedConfig: RenovateConfig,
|
|
isMigrated = true,
|
|
) {
|
|
// async load to avoid circular dependency
|
|
const { MigrationsService } =
|
|
await import('./../lib/config/migrations/migrations-service.ts');
|
|
class CustomMigrationsService extends MigrationsService {
|
|
public static override getMigrations(
|
|
original: RenovateConfig,
|
|
migrated: RenovateConfig,
|
|
): readonly Migration[] {
|
|
return [new CustomMigration(original, migrated)];
|
|
}
|
|
}
|
|
|
|
const migratedConfig = CustomMigrationsService.run(originalConfig);
|
|
|
|
if (
|
|
MigrationsService.isMigrated(migratedConfig, originalConfig) !==
|
|
isMigrated
|
|
) {
|
|
return {
|
|
message: (): string => `isMigrated should be ${isMigrated}`,
|
|
pass: false,
|
|
};
|
|
}
|
|
|
|
if (!this.equals(migratedConfig, expectedConfig)) {
|
|
return {
|
|
message: (): string =>
|
|
`Migration failed\n\nReceived config:\n${JSON.stringify(
|
|
migratedConfig,
|
|
)}\n\nExpected config:\n${JSON.stringify(expectedConfig)}`,
|
|
pass: false,
|
|
};
|
|
}
|
|
|
|
return {
|
|
message: (): string => 'Migration passed successfully',
|
|
pass: true,
|
|
};
|
|
},
|
|
});
|