mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 22:46:27 +00:00
6e94385f31
* refactor(migrations): implemented migration validator * refactor(migrations): introduce deprecated flag * refactor(migrations): tidy * refactor(migrations): improve validator * refactor: fix launch.json * refactor: fix build * refactor: fix coverage * refactor: fix coverage * refactor: introduce new jest custom matcher * refactor: revert unnecessary changes * refactor: return override
62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
import { expect } from '@jest/globals';
|
|
import type {
|
|
Migration,
|
|
MigrationConstructor,
|
|
} from '../lib/config/migrations/types';
|
|
import type { RenovateConfig } from '../lib/config/types';
|
|
import { MigrationsService } from './../lib/config/migrations/migrations-service';
|
|
|
|
declare global {
|
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
namespace jest {
|
|
interface Matchers<R> {
|
|
toMigrate(
|
|
originalConfig: RenovateConfig,
|
|
expectedConfig: RenovateConfig,
|
|
isMigrated?: boolean
|
|
): R;
|
|
}
|
|
}
|
|
}
|
|
|
|
expect.extend({
|
|
toMigrate(
|
|
CustomMigration: MigrationConstructor,
|
|
originalConfig: RenovateConfig,
|
|
expectedConfig: RenovateConfig,
|
|
isMigrated = true
|
|
) {
|
|
class CustomMigrationsService extends MigrationsService {
|
|
protected static override getMigrations(
|
|
original: RenovateConfig,
|
|
migrated: RenovateConfig
|
|
): ReadonlyArray<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',
|
|
pass: false,
|
|
};
|
|
}
|
|
|
|
return {
|
|
message: (): string => 'Migration passed successfully',
|
|
pass: true,
|
|
};
|
|
},
|
|
});
|