From 9fc6da683deb89d821483a38b034b868ac0e30f1 Mon Sep 17 00:00:00 2001 From: Maxim Palenov Date: Mon, 30 Oct 2023 14:12:19 +0100 Subject: [PATCH] allow usage of beforeAll in FTR configs --- .../functional_test_runner/lib/config/schema.ts | 3 +++ .../lib/mocha/setup_mocha.ts | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/packages/kbn-test/src/functional_test_runner/lib/config/schema.ts b/packages/kbn-test/src/functional_test_runner/lib/config/schema.ts index 2f4cb317d5615..7bdf4530c2ab8 100644 --- a/packages/kbn-test/src/functional_test_runner/lib/config/schema.ts +++ b/packages/kbn-test/src/functional_test_runner/lib/config/schema.ts @@ -146,6 +146,9 @@ export const schema = Joi.object() slow: Joi.number().default(30000), timeout: Joi.number().default(INSPECTING ? 360000 * 100 : 360000), ui: Joi.string().default('bdd'), + rootHooks: Joi.object().keys({ + beforeAll: Joi.func(), + }), }) .default(), diff --git a/packages/kbn-test/src/functional_test_runner/lib/mocha/setup_mocha.ts b/packages/kbn-test/src/functional_test_runner/lib/mocha/setup_mocha.ts index 9bc399ea1215d..95e6c320ac843 100644 --- a/packages/kbn-test/src/functional_test_runner/lib/mocha/setup_mocha.ts +++ b/packages/kbn-test/src/functional_test_runner/lib/mocha/setup_mocha.ts @@ -20,6 +20,7 @@ import { Lifecycle } from '../lifecycle'; import { Config } from '../config'; import { ProviderCollection } from '../providers'; import { EsVersion } from '../es_version'; +import { GenericFtrProviderContext } from '../../public_types'; import { MochaReporterProvider } from './reporter'; import { validateCiGroupTags } from './validate_ci_group_tags'; @@ -47,9 +48,24 @@ export async function setupMocha({ reporter, reporterOptions, }: Options) { + const mochaRootHooks = config.get('mochaOpts.rootHooks'); + const rootHookCtx: GenericFtrProviderContext = { + loadTestFile: () => { + throw new Error('loadTestFile is unsupported in root hooks'); + }, + getService: providers.getService as any, + hasService: providers.hasService as any, + getPageObject: providers.getPageObject as any, + getPageObjects: providers.getPageObjects as any, + updateBaselines: config.get('updateBaselines'), + }; + // configure mocha const mocha = new Mocha({ ...config.get('mochaOpts'), + rootHooks: { + beforeAll: () => mochaRootHooks?.beforeAll?.(rootHookCtx), + }, reporter: reporter || (await providers.loadExternalService('mocha reporter', MochaReporterProvider)), reporterOptions,