forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
servers.ts
84 lines (71 loc) · 2.06 KB
/
servers.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
/*
* 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 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 or the Server
* Side Public License, v 1.
*/
import type supertest from 'supertest';
import type { SavedObjectsClientContract, IUiSettingsClient } from 'src/core/server';
import type { KibanaClient } from '@elastic/elasticsearch/api/kibana';
import {
createTestServers,
TestElasticsearchUtils,
TestKibanaUtils,
TestUtils,
HttpMethod,
getSupertest,
} from '../../../../test_helpers/kbn_server';
import { httpServerMock } from '../../../http/http_server.mocks';
let servers: TestUtils;
let esServer: TestElasticsearchUtils;
let kbn: TestKibanaUtils;
interface AllServices {
savedObjectsClient: SavedObjectsClientContract;
esClient: KibanaClient;
uiSettings: IUiSettingsClient;
supertest: (method: HttpMethod, path: string) => supertest.Test;
}
let services: AllServices;
export async function startServers() {
servers = createTestServers({
adjustTimeout: (t) => jest.setTimeout(t),
settings: {
kbn: {
uiSettings: {
overrides: {
foo: 'bar',
},
},
},
},
});
esServer = await servers.startES();
kbn = await servers.startKibana();
}
export function getServices() {
if (services) {
return services;
}
const esClient = esServer.es.getClient();
const savedObjectsClient = kbn.coreStart.savedObjects.getScopedClient(
httpServerMock.createKibanaRequest()
);
const uiSettings = kbn.coreStart.uiSettings.asScopedToClient(savedObjectsClient);
services = {
supertest: (method: HttpMethod, path: string) => getSupertest(kbn.root, method, path),
esClient,
savedObjectsClient,
uiSettings,
};
return services;
}
export async function stopServers() {
services = null!;
if (esServer) {
await esServer.stop();
}
if (kbn) {
await kbn.stop();
}
}