Skip to content
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

enhancement/issue 124 refactor handling and logging for entry points and dependencies with no custom element export #125

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions src/wcc.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ async function initializeCustomElement(elementURL, tagName, attrs = [], definiti
await elementInstance.connectedCallback();

return elementInstance;
} else {
console.debug('No custom element class found for this file');
return new HTMLElement();
}
}

Expand All @@ -169,18 +166,25 @@ async function renderToString(elementURL, wrappingEntryTag = true, props = {}) {
const elementTagName = wrappingEntryTag && await getTagName(elementURL);
const isEntry = !!elementTagName;
const elementInstance = await initializeCustomElement(elementURL, undefined, undefined, definitions, isEntry, props);

const elementHtml = elementInstance.shadowRoot
? elementInstance.getInnerHTML({ includeShadowRoots: true })
: elementInstance.innerHTML;
const elementTree = getParse(elementHtml)(elementHtml);
const finalTree = await renderComponentRoots(elementTree, definitions);
const html = wrappingEntryTag && elementTagName ? `
<${elementTagName}>
${serialize(finalTree)}
</${elementTagName}>
`
: serialize(finalTree);
let html;

// in case the entry point isn't valid
if (elementInstance) {
const elementHtml = elementInstance.shadowRoot
? elementInstance.getInnerHTML({ includeShadowRoots: true })
: elementInstance.innerHTML;
const elementTree = getParse(elementHtml)(elementHtml);
const finalTree = await renderComponentRoots(elementTree, definitions);

html = wrappingEntryTag && elementTagName ? `
<${elementTagName}>
${serialize(finalTree)}
</${elementTagName}>
`
: serialize(finalTree);
} else {
console.warn('WARNING: No custom element class found for this entry point.');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In retrospect, maybe this should be more of a debug instead of warn?

}

return {
html,
Expand Down
10 changes: 8 additions & 2 deletions test/cases/no-export/no-export.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,22 @@ const expect = chai.expect;
describe('Run WCC For ', function() {
const LABEL = 'Single Custom Element with no default export';
let rawHtml;
let meta;

before(async function() {
const { html } = await renderToString(new URL('./src/no-export.js', import.meta.url));
const { html, metadata } = await renderToString(new URL('./src/no-export.js', import.meta.url));

rawHtml = html;
meta = metadata;
});

describe(LABEL, function() {
it('should not throw an error', function() {
expect(rawHtml).to.equal('');
expect(rawHtml).to.equal(undefined);
});

it('should not have any definition', function() {
expect(meta.length).to.equal(0);
});
});

Expand Down
Loading