Skip to content

Commit

Permalink
Add support for --include-file and --exclude-file to FTR
Browse files Browse the repository at this point in the history
  • Loading branch information
brianseeders committed Mar 13, 2020
1 parent 5d428b0 commit 26dc6a3
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 4 deletions.
17 changes: 16 additions & 1 deletion packages/kbn-test/src/functional_test_runner/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export function runFtrCli() {
kbnTestServer: {
installDir: parseInstallDir(flags),
},
suiteFiles: {
include: toArray(flags['include-file'] as string | string[]),
exclude: toArray(flags['exclude-file'] as string | string[]),
},
suiteTags: {
include: toArray(flags['include-tag'] as string | string[]),
exclude: toArray(flags['exclude-tag'] as string | string[]),
Expand Down Expand Up @@ -104,7 +108,16 @@ export function runFtrCli() {
},
{
flags: {
string: ['config', 'grep', 'exclude', 'include-tag', 'exclude-tag', 'kibana-install-dir'],
string: [
'config',
'grep',
'exclude',
'include-file',
'exclude-file',
'include-tag',
'exclude-tag',
'kibana-install-dir',
],
boolean: ['bail', 'invert', 'test-stats', 'updateBaselines', 'throttle', 'headless'],
default: {
config: 'test/functional/config.js',
Expand All @@ -116,6 +129,8 @@ export function runFtrCli() {
--grep <pattern> pattern used to select which tests to run
--invert invert grep to exclude tests
--exclude=file path to a test file that should not be loaded
--include-file=file a test file to be included, pass multiple times for multiple files
--exclude-file=file a test file to be excluded, pass multiple times for multiple files
--include-tag=tag a tag to be included, pass multiple times for multiple tags
--exclude-tag=tag a tag to be excluded, pass multiple times for multiple tags
--test-stats print the number of tests (included and excluded) to STDERR
Expand Down
11 changes: 11 additions & 0 deletions packages/kbn-test/src/functional_test_runner/lib/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ export const schema = Joi.object()
.items(Joi.string())
.default([]),

suiteFiles: Joi.object()
.keys({
include: Joi.array()
.items(Joi.string())
.default([]),
exclude: Joi.array()
.items(Joi.string())
.default([]),
})
.default(),

suiteTags: Joi.object()
.keys({
include: Joi.array()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/

import { sep } from 'path';
import { REPO_ROOT } from '@kbn/dev-utils';
import { createAssignmentProxy } from './assignment_proxy';
import { wrapFunction } from './wrap_function';
import { wrapRunnableArgs } from './wrap_runnable_args';

export function decorateMochaUi(lifecycle, context) {
export function decorateMochaUi(lifecycle, context, config) {
// incremented at the start of each suite, decremented after
// so that in each non-suite call we can know if we are within
// a suite, or that when a suite is defined it is within a suite
Expand Down Expand Up @@ -65,6 +66,12 @@ export function decorateMochaUi(lifecycle, context) {
this._tags = [].concat(this._tags || [], tags);
};

const filePath = this.file.replace(REPO_ROOT + sep, '');
this.tags(filePath);
this.suiteTag = filePath; // The tag that uniquely targets this suite/file

this.ftrConfig = config;

provider.call(this);

after(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
*/

import Mocha from 'mocha';
import { realpathSync } from 'fs';
import { sep } from 'path';
import { REPO_ROOT } from '@kbn/dev-utils';

import { loadTestFiles } from './load_test_files';
import { filterSuitesByTags } from './filter_suites_by_tags';
Expand Down Expand Up @@ -49,11 +52,23 @@ export async function setupMocha(lifecycle, log, config, providers) {
log,
lifecycle,
providers,
config,
paths: config.get('testFiles'),
excludePaths: config.get('excludeTestFiles'),
updateBaselines: config.get('updateBaselines'),
});

filterSuitesByTags({
log,
mocha,
include: config
.get('suiteFiles.include')
.map(f => realpathSync(f).replace(REPO_ROOT + sep, '')),
exclude: config
.get('suiteFiles.exclude')
.map(f => realpathSync(f).replace(REPO_ROOT + sep, '')),
});

filterSuitesByTags({
log,
mocha,
Expand Down
15 changes: 15 additions & 0 deletions packages/kbn-test/src/functional_tests/cli/run_tests/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ const options = {
updateBaselines: {
desc: 'Replace baseline screenshots with whatever is generated from the test.',
},
'include-file': {
arg: '<file>',
desc: 'Files that must included to be run, can be included multiple times.',
},
'exclude-file': {
arg: '<file>',
desc: 'Files that must NOT be included to be run, can be included multiple times.',
},
'include-tag': {
arg: '<tag>',
desc: 'Tags that suites must include to be run, can be included multiple times.',
Expand Down Expand Up @@ -115,6 +123,13 @@ export function processOptions(userOptions, defaultConfigPaths) {
delete userOptions['kibana-install-dir'];
}

userOptions.suiteFiles = {
include: [].concat(userOptions['include-file'] || []),
exclude: [].concat(userOptions['exclude-file'] || []),
};
delete userOptions['include-file'];
delete userOptions['exclude-file'];

userOptions.suiteTags = {
include: [].concat(userOptions['include-tag'] || []),
exclude: [].concat(userOptions['exclude-tag'] || []),
Expand Down
6 changes: 5 additions & 1 deletion packages/kbn-test/src/functional_tests/lib/run_ftr.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { CliError } from './run_cli';

async function createFtr({
configPath,
options: { installDir, log, bail, grep, updateBaselines, suiteTags },
options: { installDir, log, bail, grep, updateBaselines, suiteFiles, suiteTags },
}) {
const config = await readConfigFile(log, configPath);

Expand All @@ -37,6 +37,10 @@ async function createFtr({
installDir,
},
updateBaselines,
suiteFiles: {
include: [...suiteFiles.include, ...config.get('suiteFiles.include')],
exclude: [...suiteFiles.exclude, ...config.get('suiteFiles.exclude')],
},
suiteTags: {
include: [...suiteTags.include, ...config.get('suiteTags.include')],
exclude: [...suiteTags.exclude, ...config.get('suiteTags.exclude')],
Expand Down

0 comments on commit 26dc6a3

Please sign in to comment.