* @param {string} assetName asset name * @param {Compiler} compiler compiler * @param {Stats} stats stats * @param {(dom: JSDOM, code: string) => void} testFn test function
(assetName, compiler, stats, testFn)
| 9 | * @param {(dom: JSDOM, code: string) => void} testFn test function |
| 10 | */ |
| 11 | function runInJsDom(assetName, compiler, stats, testFn) { |
| 12 | const bundle = readAsset(assetName, compiler, stats); |
| 13 | const virtualConsole = new jsdom.VirtualConsole(); |
| 14 | |
| 15 | virtualConsole.sendTo(console); |
| 16 | |
| 17 | const dom = new jsdom.JSDOM( |
| 18 | `<!doctype html> |
| 19 | <html> |
| 20 | <head> |
| 21 | <title>style-loader test</title> |
| 22 | <style id="existing-style">.existing { color: yellow }</style> |
| 23 | </head> |
| 24 | <body> |
| 25 | <h1>Body</h1> |
| 26 | <div class="target"></div> |
| 27 | <iframe class='iframeTarget'></iframe> |
| 28 | </body> |
| 29 | </html> |
| 30 | `, |
| 31 | { |
| 32 | resources: "usable", |
| 33 | runScripts: "dangerously", |
| 34 | virtualConsole, |
| 35 | }, |
| 36 | ); |
| 37 | |
| 38 | dom.window.eval(bundle); |
| 39 | |
| 40 | testFn(dom, bundle); |
| 41 | |
| 42 | // free memory associated with the window |
| 43 | dom.window.close(); |
| 44 | } |
| 45 | |
| 46 | export default runInJsDom; |
no test coverage detected
searching dependent graphs…