mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[ftr/startServers] resolve relative config arguments at CLI (#141450)
This commit is contained in:
parent
da8eb44f92
commit
a5afcd7ae9
2 changed files with 26 additions and 3 deletions
|
@ -6,13 +6,19 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import Path from 'path';
|
||||
|
||||
import { getFlags, FlagsReader } from '@kbn/dev-cli-runner';
|
||||
import { createAnyInstanceSerializer, createAbsolutePathSerializer } from '@kbn/jest-serializers';
|
||||
import { REPO_ROOT } from '@kbn/utils';
|
||||
|
||||
import { EsVersion } from '../../functional_test_runner';
|
||||
import { parseFlags, FLAG_OPTIONS } from './flags';
|
||||
|
||||
jest.mock('uuid', () => ({ v4: () => 'some-uuid' }));
|
||||
|
||||
const cwdMock = (process.cwd = jest.fn().mockReturnValue(REPO_ROOT));
|
||||
|
||||
expect.addSnapshotSerializer(
|
||||
createAnyInstanceSerializer(EsVersion, (v: EsVersion) => `EsVersion ${v.toString()}`)
|
||||
);
|
||||
|
@ -23,10 +29,27 @@ const defaults = getFlags(['--config=foo'], FLAG_OPTIONS);
|
|||
const test = (opts: Record<string, string | string[] | boolean | undefined>) =>
|
||||
parseFlags(new FlagsReader({ ...defaults, ...opts }));
|
||||
|
||||
beforeEach(() => {
|
||||
cwdMock.mockReturnValue(REPO_ROOT);
|
||||
});
|
||||
|
||||
it('parses a subset of the flags from runTests', () => {
|
||||
expect(test({ config: 'foo' })).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"config": "foo",
|
||||
"config": <absolute path>/foo,
|
||||
"esFrom": undefined,
|
||||
"esVersion": <EsVersion 9.9.9>,
|
||||
"installDir": undefined,
|
||||
"logsDir": undefined,
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('respects the cwd of the script', () => {
|
||||
cwdMock.mockReturnValue(Path.resolve(REPO_ROOT, 'x-pack'));
|
||||
expect(test({ config: 'foo' })).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"config": <absolute path>/x-pack/foo,
|
||||
"esFrom": undefined,
|
||||
"esVersion": <EsVersion 9.9.9>,
|
||||
"installDir": undefined,
|
||||
|
|
|
@ -31,8 +31,8 @@ export const FLAG_OPTIONS: FlagOptions = {
|
|||
|
||||
export function parseFlags(flags: FlagsReader) {
|
||||
const configs = [
|
||||
...(flags.arrayOfStrings('config') ?? []),
|
||||
...(flags.arrayOfStrings('journey') ?? []),
|
||||
...(flags.arrayOfPaths('config') ?? []),
|
||||
...(flags.arrayOfPaths('journey') ?? []),
|
||||
];
|
||||
if (configs.length !== 1) {
|
||||
throw createFlagError(`expected exactly one --config or --journey flag`);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue