-
Notifications
You must be signed in to change notification settings - Fork 142
Add isCustomElement flag for plugin tag configurations
#2786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e774318
Add `customComponent` flag for plugin tag configurations
gerteck fe62221
Use Set over array for inclusion check
gerteck d382482
Merge branch 'master' into feat/AddPluginTagIgnore
gerteck eb5345c
Merge branch 'master' into feat/AddPluginTagIgnore
gerteck 51a49d1
Merge branch 'master' into feat/AddPluginTagIgnore
gerteck 0ed6b7e
Update tag docs
gerteck 76f6382
Add testcase
gerteck 0fde401
Rename to isCustomElement
gerteck 265755f
Abstract out customElement Tags into helper function
gerteck 7c1c193
Fix test naming nit
gerteck 74858c3
Add caching
gerteck 3424d12
Fix lint
gerteck b759947
Add another testcase
gerteck 027ec77
refactor: make `isSpecial` and `attributes` optional in `TagConfigs` …
gerteck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
91 changes: 91 additions & 0 deletions
91
packages/core/test/unit/Page/PageVueServerRenderer.test.ts
This file contains hidden or 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,91 @@ | ||
| jest.mock('../../../src/plugins/PluginManager'); | ||
| jest.mock('vue/compiler-sfc'); | ||
| jest.mock('fs-extra'); | ||
|
|
||
| describe('PageVueServerRenderer', () => { | ||
| let pageVueServerRenderer: any; | ||
| let PluginManager: any; | ||
| let compileTemplate: any; | ||
|
|
||
| beforeEach(async () => { | ||
| jest.resetModules(); | ||
|
|
||
| // Re-acquire dependencies for the new module context (As Tags are cached in PluginManager) | ||
| PluginManager = (await import('../../../src/plugins/PluginManager')).PluginManager; | ||
| compileTemplate = (await import('vue/compiler-sfc')).compileTemplate; | ||
| pageVueServerRenderer = (await import('../../../src/Page/PageVueServerRenderer')).pageVueServerRenderer; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
gerteck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| describe('compileVuePageCreateAndReturnScript', () => { | ||
| test('correctly filters isCustomElement flag elements, ' | ||
| + 'passes to Vue compiler isCustomElement option', async () => { | ||
| // Setup | ||
| (PluginManager as any).tagConfig = { | ||
| 'my-custom-element': { | ||
| isCustomElement: true, | ||
| }, | ||
| 'regular-element': { | ||
| isCustomElement: false, | ||
| }, | ||
| }; | ||
|
|
||
| (compileTemplate as jest.Mock).mockReturnValue({ | ||
| code: '/* compiled code */', | ||
| }); | ||
|
|
||
| const pageConfig = { | ||
| sourcePath: 'test.md', | ||
| resultPath: 'test.html', | ||
| }; | ||
| const pageAsset = {}; | ||
|
|
||
| // Execute | ||
| await pageVueServerRenderer.compileVuePageCreateAndReturnScript( | ||
| 'content', | ||
| pageConfig as any, | ||
| pageAsset as any, | ||
| ); | ||
|
|
||
| // Verify | ||
| expect(compileTemplate).toHaveBeenCalled(); | ||
|
|
||
| const { compilerOptions } = (compileTemplate as jest.Mock).mock.calls[0][0]; | ||
| const { isCustomElement } = compilerOptions; | ||
|
|
||
| expect(isCustomElement('my-custom-element')).toBe(true); | ||
| expect(isCustomElement('regular-element')).toBe(false); | ||
| expect(isCustomElement('div')).toBe(false); | ||
| }); | ||
|
|
||
| test('handles empty tagConfig or tags without isCustomElement property', async () => { | ||
| (PluginManager as any).tagConfig = { | ||
| 'some-tag': { | ||
| // isSpecial and attributes are optional now | ||
| }, | ||
| }; | ||
|
|
||
| (compileTemplate as jest.Mock).mockReturnValue({ | ||
| code: '/* compiled code */', | ||
| }); | ||
|
|
||
| const pageConfig = { sourcePath: 'test.md', resultPath: 'test.html' }; | ||
| const pageAsset = {}; | ||
|
|
||
| await pageVueServerRenderer.compileVuePageCreateAndReturnScript( | ||
| 'content', | ||
| pageConfig as any, | ||
| pageAsset as any, | ||
| ); | ||
|
|
||
| const { compilerOptions } = (compileTemplate as jest.Mock).mock.calls[0][0]; | ||
| const { isCustomElement } = compilerOptions; | ||
|
|
||
| expect(isCustomElement('some-tag')).toBe(false); | ||
| expect(isCustomElement('any-tag')).toBe(false); | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.