html-browser-tester 0.0.20 → 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser-test.d.ts +2 -0
- package/lib/browser-test.js +9 -2
- package/package.json +1 -1
package/lib/browser-test.d.ts
CHANGED
@@ -18,6 +18,7 @@ export declare class BrowserTester {
|
|
18
18
|
private iframe;
|
19
19
|
private tests;
|
20
20
|
private expects;
|
21
|
+
private setups;
|
21
22
|
private beforeAllCallbacks;
|
22
23
|
private afterAllCallbacks;
|
23
24
|
private beforeEachCallbacks;
|
@@ -25,6 +26,7 @@ export declare class BrowserTester {
|
|
25
26
|
constructor({ html, url, width, height, }: Option);
|
26
27
|
spyOn<T extends string>(obj: Record<T, Function>, key: T): Spy<T>;
|
27
28
|
setBrowserSize(width: number, height: number): void;
|
29
|
+
setup(callback: (window: Window, doc: Document) => Promise<void>): void;
|
28
30
|
beforeAll(callback: (window: Window, doc: Document) => Promise<void>): void;
|
29
31
|
afterAll(callback: (window: Window, doc: Document) => Promise<void>): void;
|
30
32
|
beforeEach(callback: (window: Window, doc: Document) => Promise<void>): void;
|
package/lib/browser-test.js
CHANGED
@@ -11,6 +11,7 @@ class BrowserTester {
|
|
11
11
|
iframe;
|
12
12
|
tests = [];
|
13
13
|
expects = new expect_1.Expect();
|
14
|
+
setups = [];
|
14
15
|
beforeAllCallbacks = [];
|
15
16
|
afterAllCallbacks = [];
|
16
17
|
beforeEachCallbacks = [];
|
@@ -36,6 +37,9 @@ class BrowserTester {
|
|
36
37
|
this.iframe.height = `${height}px`;
|
37
38
|
}
|
38
39
|
}
|
40
|
+
setup(callback) {
|
41
|
+
this.setups.push(callback);
|
42
|
+
}
|
39
43
|
beforeAll(callback) {
|
40
44
|
this.beforeAllCallbacks.push(callback);
|
41
45
|
}
|
@@ -68,8 +72,8 @@ class BrowserTester {
|
|
68
72
|
this.tests = [];
|
69
73
|
}
|
70
74
|
evaluate(code, args = {}) {
|
71
|
-
const func = new Function('test', 'it', 'expect', 'beforeEach', 'afterEach', 'beforeAll', 'afterAll', 'setBrowserSize', 'spyOn', ...Object.keys(args), code);
|
72
|
-
func(this.test.bind(this), this.it.bind(this), this.expect.bind(this), this.beforeEach.bind(this), this.afterEach.bind(this), this.beforeAll.bind(this), this.afterAll.bind(this), this.setBrowserSize.bind(this), this.spyOn, ...Object.values(args));
|
75
|
+
const func = new Function('test', 'it', 'expect', 'beforeEach', 'afterEach', 'beforeAll', 'afterAll', 'setup', 'setBrowserSize', 'spyOn', ...Object.keys(args), code);
|
76
|
+
func(this.test.bind(this), this.it.bind(this), this.expect.bind(this), this.beforeEach.bind(this), this.afterEach.bind(this), this.beforeAll.bind(this), this.afterAll.bind(this), this.setup.bind(this), this.setBrowserSize.bind(this), this.spyOn, ...Object.values(args));
|
73
77
|
}
|
74
78
|
run() {
|
75
79
|
return new Promise((resolve) => {
|
@@ -91,6 +95,9 @@ class BrowserTester {
|
|
91
95
|
const iframeCallback = async () => {
|
92
96
|
iframe.removeEventListener('load', iframeCallback);
|
93
97
|
const results = [];
|
98
|
+
for (const s of this.setups) {
|
99
|
+
await s(iframe.contentWindow, iframe.contentDocument);
|
100
|
+
}
|
94
101
|
for (const b of this.beforeAllCallbacks) {
|
95
102
|
await b(iframe.contentWindow, iframe.contentDocument);
|
96
103
|
}
|