@luma.gl/test-utils 9.0.0-alpha.8 → 9.0.0-beta.1
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/LICENSE +3 -1
- package/dist/check-type.js +0 -1
- package/dist/check-type.js.map +1 -1
- package/dist/create-test-device.d.ts +8 -4
- package/dist/create-test-device.d.ts.map +1 -1
- package/dist/create-test-device.js +26 -13
- package/dist/create-test-device.js.map +1 -1
- package/dist/engine/classic-animation-loop.d.ts +135 -0
- package/dist/engine/classic-animation-loop.d.ts.map +1 -0
- package/dist/engine/classic-animation-loop.js +434 -0
- package/dist/engine/classic-animation-loop.js.map +1 -0
- package/dist/index.cjs +828 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/performance-test-runner.d.ts +7 -6
- package/dist/performance-test-runner.d.ts.map +1 -1
- package/dist/performance-test-runner.js +10 -22
- package/dist/performance-test-runner.js.map +1 -1
- package/dist/register-devices.js +1 -1
- package/dist/register-devices.js.map +1 -1
- package/dist/snapshot-test-runner.d.ts +11 -7
- package/dist/snapshot-test-runner.d.ts.map +1 -1
- package/dist/snapshot-test-runner.js +23 -29
- package/dist/snapshot-test-runner.js.map +1 -1
- package/dist/test-runner.d.ts +35 -23
- package/dist/test-runner.d.ts.map +1 -1
- package/dist/test-runner.js +62 -81
- package/dist/test-runner.js.map +1 -1
- package/dist/utils.d.ts +5 -5
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +28 -8
- package/src/check-type.ts +1 -1
- package/src/create-test-device.ts +28 -9
- package/src/engine/classic-animation-loop.ts +714 -0
- package/src/index.ts +3 -3
- package/src/performance-test-runner.ts +17 -13
- package/src/register-devices.ts +2 -1
- package/src/snapshot-test-runner.ts +33 -31
- package/src/test-runner.ts +100 -75
- package/src/utils.ts +1 -1
package/src/index.ts
CHANGED
|
@@ -3,9 +3,9 @@ import './register-devices';
|
|
|
3
3
|
export type {TestRunnerTestCase} from './test-runner';
|
|
4
4
|
export type {SnapshotTestRunnerTestCase} from './snapshot-test-runner';
|
|
5
5
|
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {createTestDevice, createTestContext,
|
|
6
|
+
export {SnapshotTestRunner} from './snapshot-test-runner';
|
|
7
|
+
export {PerformanceTestRunner} from './performance-test-runner';
|
|
8
|
+
export {createTestDevice, createTestContext, webgl1Device, webgl2Device, webgpuDevice} from './create-test-device';
|
|
9
9
|
export {getTestDevices, getWebGLTestDevices} from './create-test-device';
|
|
10
10
|
|
|
11
11
|
export {checkType} from './check-type';
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
// luma.gl, MIT license
|
|
2
|
+
// Copyright (c) vis.gl contributors
|
|
3
|
+
|
|
1
4
|
import {Stats, Stat} from '@probe.gl/stats';
|
|
2
|
-
import TestRunner,
|
|
5
|
+
import {TestRunner, TestRunnerProps, TestRunnerTestCase} from './test-runner';
|
|
6
|
+
|
|
7
|
+
export type PerformanceTestRunnerProps = TestRunnerProps;
|
|
3
8
|
|
|
4
|
-
export
|
|
5
|
-
private _stats: Stats;
|
|
6
|
-
private _fps: Stat;
|
|
9
|
+
export class PerformanceTestRunner extends TestRunner {
|
|
10
|
+
private _stats: Stats | null = null;
|
|
11
|
+
private _fps: Stat | null = null;
|
|
7
12
|
|
|
8
|
-
constructor(props:
|
|
13
|
+
constructor(props: PerformanceTestRunnerProps) {
|
|
9
14
|
super(props);
|
|
10
15
|
|
|
11
16
|
Object.assign(this.testOptions, {
|
|
@@ -14,17 +19,16 @@ export default class PerformanceTestRunner extends TestRunner {
|
|
|
14
19
|
});
|
|
15
20
|
}
|
|
16
21
|
|
|
17
|
-
initTestCase(testCase) {
|
|
22
|
+
override initTestCase(testCase: TestRunnerTestCase): void {
|
|
18
23
|
super.initTestCase(testCase);
|
|
19
24
|
this._stats = new Stats({id: testCase.name});
|
|
20
25
|
this._fps = this._stats.get('fps');
|
|
21
26
|
}
|
|
22
27
|
|
|
23
|
-
shouldRender(animationProps) {
|
|
24
|
-
this._fps
|
|
25
|
-
this._fps
|
|
28
|
+
override shouldRender(animationProps: Record<string, any>): boolean {
|
|
29
|
+
this._fps?.timeEnd();
|
|
30
|
+
this._fps?.timeStart();
|
|
26
31
|
|
|
27
|
-
// @ts-expect-error
|
|
28
32
|
if (this._fps.count > this.testOptions.maxFramesToRender) {
|
|
29
33
|
animationProps.done();
|
|
30
34
|
}
|
|
@@ -32,11 +36,11 @@ export default class PerformanceTestRunner extends TestRunner {
|
|
|
32
36
|
return true;
|
|
33
37
|
}
|
|
34
38
|
|
|
35
|
-
assert(testCase) {
|
|
39
|
+
override assert(testCase: TestRunnerTestCase): void {
|
|
36
40
|
// @ts-expect-error
|
|
37
41
|
const targetFPS = testCase.targetFPS || this.testOptions.targetFPS;
|
|
38
|
-
const count = this._fps
|
|
39
|
-
const fps = this._fps
|
|
42
|
+
const count = this._fps?.count;
|
|
43
|
+
const fps = this._fps?.getHz() || 0;
|
|
40
44
|
|
|
41
45
|
if (fps >= targetFPS) {
|
|
42
46
|
this._pass({fps, framesRendered: count});
|
package/src/register-devices.ts
CHANGED
|
@@ -1,65 +1,67 @@
|
|
|
1
|
-
import TestRunner,
|
|
1
|
+
import {TestRunner, TestRunnerProps, TestRunnerTestCase} from './test-runner';
|
|
2
2
|
import {getBoundingBoxInPage} from './utils';
|
|
3
3
|
|
|
4
4
|
/** A snapshot test case */
|
|
5
5
|
export type SnapshotTestRunnerTestCase = TestRunnerTestCase & {
|
|
6
6
|
/** URL to golden image */
|
|
7
7
|
goldenImage: string;
|
|
8
|
+
/** Diff options */
|
|
9
|
+
imageDiffOptions?: {[key: string]: any};
|
|
8
10
|
}
|
|
9
11
|
|
|
10
|
-
export
|
|
11
|
-
private isDiffing: boolean = false;
|
|
12
|
+
export type SnapshotTestRunnerProps = TestRunnerProps;
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
export class SnapshotTestRunner extends TestRunner {
|
|
15
|
+
// should be defined here but hack access in TestRunner
|
|
16
|
+
// private isDiffing: boolean = false;
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
constructor(props: SnapshotTestRunnerProps) {
|
|
19
|
+
super(props);
|
|
17
20
|
this.testOptions.imageDiffOptions = {};
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
initTestCase(testCase) {
|
|
23
|
+
override initTestCase(testCase: SnapshotTestRunnerTestCase): void {
|
|
21
24
|
super.initTestCase(testCase);
|
|
22
25
|
if (!testCase.goldenImage) {
|
|
23
26
|
throw new Error(`Test case ${testCase.name} does not have golden image`);
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
29
|
|
|
27
|
-
shouldRender() {
|
|
30
|
+
override shouldRender(): boolean {
|
|
28
31
|
// wait for the current diffing to finish
|
|
29
32
|
return !this.isDiffing;
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
assert(testCase) {
|
|
35
|
+
override async assert(testCase: SnapshotTestRunnerTestCase): Promise<void> {
|
|
33
36
|
if (this.isDiffing) {
|
|
34
37
|
// Already performing diffing
|
|
35
38
|
return;
|
|
36
39
|
}
|
|
37
40
|
this.isDiffing = true;
|
|
38
41
|
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
const canvas = this._animationProps?.canvas;
|
|
43
|
+
if (!(canvas instanceof HTMLCanvasElement)) {
|
|
44
|
+
throw new Error('canvas');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const diffOptions = {
|
|
48
|
+
...this.testOptions.imageDiffOptions,
|
|
49
|
+
...testCase.imageDiffOptions,
|
|
50
|
+
goldenImage: testCase.goldenImage,
|
|
51
|
+
region: getBoundingBoxInPage(canvas)
|
|
52
|
+
};
|
|
50
53
|
|
|
51
54
|
// Take screenshot and compare
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
const result = await globalThis.browserTestDriver_captureAndDiffScreen(diffOptions);
|
|
56
|
+
|
|
57
|
+
// invoke user callback
|
|
58
|
+
if (result.success) {
|
|
59
|
+
this._pass(result);
|
|
60
|
+
} else {
|
|
61
|
+
this._fail(result);
|
|
62
|
+
}
|
|
60
63
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
+
this.isDiffing = false;
|
|
65
|
+
this._next();
|
|
64
66
|
}
|
|
65
67
|
}
|
package/src/test-runner.ts
CHANGED
|
@@ -1,58 +1,78 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
/* eslint-disable
|
|
3
|
-
|
|
4
|
-
import {
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
import {AnimationProps} from '@luma.gl/engine';
|
|
5
|
+
import {webglDevice} from './create-test-device';
|
|
6
|
+
|
|
7
|
+
// TODO - Replace with new AnimationLoop from `@luma.gl/engine`
|
|
8
|
+
import {ClassicAnimationLoop as AnimationLoop} from './engine/classic-animation-loop';
|
|
5
9
|
|
|
6
10
|
/** Describes a test case */
|
|
7
11
|
export type TestRunnerTestCase = {
|
|
8
12
|
/** Name of the test case (for logging) */
|
|
9
13
|
name: string;
|
|
10
14
|
/** Initialize the test case. Can return a promise */
|
|
11
|
-
onInitialize:
|
|
15
|
+
onInitialize: (props: AnimationProps) => Promise<void | {}>;
|
|
12
16
|
/** Perform rendering */
|
|
13
|
-
onRender:
|
|
17
|
+
onRender: (props: AnimationProps & {done}) => void;
|
|
14
18
|
/** Clean up after the test case */
|
|
15
|
-
onFinalize:
|
|
19
|
+
onFinalize: (props: AnimationProps) => void;
|
|
20
|
+
animationLoop?: AnimationLoop;
|
|
16
21
|
};
|
|
17
22
|
|
|
18
|
-
function noop() {}
|
|
19
|
-
|
|
20
23
|
const DEFAULT_TEST_CASE: TestRunnerTestCase = {
|
|
21
24
|
name: 'Unnamed test',
|
|
22
|
-
onInitialize:
|
|
25
|
+
onInitialize: async () => {},
|
|
23
26
|
onRender: ({done}) => done(),
|
|
24
|
-
onFinalize:
|
|
27
|
+
onFinalize: () => {}
|
|
25
28
|
};
|
|
26
29
|
|
|
27
30
|
/** Options for a TestRunner */
|
|
28
|
-
export type
|
|
31
|
+
export type TestRunnerProps = {
|
|
32
|
+
width?: number;
|
|
33
|
+
height?: number;
|
|
29
34
|
// test lifecycle callback
|
|
30
|
-
onTestStart?:
|
|
31
|
-
onTestPass?:
|
|
32
|
-
onTestFail?:
|
|
33
|
-
|
|
35
|
+
onTestStart?: (testCase: TestRunnerTestCase) => void;
|
|
36
|
+
onTestPass?: (testCase: TestRunnerTestCase, result?: unknown) => void;
|
|
37
|
+
onTestFail?: (testCase: TestRunnerTestCase, error?: unknown) => void;
|
|
34
38
|
/** milliseconds to wait for each test case before aborting */
|
|
35
39
|
timeout?: number;
|
|
40
|
+
maxFramesToRender?: number;
|
|
41
|
+
// HACK - this is for the snapshot test runner
|
|
42
|
+
imageDiffOptions?: any;
|
|
36
43
|
};
|
|
37
44
|
|
|
38
|
-
const
|
|
45
|
+
const DEFAULT_TEST_PROPS: Required<TestRunnerProps> = {
|
|
46
|
+
width: undefined,
|
|
47
|
+
height: undefined,
|
|
48
|
+
|
|
39
49
|
// test lifecycle callback
|
|
40
|
-
onTestStart: (testCase) => console.log(`# ${testCase.name}`),
|
|
41
|
-
onTestPass: (testCase) => console.log(`ok ${testCase.name} passed`),
|
|
42
|
-
onTestFail: (testCase) => console.log(`not ok ${testCase.name} failed`),
|
|
50
|
+
onTestStart: (testCase: TestRunnerTestCase) => console.log(`# ${testCase.name}`),
|
|
51
|
+
onTestPass: (testCase: TestRunnerTestCase, result?: unknown) => console.log(`ok ${testCase.name} passed`),
|
|
52
|
+
onTestFail: (testCase: TestRunnerTestCase, error?: unknown) => console.log(`not ok ${testCase.name} failed`),
|
|
43
53
|
|
|
44
54
|
// milliseconds to wait for each test case before aborting
|
|
45
|
-
timeout: 2000
|
|
55
|
+
timeout: 2000,
|
|
56
|
+
maxFramesToRender: undefined,
|
|
57
|
+
imageDiffOptions: undefined
|
|
46
58
|
};
|
|
47
59
|
|
|
48
60
|
/** Runs an array of test cases */
|
|
49
|
-
export
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
61
|
+
export class TestRunner {
|
|
62
|
+
device = webglDevice;
|
|
63
|
+
props: Record<string, any>;
|
|
64
|
+
isRunning: boolean = false;
|
|
65
|
+
testOptions: Required<TestRunnerProps> = {...DEFAULT_TEST_PROPS};
|
|
66
|
+
readonly _animationProps?: AnimationProps;
|
|
67
|
+
private _animationLoop: AnimationLoop | null;
|
|
54
68
|
private _testCases: TestRunnerTestCase[] = [];
|
|
55
|
-
private _testCaseData = null;
|
|
69
|
+
private _testCaseData: any = null;
|
|
70
|
+
private _currentTestCase: TestRunnerTestCase | null;
|
|
71
|
+
private _currentTestCaseStartTime: number;
|
|
72
|
+
private _currentTestCaseStartTick: number;
|
|
73
|
+
|
|
74
|
+
// should be defined in snapshot-test-runner
|
|
75
|
+
isDiffing: boolean = false;
|
|
56
76
|
|
|
57
77
|
// @ts-expect-error
|
|
58
78
|
isHeadless: boolean = Boolean(window.browserTestDriver_isHeadless);
|
|
@@ -61,17 +81,14 @@ export default class TestRunner {
|
|
|
61
81
|
* props
|
|
62
82
|
* AnimationLoop props
|
|
63
83
|
*/
|
|
64
|
-
constructor(props = {}) {
|
|
84
|
+
constructor(props: Record<string, any> = {}) {
|
|
65
85
|
this.props = props;
|
|
66
86
|
}
|
|
67
87
|
|
|
68
88
|
/**
|
|
69
89
|
* Add testCase(s)
|
|
70
90
|
*/
|
|
71
|
-
|
|
72
|
-
* Add testCase(s)
|
|
73
|
-
*/
|
|
74
|
-
add(testCases: TestRunnerTestCase[]): this {
|
|
91
|
+
add(testCases: TestRunnerTestCase[]): this {
|
|
75
92
|
if (!Array.isArray(testCases)) {
|
|
76
93
|
testCases = [testCases];
|
|
77
94
|
}
|
|
@@ -81,75 +98,75 @@ export default class TestRunner {
|
|
|
81
98
|
return this;
|
|
82
99
|
}
|
|
83
100
|
|
|
84
|
-
|
|
101
|
+
/**
|
|
85
102
|
* Returns a promise that resolves when all the test cases are done
|
|
86
103
|
*/
|
|
87
104
|
run(options: object = {}): Promise<void> {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return new Promise<void>(resolve => {
|
|
91
|
-
this._animationLoop = new AnimationLoop(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
);
|
|
105
|
+
this.testOptions = {...this.testOptions, ...options};
|
|
106
|
+
|
|
107
|
+
return new Promise<void>((resolve, reject) => {
|
|
108
|
+
this._animationLoop = new AnimationLoop({
|
|
109
|
+
...this.props,
|
|
110
|
+
device: this.device,
|
|
111
|
+
onRender: this._onRender.bind(this),
|
|
112
|
+
onFinalize: () => {
|
|
113
|
+
this.isRunning = false;
|
|
114
|
+
resolve();
|
|
115
|
+
}
|
|
116
|
+
});
|
|
101
117
|
this._animationLoop.start(this.props);
|
|
102
118
|
|
|
103
119
|
this.isRunning = true;
|
|
104
120
|
this.isDiffing = false;
|
|
105
121
|
this._currentTestCase = null;
|
|
106
|
-
}).catch(
|
|
122
|
+
}).catch (error => {
|
|
107
123
|
this._fail({error: error.message});
|
|
124
|
+
// reject(error);
|
|
108
125
|
});
|
|
109
126
|
}
|
|
110
127
|
|
|
111
128
|
/* Lifecycle methods for subclassing */
|
|
112
129
|
|
|
113
|
-
initTestCase(testCase) {
|
|
130
|
+
initTestCase(testCase: TestRunnerTestCase) {
|
|
114
131
|
const {animationLoop} = testCase;
|
|
115
132
|
if (animationLoop) {
|
|
116
|
-
testCase.onInitialize = animationLoop.onInitialize.bind(animationLoop);
|
|
117
|
-
testCase.onRender = animationLoop.onRender.bind(animationLoop);
|
|
118
|
-
testCase.onFinalize = animationLoop.onFinalize.bind(animationLoop);
|
|
133
|
+
testCase.onInitialize = animationLoop.props.onInitialize.bind(animationLoop);
|
|
134
|
+
testCase.onRender = animationLoop.props.onRender.bind(animationLoop);
|
|
135
|
+
testCase.onFinalize = animationLoop.props.onFinalize.bind(animationLoop);
|
|
119
136
|
}
|
|
120
137
|
for (const key in DEFAULT_TEST_CASE) {
|
|
121
138
|
testCase[key] = testCase[key] || DEFAULT_TEST_CASE[key];
|
|
122
139
|
}
|
|
123
140
|
}
|
|
124
141
|
|
|
125
|
-
shouldRender(animationProps) {
|
|
142
|
+
shouldRender(animationProps): boolean {
|
|
126
143
|
return true;
|
|
127
144
|
}
|
|
128
145
|
|
|
129
|
-
assert(testCase) {
|
|
146
|
+
assert(testCase: TestRunnerTestCase): void {
|
|
130
147
|
this._pass(testCase);
|
|
131
148
|
this._next();
|
|
132
149
|
}
|
|
133
150
|
|
|
134
151
|
/* Utilities */
|
|
135
152
|
|
|
136
|
-
_pass(result) {
|
|
137
|
-
// @ts-expect-error
|
|
153
|
+
_pass(result: unknown): void {
|
|
138
154
|
this.testOptions.onTestPass(this._currentTestCase, result);
|
|
155
|
+
// this._animationLoop?.stop();
|
|
139
156
|
}
|
|
140
157
|
|
|
141
|
-
_fail(result) {
|
|
142
|
-
// @ts-expect-error
|
|
158
|
+
_fail(result: unknown): void {
|
|
143
159
|
this.testOptions.onTestFail(this._currentTestCase, result);
|
|
160
|
+
// this._animationLoop?.stop();
|
|
144
161
|
}
|
|
145
162
|
|
|
146
|
-
_next() {
|
|
163
|
+
_next(): void {
|
|
147
164
|
this._nextTestCase();
|
|
148
165
|
}
|
|
149
166
|
|
|
150
167
|
/* Private methods */
|
|
151
168
|
|
|
152
|
-
_onRender(animationProps) {
|
|
169
|
+
_onRender(animationProps): void {
|
|
153
170
|
this._animationProps = animationProps;
|
|
154
171
|
|
|
155
172
|
const testCase = this._currentTestCase || this._nextTestCase();
|
|
@@ -160,7 +177,9 @@ export default class TestRunner {
|
|
|
160
177
|
}
|
|
161
178
|
|
|
162
179
|
let isDone = false;
|
|
163
|
-
const testCaseAnimationProps =
|
|
180
|
+
const testCaseAnimationProps: AnimationProps = {
|
|
181
|
+
...animationProps,
|
|
182
|
+
...this._testCaseData,
|
|
164
183
|
// tick/time starts from 0 for each test case
|
|
165
184
|
startTime: this._currentTestCaseStartTime,
|
|
166
185
|
time: animationProps.time - this._currentTestCaseStartTime,
|
|
@@ -169,11 +188,15 @@ export default class TestRunner {
|
|
|
169
188
|
done: () => {
|
|
170
189
|
isDone = true;
|
|
171
190
|
}
|
|
172
|
-
}
|
|
191
|
+
};
|
|
173
192
|
|
|
174
193
|
if (this._testCaseData && this.shouldRender(testCaseAnimationProps)) {
|
|
194
|
+
// try {
|
|
175
195
|
// test case is initialized, render frame
|
|
176
196
|
testCase.onRender(testCaseAnimationProps);
|
|
197
|
+
// } catch {
|
|
198
|
+
// isDone = true;
|
|
199
|
+
// }
|
|
177
200
|
}
|
|
178
201
|
|
|
179
202
|
const timeout = testCase.timeout || this.testOptions.timeout;
|
|
@@ -186,7 +209,7 @@ export default class TestRunner {
|
|
|
186
209
|
}
|
|
187
210
|
}
|
|
188
211
|
|
|
189
|
-
_nextTestCase() {
|
|
212
|
+
_nextTestCase(): Promise<TestRunnerTestCase> {
|
|
190
213
|
const animationProps = this._animationProps;
|
|
191
214
|
|
|
192
215
|
// finalize the current test case
|
|
@@ -194,13 +217,13 @@ export default class TestRunner {
|
|
|
194
217
|
for (const key in this._testCaseData) {
|
|
195
218
|
const value = this._testCaseData[key];
|
|
196
219
|
if (value && value.delete) {
|
|
197
|
-
value.
|
|
220
|
+
value.destroy();
|
|
198
221
|
}
|
|
199
222
|
}
|
|
200
223
|
this._currentTestCase.onFinalize(Object.assign({}, animationProps, this._testCaseData));
|
|
201
224
|
|
|
202
225
|
// reset WebGL context
|
|
203
|
-
|
|
226
|
+
this.device.popState();
|
|
204
227
|
|
|
205
228
|
this._currentTestCase = null;
|
|
206
229
|
this._testCaseData = null;
|
|
@@ -218,22 +241,24 @@ export default class TestRunner {
|
|
|
218
241
|
// initialize test case
|
|
219
242
|
|
|
220
243
|
// save WebGL context
|
|
221
|
-
|
|
244
|
+
this.device.pushState();
|
|
222
245
|
|
|
223
246
|
// aligned with the behavior of AnimationLoop.onInitialized
|
|
224
247
|
// onInitialized could return a plain object or a promise
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
248
|
+
const initProps = {
|
|
249
|
+
...animationProps,
|
|
250
|
+
// tick/time starts from 0 for each test case
|
|
251
|
+
startTime: animationProps.time,
|
|
252
|
+
time: 0,
|
|
253
|
+
tick: 0
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// aligned with the behavior of AnimationLoop.onInitialized
|
|
257
|
+
// onInitialized could return a plain object or a promise
|
|
258
|
+
Promise.resolve(testCase.onInitialize(initProps)).then((userData) => {
|
|
235
259
|
this._testCaseData = userData || {};
|
|
236
260
|
});
|
|
261
|
+
|
|
237
262
|
// invoke user callback
|
|
238
263
|
this.testOptions.onTestStart(testCase);
|
|
239
264
|
}
|
package/src/utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Get the bounding box of a DOMElement relative to the page
|
|
2
|
-
export function getBoundingBoxInPage(domElement) {
|
|
2
|
+
export function getBoundingBoxInPage(domElement: HTMLElement): {x: number; y: number; width: number; height: number;} {
|
|
3
3
|
const bbox = domElement.getBoundingClientRect();
|
|
4
4
|
return {
|
|
5
5
|
x: window.scrollX + bbox.x,
|