Skip to content

Commit e74a806

Browse files
authored
Typescriptify and shim kbn_tp_run_pipeline test plugin (#50645) (#51714)
* Typscriptify and shim kbn_tp_run_pipeline test plugin * fix imports to not re-export ‘legacy’ from root of plugin
1 parent f44a220 commit e74a806

File tree

23 files changed

+593
-276
lines changed

23 files changed

+593
-276
lines changed

scripts/functional_tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ require('@kbn/test').runTestsCli([
2222
require.resolve('../test/functional/config.js'),
2323
require.resolve('../test/api_integration/config.js'),
2424
require.resolve('../test/plugin_functional/config.js'),
25-
require.resolve('../test/interpreter_functional/config.js'),
25+
require.resolve('../test/interpreter_functional/config.ts'),
2626
require.resolve('../test/ui_capabilities/newsfeed_err/config.ts'),
2727
]);

src/plugins/expressions/public/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@
2020
import { PluginInitializerContext } from '../../../core/public';
2121
import { ExpressionsPublicPlugin } from './plugin';
2222

23-
export function plugin(initializerContext: PluginInitializerContext) {
24-
return new ExpressionsPublicPlugin(initializerContext);
25-
}
26-
2723
export { ExpressionsPublicPlugin as Plugin };
2824

2925
export * from './plugin';
3026
export * from './types';
3127
export * from '../common';
3228
export { interpreterProvider, ExpressionInterpret } from './interpreter_provider';
3329
export { ExpressionRenderer, ExpressionRendererProps } from './expression_renderer';
30+
export { ExpressionDataHandler } from './execute';
31+
32+
export { RenderResult, ExpressionRenderHandler } from './render';
33+
34+
export function plugin(initializerContext: PluginInitializerContext) {
35+
return new ExpressionsPublicPlugin(initializerContext);
36+
}

src/plugins/expressions/public/render.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@ interface RenderError {
3030

3131
export type IExpressionRendererExtraHandlers = Record<string, any>;
3232

33+
export type RenderResult = RenderId | RenderError;
34+
3335
export class ExpressionRenderHandler {
34-
render$: Observable<RenderId | RenderError>;
36+
render$: Observable<RenderResult>;
3537
update$: Observable<any>;
3638
events$: Observable<event>;
3739

3840
private element: HTMLElement;
3941
private destroyFn?: any;
4042
private renderCount: number = 0;
41-
private renderSubject: Rx.BehaviorSubject<RenderId | RenderError | null>;
43+
private renderSubject: Rx.BehaviorSubject<RenderResult | null>;
4244
private eventsSubject: Rx.Subject<unknown>;
4345
private updateSubject: Rx.Subject<unknown>;
4446
private handlers: IInterpreterRenderHandlers;
@@ -49,11 +51,11 @@ export class ExpressionRenderHandler {
4951
this.eventsSubject = new Rx.Subject();
5052
this.events$ = this.eventsSubject.asObservable().pipe(share());
5153

52-
this.renderSubject = new Rx.BehaviorSubject(null as RenderId | RenderError | null);
54+
this.renderSubject = new Rx.BehaviorSubject(null as RenderResult | null);
5355
this.render$ = this.renderSubject.asObservable().pipe(
5456
share(),
5557
filter(_ => _ !== null)
56-
) as Observable<RenderId | RenderError>;
58+
) as Observable<RenderResult>;
5759

5860
this.updateSubject = new Rx.Subject();
5961
this.update$ = this.updateSubject.asObservable().pipe(share());

tasks/config/run.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ module.exports = function (grunt) {
254254
cmd: NODE,
255255
args: [
256256
'scripts/functional_tests',
257-
'--config', 'test/interpreter_functional/config.js',
257+
'--config', 'test/interpreter_functional/config.ts',
258258
'--bail',
259259
'--debug',
260260
'--kibana-install-dir', KIBANA_INSTALL_DIR,

test/functional/services/browser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,10 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
470470
);
471471
}
472472

473-
public async executeAsync<R>(fn: string | ((...args: any[]) => R), ...args: any[]): Promise<R> {
473+
public async executeAsync<R>(
474+
fn: string | ((...args: any[]) => Promise<R>),
475+
...args: any[]
476+
): Promise<R> {
474477
return await driver.executeAsyncScript(
475478
fn,
476479
...cloneDeep<any>(args, arg => {

test/interpreter_functional/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
This folder contains interpreter functional tests.
44

55
Add new test suites into the `test_suites` folder and reference them from the
6-
`config.js` file. These test suites work the same as regular functional test.
6+
`config.ts` file. These test suites work the same as regular functional test.
77

88
## Run the test
99

1010
To run these tests during development you can use the following commands:
1111

1212
```
1313
# Start the test server (can continue running)
14-
node scripts/functional_tests_server.js --config test/interpreter_functional/config.js
14+
node scripts/functional_tests_server.js --config test/interpreter_functional/config.ts
1515
1616
# Start a test run
17-
node scripts/functional_test_runner.js --config test/interpreter_functional/config.js
17+
node scripts/functional_test_runner.js --config test/interpreter_functional/config.ts
1818
```
1919

2020
# Writing tests
2121

22-
Look into test_suites/run_pipeline/basic.js for examples
22+
Look into test_suites/run_pipeline/basic.ts for examples
2323

2424
to update baseline screenshots and snapshots run with:
2525
```
26-
node scripts/functional_test_runner.js --config test/interpreter_functional/config.js --updateBaselines
26+
node scripts/functional_test_runner.js --config test/interpreter_functional/config.ts --updateBaselines
2727
```

test/interpreter_functional/config.js renamed to test/interpreter_functional/config.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,26 @@
1919

2020
import path from 'path';
2121
import fs from 'fs';
22+
import { FtrConfigProviderContext } from '@kbn/test/types/ftr';
2223

23-
export default async function ({ readConfigFile }) {
24+
export default async function({ readConfigFile }: FtrConfigProviderContext) {
2425
const functionalConfig = await readConfigFile(require.resolve('../functional/config'));
2526

2627
// Find all folders in ./plugins since we treat all them as plugin folder
2728
const allFiles = fs.readdirSync(path.resolve(__dirname, 'plugins'));
28-
const plugins = allFiles.filter(file => fs.statSync(path.resolve(__dirname, 'plugins', file)).isDirectory());
29+
const plugins = allFiles.filter(file =>
30+
fs.statSync(path.resolve(__dirname, 'plugins', file)).isDirectory()
31+
);
2932

3033
return {
31-
testFiles: [
32-
require.resolve('./test_suites/run_pipeline'),
33-
],
34+
testFiles: [require.resolve('./test_suites/run_pipeline')],
3435
services: functionalConfig.get('services'),
3536
pageObjects: functionalConfig.get('pageObjects'),
3637
servers: functionalConfig.get('servers'),
3738
esTestCluster: functionalConfig.get('esTestCluster'),
3839
apps: functionalConfig.get('apps'),
3940
esArchiver: {
40-
directory: path.resolve(__dirname, '../es_archives')
41+
directory: path.resolve(__dirname, '../es_archives'),
4142
},
4243
snapshots: {
4344
directory: path.resolve(__dirname, 'snapshots'),
@@ -49,7 +50,9 @@ export default async function ({ readConfigFile }) {
4950
...functionalConfig.get('kbnTestServer'),
5051
serverArgs: [
5152
...functionalConfig.get('kbnTestServer.serverArgs'),
52-
...plugins.map(pluginDir => `--plugin-path=${path.resolve(__dirname, 'plugins', pluginDir)}`),
53+
...plugins.map(
54+
pluginDir => `--plugin-path=${path.resolve(__dirname, 'plugins', pluginDir)}`
55+
),
5356
],
5457
},
5558
};

test/interpreter_functional/plugins/kbn_tp_run_pipeline/index.js renamed to test/interpreter_functional/plugins/kbn_tp_run_pipeline/index.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,34 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19+
import { Legacy } from 'kibana';
20+
import {
21+
ArrayOrItem,
22+
LegacyPluginApi,
23+
LegacyPluginSpec,
24+
LegacyPluginOptions,
25+
} from 'src/legacy/plugin_discovery/types';
1926

20-
export default function (kibana) {
21-
return new kibana.Plugin({
27+
// eslint-disable-next-line import/no-default-export
28+
export default function(kibana: LegacyPluginApi): ArrayOrItem<LegacyPluginSpec> {
29+
const pluginSpec: Partial<LegacyPluginOptions> = {
30+
id: 'kbn_tp_run_pipeline',
2231
uiExports: {
2332
app: {
2433
title: 'Run Pipeline',
2534
description: 'This is a sample plugin to test running pipeline expressions',
26-
main: 'plugins/kbn_tp_run_pipeline/app',
27-
}
35+
main: 'plugins/kbn_tp_run_pipeline/legacy',
36+
},
2837
},
2938

30-
init(server) {
39+
init(server: Legacy.Server) {
3140
// The following lines copy over some configuration variables from Kibana
3241
// to this plugin. This will be needed when embedding visualizations, so that e.g.
3342
// region map is able to get its configuration.
3443
server.injectUiAppVars('kbn_tp_run_pipeline', async () => {
35-
return await server.getInjectedUiAppVars('kibana');
44+
return server.getInjectedUiAppVars('kibana');
3645
});
37-
}
38-
});
46+
},
47+
};
48+
return new kibana.Plugin(pluginSpec);
3949
}

test/interpreter_functional/plugins/kbn_tp_run_pipeline/public/app.js

Lines changed: 0 additions & 76 deletions
This file was deleted.

test/interpreter_functional/plugins/kbn_tp_run_pipeline/public/components/main.js

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)