generated from maxwroc/typescript-project-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jest-setup.ts
57 lines (45 loc) · 1.52 KB
/
jest-setup.ts
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
45
46
47
48
49
50
51
52
53
54
55
56
57
import { readFileSync } from "fs";
export const setupTest = async () => {
page.on('pageerror', ({ message }) => console.log(message));
await page.setViewport({
width: 640,
height: 480,
deviceScaleFactor: 1,
});
await page.setContent(testPageHtml, { waitUntil: "load" });
await page.evaluate(() => {
(<any>window)["testSonjPlugins"] = [];
});
}
export const initPageAndReturnViewerElem = async (data: any, additionalSetup?: { (data: any, ...params: any[]): void }, ...params: any[]) => {
if (additionalSetup) {
params = params || [];
params.unshift(additionalSetup, data);
await page.evaluate.apply(page, <any>params);
}
await page.evaluate((dataInternal: any) => {
// plugin for adding unique IDs on each node
const addNodeIds: SonjReview.IPlugin = {
afterRender: context => {
context.node.header.elem!.setAttribute("id", context.node.path.join("-"));
}
}
testSonjPlugins.push(addNodeIds);
const viewer = new SonjReview.JsonViewer(dataInternal, "root", testSonjPlugins);
viewer.render("viewer");
}, data);
return await page.$("#viewer");
}
const sonj = readFileSync("./dist/sonj-review.js");
const testPageHtml = `
<!DOCTYPE html>
<html>
<head>
<title>Test page</title>
<script type="text/javascript">${sonj}</script>
</head>
<body>
<div id="viewer" style="display: inline-block; padding: 5px;"></div>
</body>
</html>
`;