Skip to content

Commit

Permalink
[kbn-test] improve check_ftr_configs script (#189357)
Browse files Browse the repository at this point in the history
## 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)
  • Loading branch information
dmlemeshko authored Jul 29, 2024
1 parent b64084b commit 0c45b11
Showing 1 changed file with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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));
Expand Down

0 comments on commit 0c45b11

Please sign in to comment.