Migrate test plugins ⇒ NP (kbn_tp_run_pipeline) (#64780) (#65617)

* Migrated kbn_tp_run_pipeline to the new Platform

* Updated config.

* Added tsconfig.

* Updated index.ts for tests

* updated tsconfig

* Updated typescript task

* fixed tests

* Fixed tests

* updated comment

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Uladzislau Lasitsa 2020-05-07 16:27:11 +03:00 committed by GitHub
parent a8687300a8
commit b9a3f912a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 73 additions and 125 deletions

View file

@ -50,6 +50,9 @@ export const PROJECTS = [
...glob
.sync('test/plugin_functional/plugins/*/tsconfig.json', { cwd: REPO_ROOT })
.map(path => new Project(resolve(REPO_ROOT, path))),
...glob
.sync('test/interpreter_functional/plugins/*/tsconfig.json', { cwd: REPO_ROOT })
.map(path => new Project(resolve(REPO_ROOT, path))),
];
export function filterProjectsByFlag(projectFlag?: string) {

View file

@ -50,6 +50,9 @@ export default async function({ readConfigFile }: FtrConfigProviderContext) {
...functionalConfig.get('kbnTestServer'),
serverArgs: [
...functionalConfig.get('kbnTestServer.serverArgs'),
// Required to load new platform plugins via `--plugin-path` flag.
'--env.name=development',
...plugins.map(
pluginDir => `--plugin-path=${path.resolve(__dirname, 'plugins', pluginDir)}`
),

View file

@ -1,49 +0,0 @@
/*
* 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 { Legacy } from 'kibana';
import {
ArrayOrItem,
LegacyPluginApi,
LegacyPluginSpec,
LegacyPluginOptions,
} from 'src/legacy/plugin_discovery/types';
// eslint-disable-next-line import/no-default-export
export default function(kibana: LegacyPluginApi): ArrayOrItem<LegacyPluginSpec> {
const pluginSpec: Partial<LegacyPluginOptions> = {
id: 'kbn_tp_run_pipeline',
uiExports: {
app: {
title: 'Run Pipeline',
description: 'This is a sample plugin to test running pipeline expressions',
main: 'plugins/kbn_tp_run_pipeline/legacy',
},
},
init(server: Legacy.Server) {
// The following lines copy over some configuration variables from Kibana
// to this plugin. This will be needed when embedding visualizations, so that e.g.
// region map is able to get its configuration.
server.injectUiAppVars('kbn_tp_run_pipeline', async () => {
return server.getInjectedUiAppVars('kibana');
});
},
};
return new kibana.Plugin(pluginSpec);
}

View file

@ -0,0 +1,13 @@
{
"id": "kbn_tp_run_pipeline",
"version": "0.0.1",
"kibanaVersion": "kibana",
"requiredPlugins": [
"data",
"savedObjects",
"kibanaUtils",
"expressions"
],
"server": false,
"ui": true
}

View file

@ -1,6 +1,7 @@
{
"name": "kbn_tp_run_pipeline",
"version": "1.0.0",
"main": "target/test/interpreter_functional/plugins/kbn_tp_run_pipeline",
"kibana": {
"version": "kibana",
"templateVersion": "1.0.0"
@ -10,5 +11,13 @@
"@elastic/eui": "22.3.1",
"react": "^16.12.0",
"react-dom": "^16.12.0"
},
"scripts": {
"kbn": "node ../../../../scripts/kbn.js",
"build": "rm -rf './target' && tsc"
},
"devDependencies": {
"@kbn/plugin-helpers": "9.0.2",
"typescript": "3.7.2"
}
}

View file

@ -21,7 +21,7 @@ import React from 'react';
import { EuiPage, EuiPageBody, EuiPageContent, EuiPageContentHeader } from '@elastic/eui';
import { first } from 'rxjs/operators';
import { IInterpreterRenderHandlers, ExpressionValue } from 'src/plugins/expressions';
import { RequestAdapter, DataAdapter } from '../../../../../../../../src/plugins/inspector';
import { RequestAdapter, DataAdapter } from '../../../../../../../src/plugins/inspector';
import { Adapters, ExpressionRenderHandler } from '../../types';
import { getExpressions } from '../../services';

View file

@ -17,4 +17,12 @@
* under the License.
*/
export * from './np_ready';
import { PluginInitializer, PluginInitializerContext } from 'src/core/public';
import { Plugin, StartDeps } from './plugin';
export { StartDeps };
export const plugin: PluginInitializer<void, void, {}, StartDeps> = (
initializerContext: PluginInitializerContext
) => {
return new Plugin(initializerContext);
};

View file

@ -1,39 +0,0 @@
/*
* 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 { PluginInitializerContext } from 'src/core/public';
import { npSetup, npStart } from 'ui/new_platform';
import { plugin } from './np_ready';
// This is required so some default styles and required scripts/Angular modules are loaded,
// or the timezone setting is correctly applied.
import 'ui/autoload/all';
// Used to run esaggs queries
import 'uiExports/fieldFormats';
import 'uiExports/search';
// Used for kibana_context function
import 'uiExports/savedObjectTypes';
import 'uiExports/interpreter';
const pluginInstance = plugin({} as PluginInitializerContext);
export const setup = pluginInstance.setup(npSetup.core, npSetup.plugins);
export const start = pluginInstance.start(npStart.core, npStart.plugins);

View file

@ -1,28 +0,0 @@
/*
* 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 { PluginInitializer, PluginInitializerContext } from 'src/core/public';
import { Plugin, StartDeps } from './plugin';
export { StartDeps };
export const plugin: PluginInitializer<void, void, {}, StartDeps> = (
initializerContext: PluginInitializerContext
) => {
return new Plugin(initializerContext);
};

View file

@ -17,7 +17,7 @@
* under the License.
*/
import { createGetterSetter } from '../../../../../../src/plugins/kibana_utils/public';
import { createGetterSetter } from '../../../../../src/plugins/kibana_utils/public';
import { ExpressionsStart } from './types';
export const [getExpressions, setExpressions] = createGetterSetter<ExpressionsStart>('Expressions');

View file

@ -0,0 +1,14 @@
{
"extends": "../../../../tsconfig.json",
"compilerOptions": {
"outDir": "./target",
"skipLibCheck": true
},
"include": [
"index.ts",
"public/**/*.ts",
"public/**/*.tsx",
"../../../../typings/**/*",
],
"exclude": []
}

View file

@ -113,10 +113,11 @@ export default function({
await expectExpression('partial_test_2', metricExpr, context).toMatchSnapshot()
).toMatchScreenshot();
const regionMapExpr = `regionmap visConfig='{"metric":{"accessor":1,"format":{"id":"number"}},"bucket":{"accessor":0}}'`;
await (
await expectExpression('partial_test_3', regionMapExpr, context).toMatchSnapshot()
).toMatchScreenshot();
// TODO: should be uncommented when the region map is migrated to the new platform
// const regionMapExpr = `regionmap visConfig='{"metric":{"accessor":1,"format":{"id":"number"}},"bucket":{"accessor":0}}'`;
// await (
// await expectExpression('partial_test_3', regionMapExpr, context).toMatchSnapshot()
// ).toMatchScreenshot();
});
});
});

