Skip to content

Commit

Permalink
[ftr] support --kibana-install-dir flag (#44552) (#44935)
Browse files Browse the repository at this point in the history
* [ftr] support --kibana-install-dir flag

* improve spacing/style of success message

* Remove unused var
  • Loading branch information
Spencer authored Sep 6, 2019
1 parent 2491e92 commit 124f91c
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-dev-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export { withProcRunner } from './proc_runner';
export { ToolingLog, ToolingLogTextWriter, pickLevelFromFlags } from './tooling_log';
export { createAbsolutePathSerializer } from './serializers';
export { CA_CERT_PATH, ES_KEY_PATH, ES_CERT_PATH } from './certs';
export { run, createFailError, createFlagError, combineErrors, isFailError } from './run';
export { run, createFailError, createFlagError, combineErrors, isFailError, Flags } from './run';
export { REPO_ROOT } from './constants';
1 change: 1 addition & 0 deletions packages/kbn-dev-utils/src/run/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
*/

export { run } from './run';
export { Flags } from './flags';
export { createFailError, createFlagError, combineErrors, isFailError } from './fail';
25 changes: 19 additions & 6 deletions packages/kbn-test/src/functional_test_runner/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,36 @@
*/

import { resolve } from 'path';
import { run } from '@kbn/dev-utils';
import { run, createFlagError, Flags } from '@kbn/dev-utils';
import { FunctionalTestRunner } from './functional_test_runner';

const makeAbsolutePath = (v: string) => resolve(process.cwd(), v);
const toArray = (v: string | string[]) => ([] as string[]).concat(v || []);
const parseInstallDir = (flags: Flags) => {
const flag = flags['kibana-install-dir'];

if (typeof flag !== 'string' && flag !== undefined) {
throw createFlagError('--kibana-install-dir must be a string or not defined');
}

return flag ? makeAbsolutePath(flag) : undefined;
};

export function runFtrCli() {
run(
async ({ flags, log }) => {
const resolveConfigPath = (v: string) => resolve(process.cwd(), v);
const toArray = (v: string | string[]) => ([] as string[]).concat(v || []);

const functionalTestRunner = new FunctionalTestRunner(
log,
resolveConfigPath(flags.config as string),
makeAbsolutePath(flags.config as string),
{
mochaOpts: {
bail: flags.bail,
grep: flags.grep || undefined,
invert: flags.invert,
},
kbnTestServer: {
installDir: parseInstallDir(flags),
},
suiteTags: {
include: toArray(flags['include-tag'] as string | string[]),
exclude: toArray(flags['exclude-tag'] as string | string[]),
Expand Down Expand Up @@ -84,7 +96,7 @@ export function runFtrCli() {
},
{
flags: {
string: ['config', 'grep', 'exclude', 'include-tag', 'exclude-tag'],
string: ['config', 'grep', 'exclude', 'include-tag', 'exclude-tag', 'kibana-install-dir'],
boolean: ['bail', 'invert', 'test-stats', 'updateBaselines'],
default: {
config: 'test/functional/config.js',
Expand All @@ -100,6 +112,7 @@ export function runFtrCli() {
--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
--updateBaselines replace baseline screenshots with whatever is generated from the test
--kibana-install-dir directory where the Kibana install being tested resides
`,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export const schema = Joi.object()
buildArgs: Joi.array(),
sourceArgs: Joi.array(),
serverArgs: Joi.array(),
installDir: Joi.string(),
})
.default(),

Expand Down
8 changes: 7 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 @@ -20,14 +20,20 @@
import { FunctionalTestRunner, readConfigFile } from '../../functional_test_runner';
import { CliError } from './run_cli';

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

return new FunctionalTestRunner(log, configPath, {
mochaOpts: {
bail: !!bail,
grep,
},
kbnTestServer: {
installDir,
},
updateBaselines,
suiteTags: {
include: [...suiteTags.include, ...config.get('suiteTags.include')],
Expand Down
25 changes: 16 additions & 9 deletions packages/kbn-test/src/functional_tests/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { relative } from 'path';
import * as Rx from 'rxjs';
import { startWith, switchMap, take } from 'rxjs/operators';
import { withProcRunner } from '@kbn/dev-utils';
import dedent from 'dedent';

import {
runElasticsearch,
Expand All @@ -33,14 +34,20 @@ import {

import { readConfigFile } from '../functional_test_runner/lib';

const SUCCESS_MESSAGE = `
const makeSuccessMessage = options => {
const installDirFlag = options.installDir ? ` --kibana-install-dir=${options.installDir}` : '';

Elasticsearch and Kibana are ready for functional testing. Start the functional tests
in another terminal session by running this command from this directory:
return (
'\n\n' +
dedent`
Elasticsearch and Kibana are ready for functional testing. Start the functional tests
in another terminal session by running this command from this directory:
node ${relative(process.cwd(), KIBANA_FTR_SCRIPT)}
`;
node ${relative(process.cwd(), KIBANA_FTR_SCRIPT)}${installDirFlag}
` +
'\n\n'
);
};

/**
* Run servers and tests for each config
Expand Down Expand Up @@ -118,15 +125,15 @@ export async function startServers(options) {

// wait for 5 seconds of silence before logging the
// success message so that it doesn't get buried
await silence(5000, { log });
log.info(SUCCESS_MESSAGE);
await silence(log, 5000);
log.success(makeSuccessMessage(options));

await procs.waitForAllToStop();
await es.cleanup();
});
}

async function silence(milliseconds, { log }) {
async function silence(log, milliseconds) {
await log
.getWritten$()
.pipe(
Expand Down

0 comments on commit 124f91c

Please sign in to comment.