diff --git a/x-pack/test/apm_api_integration/common/registry.ts b/x-pack/test/apm_api_integration/common/registry.ts index 8c918eae5a5a..ba43db2fd583 100644 --- a/x-pack/test/apm_api_integration/common/registry.ts +++ b/x-pack/test/apm_api_integration/common/registry.ts @@ -36,55 +36,69 @@ let configName: APMFtrConfigName | undefined; let running: boolean = false; +function when( + title: string, + conditions: RunCondition | RunCondition[], + callback: (condition: RunCondition) => void, + skip?: boolean +) { + const allConditions = castArray(conditions); + + if (!allConditions.length) { + throw new Error('At least one condition should be defined'); + } + + if (running) { + throw new Error("Can't add tests when running"); + } + + const frame = maybe(callsites()[1]); + + const file = frame?.getFileName(); + + if (!file) { + throw new Error('Could not infer file for suite'); + } + + allConditions.forEach((matchedCondition) => { + callbacks.push({ + ...matchedCondition, + runs: [ + { + cb: () => { + const suite: ReturnType = (skip ? describe.skip : describe)( + title, + () => { + callback(matchedCondition); + } + ) as any; + + suite.file = file; + suite.eachTest((test) => { + test.file = file; + }); + }, + }, + ], + }); + }); +} + +when.skip = ( + title: string, + conditions: RunCondition | RunCondition[], + callback: (condition: RunCondition) => void +) => { + when(title, conditions, callback, true); +}; + export const registry = { init: (config: APMFtrConfigName) => { configName = config; callbacks.length = 0; running = false; }, - when: ( - title: string, - conditions: RunCondition | RunCondition[], - callback: (condition: RunCondition) => void - ) => { - const allConditions = castArray(conditions); - - if (!allConditions.length) { - throw new Error('At least one condition should be defined'); - } - - if (running) { - throw new Error("Can't add tests when running"); - } - - const frame = maybe(callsites()[1]); - - const file = frame?.getFileName(); - - if (!file) { - throw new Error('Could not infer file for suite'); - } - - allConditions.forEach((matchedCondition) => { - callbacks.push({ - ...matchedCondition, - runs: [ - { - cb: () => { - const suite = describe(title, () => { - callback(matchedCondition); - }); - - suite.file = file; - suite.eachTest((test) => { - test.file = file; - }); - }, - }, - ], - }); - }); - }, + when, run: (context: FtrProviderContext) => { if (!configName) { throw new Error(`registry was not init() before running`);