()
| 36 | const sanitizeTestSuite = require('./test-suite'); |
| 37 | |
| 38 | async 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 | |
| 89 | module.exports = startQUnit; |
nothing calls this directly
no test coverage detected
searching dependent graphs…