import { CoreWindow , read } from './plugin_reader' ; const coreWindow = window as any ; beforeEach ( ( ) => { const stubs = new Map < string , any > ( ) ; coreWindow . __osdBundles__ = { get ( key ) { return stubs . get ( key ) ; } , has ( key ) { return stubs . has ( key ) ; } , stub ( key , value ) { stubs . set ( key , value ) ; } , } ; } ) ; it ( 'handles undefined plugin exports' , ( ) => { expect ( ( ) => { read ( 'foo' ) ; } ) . toThrowError ( `Definition of plugin "foo" not found and may have failed to load.` ) ; } ) ; it ( 'handles plugin exports with a "plugin" export that is not a function' , ( ) => { coreWindow . __osdBundles__ . stub ( 'plugin/foo/public' , { plugin : 1234 , } ) ; expect ( ( ) => { read ( 'foo' ) ; } ) . toThrowError ( `Definition of plugin "foo" should be a function.` ) ; } ) ; it ( 'returns the plugin initializer when the "plugin" named export is a function' , ( ) => { const plugin = ( ) => { } ; coreWindow . __osdBundles__ . stub ( 'plugin/foo/public' , { plugin } ) ; expect ( read ( 'foo' ) ) . toBe ( plugin ) ; } ) ;