-
-
Notifications
You must be signed in to change notification settings - Fork 384
/
Copy pathrunInJsDom.js
44 lines (36 loc) · 868 Bytes
/
runInJsDom.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import jsdom from "jsdom";
import { readAsset } from "./index";
function runInJsDom(assetName, compiler, stats, testFn) {
const bundle = readAsset(assetName, compiler, stats);
const virtualConsole = new jsdom.VirtualConsole();
virtualConsole.sendTo(console);
try {
const dom = new jsdom.JSDOM(
`<!doctype html>
<html>
<head>
<title>style-loader test</title>
<style id="existing-style">.existing { color: yellow }</style>
</head>
<body>
<h1>Body</h1>
<div class="target"></div>
<iframe class='iframeTarget'></iframe>
</body>
</html>
`,
{
resources: "usable",
runScripts: "dangerously",
virtualConsole,
}
);
dom.window.eval(bundle);
testFn(dom, bundle);
// free memory associated with the window
dom.window.close();
} catch (e) {
throw e;
}
}
export default runInJsDom;