Skip to content

Commit 88f8bef

Browse files
Licensing plugin functional tests (#53580) (#53784)
* NP licensing add functional tests (#53002) * fix comment * introduce core provider plugin for integration tests * platform functional tests use core_provider_plugin for testing * add 3 scenario for licensing plugins: server, client, legacy * remove unused code * run all licensing_plugin tests on CI * remove duplicated config * address comments * declare global type for core provider * remove potentially dangerous operation Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
1 parent 4163d7a commit 88f8bef

File tree

25 files changed

+544
-235
lines changed

25 files changed

+544
-235
lines changed

test/plugin_functional/config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ export default async function({ readConfigFile }) {
5757
...functionalConfig.get('kbnTestServer'),
5858
serverArgs: [
5959
...functionalConfig.get('kbnTestServer.serverArgs'),
60+
61+
// Required to load new platform plugins via `--plugin-path` flag.
62+
'--env.name=development',
6063
...plugins.map(
6164
pluginDir => `--plugin-path=${path.resolve(__dirname, 'plugins', pluginDir)}`
6265
),
63-
// Required to load new platform plugins via `--plugin-path` flag.
64-
'--env.name=development',
6566
],
6667
},
6768
};

test/plugin_functional/plugins/core_plugin_b/public/plugin.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ import { CorePluginAPluginSetup } from '../../core_plugin_a/public/plugin';
2222

2323
declare global {
2424
interface Window {
25-
corePluginB?: string;
26-
hasAccessToInjectedMetadata?: boolean;
27-
receivedStartServices?: boolean;
2825
env?: PluginInitializerContext['env'];
2926
}
3027
}
@@ -39,12 +36,6 @@ export class CorePluginBPlugin
3936
window.env = pluginContext.env;
4037
}
4138
public setup(core: CoreSetup, deps: CorePluginBDeps) {
42-
window.corePluginB = `Plugin A said: ${deps.core_plugin_a.getGreeting()}`;
43-
window.hasAccessToInjectedMetadata = 'getInjectedVar' in core.injectedMetadata;
44-
core.getStartServices().then(([coreStart, plugins]) => {
45-
window.receivedStartServices = 'overlays' in coreStart;
46-
});
47-
4839
core.application.register({
4940
id: 'bar',
5041
title: 'Bar',
@@ -53,6 +44,12 @@ export class CorePluginBPlugin
5344
return renderApp(context, params);
5445
},
5546
});
47+
48+
return {
49+
sayHi() {
50+
return `Plugin A said: ${deps.core_plugin_a.getGreeting()}`;
51+
},
52+
};
5653
}
5754

5855
public start() {}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { resolve } from 'path';
21+
import { Legacy } from '../../../../kibana';
22+
23+
// eslint-disable-next-line import/no-default-export
24+
export default function CoreProviderPlugin(kibana: any) {
25+
const config: Legacy.PluginSpecOptions = {
26+
id: 'core-provider',
27+
require: [],
28+
publicDir: resolve(__dirname, 'public'),
29+
init: (server: Legacy.Server) => ({}),
30+
uiExports: {
31+
hacks: [resolve(__dirname, 'public/index')],
32+
},
33+
};
34+
35+
return new kibana.Plugin(config);
36+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "core_provider_plugin",
3+
"version": "1.0.0",
4+
"main": "target/test/plugin_functional/plugins/core_provider_plugin",
5+
"kibana": {
6+
"version": "kibana",
7+
"templateVersion": "1.0.0"
8+
},
9+
"license": "Apache-2.0",
10+
"scripts": {
11+
"kbn": "node ../../../../scripts/kbn.js",
12+
"build": "rm -rf './target' && tsc"
13+
},
14+
"devDependencies": {
15+
"typescript": "3.5.3"
16+
}
17+
}

test/plugin_functional/plugins/ui_settings_plugin/public/index.ts renamed to test/plugin_functional/plugins/core_provider_plugin/public/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
import { UiSettingsPlugin } from './plugin';
19+
import { npSetup, npStart } from 'ui/new_platform';
20+
import '../types';
2021

21-
export const plugin = () => new UiSettingsPlugin();
22+
window.__coreProvider = {
23+
setup: npSetup,
24+
start: npStart,
25+
testUtils: {
26+
delay: (ms: number) => new Promise(res => setTimeout(res, ms)),
27+
},
28+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "../../../../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "./target",
5+
"skipLibCheck": true
6+
},
7+
"include": [
8+
"index.ts",
9+
"types.ts",
10+
"public/**/*.ts",
11+
"../../../../typings/**/*",
12+
],
13+
"exclude": []
14+
}

test/plugin_functional/plugins/ui_settings_plugin/public/plugin.tsx renamed to test/plugin_functional/plugins/core_provider_plugin/types.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
20-
import { CoreSetup, Plugin } from 'kibana/public';
19+
import { LegacyCoreSetup, LegacyCoreStart } from 'kibana/public';
2120

2221
declare global {
2322
interface Window {
24-
uiSettingsPlugin?: Record<string, any>;
25-
uiSettingsPluginValue?: string;
23+
__coreProvider: {
24+
setup: {
25+
core: LegacyCoreSetup;
26+
plugins: Record<string, any>;
27+
};
28+
start: {
29+
core: LegacyCoreStart;
30+
plugins: Record<string, any>;
31+
};
32+
testUtils: {
33+
delay: (ms: number) => Promise<void>;
34+
};
35+
};
2636
}
2737
}
28-
29-
export class UiSettingsPlugin implements Plugin {
30-
public setup(core: CoreSetup) {
31-
window.uiSettingsPlugin = core.uiSettings.getAll().ui_settings_plugin;
32-
window.uiSettingsPluginValue = core.uiSettings.get('ui_settings_plugin');
33-
}
34-
35-
public start() {}
36-
public stop() {}
37-
}

test/plugin_functional/plugins/ui_settings_plugin/kibana.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
"kibanaVersion": "kibana",
55
"configPath": ["ui_settings_plugin"],
66
"server": true,
7-
"ui": true
7+
"ui": false
88
}

test/plugin_functional/plugins/ui_settings_plugin/tsconfig.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
"skipLibCheck": true
66
},
77
"include": [
8-
"index.ts",
9-
"public/**/*.ts",
10-
"public/**/*.tsx",
118
"server/**/*.ts",
129
"../../../../typings/**/*",
1310
],

test/plugin_functional/test_suites/core_plugins/ui_plugins.ts

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import expect from '@kbn/expect';
2121
import { PluginFunctionalProviderContext } from '../../services';
22+
import '../../../../test/plugin_functional/plugins/core_provider_plugin/types';
2223

2324
// eslint-disable-next-line import/no-default-export
2425
export default function({ getService, getPageObjects }: PluginFunctionalProviderContext) {
@@ -31,22 +32,35 @@ export default function({ getService, getPageObjects }: PluginFunctionalProvider
3132
await PageObjects.common.navigateToApp('settings');
3233
});
3334

34-
it('should attach string to window.corePluginB', async () => {
35-
const corePluginB = await browser.execute('return window.corePluginB');
36-
expect(corePluginB).to.equal(`Plugin A said: Hello from Plugin A!`);
35+
it('should run the new platform plugins', async () => {
36+
expect(
37+
await browser.execute(() => {
38+
return window.__coreProvider.setup.plugins.core_plugin_b.sayHi();
39+
})
40+
).to.be('Plugin A said: Hello from Plugin A!');
3741
});
3842
});
3943

40-
describe('have injectedMetadata service provided', function describeIndexTests() {
44+
describe('should have access to the core services', function describeIndexTests() {
4145
before(async () => {
42-
await PageObjects.common.navigateToApp('bar');
46+
await PageObjects.common.navigateToApp('settings');
47+
});
48+
49+
it('to injectedMetadata service', async () => {
50+
expect(
51+
await browser.execute(() => {
52+
return window.__coreProvider.setup.core.injectedMetadata.getKibanaBuildNumber();
53+
})
54+
).to.be.a('number');
4355
});
4456

45-
it('should attach boolean to window.hasAccessToInjectedMetadata', async () => {
46-
const hasAccessToInjectedMetadata = await browser.execute(
47-
'return window.hasAccessToInjectedMetadata'
48-
);
49-
expect(hasAccessToInjectedMetadata).to.equal(true);
57+
it('to start services via coreSetup.getStartServices', async () => {
58+
expect(
59+
await browser.executeAsync(async cb => {
60+
const [coreStart] = await window.__coreProvider.setup.core.getStartServices();
61+
cb(Boolean(coreStart.overlays));
62+
})
63+
).to.be(true);
5064
});
5165
});
5266

@@ -61,16 +75,5 @@ export default function({ getService, getPageObjects }: PluginFunctionalProvider
6175
expect(envData.packageInfo.version).to.be.a('string');
6276
});
6377
});
64-
65-
describe('have access to start services via coreSetup.getStartServices', function describeIndexTests() {
66-
before(async () => {
67-
await PageObjects.common.navigateToApp('bar');
68-
});
69-
70-
it('should attach boolean to window.receivedStartServices', async () => {
71-
const receivedStartServices = await browser.execute('return window.receivedStartServices');
72-
expect(receivedStartServices).to.equal(true);
73-
});
74-
});
7578
});
7679
}

0 commit comments

Comments
 (0)