11import expect from 'expect.js' ;
2+ import { resolve } from 'path' ;
23
34import UiExports from '../ui_exports' ;
5+ import * as kbnTestServer from '../../../test/utils/kbn_server' ;
46
57describe ( '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