MCPcopy
hub / github.com/cure53/DOMPurify / startQUnit

Function startQUnit

test/happydom-node.js:38–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

36const sanitizeTestSuite = require('./test-suite');
37
38async function startQUnit() {
39 const { default: tests } = await import('./fixtures/expect.mjs');
40 const xssTests = tests.filter((element) => /alert/.test(element.payload));
41
42 QUnit.assert.contains = function (actual, expected, message) {
43 const result = expected.indexOf(actual) > -1;
44 // Ref: https://api.qunitjs.com/assert/pushResult/
45 this.pushResult({
46 result: result,
47 actual: actual,
48 expected: expected,
49 message: message,
50 });
51 };
52
53 QUnit.config.autostart = false;
54
55 QUnit.module('DOMPurify in happy-dom');
56
57 if (!window.jQuery) {
58 console.warn('Unable to load jQuery');
59 }
60
61 const DOMPurify = createDOMPurify(window);
62 if (!DOMPurify.isSupported) {
63 console.error('DOMPurify reports isSupported === false under happy-dom');
64 process.exit(1);
65 }
66
67 window.alert = () => {
68 window.xssed = true;
69 };
70
71 sanitizeTestSuite(DOMPurify, window, tests, xssTests);
72
73 // happy-dom keeps its own timers/async tasks alive on the window; close it
74 // once QUnit has finished so the Node process can exit cleanly. jsdom does
75 // not require this.
76 QUnit.done(() => {
77 try {
78 if (window.happyDOM && typeof window.happyDOM.close === 'function') {
79 window.happyDOM.close();
80 }
81 } catch (error) {
82 /* best-effort cleanup */
83 }
84 });
85
86 QUnit.start();
87}
88
89module.exports = startQUnit;

Callers

nothing calls this directly

Calls 1

createDOMPurifyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…