mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-29 17:02:28 +00:00
- Added comprehensive comments to `js/webtorrent.js` explaining the playback strategy, service worker integration, and browser-specific quirks (Brave/Firefox). - Patched `tests/ui/helpers/jsdom-test-helpers.mjs` to expose `HTMLStyleElement` and other globals to JSDOM, fixing `ReferenceError` in UI tests. - Fixed `tests/ui/similar-content-card.test.mjs` to align with the current component implementation (handling detached elements) and resolving environment issues. - Updated `tests/video-modal-accessibility.test.mjs` to safely mock `navigator` and `HTMLCanvasElement.getContext`, resolving `TypeError` and "Not implemented" errors during testing.
47 lines
1.2 KiB
JavaScript
47 lines
1.2 KiB
JavaScript
import { JSDOM } from "jsdom";
|
|
|
|
export function createUiDom({
|
|
html = "<!DOCTYPE html><html><body></body></html>",
|
|
url = "https://bitvid.invalid/",
|
|
pretendToBeVisual = true,
|
|
} = {}) {
|
|
const dom = new JSDOM(html, {
|
|
url,
|
|
pretendToBeVisual,
|
|
});
|
|
|
|
const { window } = dom;
|
|
|
|
// Expose necessary globals for instance checks
|
|
// JSDOM runs in its own context, so instanceof checks against global constructors
|
|
// will fail unless we expose the JSDOM's constructors to the global scope.
|
|
global.HTMLStyleElement = window.HTMLStyleElement;
|
|
global.HTMLElement = window.HTMLElement;
|
|
global.Element = window.Element;
|
|
global.CustomEvent = window.CustomEvent;
|
|
|
|
// Mock Request/Response for fetch if not available
|
|
if (!global.Request) {
|
|
global.Request = window.Request;
|
|
}
|
|
if (!global.Response) {
|
|
global.Response = window.Response;
|
|
}
|
|
if (!global.Headers) {
|
|
global.Headers = window.Headers;
|
|
}
|
|
|
|
return {
|
|
window,
|
|
document: window.document,
|
|
cleanup: () => {
|
|
// Clean up globals to avoid pollution between tests
|
|
delete global.HTMLStyleElement;
|
|
delete global.HTMLElement;
|
|
delete global.Element;
|
|
delete global.CustomEvent;
|
|
window.close();
|
|
},
|
|
};
|
|
}
|