@@ -135,15 +135,63 @@ describe('Custom Elements output target', () => {
135135 let compilerCtx : d . CompilerCtx ;
136136 let buildCtx : d . BuildCtx ;
137137
138- const bundleOptions = getBundleOptions (
139- config ,
140- buildCtx ,
141- compilerCtx ,
142- config . outputTargets [ 0 ] as OutputTargetDistCustomElements
143- ) ;
144- addCustomElementInputs ( buildCtx , bundleOptions ) ;
145- expect ( bundleOptions . loader [ '\0core' ] ) . toEqual (
146- `export { setAssetPath, setNonce, setPlatformOptions } from '${ STENCIL_INTERNAL_CLIENT_ID } ';
138+ beforeEach ( ( ) => {
139+ ( { config, compilerCtx, buildCtx } = setup ( ) ) ;
140+ } ) ;
141+
142+ describe ( 'no defined CustomElementsExportBehavior' , ( ) => {
143+ it ( "doesn't re-export components from the index.js barrel file" , ( ) => {
144+ const componentOne = stubComponentCompilerMeta ( ) ;
145+ const componentTwo = stubComponentCompilerMeta ( {
146+ componentClassName : 'MyBestComponent' ,
147+ tagName : 'my-best-component' ,
148+ } ) ;
149+
150+ buildCtx . components = [ componentOne , componentTwo ] ;
151+
152+ const bundleOptions = getBundleOptions (
153+ config ,
154+ buildCtx ,
155+ compilerCtx ,
156+ config . outputTargets [ 0 ] as OutputTargetDistCustomElements
157+ ) ;
158+ addCustomElementInputs ( buildCtx , bundleOptions , config . outputTargets [ 0 ] as OutputTargetDistCustomElements ) ;
159+ expect ( bundleOptions . loader [ '\0core' ] ) . toEqual (
160+ `import { globalScripts } from '${ STENCIL_APP_GLOBALS_ID } ';
161+ export { setAssetPath, setNonce, setPlatformOptions } from '${ STENCIL_INTERNAL_CLIENT_ID } ';
162+ export * from '${ USER_INDEX_ENTRY_ID } ';
163+
164+ globalScripts();
165+ `
166+ ) ;
167+ } ) ;
168+ } ) ;
169+
170+ describe ( 'CustomElementsExportBehavior.SINGLE_EXPORT_MODULE' , ( ) => {
171+ beforeEach ( ( ) => {
172+ ( config . outputTargets [ 0 ] as OutputTargetDistCustomElements ) . customElementsExportBehavior =
173+ 'single-export-module' ;
174+ } ) ;
175+
176+ it ( 'should add imports to index.js for all included components' , ( ) => {
177+ const componentOne = stubComponentCompilerMeta ( ) ;
178+ const componentTwo = stubComponentCompilerMeta ( {
179+ componentClassName : 'MyBestComponent' ,
180+ tagName : 'my-best-component' ,
181+ } ) ;
182+
183+ buildCtx . components = [ componentOne , componentTwo ] ;
184+
185+ const bundleOptions = getBundleOptions (
186+ config ,
187+ buildCtx ,
188+ compilerCtx ,
189+ config . outputTargets [ 0 ] as OutputTargetDistCustomElements
190+ ) ;
191+ addCustomElementInputs ( buildCtx , bundleOptions , config . outputTargets [ 0 ] as OutputTargetDistCustomElements ) ;
192+ expect ( bundleOptions . loader [ '\0core' ] ) . toEqual (
193+ `import { globalScripts } from '${ STENCIL_APP_GLOBALS_ID } ';
194+ export { setAssetPath, setNonce, setPlatformOptions } from '${ STENCIL_INTERNAL_CLIENT_ID } ';
147195export * from '${ USER_INDEX_ENTRY_ID } ';
148196import { globalScripts } from '${ STENCIL_APP_GLOBALS_ID } ';
149197globalScripts();
@@ -158,15 +206,18 @@ export { MyBestComponent, defineCustomElement as defineCustomElementMyBestCompon
158206 tagName : 'component-with-jsx' ,
159207 } ) ;
160208
161- const bundleOptions = getBundleOptions (
162- config ,
163- buildCtx ,
164- compilerCtx ,
165- config . outputTargets [ 0 ] as OutputTargetDistCustomElements
166- ) ;
167- addCustomElementInputs ( buildCtx , bundleOptions ) ;
168- expect ( bundleOptions . loader [ '\0core' ] ) . toEqual (
169- `export { setAssetPath, setNonce, setPlatformOptions } from '${ STENCIL_INTERNAL_CLIENT_ID } ';
209+ buildCtx . components = [ component ] ;
210+
211+ const bundleOptions = getBundleOptions (
212+ config ,
213+ buildCtx ,
214+ compilerCtx ,
215+ config . outputTargets [ 0 ] as OutputTargetDistCustomElements
216+ ) ;
217+ addCustomElementInputs ( buildCtx , bundleOptions , config . outputTargets [ 0 ] as OutputTargetDistCustomElements ) ;
218+ expect ( bundleOptions . loader [ '\0core' ] ) . toEqual (
219+ `import { globalScripts } from '${ STENCIL_APP_GLOBALS_ID } ';
220+ export { setAssetPath, setNonce, setPlatformOptions } from '${ STENCIL_INTERNAL_CLIENT_ID } ';
170221export * from '${ USER_INDEX_ENTRY_ID } ';
171222import { globalScripts } from '${ STENCIL_APP_GLOBALS_ID } ';
172223globalScripts();
0 commit comments