View file

@ -21,6 +21,17 @@ import expect from '@kbn/expect';
import { ExpressionValue } from 'src/plugins/expressions';
import { FtrProviderContext } from '../../../functional/ftr_provider_context';
declare global {
interface Window {
runPipeline: (
expressions: string,
context?: ExpressionValue,
initialContext?: ExpressionValue
) => any;
renderPipelineResponse: (context?: ExpressionValue) => Promise<any>;
}
}
export type ExpressionResult = any;
export type ExpectExpression = (
@ -165,7 +176,7 @@ export function expectExpressionProvider({
log.debug('starting to render');
const result = await browser.executeAsync<any>(
(_context: ExpressionResult, done: (renderResult: any) => void) =>
window.renderPipelineResponse(_context).then(renderResult => {
window.renderPipelineResponse(_context).then((renderResult: any) => {
done(renderResult);
return renderResult;
}),

View file

@ -6,6 +6,7 @@ echo " -> building kibana platform plugins"
node scripts/build_kibana_platform_plugins \
--oss \
--scan-dir "$KIBANA_DIR/test/plugin_functional/plugins" \
--scan-dir "$KIBANA_DIR/test/interpreter_functional/plugins" \
--verbose;
# doesn't persist, also set in kibanaPipeline.groovy

View file

@ -19,6 +19,7 @@
"typings/**/*"
],
"exclude": [
"plugin_functional/plugins/**/*"
"plugin_functional/plugins/**/*",
"interpreter_functional/plugins/**/*"
]
}