-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
schema.ts
347 lines (306 loc) · 11.3 KB
/
schema.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import { dirname, resolve } from 'path';
import Joi from 'joi';
import type { CustomHelpers } from 'joi';
// valid pattern for ID
// enforced camel-case identifiers for consistency
const ID_PATTERN = /^[a-zA-Z0-9_]+$/;
// it will search both --inspect and --inspect-brk
const INSPECTING = !!process.execArgv.find((arg) => arg.includes('--inspect'));
const maybeRequireKeys = (keys: string[], schemas: Record<string, Joi.Schema>) => {
if (!keys.length) {
return schemas;
}
const withRequires: Record<string, Joi.Schema> = {};
for (const [key, schema] of Object.entries(schemas)) {
withRequires[key] = keys.includes(key) ? schema.required() : schema;
}
return withRequires;
};
const urlPartsSchema = ({ requiredKeys }: { requiredKeys?: string[] } = {}) =>
Joi.object()
.keys(
maybeRequireKeys(requiredKeys ?? [], {
protocol: Joi.string().valid('http', 'https').default('http'),
hostname: Joi.string().hostname().default('localhost'),
port: Joi.number(),
auth: Joi.string().regex(/^[^:]+:.+$/, 'username and password separated by a colon'),
username: Joi.string(),
password: Joi.string(),
pathname: Joi.string().regex(/^\//, 'start with a /'),
hash: Joi.string().regex(/^\//, 'start with a /'),
certificateAuthorities: Joi.array().items(Joi.binary()).optional(),
})
)
.default();
const appUrlPartsSchema = () =>
Joi.object()
.keys({
pathname: Joi.string().regex(/^\//, 'start with a /'),
hash: Joi.string().regex(/^\//, 'start with a /'),
})
.default();
const requiredWhenEnabled = (schema: Joi.Schema) => {
return Joi.when('enabled', {
is: true,
then: schema.required(),
otherwise: schema.optional(),
});
};
const dockerServerSchema = () =>
Joi.object()
.keys({
enabled: Joi.boolean().required(),
image: requiredWhenEnabled(Joi.string()),
port: requiredWhenEnabled(Joi.number()),
portInContainer: requiredWhenEnabled(Joi.number()),
waitForLogLine: Joi.alternatives(Joi.object().instance(RegExp), Joi.string()).optional(),
waitForLogLineTimeoutMs: Joi.number().integer().optional(),
waitFor: Joi.func().optional(),
args: Joi.array().items(Joi.string()).optional(),
})
.default();
const defaultRelativeToConfigPath = (path: string) => {
const makeDefault = (parent: any, helpers: CustomHelpers) => {
helpers.schema.description(`<config.js directory>/${path}`);
return resolve(dirname(helpers.prefs.context!.path), path);
};
return makeDefault;
};
export const schema = Joi.object()
.keys({
rootTags: Joi.array().items(Joi.string()),
testFiles: Joi.array().items(Joi.string()),
testRunner: Joi.func(),
serverless: Joi.boolean().default(false),
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().items(Joi.string()).default([]),
exclude: Joi.array().items(Joi.string()).default([]),
})
.default(),
servicesRequiredForTestAnalysis: Joi.array().items(Joi.string()).default([]),
services: Joi.object().pattern(ID_PATTERN, Joi.func().required()).default(),
pageObjects: Joi.object().pattern(ID_PATTERN, Joi.func().required()).default(),
timeouts: Joi.object()
.keys({
find: Joi.number().default(10000),
try: Joi.number().default(120000),
waitFor: Joi.number().default(20000),
esRequestTimeout: Joi.number().default(30000),
kibanaReportCompletion: Joi.number().default(60_000),
kibanaStabilize: Joi.number().default(15000),
navigateStatusPageCheck: Joi.number().default(250),
// Many of our tests use the `exists` functions to determine where the user is. For
// example, you'll see a lot of code like:
// if (!testSubjects.exists('someElementOnPageA')) {
// navigateToPageA();
// }
// If the element doesn't exist, selenium would wait up to defaultFindTimeout for it to
// appear. Because there are many times when we expect it to not be there, we don't want
// to wait the full amount of time, or it would greatly slow our tests down. We used to have
// this value at 1 second, but this caused flakiness because sometimes the element was deemed missing
// only because the page hadn't finished loading.
// The best path forward it to prefer functions like `testSubjects.existOrFail` or
// `testSubjects.missingOrFail` instead of just the `exists` checks, and be deterministic about
// where your user is and what they should click next.
waitForExists: Joi.number().default(2500),
})
.default(),
mochaOpts: Joi.object()
.keys({
bail: Joi.boolean().default(false),
dryRun: Joi.boolean().default(false),
grep: Joi.string(),
invert: Joi.boolean().default(false),
slow: Joi.number().default(30000),
timeout: Joi.number().default(INSPECTING ? 360000 * 100 : 360000),
ui: Joi.string().default('bdd'),
})
.default(),
updateBaselines: Joi.boolean().default(false),
updateSnapshots: Joi.boolean().default(false),
browser: Joi.object()
.keys({
type: Joi.string().valid('chrome', 'firefox', 'msedge').default('chrome'),
logPollingMs: Joi.number().default(100),
acceptInsecureCerts: Joi.boolean().default(false),
})
.default(),
junit: Joi.object()
.keys({
enabled: Joi.boolean().default(!!process.env.CI && !process.env.DISABLE_JUNIT_REPORTER),
reportName: Joi.string(),
metadata: Joi.object().unknown(true).default(),
})
.default(),
mochaReporter: Joi.object()
.keys({
captureLogOutput: Joi.boolean().default(
!!process.env.CI && !process.env.DISABLE_CI_LOG_OUTPUT_CAPTURE
),
sendToCiStats: Joi.boolean().default(!!process.env.CI),
})
.default(),
scoutReporter: Joi.object()
.keys({
enabled: Joi.boolean().default(process.env.ENABLE_SCOUT_REPORTER || false),
})
.default(),
users: Joi.object().pattern(
ID_PATTERN,
Joi.object()
.keys({
username: Joi.string().required(),
password: Joi.string().required(),
})
.required()
),
servers: Joi.object()
.keys({
kibana: urlPartsSchema(),
elasticsearch: urlPartsSchema({
requiredKeys: ['port'],
}),
fleetserver: urlPartsSchema(),
})
.default(),
esTestCluster: Joi.object()
.keys({
license: Joi.valid('basic', 'trial', 'gold').default('basic'),
from: Joi.string().default('snapshot'),
serverArgs: Joi.array().items(Joi.string()).default([]),
esJavaOpts: Joi.string(),
dataArchive: Joi.string(),
ssl: Joi.boolean().default(false),
ccs: Joi.object().keys({
remoteClusterUrl: Joi.string().uri({
scheme: /https?/,
}),
}),
files: Joi.array().items(Joi.string()),
})
.default(),
esServerlessOptions: Joi.object()
.keys({
host: Joi.string().ip(),
resources: Joi.array().items(Joi.string()).default([]),
})
.default(),
kbnTestServer: Joi.object()
.keys({
buildArgs: Joi.array(),
sourceArgs: Joi.array(),
serverArgs: Joi.array(),
installDir: Joi.string(),
useDedicatedTaskRunner: Joi.boolean().default(false),
/** Options for how FTR should execute and interact with Kibana */
runOptions: Joi.object()
.keys({
/**
* Log message to wait for before initiating tests, defaults to waiting for Kibana status to be `available`.
* Note that this log message must not be filtered out by the current logging config, for example by the
* log level. If needed, you can adjust the logging level via `kbnTestServer.serverArgs`.
*/
wait: Joi.object()
.regex()
.default(/Kibana is now available/),
/**
* Does this test config only work when run against source?
*/
alwaysUseSource: Joi.boolean().default(false),
})
.default(),
env: Joi.object().unknown().default(),
delayShutdown: Joi.number(),
})
.default(),
chromedriver: Joi.object()
.keys({
url: Joi.string()
.uri({ scheme: /https?/ })
.default('http://localhost:9515'),
})
.default(),
firefoxdriver: Joi.object()
.keys({
url: Joi.string()
.uri({ scheme: /https?/ })
.default('http://localhost:2828'),
})
.default(),
// definition of apps that work with `common.navigateToApp()`
apps: Joi.object().pattern(ID_PATTERN, appUrlPartsSchema()).default(),
// settings for the saved objects svc
esArchiver: Joi.object()
.keys({
baseDirectory: Joi.string().optional(),
})
.default(),
// settings for the saved objects svc
kbnArchiver: Joi.object()
.keys({
directory: Joi.string().default(defaultRelativeToConfigPath('fixtures/kbn_archiver')),
})
.default(),
// settings for the kibanaServer.uiSettings module
uiSettings: Joi.object()
.keys({
defaults: Joi.object().unknown(true),
})
.default(),
// settings for the screenshots module
screenshots: Joi.object()
.keys({
directory: Joi.string().default(defaultRelativeToConfigPath('screenshots')),
})
.default(),
// settings for the snapshots module
snapshots: Joi.object()
.keys({
directory: Joi.string().default(defaultRelativeToConfigPath('snapshots')),
})
.default(),
// settings for the failureDebugging module
failureDebugging: Joi.object()
.keys({
htmlDirectory: Joi.string().default(defaultRelativeToConfigPath('failure_debug/html')),
})
.default(),
// settings for the find service
layout: Joi.object()
.keys({
fixedHeaderHeight: Joi.number().default(100),
})
.default(),
// settings for the security service if there is no defaultRole defined, then default to superuser role.
security: Joi.object()
.keys({
roles: Joi.object().default(),
remoteEsRoles: Joi.object(),
defaultRoles: Joi.array()
.items(Joi.string())
.when('$primary', {
is: true,
then: Joi.array().min(1),
})
.default(['superuser']),
disableTestUser: Joi.boolean(),
})
.default(),
dockerServers: Joi.object().pattern(Joi.string(), dockerServerSchema()).default(),
})
.default();