From a4c553d8f1ff1c9a8b59bc0d7abd2e08e6d286b8 Mon Sep 17 00:00:00 2001 From: Owen Buckley Date: Tue, 9 Apr 2024 21:02:28 -0400 Subject: [PATCH 1/4] CSSStylesheet DOM Shim --- src/dom-shim.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/dom-shim.js b/src/dom-shim.js index ee621ea..8f3c044 100644 --- a/src/dom-shim.js +++ b/src/dom-shim.js @@ -1,5 +1,12 @@ function noop() { } +// https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/CSSStyleSheet +class CSSStyleSheet { + constructor() { } + replace() { } + replaceSync() { } +} + // https://developer.mozilla.org/en-US/docs/Web/API/EventTarget class EventTarget { constructor() { @@ -146,4 +153,5 @@ class CustomElementsRegistry { globalThis.addEventListener = globalThis.addEventListener ?? noop; globalThis.document = globalThis.document ?? new Document(); globalThis.customElements = globalThis.customElements ?? new CustomElementsRegistry(); -globalThis.HTMLElement = globalThis.HTMLElement ?? HTMLElement; \ No newline at end of file +globalThis.HTMLElement = globalThis.HTMLElement ?? HTMLElement; +globalThis.CSSStyleSheet = globalThis.CSSStyleSheet ?? CSSStyleSheet; \ No newline at end of file From e3594ae2ea555c6e8b6413740782c2512e48fee9 Mon Sep 17 00:00:00 2001 From: Owen Buckley Date: Fri, 12 Apr 2024 19:48:03 -0400 Subject: [PATCH 2/4] add test case for constructable stylesheets --- .../constructabe-stylesheet.spec.js | 38 +++++++++++++++++++ .../src/components/header/header.js | 23 +++++++++++ .../src/pages/index.js | 10 +++++ .../import-attributes.spec.js | 6 +-- 4 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 test/cases/constructable-stylesheet/constructabe-stylesheet.spec.js create mode 100644 test/cases/constructable-stylesheet/src/components/header/header.js create mode 100644 test/cases/constructable-stylesheet/src/pages/index.js diff --git a/test/cases/constructable-stylesheet/constructabe-stylesheet.spec.js b/test/cases/constructable-stylesheet/constructabe-stylesheet.spec.js new file mode 100644 index 0000000..fd433d9 --- /dev/null +++ b/test/cases/constructable-stylesheet/constructabe-stylesheet.spec.js @@ -0,0 +1,38 @@ +/* + * Use Case + * Run wcc against a custom element using constructible stylesheets. + * + * User Result + * Should return the expected HTML and no error instatiating a CSSStyleSheet.. + * + * User Workspace + * src/ + * components/ + * header/ + * header.js + * pages/ + * index.js + */ +import chai from 'chai'; +import { JSDOM } from 'jsdom'; +import { renderToString } from '../../../src/wcc.js'; + +const expect = chai.expect; + +describe('Run WCC For ', function() { + const LABEL = 'Constructible Stylesheets usage'; + let dom; + + before(async function() { + const { html } = await renderToString(new URL('./src/pages/index.js', import.meta.url)); + + dom = new JSDOM(html); + }); + + describe(LABEL, function() { + it('should have one top level element with a