diff --git a/src/wcc.js b/src/wcc.js index f9b3998..887e0b6 100644 --- a/src/wcc.js +++ b/src/wcc.js @@ -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(); } } @@ -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)} - - ` - : 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)} + + ` + : serialize(finalTree); + } else { + console.warn('WARNING: No custom element class found for this entry point.'); + } return { html, diff --git a/test/cases/no-export/no-export.spec.js b/test/cases/no-export/no-export.spec.js index bb3e153..d3257ca 100644 --- a/test/cases/no-export/no-export.spec.js +++ b/test/cases/no-export/no-export.spec.js @@ -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); }); });