Skip to content

Commit 4c816fa

Browse files
Merge branch '7.x' into backport/7.x/pr-58038
2 parents c2b6c6f + 5e88115 commit 4c816fa

File tree

12 files changed

+83
-72
lines changed

12 files changed

+83
-72
lines changed

packages/kbn-test/src/functional_test_runner/functional_test_runner.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ export class FunctionalTestRunner {
6060

6161
await providers.loadAll();
6262

63+
const customTestRunner = config.get('testRunner');
64+
if (customTestRunner) {
65+
this.log.warning(
66+
'custom test runner defined, ignoring all mocha/suite/filtering related options'
67+
);
68+
return (await providers.invokeProviderFn(customTestRunner)) || 0;
69+
}
70+
6371
const mocha = await setupMocha(this.lifecycle, this.log, config, providers);
6472
await this.lifecycle.beforeTests.trigger();
6573
this.log.info('Starting tests');
@@ -70,6 +78,10 @@ export class FunctionalTestRunner {
7078

7179
async getTestStats() {
7280
return await this._run(async (config, coreProviders) => {
81+
if (config.get('testRunner')) {
82+
throw new Error('Unable to get test stats for config that uses a custom test runner');
83+
}
84+
7385
// replace the function of custom service providers so that they return
7486
// promise-like objects which never resolve, essentially disabling them
7587
// allowing us to load the test files and populate the mocha suites
@@ -108,8 +120,11 @@ export class FunctionalTestRunner {
108120
const config = await readConfigFile(this.log, this.configFile, this.configOverrides);
109121
this.log.info('Config loaded');
110122

111-
if (config.get('testFiles').length === 0) {
112-
throw new Error('No test files defined.');
123+
if (
124+
(!config.get('testFiles') || config.get('testFiles').length === 0) &&
125+
!config.get('testRunner')
126+
) {
127+
throw new Error('No tests defined.');
113128
}
114129

115130
// base level services that functional_test_runner exposes

packages/kbn-test/src/functional_test_runner/lib/config/__tests__/read_config_file.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,4 @@ describe('readConfigFile()', () => {
5555
expect(err.message).to.match(/"foo"/);
5656
}
5757
});
58-
59-
it('throws if config does not define testFiles', async () => {
60-
try {
61-
await readConfigFile(log, require.resolve('./fixtures/config.4'));
62-
throw new Error('expected readConfigFile() to fail');
63-
} catch (err) {
64-
expect(err.message).to.match(/"testFiles"/);
65-
}
66-
});
67-
68-
it('does not throw if child config file does not have any testFiles', async () => {
69-
const config = await readConfigFile(log, require.resolve('./fixtures/config.3'));
70-
expect(config.get('screenshots.directory')).to.be('bar');
71-
});
7258
});

packages/kbn-test/src/functional_test_runner/lib/config/schema.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,8 @@ const defaultRelativeToConfigPath = (path: string) => {
6161

6262
export const schema = Joi.object()
6363
.keys({
64-
testFiles: Joi.array()
65-
.items(Joi.string())
66-
.when('$primary', {
67-
is: true,
68-
then: Joi.required(),
69-
otherwise: Joi.any().default([]),
70-
}),
64+
testFiles: Joi.array().items(Joi.string()),
65+
testRunner: Joi.func(),
7166

7267
excludeTestFiles: Joi.array()
7368
.items(Joi.string())

packages/kbn-test/src/functional_test_runner/lib/providers/provider_collection.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ export class ProviderCollection {
6868
}
6969
}
7070

71+
public invokeProviderFn(provider: (args: any) => any) {
72+
return provider({
73+
getService: this.getService,
74+
hasService: this.hasService,
75+
getPageObject: this.getPageObject,
76+
getPageObjects: this.getPageObjects,
77+
});
78+
}
79+
7180
private findProvider(type: string, name: string) {
7281
return this.providers.find(p => p.type === type && p.name === name);
7382
}
@@ -89,12 +98,7 @@ export class ProviderCollection {
8998
}
9099

91100
if (!instances.has(provider)) {
92-
let instance = provider({
93-
getService: this.getService,
94-
hasService: this.hasService,
95-
getPageObject: this.getPageObject,
96-
getPageObjects: this.getPageObjects,
97-
});
101+
let instance = this.invokeProviderFn(provider);
98102

99103
if (instance && typeof instance.then === 'function') {
100104
instance = createAsyncInstance(type, name, instance);

packages/kbn-test/src/functional_tests/cli/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@
1818
*/
1919

2020
export { runTestsCli } from './run_tests/cli';
21+
export { processOptions as processRunTestsCliOptions } from './run_tests/args';
2122
export { startServersCli } from './start_servers/cli';
23+
export { processOptions as processStartServersCliOptions } from './start_servers/args';

packages/kbn-test/src/functional_tests/lib/run_ftr.js

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,32 @@ async function createFtr({
2626
}) {
2727
const config = await readConfigFile(log, configPath);
2828

29-
return new FunctionalTestRunner(log, configPath, {
30-
mochaOpts: {
31-
bail: !!bail,
32-
grep,
33-
},
34-
kbnTestServer: {
35-
installDir,
36-
},
37-
updateBaselines,
38-
suiteTags: {
39-
include: [...suiteTags.include, ...config.get('suiteTags.include')],
40-
exclude: [...suiteTags.exclude, ...config.get('suiteTags.exclude')],
41-
},
42-
});
29+
return {
30+
config,
31+
ftr: new FunctionalTestRunner(log, configPath, {
32+
mochaOpts: {
33+
bail: !!bail,
34+
grep,
35+
},
36+
kbnTestServer: {
37+
installDir,
38+
},
39+
updateBaselines,
40+
suiteTags: {
41+
include: [...suiteTags.include, ...config.get('suiteTags.include')],
42+
exclude: [...suiteTags.exclude, ...config.get('suiteTags.exclude')],
43+
},
44+
}),
45+
};
4346
}
4447

4548
export async function assertNoneExcluded({ configPath, options }) {
46-
const ftr = await createFtr({ configPath, options });
49+
const { config, ftr } = await createFtr({ configPath, options });
50+
51+
if (config.get('testRunner')) {
52+
// tests with custom test runners are not included in this check
53+
return;
54+
}
4755

4856
const stats = await ftr.getTestStats();
4957
if (stats.excludedTests.length > 0) {
@@ -60,7 +68,7 @@ export async function assertNoneExcluded({ configPath, options }) {
6068
}
6169

6270
export async function runFtr({ configPath, options }) {
63-
const ftr = await createFtr({ configPath, options });
71+
const { ftr } = await createFtr({ configPath, options });
6472

6573
const failureCount = await ftr.run();
6674
if (failureCount > 0) {
@@ -71,7 +79,12 @@ export async function runFtr({ configPath, options }) {
7179
}
7280

7381
export async function hasTests({ configPath, options }) {
74-
const ftr = await createFtr({ configPath, options });
82+
const { ftr, config } = await createFtr({ configPath, options });
83+
84+
if (config.get('testRunner')) {
85+
// configs with custom test runners are assumed to always have tests
86+
return true;
87+
}
7588
const stats = await ftr.getTestStats();
7689
return stats.testCount > 0;
7790
}

packages/kbn-test/src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@
1717
* under the License.
1818
*/
1919

20-
// @ts-ignore not typed yet
21-
export { runTestsCli, startServersCli } from './functional_tests/cli';
20+
import {
21+
runTestsCli,
22+
processRunTestsCliOptions,
23+
startServersCli,
24+
processStartServersCliOptions,
25+
// @ts-ignore not typed yet
26+
} from './functional_tests/cli';
27+
28+
export { runTestsCli, processRunTestsCliOptions, startServersCli, processStartServersCliOptions };
2229

2330
// @ts-ignore not typed yet
2431
export { runTests, startServers } from './functional_tests/tasks';

x-pack/legacy/plugins/maps/public/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import 'uiExports/inspectorViews';
1111
import 'uiExports/search';
1212
import 'uiExports/embeddableFactories';
1313
import 'uiExports/embeddableActions';
14-
import 'ui/agg_types';
1514

1615
import 'ui/autoload/all';
1716
import 'react-vis/dist/style.css';

x-pack/legacy/plugins/maps/public/layers/joins/inner_join.test.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77
import { InnerJoin } from './inner_join';
88

99
jest.mock('../../kibana_services', () => {});
10-
jest.mock('ui/agg_types', () => {
11-
class MockSchemas {}
12-
return {
13-
Schemas: MockSchemas,
14-
};
15-
});
1610
jest.mock('ui/timefilter', () => {});
1711
jest.mock('../vector_layer', () => {});
1812

x-pack/legacy/plugins/maps/public/layers/sources/es_source.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
import { createExtentFilter } from '../../elasticsearch_geo_utils';
1515
import { timefilter } from 'ui/timefilter';
1616
import _ from 'lodash';
17-
import { AggConfigs } from 'ui/agg_types';
1817
import { i18n } from '@kbn/i18n';
1918
import uuid from 'uuid/v4';
2019
import { copyPersistentState } from '../../reducers/util';
@@ -151,27 +150,18 @@ export class AbstractESSource extends AbstractVectorSource {
151150
{ sourceQuery, query, timeFilters, filters, applyGlobalQuery },
152151
0
153152
);
154-
const geoField = await this._getGeoField();
155-
const indexPattern = await this.getIndexPattern();
156-
157-
const geoBoundsAgg = [
158-
{
159-
type: 'geo_bounds',
160-
enabled: true,
161-
params: {
162-
field: geoField,
153+
searchSource.setField('aggs', {
154+
fitToBounds: {
155+
geo_bounds: {
156+
field: this._descriptor.geoField,
163157
},
164-
schema: 'metric',
165158
},
166-
];
167-
168-
const aggConfigs = new AggConfigs(indexPattern, geoBoundsAgg);
169-
searchSource.setField('aggs', aggConfigs.toDsl());
159+
});
170160

171161
let esBounds;
172162
try {
173163
const esResp = await searchSource.fetch();
174-
esBounds = _.get(esResp, 'aggregations.1.bounds');
164+
esBounds = _.get(esResp, 'aggregations.fitToBounds.bounds');
175165
} catch (error) {
176166
esBounds = {
177167
top_left: {

0 commit comments

Comments
 (0)