()
| 19 | const bootstrapTestSuite = require('./bootstrap-test-suite'); |
| 20 | |
| 21 | async function startQUnit() { |
| 22 | const { default: tests } = await import('./fixtures/expect.mjs'); |
| 23 | const xssTests = tests.filter((element) => /alert/.test(element.payload)); |
| 24 | |
| 25 | QUnit.assert.contains = function (actual, expected, message) { |
| 26 | const result = expected.indexOf(actual) > -1; |
| 27 | // Ref: https://api.qunitjs.com/assert/pushResult/ |
| 28 | this.pushResult({ |
| 29 | result: result, |
| 30 | actual: actual, |
| 31 | expected: expected, |
| 32 | message: message, |
| 33 | }); |
| 34 | }; |
| 35 | |
| 36 | QUnit.config.autostart = false; |
| 37 | |
| 38 | QUnit.module('DOMPurify - bootstrap', bootstrapTestSuite(JSDOM)); |
| 39 | |
| 40 | QUnit.module('DOMPurify in jsdom'); |
| 41 | |
| 42 | if (!window.jQuery) { |
| 43 | console.warn('Unable to load jQuery'); |
| 44 | } |
| 45 | |
| 46 | const DOMPurify = createDOMPurify(window); |
| 47 | if (!DOMPurify.isSupported) { |
| 48 | console.error('Unexpected error returned by jsdom.env():', err, err.stack); |
| 49 | process.exit(1); |
| 50 | } |
| 51 | |
| 52 | window.alert = () => { |
| 53 | window.xssed = true; |
| 54 | }; |
| 55 | |
| 56 | sanitizeTestSuite(DOMPurify, window, tests, xssTests); |
| 57 | |
| 58 | if (process.env.DOMPURIFY_COV) { |
| 59 | QUnit.done(() => { |
| 60 | const fs = require('fs'); |
| 61 | fs.mkdirSync('.nyc_output', { recursive: true }); |
| 62 | fs.writeFileSync( |
| 63 | '.nyc_output/out.json', |
| 64 | JSON.stringify(global.__coverage__ || {}) |
| 65 | ); |
| 66 | }); |
| 67 | } |
| 68 | |
| 69 | QUnit.start(); |
| 70 | } |
| 71 | |
| 72 | module.exports = startQUnit; |
no test coverage detected
searching dependent graphs…