-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
Copy pathcli.ts
163 lines (149 loc) · 5.28 KB
/
cli.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { resolve } from 'path';
import { inspect } from 'util';
import { run, createFlagError, Flags } from '@kbn/dev-utils';
import exitHook from 'exit-hook';
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 functionalTestRunner = new FunctionalTestRunner(
log,
makeAbsolutePath(flags.config as string),
{
mochaOpts: {
bail: flags.bail,
grep: flags.grep || undefined,
invert: flags.invert,
},
kbnTestServer: {
installDir: parseInstallDir(flags),
},
suiteFiles: {
include: toArray(flags.include as string | string[]).map(makeAbsolutePath),
exclude: toArray(flags.exclude as string | string[]).map(makeAbsolutePath),
},
suiteTags: {
include: toArray(flags['include-tag'] as string | string[]),
exclude: toArray(flags['exclude-tag'] as string | string[]),
},
updateBaselines: flags.updateBaselines || flags.u,
updateSnapshots: flags.updateSnapshots || flags.u,
}
);
if (flags.throttle) {
process.env.TEST_THROTTLE_NETWORK = '1';
}
if (flags.headless) {
process.env.TEST_BROWSER_HEADLESS = '1';
}
let teardownRun = false;
const teardown = async (err?: Error) => {
if (teardownRun) return;
teardownRun = true;
if (err) {
log.indent(-log.indent());
log.error(err);
process.exitCode = 1;
}
try {
await functionalTestRunner.close();
} finally {
process.exit();
}
};
process.on('unhandledRejection', (err) =>
teardown(
err instanceof Error ? err : new Error(`non-Error type rejection value: ${inspect(err)}`)
)
);
exitHook(teardown);
try {
if (flags['test-stats']) {
process.stderr.write(
JSON.stringify(await functionalTestRunner.getTestStats(), null, 2) + '\n'
);
} else {
const failureCount = await functionalTestRunner.run();
process.exitCode = failureCount ? 1 : 0;
}
} catch (err) {
await teardown(err);
} finally {
await teardown();
}
},
{
log: {
defaultLevel: 'debug',
},
flags: {
string: [
'config',
'grep',
'include',
'exclude',
'include-tag',
'exclude-tag',
'kibana-install-dir',
],
boolean: [
'bail',
'invert',
'test-stats',
'updateBaselines',
'updateSnapshots',
'u',
'throttle',
'headless',
],
default: {
config: 'test/functional/config.js',
},
help: `
--config=path path to a config file
--bail stop tests after the first failure
--grep <pattern> pattern used to select which tests to run
--invert invert grep to exclude tests
--include=file a test file to be included, pass multiple times for multiple files
--exclude=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
--updateBaselines replace baseline screenshots with whatever is generated from the test
--updateSnapshots replace inline and file snapshots with whatever is generated from the test
-u replace both baseline screenshots and snapshots
--kibana-install-dir directory where the Kibana install being tested resides
--throttle enable network throttling in Chrome browser
--headless run browser in headless mode
`,
},
}
);
}