Skip to content

Commit

Permalink
allow usage of beforeAll in FTR configs
Browse files Browse the repository at this point in the history
  • Loading branch information
maximpn committed Oct 31, 2023
1 parent a35f91e commit 9fc6da6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -47,9 +48,24 @@ export async function setupMocha({
reporter,
reporterOptions,
}: Options) {
const mochaRootHooks = config.get('mochaOpts.rootHooks');
const rootHookCtx: GenericFtrProviderContext<any, any> = {
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,
Expand Down

0 comments on commit 9fc6da6

Please sign in to comment.