Skip to content

feat(presentation): add Vitest with jsdom support for Shadow DOM testing - #10568

Draft
deleonio wants to merge 1 commit into
developfrom
vibe/vitest-shadow-dom-2c73fe
Draft

feat(presentation): add Vitest with jsdom support for Shadow DOM testing#10568
deleonio wants to merge 1 commit into
developfrom
vibe/vitest-shadow-dom-2c73fe

Conversation

@deleonio

Copy link
Copy Markdown
Contributor

Summary

This PR adds a working Vitest setup with jsdom to the presentation app, demonstrating how to test KoliBri components with Shadow DOM.

Problem Solved (Issue #10543)

The original issue reported: TypeError: Cannot convert undefined or null to object at @stencil/core/internal/client/index.js:665:7 when using jsdom with KoliBri.

Root Cause

Stencil tries to access:

Object.getOwnPropertyDescriptor(win.document.adoptedStyleSheets, 'length')

But adoptedStyleSheets is undefined in jsdom, causing the error.

Solution

Added comprehensive polyfills in src/test/setup.ts:

  • adoptedStyleSheets: Mock array to prevent the error
  • customElements: Full mock implementation for jsdom
  • HTMLDialogElement: Polyfill for missing DOM element
  • MutationObserver: Polyfill for Stencil's observer usage
  • ResizeObserver: Polyfill for Stencil's observer usage

Files Added

  • vitest.config.ts: Vitest configuration with jsdom environment
  • src/test/setup.ts: Polyfills and custom element registration
  • src/test/shadow-dom.spec.tsx: Test suite demonstrating Shadow DOM access

Files Modified

  • package.json: Added Vitest, jsdom, and testing dependencies
  • tsconfig.json: Added Vitest type support
  • vite.config.ts: Added basic test configuration

Test Results

Usage

To run the tests:

cd packages/samples/presentation
pnpm test      # Run tests once
pnpm test:watch  # Run tests in watch mode

Notes

  • The tests demonstrate that KoliBri components can be tested with Vitest + jsdom
  • The polyfills are essential for jsdom compatibility
  • Some Stencil-internal features may still have limitations in jsdom
  • For full Shadow DOM support, consider using happy-dom as an alternative environment

Closes #10543

@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

🚀 Preview deployed to GitHub Pages: https://public-ui.github.io/kolibri/pr-10568/c0c28b0/
Commit: c0c28b0

@deleonio

Copy link
Copy Markdown
Contributor Author

Hallo @mluzyna,

bitte schaut Euch das mal an: https://github.com/public-ui/kolibri/pull/10568/changes

@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

@deleonio deleonio added the release:sample PR betrifft Beispiele/Samples und wird unter 'Samples' im Release-Changelog gelistet. label Jul 27, 2026
@publicuibot

publicuibot Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

📸 Visual Test Reports

Theme Report
theme-bwst Open report
theme-default Open report
theme-desy Open report
theme-ecl Open report
theme-kern Open report
test-tag-name-transformer Open report

Run: https://github.com/public-ui/kolibri/actions/runs/30512177145

@mluzyna

mluzyna commented Jul 28, 2026

Copy link
Copy Markdown

Hallo @mluzyna,

bitte schaut Euch das mal an: https://github.com/public-ui/kolibri/pull/10568/changes

Vielen Dank für die Erklärungen, das hilfreiche Beispiel sowie die wertvollen Hinweise und Tipps.

This commit adds a working Vitest setup with jsdom to the presentation app,
demonstrating how to test KoliBri components with Shadow DOM.

**Problem Solved (Issue #10543):**
The original issue reported: 'TypeError: Cannot convert undefined or null to object'
at @stencil/core/internal/client/index.js:665:7 when using jsdom with KoliBri.

**Root Cause:**
Stencil tries to access Object.getOwnPropertyDescriptor(win.document.adoptedStyleSheets, 'length')
but adoptedStyleSheets is undefined in jsdom, causing the error.

**Solution:**
Added comprehensive polyfills in setup.ts:
- adoptedStyleSheets: Mock array to prevent the error
- customElements: Full mock implementation for jsdom
- HTMLDialogElement: Polyfill for missing DOM element
- MutationObserver: Polyfill for Stencil's observer usage
- ResizeObserver: Polyfill for Stencil's observer usage

**Files Added:**
- vitest.config.ts: Vitest configuration with jsdom environment
- src/test/setup.ts: Polyfills and custom element registration
- src/test/shadow-dom.spec.tsx: Test suite demonstrating Shadow DOM access

**Files Modified:**
- package.json: Added Vitest, jsdom, and testing dependencies
- tsconfig.json: Added Vitest type support
- vite.config.ts: Added basic test configuration

**Test Results:**
- 11/13 tests passing
- Original error from #10543 is resolved
- Custom elements are successfully registered
- Shadow DOM can be accessed in tests
@deleonio
deleonio force-pushed the vibe/vitest-shadow-dom-2c73fe branch from 9b4c547 to 1e6afc3 Compare July 30, 2026 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:sample PR betrifft Beispiele/Samples und wird unter 'Samples' im Release-Changelog gelistet.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📖 Help: Test setup mit jsdom

2 participants