-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(compiler): fix generated import statement (#5419)
* fix(compiler): fix generated import statement STENCIL-855 * prettier * apply provided patch * add more tests * prettier
- Loading branch information
1 parent
37bbd8c
commit 502da1b
Showing
2 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/compiler/output-targets/dist-custom-elements/test/dist-custom-elements.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type * as d from '@stencil/core/declarations'; | ||
import { mockBuildCtx } from '@stencil/core/testing'; | ||
|
||
import { BundleOptions } from '../../../bundle/bundle-interface'; | ||
import { stubComponentCompilerMeta } from '../../../types/tests/ComponentCompilerMeta.stub'; | ||
import { addCustomElementInputs } from '../index'; | ||
|
||
describe('dist-custom-elements', () => { | ||
it('should export plain component', () => { | ||
const cmpMeta = stubComponentCompilerMeta({ isPlain: true, sourceFilePath: './foo/bar.tsx', tagName: 'my-tag' }); | ||
const buildCtx = mockBuildCtx(); | ||
buildCtx.components = [cmpMeta]; | ||
const bundleOpts: BundleOptions = { | ||
id: 'customElements', | ||
platform: 'client', | ||
inputs: {}, | ||
loader: {}, | ||
}; | ||
const outputTarget: d.OutputTargetDistCustomElements = { | ||
type: 'dist-custom-elements', | ||
customElementsExportBehavior: 'single-export-module', | ||
}; | ||
addCustomElementInputs(buildCtx, bundleOpts, outputTarget); | ||
expect(bundleOpts.loader['\x00MyTag']).toContain("export { StubCmp as MyTag } from './foo/bar.tsx';"); | ||
expect(bundleOpts.loader['\x00core']).toContain(`export { MyTag } from '\x00MyTag';\n`); | ||
}); | ||
|
||
it('should export component with a defineCustomElement function', () => { | ||
const cmpMeta = stubComponentCompilerMeta({ sourceFilePath: './foo/bar.tsx', tagName: 'my-tag' }); | ||
const buildCtx = mockBuildCtx(); | ||
buildCtx.components = [cmpMeta]; | ||
const bundleOpts: BundleOptions = { | ||
id: 'customElements', | ||
platform: 'client', | ||
inputs: {}, | ||
loader: {}, | ||
}; | ||
const outputTarget: d.OutputTargetDistCustomElements = { | ||
type: 'dist-custom-elements', | ||
customElementsExportBehavior: 'single-export-module', | ||
}; | ||
addCustomElementInputs(buildCtx, bundleOpts, outputTarget); | ||
expect(bundleOpts.loader['\x00MyTag']).toContain('export const defineCustomElement = cmpDefCustomEle;'); | ||
expect(bundleOpts.loader['\x00MyTag']).toContain( | ||
"import { StubCmp as $CmpMyTag, defineCustomElement as cmpDefCustomEle } from './foo/bar.tsx';", | ||
); | ||
expect(bundleOpts.loader['\x00core']).toContain( | ||
`export { MyTag, defineCustomElement as defineCustomElementMyTag } from '\x00MyTag';\n`, | ||
); | ||
}); | ||
}); |