Skip to content

Commit f267ab1

Browse files
committed
[uiExports] test injectDefaultVars()
1 parent cdcc795 commit f267ab1

File tree

7 files changed

+139
-0
lines changed

7 files changed

+139
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Bluebird from 'bluebird';
2+
3+
export default kibana => new kibana.Plugin({
4+
config(Joi) {
5+
return Joi.object().keys({
6+
enabled: Joi.boolean().default(true),
7+
delay: Joi.number().required(),
8+
shared: Joi.string(),
9+
}).default();
10+
},
11+
12+
uiExports: {
13+
async injectDefaultVars(server, options) {
14+
await Bluebird.delay(options.delay);
15+
return { shared: options.shared };
16+
}
17+
}
18+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "plugin_async_foo",
3+
"version": "0.0.0"
4+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default kibana => new kibana.Plugin({
2+
config(Joi) {
3+
return Joi.object().keys({
4+
enabled: Joi.boolean().default(true),
5+
shared: Joi.string()
6+
}).default();
7+
},
8+
9+
uiExports: {
10+
injectDefaultVars(server, options) {
11+
return { shared: options.shared };
12+
}
13+
}
14+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "plugin_bar",
3+
"version": "0.0.0"
4+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default kibana => new kibana.Plugin({
2+
config(Joi) {
3+
return Joi.object().keys({
4+
enabled: Joi.boolean().default(true),
5+
shared: Joi.string()
6+
}).default();
7+
},
8+
9+
uiExports: {
10+
injectDefaultVars(server, options) {
11+
return { shared: options.shared };
12+
}
13+
}
14+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "plugin_foo",
3+
"version": "0.0.0"
4+
}

src/ui/__tests__/ui_exports.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import expect from 'expect.js';
2+
import { resolve } from 'path';
23

34
import UiExports from '../ui_exports';
5+
import * as kbnTestServer from '../../../test/utils/kbn_server';
46

57
describe('UiExports', function () {
68
describe('#find()', function () {
@@ -23,4 +25,83 @@ describe('UiExports', function () {
2325
expect(uiExports.find(['foo', 'bar'])).to.eql(['a', 'b', 'c']);
2426
});
2527
});
28+
//
29+
describe('#defaultInjectedVars', function () {
30+
context('two plugins, two sync', function () {
31+
this.slow(10000);
32+
this.timeout(60000);
33+
34+
let kbnServer;
35+
before(async function () {
36+
kbnServer = kbnTestServer.createServer({
37+
plugins: {
38+
paths: [
39+
resolve(__dirname, 'fixtures/plugin_bar'),
40+
resolve(__dirname, 'fixtures/plugin_foo')
41+
]
42+
},
43+
44+
plugin_foo: {
45+
shared: 'foo'
46+
},
47+
48+
plugin_bar: {
49+
shared: 'bar'
50+
}
51+
});
52+
53+
await kbnServer.ready();
54+
});
55+
56+
after(async function () {
57+
await kbnServer.close();
58+
});
59+
60+
it('merges the two plugins in the order they are loaded', function () {
61+
expect(kbnServer.uiExports.defaultInjectedVars).to.eql({
62+
shared: 'foo'
63+
});
64+
});
65+
});
66+
67+
context('two plugins, one async', function () {
68+
this.slow(10000);
69+
this.timeout(60000);
70+
71+
let kbnServer;
72+
before(async function () {
73+
kbnServer = kbnTestServer.createServer({
74+
plugins: {
75+
scanDirs: [],
76+
paths: [
77+
resolve(__dirname, 'fixtures/plugin_async_foo'),
78+
resolve(__dirname, 'fixtures/plugin_foo')
79+
]
80+
},
81+
82+
plugin_async_foo: {
83+
delay: 500,
84+
shared: 'foo'
85+
},
86+
87+
plugin_bar: {
88+
shared: 'bar'
89+
}
90+
});
91+
92+
await kbnServer.ready();
93+
});
94+
95+
after(async function () {
96+
await kbnServer.close();
97+
});
98+
99+
it('merges the two plugins in the order they are loaded', function () {
100+
// even though plugin_async_foo loads 500ms later, it is still "first" to merge
101+
expect(kbnServer.uiExports.defaultInjectedVars).to.eql({
102+
shared: 'foo'
103+
});
104+
});
105+
});
106+
});
26107
});

0 commit comments

Comments
 (0)