[uiExports] test injectDefaultVars()
This commit is contained in:
parent
cdcc795af8
commit
f267ab1059
18
src/ui/__tests__/fixtures/plugin_async_foo/index.js
Normal file
18
src/ui/__tests__/fixtures/plugin_async_foo/index.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
import Bluebird from 'bluebird';
|
||||
|
||||
export default kibana => new kibana.Plugin({
|
||||
config(Joi) {
|
||||
return Joi.object().keys({
|
||||
enabled: Joi.boolean().default(true),
|
||||
delay: Joi.number().required(),
|
||||
shared: Joi.string(),
|
||||
}).default();
|
||||
},
|
||||
|
||||
uiExports: {
|
||||
async injectDefaultVars(server, options) {
|
||||
await Bluebird.delay(options.delay);
|
||||
return { shared: options.shared };
|
||||
}
|
||||
}
|
||||
});
|
4
src/ui/__tests__/fixtures/plugin_async_foo/package.json
Normal file
4
src/ui/__tests__/fixtures/plugin_async_foo/package.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"name": "plugin_async_foo",
|
||||
"version": "0.0.0"
|
||||
}
|
14
src/ui/__tests__/fixtures/plugin_bar/index.js
Normal file
14
src/ui/__tests__/fixtures/plugin_bar/index.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
export default kibana => new kibana.Plugin({
|
||||
config(Joi) {
|
||||
return Joi.object().keys({
|
||||
enabled: Joi.boolean().default(true),
|
||||
shared: Joi.string()
|
||||
}).default();
|
||||
},
|
||||
|
||||
uiExports: {
|
||||
injectDefaultVars(server, options) {
|
||||
return { shared: options.shared };
|
||||
}
|
||||
}
|
||||
});
|
4
src/ui/__tests__/fixtures/plugin_bar/package.json
Normal file
4
src/ui/__tests__/fixtures/plugin_bar/package.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"name": "plugin_bar",
|
||||
"version": "0.0.0"
|
||||
}
|
14
src/ui/__tests__/fixtures/plugin_foo/index.js
Normal file
14
src/ui/__tests__/fixtures/plugin_foo/index.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
export default kibana => new kibana.Plugin({
|
||||
config(Joi) {
|
||||
return Joi.object().keys({
|
||||
enabled: Joi.boolean().default(true),
|
||||
shared: Joi.string()
|
||||
}).default();
|
||||
},
|
||||
|
||||
uiExports: {
|
||||
injectDefaultVars(server, options) {
|
||||
return { shared: options.shared };
|
||||
}
|
||||
}
|
||||
});
|
4
src/ui/__tests__/fixtures/plugin_foo/package.json
Normal file
4
src/ui/__tests__/fixtures/plugin_foo/package.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"name": "plugin_foo",
|
||||
"version": "0.0.0"
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
import expect from 'expect.js';
|
||||
import { resolve } from 'path';
|
||||
|
||||
import UiExports from '../ui_exports';
|
||||
import * as kbnTestServer from '../../../test/utils/kbn_server';
|
||||
|
||||
describe('UiExports', function () {
|
||||
describe('#find()', function () {
|
||||
|
@ -23,4 +25,83 @@ describe('UiExports', function () {
|
|||
expect(uiExports.find(['foo', 'bar'])).to.eql(['a', 'b', 'c']);
|
||||
});
|
||||
});
|
||||
//
|
||||
describe('#defaultInjectedVars', function () {
|
||||
context('two plugins, two sync', function () {
|
||||
this.slow(10000);
|
||||
this.timeout(60000);
|
||||
|
||||
let kbnServer;
|
||||
before(async function () {
|
||||
kbnServer = kbnTestServer.createServer({
|
||||
plugins: {
|
||||
paths: [
|
||||
resolve(__dirname, 'fixtures/plugin_bar'),
|
||||
resolve(__dirname, 'fixtures/plugin_foo')
|
||||
]
|
||||
},
|
||||
|
||||
plugin_foo: {
|
||||
shared: 'foo'
|
||||
},
|
||||
|
||||
plugin_bar: {
|
||||
shared: 'bar'
|
||||
}
|
||||
});
|
||||
|
||||
await kbnServer.ready();
|
||||
});
|
||||
|
||||
after(async function () {
|
||||
await kbnServer.close();
|
||||
});
|
||||
|
||||
it('merges the two plugins in the order they are loaded', function () {
|
||||
expect(kbnServer.uiExports.defaultInjectedVars).to.eql({
|
||||
shared: 'foo'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('two plugins, one async', function () {
|
||||
this.slow(10000);
|
||||
this.timeout(60000);
|
||||
|
||||
let kbnServer;
|
||||
before(async function () {
|
||||
kbnServer = kbnTestServer.createServer({
|
||||
plugins: {
|
||||
scanDirs: [],
|
||||
paths: [
|
||||
resolve(__dirname, 'fixtures/plugin_async_foo'),
|
||||
resolve(__dirname, 'fixtures/plugin_foo')
|
||||
]
|
||||
},
|
||||
|
||||
plugin_async_foo: {
|
||||
delay: 500,
|
||||
shared: 'foo'
|
||||
},
|
||||
|
||||
plugin_bar: {
|
||||
shared: 'bar'
|
||||
}
|
||||
});
|
||||
|
||||
await kbnServer.ready();
|
||||
});
|
||||
|
||||
after(async function () {
|
||||
await kbnServer.close();
|
||||
});
|
||||
|
||||
it('merges the two plugins in the order they are loaded', function () {
|
||||
// even though plugin_async_foo loads 500ms later, it is still "first" to merge
|
||||
expect(kbnServer.uiExports.defaultInjectedVars).to.eql({
|
||||
shared: 'foo'
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue