[kbn-test] improve check_ftr_configs script (#189357)

## Summary

Follow-up to #188854

On CI script is taking >1 min, while before it was taking seconds. 
Probably because 80+ files were loaded as potential FTR configs. I
adjusted regular expressions to minimize the amount of files that we
need to load to validate if it is FTR config or not.

In this CI run script took 20s (part of `Quick Checks` group)
This commit is contained in:
Dzmitry Lemechko 2024-07-29 15:27:46 +02:00 committed by GitHub
parent b64084b7f4
commit 0c45b1169c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -41,6 +41,8 @@ export async function runCheckFtrConfigsCli() {
.split('\n')
.map((file) => Path.resolve(REPO_ROOT, file));
const loadingConfigs = [];
const possibleConfigs = files.filter((file) => {
if (IGNORED_PATHS.includes(file)) {
return false;
@ -66,24 +68,45 @@ export async function runCheckFtrConfigsCli() {
return false;
}
if (file.match(/mocks.ts$/)) {
// No FTR configs in /packages/
if (file.match(/\/packages\//)) {
return false;
}
if (file.match(/(mock|mocks).ts$/)) {
return false;
}
const fileContent = readFileSync(file).toString();
if (fileContent.match(/(testRunner)|(testFiles)/)) {
if (
// explicitly define 'testRunner' or 'testFiles'
fileContent.match(/(testRunner)|(testFiles)/) ||
// export default createTestConfig
fileContent.match(/export\s+default\s+createTestConfig/) ||
// export default async function ({ readConfigFile }: FtrConfigProviderContext)
// async function config({ readConfigFile }: FtrConfigProviderContext)
// export default async function (ftrConfigProviderContext: FtrConfigProviderContext)
fileContent.match(
/(?:export\s+default\s+)?async\s+function(?:\s+\w+)?\s*\(\s*(?:\{\s*readConfigFile\s*\}|\w+)\s*(?::\s*FtrConfigProviderContext\s*)?\)/
)
) {
// test config
return true;
}
if (fileContent.match(/(describe)|(defineCypressConfig)/)) {
if (file.match(/config.ts$/) && fileContent.match(/export\s+default\s+configs\./)) {
return true;
}
if (fileContent.match(/(describe)|(defineCypressConfig)|(cy\.)/)) {
// test file or Cypress config
return false;
}
// FTR config file should have default export
try {
loadingConfigs.push(file);
// eslint-disable-next-line @typescript-eslint/no-var-requires
const exports = require(file);
const defaultExport = exports.__esModule ? exports.default : exports;
@ -94,6 +117,10 @@ export async function runCheckFtrConfigsCli() {
}
});
if (loadingConfigs.length) {
log.info(`${loadingConfigs.length} files were loaded as FTR configs for validation`);
}
const { allFtrConfigs, manifestPaths } = getAllFtrConfigsAndManifests();
const invalid = possibleConfigs.filter((path) => !allFtrConfigs.includes(path));