@luma.gl/test-utils 8.6.0-alpha.5 → 9.0.0-alpha.10
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/dist/check-type.d.ts +6 -0
- package/dist/check-type.d.ts.map +1 -0
- package/dist/check-type.js +3 -0
- package/dist/check-type.js.map +1 -0
- package/dist/create-test-device.d.ts +15 -4
- package/dist/create-test-device.d.ts.map +1 -1
- package/dist/create-test-device.js +46 -9
- package/dist/create-test-device.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/performance-test-runner.d.ts +4 -4
- package/dist/performance-test-runner.d.ts.map +1 -1
- package/dist/performance-test-runner.js +9 -7
- package/dist/performance-test-runner.js.map +1 -1
- package/dist/register-devices.d.ts +2 -0
- package/dist/register-devices.d.ts.map +1 -0
- package/dist/register-devices.js +7 -0
- package/dist/register-devices.js.map +1 -0
- package/dist/snapshot-test-runner.d.ts +6 -1
- package/dist/snapshot-test-runner.d.ts.map +1 -1
- package/dist/snapshot-test-runner.js.map +1 -1
- package/dist/test-runner.d.ts +9 -0
- package/dist/test-runner.d.ts.map +1 -1
- package/dist/test-runner.js +4 -3
- 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 +9 -6
- package/src/check-type.ts +6 -0
- package/src/create-test-device.ts +53 -17
- package/src/index.ts +9 -3
- package/src/performance-test-runner.ts +12 -10
- package/src/register-devices.ts +10 -0
- package/src/snapshot-test-runner.ts +6 -1
- package/src/test-runner.ts +12 -7
- package/src/utils.ts +1 -1
- package/dist/create-headless-context.d.ts +0 -2
- package/dist/create-headless-context.d.ts.map +0 -1
- package/dist/create-headless-context.js +0 -37
- package/dist/create-headless-context.js.map +0 -1
- package/dist/create-test-context.d.ts +0 -2
- package/dist/create-test-context.d.ts.map +0 -1
- package/dist/create-test-context.js +0 -6
- package/dist/create-test-context.js.map +0 -1
- package/src/create-headless-context.ts +0 -36
- package/src/create-test-context.ts +0 -29
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-type.d.ts","sourceRoot":"","sources":["../src/check-type.ts"],"names":[],"mappings":"AACA;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/check-type.ts"],"names":["checkType","value"],"mappings":"AAKA,OAAO,SAASA,SAAT,CAAsBC,KAAtB,EAAsC,CAAE;AAAA","sourcesContent":["\n/**\n * Tests that an argument matches the type.\n * @note fails during typescript type check, not during runtime.\n */\nexport function checkType<T>(value: T): void {};\n"],"file":"check-type.js"}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { Device, DeviceProps } from '@luma.gl/api';
|
|
2
|
+
import { WebGLDevice } from '@luma.gl/webgl';
|
|
3
|
+
import { WebGPUDevice } from '@luma.gl/webgpu';
|
|
4
|
+
/** Create a test WebGL context */
|
|
5
|
+
export declare function createTestContext(opts?: Record<string, any>): WebGLRenderingContext | null;
|
|
6
|
+
/** Create a test WebGLDevice */
|
|
7
|
+
export declare function createTestDevice(props?: DeviceProps): WebGLDevice | null;
|
|
8
|
+
export declare const webgl1Device: WebGLDevice;
|
|
9
|
+
export declare const webgl2Device: WebGLDevice;
|
|
10
|
+
/** Only available after getTestDevices() has completed */
|
|
11
|
+
export declare let webgpuDevice: WebGPUDevice;
|
|
12
|
+
/** Synchronously get test devices (only WebGLDevices) */
|
|
13
|
+
export declare function getWebGLTestDevices(): WebGLDevice[];
|
|
14
|
+
/** Includes WebGPU device if available */
|
|
15
|
+
export declare function getTestDevices(): Promise<Device[]>;
|
|
5
16
|
//# sourceMappingURL=create-test-device.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-test-device.d.ts","sourceRoot":"","sources":["../src/create-test-device.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-test-device.d.ts","sourceRoot":"","sources":["../src/create-test-device.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,MAAM,EAAE,WAAW,EAAC,MAAM,cAAc,CAAC;AAEtD,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAQ7C,kCAAkC;AAClC,wBAAgB,iBAAiB,CAAC,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,qBAAqB,GAAG,IAAI,CAG9F;AAED,gCAAgC;AAChC,wBAAgB,gBAAgB,CAAC,KAAK,GAAE,WAAgB,GAAG,WAAW,GAAG,IAAI,CAS5E;AAED,eAAO,MAAM,YAAY,EAAE,WAAuF,CAAC;AACnH,eAAO,MAAM,YAAY,EAAE,WAAuF,CAAC;AACnH,0DAA0D;AAC1D,eAAO,IAAI,YAAY,EAAE,YAAY,CAAC;AAItC,yDAAyD;AACzD,wBAAgB,mBAAmB,IAAI,WAAW,EAAE,CASnD;AAED,0CAA0C;AAC1C,wBAAsB,cAAc,IAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAezD"}
|
|
@@ -1,32 +1,69 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { luma } from '@luma.gl/api';
|
|
2
2
|
import { WebGLDevice } from '@luma.gl/webgl';
|
|
3
|
-
import { createHeadlessContext } from './create-headless-context';
|
|
4
|
-
const ERR_HEADLESSGL_FAILED = 'Failed to create WebGL context in Node.js, headless gl returned null';
|
|
5
|
-
const ERR_HEADLESSGL_LOAD = " luma.gl: loaded under Node.js without headless gl installed, meaning that WebGL contexts can not be created. This may not be an error. For example, this is a typical configuration for isorender applications running on the server.";
|
|
6
3
|
const CONTEXT_DEFAULTS = {
|
|
7
4
|
width: 1,
|
|
8
5
|
height: 1,
|
|
9
6
|
debug: true
|
|
10
7
|
};
|
|
8
|
+
export function createTestContext(opts = {}) {
|
|
9
|
+
const device = createTestDevice(opts);
|
|
10
|
+
return device && device.gl;
|
|
11
|
+
}
|
|
11
12
|
export function createTestDevice(props = {}) {
|
|
12
13
|
try {
|
|
13
|
-
const gl = !isBrowser() ? createHeadlessContext(props) : undefined;
|
|
14
14
|
props = { ...CONTEXT_DEFAULTS,
|
|
15
15
|
...props,
|
|
16
|
-
|
|
16
|
+
debug: true
|
|
17
17
|
};
|
|
18
18
|
return new WebGLDevice(props);
|
|
19
19
|
} catch (error) {
|
|
20
|
-
console.error(error.message);
|
|
20
|
+
console.error("Failed to created device '".concat(props.id, "': ").concat(error.message));
|
|
21
21
|
return null;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
export const
|
|
24
|
+
export const webgl1Device = createTestDevice({
|
|
25
|
+
id: 'webgl1-test-device',
|
|
25
26
|
webgl1: true,
|
|
26
27
|
webgl2: false
|
|
27
28
|
});
|
|
28
|
-
export const
|
|
29
|
+
export const webgl2Device = createTestDevice({
|
|
30
|
+
id: 'webgl2-test-device',
|
|
29
31
|
webgl1: false,
|
|
30
32
|
webgl2: true
|
|
31
33
|
});
|
|
34
|
+
export let webgpuDevice;
|
|
35
|
+
let webgpuCreated = false;
|
|
36
|
+
export function getWebGLTestDevices() {
|
|
37
|
+
const devices = [];
|
|
38
|
+
|
|
39
|
+
if (webgl2Device) {
|
|
40
|
+
devices.push(webgl2Device);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (webgl1Device) {
|
|
44
|
+
devices.push(webgl1Device);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return devices;
|
|
48
|
+
}
|
|
49
|
+
export async function getTestDevices() {
|
|
50
|
+
if (!webgpuCreated) {
|
|
51
|
+
webgpuCreated = true;
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
webgpuDevice = await luma.createDevice({
|
|
55
|
+
id: 'webgpu-test-device',
|
|
56
|
+
type: 'webgpu'
|
|
57
|
+
});
|
|
58
|
+
} catch {}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const devices = getWebGLTestDevices();
|
|
62
|
+
|
|
63
|
+
if (webgpuDevice) {
|
|
64
|
+
devices.unshift(webgpuDevice);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return devices;
|
|
68
|
+
}
|
|
32
69
|
//# sourceMappingURL=create-test-device.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/create-test-device.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["../src/create-test-device.ts"],"names":["luma","WebGLDevice","CONTEXT_DEFAULTS","width","height","debug","createTestContext","opts","device","createTestDevice","gl","props","error","console","id","message","webgl1Device","webgl1","webgl2","webgl2Device","webgpuDevice","webgpuCreated","getWebGLTestDevices","devices","push","getTestDevices","createDevice","type","unshift"],"mappings":"AAGA,SAAQA,IAAR,QAAmB,cAAnB;AACA,SAAQC,WAAR,QAA0B,gBAA1B;AAGA,MAAMC,gBAAsC,GAAG;AAC7CC,EAAAA,KAAK,EAAE,CADsC;AAE7CC,EAAAA,MAAM,EAAE,CAFqC;AAG7CC,EAAAA,KAAK,EAAE;AAHsC,CAA/C;AAOA,OAAO,SAASC,iBAAT,CAA2BC,IAAyB,GAAG,EAAvD,EAAyF;AAC9F,QAAMC,MAAM,GAAGC,gBAAgB,CAACF,IAAD,CAA/B;AACA,SAAOC,MAAM,IAAIA,MAAM,CAACE,EAAxB;AACD;AAGD,OAAO,SAASD,gBAAT,CAA0BE,KAAkB,GAAG,EAA/C,EAAuE;AAC5E,MAAI;AACFA,IAAAA,KAAK,GAAG,EAAC,GAAGT,gBAAJ;AAAsB,SAAGS,KAAzB;AAAgCN,MAAAA,KAAK,EAAE;AAAvC,KAAR;AAEA,WAAO,IAAIJ,WAAJ,CAAgBU,KAAhB,CAAP;AACD,G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l, MIT license\n\nimport type {Device, DeviceProps} from '@luma.gl/api';\nimport {luma} from '@luma.gl/api';\nimport {WebGLDevice} from '@luma.gl/webgl';\nimport {WebGPUDevice} from '@luma.gl/webgpu';\n\nconst CONTEXT_DEFAULTS: Partial<DeviceProps> = {\n width: 1,\n height: 1,\n debug: true\n};\n\n/** Create a test WebGL context */\nexport function createTestContext(opts: Record<string, any> = {}): WebGLRenderingContext | null {\n const device = createTestDevice(opts);\n return device && device.gl;\n}\n\n/** Create a test WebGLDevice */\nexport function createTestDevice(props: DeviceProps = {}): WebGLDevice | null {\n try {\n props = {...CONTEXT_DEFAULTS, ...props, debug: true};\n // We dont use luma.createDevice since this tests current expect this context to be created synchronously\n return new WebGLDevice(props);\n } catch (error) {\n console.error(`Failed to created device '${props.id}': ${(error as Error).message}`);\n return null;\n }\n}\n\nexport const webgl1Device: WebGLDevice = createTestDevice({id: 'webgl1-test-device', webgl1: true, webgl2: false});\nexport const webgl2Device: WebGLDevice = createTestDevice({id: 'webgl2-test-device', webgl1: false, webgl2: true});\n/** Only available after getTestDevices() has completed */\nexport let webgpuDevice: WebGPUDevice;\n\nlet webgpuCreated = false;\n\n/** Synchronously get test devices (only WebGLDevices) */\nexport function getWebGLTestDevices(): WebGLDevice[] {\n const devices: WebGLDevice[] = [];\n if (webgl2Device) {\n devices.push(webgl2Device);\n }\n if (webgl1Device) {\n devices.push(webgl1Device);\n }\n return devices;\n}\n\n/** Includes WebGPU device if available */\nexport async function getTestDevices() : Promise<Device[]> {\n if (!webgpuCreated) {\n webgpuCreated = true;\n try {\n webgpuDevice = await luma.createDevice({id: 'webgpu-test-device', type: 'webgpu'}) as WebGPUDevice;\n } catch {\n // ignore (assume WebGPU was not available)\n }\n }\n\n const devices: Device[] = getWebGLTestDevices();\n if (webgpuDevice) {\n devices.unshift(webgpuDevice);\n }\n return devices;\n}\n"],"file":"create-test-device.js"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import './register-devices';
|
|
2
|
+
export type { TestRunnerTestCase } from './test-runner';
|
|
3
|
+
export type { SnapshotTestRunnerTestCase } from './snapshot-test-runner';
|
|
1
4
|
export { default as SnapshotTestRunner } from './snapshot-test-runner';
|
|
2
5
|
export { default as PerformanceTestRunner } from './performance-test-runner';
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
+
export { createTestDevice, createTestContext, webgl1Device, webgl2Device, webgpuDevice } from './create-test-device';
|
|
7
|
+
export { getTestDevices, getWebGLTestDevices } from './create-test-device';
|
|
8
|
+
export { checkType } from './check-type';
|
|
6
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAC;AAE5B,YAAY,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACtD,YAAY,EAAC,0BAA0B,EAAC,MAAM,wBAAwB,CAAC;AAEvE,OAAO,EAAC,OAAO,IAAI,kBAAkB,EAAC,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAC,OAAO,IAAI,qBAAqB,EAAC,MAAM,2BAA2B,CAAC;AAC3E,OAAO,EAAC,gBAAgB,EAAE,iBAAiB,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAC,MAAM,sBAAsB,CAAC;AACnH,OAAO,EAAC,cAAc,EAAE,mBAAmB,EAAC,MAAM,sBAAsB,CAAC;AAEzE,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import './register-devices';
|
|
1
2
|
export { default as SnapshotTestRunner } from './snapshot-test-runner';
|
|
2
3
|
export { default as PerformanceTestRunner } from './performance-test-runner';
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
4
|
+
export { createTestDevice, createTestContext, webgl1Device, webgl2Device, webgpuDevice } from './create-test-device';
|
|
5
|
+
export { getTestDevices, getWebGLTestDevices } from './create-test-device';
|
|
6
|
+
export { checkType } from './check-type';
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["default","SnapshotTestRunner","PerformanceTestRunner","
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["default","SnapshotTestRunner","PerformanceTestRunner","createTestDevice","createTestContext","webgl1Device","webgl2Device","webgpuDevice","getTestDevices","getWebGLTestDevices","checkType"],"mappings":"AAAA,OAAO,oBAAP;AAKA,SAAQA,OAAO,IAAIC,kBAAnB,QAA4C,wBAA5C;AACA,SAAQD,OAAO,IAAIE,qBAAnB,QAA+C,2BAA/C;AACA,SAAQC,gBAAR,EAA0BC,iBAA1B,EAA6CC,YAA7C,EAA2DC,YAA3D,EAAyEC,YAAzE,QAA4F,sBAA5F;AACA,SAAQC,cAAR,EAAwBC,mBAAxB,QAAkD,sBAAlD;AAEA,SAAQC,SAAR,QAAwB,cAAxB","sourcesContent":["import './register-devices';\n\nexport type {TestRunnerTestCase} from './test-runner';\nexport type {SnapshotTestRunnerTestCase} from './snapshot-test-runner';\n\nexport {default as SnapshotTestRunner} from './snapshot-test-runner';\nexport {default as PerformanceTestRunner} from './performance-test-runner';\nexport {createTestDevice, createTestContext, webgl1Device, webgl2Device, webgpuDevice} from './create-test-device';\nexport {getTestDevices, getWebGLTestDevices} from './create-test-device';\n\nexport {checkType} from './check-type';\n"],"file":"index.js"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import TestRunner, { TestRunnerOptions } from './test-runner';
|
|
1
|
+
import TestRunner, { TestRunnerOptions, TestRunnerTestCase } from './test-runner';
|
|
2
2
|
export default class PerformanceTestRunner extends TestRunner {
|
|
3
3
|
private _stats;
|
|
4
4
|
private _fps;
|
|
5
5
|
constructor(props: TestRunnerOptions);
|
|
6
|
-
initTestCase(testCase:
|
|
7
|
-
shouldRender(animationProps: any): boolean;
|
|
8
|
-
assert(testCase:
|
|
6
|
+
initTestCase(testCase: TestRunnerTestCase): void;
|
|
7
|
+
shouldRender(animationProps: Record<string, any>): boolean;
|
|
8
|
+
assert(testCase: TestRunnerTestCase): void;
|
|
9
9
|
}
|
|
10
10
|
//# sourceMappingURL=performance-test-runner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"performance-test-runner.d.ts","sourceRoot":"","sources":["../src/performance-test-runner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"performance-test-runner.d.ts","sourceRoot":"","sources":["../src/performance-test-runner.ts"],"names":[],"mappings":"AAGA,OAAO,UAAU,EAAE,EAAC,iBAAiB,EAAE,kBAAkB,EAAC,MAAM,eAAe,CAAC;AAEhF,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAAQ,UAAU;IAC3D,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,IAAI,CAAqB;gBAErB,KAAK,EAAE,iBAAiB;IASpC,YAAY,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI;IAMhD,YAAY,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO;IAY1D,MAAM,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI;CAa3C"}
|
|
@@ -5,9 +5,9 @@ export default class PerformanceTestRunner extends TestRunner {
|
|
|
5
5
|
constructor(props) {
|
|
6
6
|
super(props);
|
|
7
7
|
|
|
8
|
-
_defineProperty(this, "_stats",
|
|
8
|
+
_defineProperty(this, "_stats", null);
|
|
9
9
|
|
|
10
|
-
_defineProperty(this, "_fps",
|
|
10
|
+
_defineProperty(this, "_fps", null);
|
|
11
11
|
|
|
12
12
|
Object.assign(this.testOptions, {
|
|
13
13
|
maxFramesToRender: 60,
|
|
@@ -24,9 +24,10 @@ export default class PerformanceTestRunner extends TestRunner {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
shouldRender(animationProps) {
|
|
27
|
-
|
|
27
|
+
var _this$_fps, _this$_fps2;
|
|
28
28
|
|
|
29
|
-
this._fps.
|
|
29
|
+
(_this$_fps = this._fps) === null || _this$_fps === void 0 ? void 0 : _this$_fps.timeEnd();
|
|
30
|
+
(_this$_fps2 = this._fps) === null || _this$_fps2 === void 0 ? void 0 : _this$_fps2.timeStart();
|
|
30
31
|
|
|
31
32
|
if (this._fps.count > this.testOptions.maxFramesToRender) {
|
|
32
33
|
animationProps.done();
|
|
@@ -36,10 +37,11 @@ export default class PerformanceTestRunner extends TestRunner {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
assert(testCase) {
|
|
39
|
-
|
|
40
|
-
const count = this._fps.count;
|
|
40
|
+
var _this$_fps3, _this$_fps4;
|
|
41
41
|
|
|
42
|
-
const
|
|
42
|
+
const targetFPS = testCase.targetFPS || this.testOptions.targetFPS;
|
|
43
|
+
const count = (_this$_fps3 = this._fps) === null || _this$_fps3 === void 0 ? void 0 : _this$_fps3.count;
|
|
44
|
+
const fps = ((_this$_fps4 = this._fps) === null || _this$_fps4 === void 0 ? void 0 : _this$_fps4.getHz()) || 0;
|
|
43
45
|
|
|
44
46
|
if (fps >= targetFPS) {
|
|
45
47
|
this._pass({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/performance-test-runner.ts"],"names":["Stats","TestRunner","PerformanceTestRunner","constructor","props","Object","assign","testOptions","maxFramesToRender","targetFPS","initTestCase","testCase","_stats","id","name","_fps","get","shouldRender","animationProps","timeEnd","timeStart","count","done","assert","fps","getHz","_pass","framesRendered","_fail","_next"],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../src/performance-test-runner.ts"],"names":["Stats","TestRunner","PerformanceTestRunner","constructor","props","Object","assign","testOptions","maxFramesToRender","targetFPS","initTestCase","testCase","_stats","id","name","_fps","get","shouldRender","animationProps","timeEnd","timeStart","count","done","assert","fps","getHz","_pass","framesRendered","_fail","_next"],"mappings":";AAEA,SAAQA,KAAR,QAA0B,iBAA1B;AACA,OAAOC,UAAP,MAAgE,eAAhE;AAEA,eAAe,MAAMC,qBAAN,SAAoCD,UAApC,CAA+C;AAI5DE,EAAAA,WAAW,CAACC,KAAD,EAA2B;AACpC,UAAMA,KAAN;;AADoC,oCAHP,IAGO;;AAAA,kCAFV,IAEU;;AAGpCC,IAAAA,MAAM,CAACC,MAAP,CAAc,KAAKC,WAAnB,EAAgC;AAC9BC,MAAAA,iBAAiB,EAAE,EADW;AAE9BC,MAAAA,SAAS,EAAE;AAFmB,KAAhC;AAID;;AAEDC,EAAAA,YAAY,CAACC,QAAD,EAAqC;AAC/C,UAAMD,YAAN,CAAmBC,QAAnB;AACA,SAAKC,MAAL,GAAc,IAAIZ,KAAJ,CAAU;AAACa,MAAAA,EAAE,EAAEF,QAAQ,CAACG;AAAd,KAAV,CAAd;AACA,SAAKC,IAAL,GAAY,KAAKH,MAAL,CAAYI,GAAZ,CAAgB,KAAhB,CAAZ;AACD;;AAEDC,EAAAA,YAAY,CAACC,cAAD,EAA+C;AAAA;;AACzD,uBAAKH,IAAL,0DAAWI,OAAX;AACA,wBAAKJ,IAAL,4DAAWK,SAAX;;AAGA,QAAI,KAAKL,IAAL,CAAUM,KAAV,GAAkB,KAAKd,WAAL,CAAiBC,iBAAvC,EAA0D;AACxDU,MAAAA,cAAc,CAACI,IAAf;AACD;;AAED,WAAO,IAAP;AACD;;AAEDC,EAAAA,MAAM,CAACZ,QAAD,EAAqC;AAAA;;AAEzC,UAAMF,SAAS,GAAGE,QAAQ,CAACF,SAAT,IAAsB,KAAKF,WAAL,CAAiBE,SAAzD;AACA,UAAMY,KAAK,kBAAG,KAAKN,IAAR,gDAAG,YAAWM,KAAzB;AACA,UAAMG,GAAG,GAAG,qBAAKT,IAAL,4DAAWU,KAAX,OAAsB,CAAlC;;AAEA,QAAID,GAAG,IAAIf,SAAX,EAAsB;AACpB,WAAKiB,KAAL,CAAW;AAACF,QAAAA,GAAD;AAAMG,QAAAA,cAAc,EAAEN;AAAtB,OAAX;AACD,KAFD,MAEO;AACL,WAAKO,KAAL,CAAW;AAACJ,QAAAA,GAAD;AAAMG,QAAAA,cAAc,EAAEN;AAAtB,OAAX;AACD;;AACD,SAAKQ,KAAL;AACD;;AA3C2D","sourcesContent":["// luma.gl, MIT license\n\nimport {Stats, Stat} from '@probe.gl/stats';\nimport TestRunner, {TestRunnerOptions, TestRunnerTestCase} from './test-runner';\n\nexport default class PerformanceTestRunner extends TestRunner {\n private _stats: Stats | null = null;\n private _fps: Stat | null = null;\n\n constructor(props: TestRunnerOptions) {\n super(props);\n\n Object.assign(this.testOptions, {\n maxFramesToRender: 60,\n targetFPS: 50\n });\n }\n\n initTestCase(testCase: TestRunnerTestCase): void {\n super.initTestCase(testCase);\n this._stats = new Stats({id: testCase.name});\n this._fps = this._stats.get('fps');\n }\n\n shouldRender(animationProps: Record<string, any>): boolean {\n this._fps?.timeEnd();\n this._fps?.timeStart();\n\n // @ts-expect-error\n if (this._fps.count > this.testOptions.maxFramesToRender) {\n animationProps.done();\n }\n\n return true;\n }\n\n assert(testCase: TestRunnerTestCase): void {\n // @ts-expect-error\n const targetFPS = testCase.targetFPS || this.testOptions.targetFPS;\n const count = this._fps?.count;\n const fps = this._fps?.getHz() || 0;\n\n if (fps >= targetFPS) {\n this._pass({fps, framesRendered: count});\n } else {\n this._fail({fps, framesRendered: count});\n }\n this._next();\n }\n}\n"],"file":"performance-test-runner.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-devices.d.ts","sourceRoot":"","sources":["../src/register-devices.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { luma } from '@luma.gl/api';
|
|
2
|
+
import { WebGLDevice, registerHeadlessGL } from '@luma.gl/webgl';
|
|
3
|
+
import { WebGPUDevice } from '@luma.gl/webgpu';
|
|
4
|
+
import headlessGL from 'gl';
|
|
5
|
+
registerHeadlessGL(headlessGL);
|
|
6
|
+
luma.registerDevices([WebGLDevice, WebGPUDevice]);
|
|
7
|
+
//# sourceMappingURL=register-devices.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/register-devices.ts"],"names":["luma","WebGLDevice","registerHeadlessGL","WebGPUDevice","headlessGL","registerDevices"],"mappings":"AAEA,SAAQA,IAAR,QAAmB,cAAnB;AACA,SAAQC,WAAR,EAAqBC,kBAArB,QAA8C,gBAA9C;AACA,SAAQC,YAAR,QAA2B,iBAA3B;AAEA,OAAOC,UAAP,MAAuB,IAAvB;AAEAF,kBAAkB,CAACE,UAAD,CAAlB;AACAJ,IAAI,CAACK,eAAL,CAAqB,CAACJ,WAAD,EAAcE,YAAd,CAArB","sourcesContent":["// luma.gl, MIT license\n\nimport {luma} from '@luma.gl/api';\nimport {WebGLDevice, registerHeadlessGL} from '@luma.gl/webgl';\nimport {WebGPUDevice} from '@luma.gl/webgpu';\n\nimport headlessGL from 'gl';\n\nregisterHeadlessGL(headlessGL);\nluma.registerDevices([WebGLDevice, WebGPUDevice]);\n"],"file":"register-devices.js"}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import TestRunner, { TestRunnerOptions } from './test-runner';
|
|
1
|
+
import TestRunner, { TestRunnerOptions, TestRunnerTestCase } from './test-runner';
|
|
2
|
+
/** A snapshot test case */
|
|
3
|
+
export declare type SnapshotTestRunnerTestCase = TestRunnerTestCase & {
|
|
4
|
+
/** URL to golden image */
|
|
5
|
+
goldenImage: string;
|
|
6
|
+
};
|
|
2
7
|
export default class SnapshotTestRunner extends TestRunner {
|
|
3
8
|
private isDiffing;
|
|
4
9
|
constructor(props: TestRunnerOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot-test-runner.d.ts","sourceRoot":"","sources":["../src/snapshot-test-runner.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,EAAE,EAAC,iBAAiB,EAAC,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"snapshot-test-runner.d.ts","sourceRoot":"","sources":["../src/snapshot-test-runner.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,EAAE,EAAC,iBAAiB,EAAE,kBAAkB,EAAC,MAAM,eAAe,CAAC;AAGhF,2BAA2B;AAC3B,oBAAY,0BAA0B,GAAG,kBAAkB,GAAG;IAC5D,0BAA0B;IAC1B,WAAW,EAAE,MAAM,CAAC;CACrB,CAAA;AAED,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,UAAU;IACxD,OAAO,CAAC,SAAS,CAAkB;gBAEvB,KAAK,EAAE,iBAAiB;IAOpC,YAAY,CAAC,QAAQ,KAAA;IAOrB,YAAY;IAKZ,MAAM,CAAC,QAAQ,KAAA;CAiChB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/snapshot-test-runner.ts"],"names":["TestRunner","getBoundingBoxInPage","SnapshotTestRunner","constructor","props","testOptions","imageDiffOptions","initTestCase","testCase","goldenImage","Error","name","shouldRender","isDiffing","assert","diffOptions","Object","assign","region","_animationProps","canvas","window","browserTestDriver_captureAndDiffScreen","then","result","success","_pass","_fail","_next"],"mappings":";AAAA,OAAOA,UAAP,
|
|
1
|
+
{"version":3,"sources":["../src/snapshot-test-runner.ts"],"names":["TestRunner","getBoundingBoxInPage","SnapshotTestRunner","constructor","props","testOptions","imageDiffOptions","initTestCase","testCase","goldenImage","Error","name","shouldRender","isDiffing","assert","diffOptions","Object","assign","region","_animationProps","canvas","window","browserTestDriver_captureAndDiffScreen","then","result","success","_pass","_fail","_next"],"mappings":";AAAA,OAAOA,UAAP,MAAgE,eAAhE;AACA,SAAQC,oBAAR,QAAmC,SAAnC;AAQA,eAAe,MAAMC,kBAAN,SAAiCF,UAAjC,CAA4C;AAGzDG,EAAAA,WAAW,CAACC,KAAD,EAA2B;AACpC,UAAMA,KAAN;;AADoC,uCAFT,KAES;;AAIpC,SAAKC,WAAL,CAAiBC,gBAAjB,GAAoC,EAApC;AACD;;AAEDC,EAAAA,YAAY,CAACC,QAAD,EAAW;AACrB,UAAMD,YAAN,CAAmBC,QAAnB;;AACA,QAAI,CAACA,QAAQ,CAACC,WAAd,EAA2B;AACzB,YAAM,IAAIC,KAAJ,qBAAuBF,QAAQ,CAACG,IAAhC,iCAAN;AACD;AACF;;AAEDC,EAAAA,YAAY,GAAG;AAEb,WAAO,CAAC,KAAKC,SAAb;AACD;;AAEDC,EAAAA,MAAM,CAACN,QAAD,EAAW;AACf,QAAI,KAAKK,SAAT,EAAoB;AAElB;AACD;;AACD,SAAKA,SAAL,GAAiB,IAAjB;AAEA,UAAME,WAAW,GAAGC,MAAM,CAACC,MAAP,CAClB,EADkB,EAGlB,KAAKZ,WAAL,CAAiBC,gBAHC,EAIlBE,QAAQ,CAACF,gBAJS,EAKlB;AACEG,MAAAA,WAAW,EAAED,QAAQ,CAACC,WADxB;AAGES,MAAAA,MAAM,EAAEjB,oBAAoB,CAAC,KAAKkB,eAAL,CAAqBC,MAAtB;AAH9B,KALkB,CAApB;AAcAC,IAAAA,MAAM,CAACC,sCAAP,CAA8CP,WAA9C,EAA2DQ,IAA3D,CAAiEC,MAAD,IAAY;AAE1E,UAAIA,MAAM,CAACC,OAAX,EAAoB;AAClB,aAAKC,KAAL,CAAWF,MAAX;AACD,OAFD,MAEO;AACL,aAAKG,KAAL,CAAWH,MAAX;AACD;;AAED,WAAKX,SAAL,GAAiB,KAAjB;;AACA,WAAKe,KAAL;AACD,KAVD;AAWD;;AAtDwD","sourcesContent":["import TestRunner, {TestRunnerOptions, TestRunnerTestCase} from './test-runner';\nimport {getBoundingBoxInPage} from './utils';\n\n/** A snapshot test case */\nexport type SnapshotTestRunnerTestCase = TestRunnerTestCase & {\n /** URL to golden image */\n goldenImage: string;\n}\n\nexport default class SnapshotTestRunner extends TestRunner {\n private isDiffing: boolean = false;\n\n constructor(props: TestRunnerOptions) {\n super(props);\n\n // @ts-expect-error\n this.testOptions.imageDiffOptions = {};\n }\n\n initTestCase(testCase) {\n super.initTestCase(testCase);\n if (!testCase.goldenImage) {\n throw new Error(`Test case ${testCase.name} does not have golden image`);\n }\n }\n\n shouldRender() {\n // wait for the current diffing to finish\n return !this.isDiffing;\n }\n\n assert(testCase) {\n if (this.isDiffing) {\n // Already performing diffing\n return;\n }\n this.isDiffing = true;\n\n const diffOptions = Object.assign(\n {},\n // @ts-expect-error\n this.testOptions.imageDiffOptions,\n testCase.imageDiffOptions,\n {\n goldenImage: testCase.goldenImage,\n // @ts-expect-error\n region: getBoundingBoxInPage(this._animationProps.canvas)\n }\n );\n\n // Take screenshot and compare\n // @ts-expect-error\n window.browserTestDriver_captureAndDiffScreen(diffOptions).then((result) => {\n // invoke user callback\n if (result.success) {\n this._pass(result);\n } else {\n this._fail(result);\n }\n\n this.isDiffing = false;\n this._next();\n });\n }\n}\n"],"file":"snapshot-test-runner.js"}
|
package/dist/test-runner.d.ts
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
+
/** Describes a test case */
|
|
1
2
|
export declare type TestRunnerTestCase = {
|
|
3
|
+
/** Name of the test case (for logging) */
|
|
2
4
|
name: string;
|
|
5
|
+
/** Initialize the test case. Can return a promise */
|
|
3
6
|
onInitialize: any;
|
|
7
|
+
/** Perform rendering */
|
|
4
8
|
onRender: any;
|
|
9
|
+
/** Clean up after the test case */
|
|
5
10
|
onFinalize: any;
|
|
6
11
|
};
|
|
12
|
+
/** Options for a TestRunner */
|
|
7
13
|
export declare type TestRunnerOptions = {
|
|
8
14
|
onTestStart?: any;
|
|
9
15
|
onTestPass?: any;
|
|
10
16
|
onTestFail?: any;
|
|
17
|
+
/** milliseconds to wait for each test case before aborting */
|
|
11
18
|
timeout?: number;
|
|
12
19
|
};
|
|
20
|
+
/** Runs an array of test cases */
|
|
13
21
|
export default class TestRunner {
|
|
14
22
|
props: any;
|
|
15
23
|
isRunning: boolean;
|
|
@@ -17,6 +25,7 @@ export default class TestRunner {
|
|
|
17
25
|
readonly _animationProps: object;
|
|
18
26
|
private _testCases;
|
|
19
27
|
private _testCaseData;
|
|
28
|
+
isHeadless: boolean;
|
|
20
29
|
/**
|
|
21
30
|
* props
|
|
22
31
|
* AnimationLoop props
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-runner.d.ts","sourceRoot":"","sources":["../src/test-runner.ts"],"names":[],"mappings":"AAKA,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,GAAG,CAAC;IAClB,QAAQ,EAAE,GAAG,CAAC;IACd,UAAU,EAAE,GAAG,CAAC;CACjB,CAAC;AAWF,oBAAY,iBAAiB,GAAG;IAE9B,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,UAAU,CAAC,EAAE,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"test-runner.d.ts","sourceRoot":"","sources":["../src/test-runner.ts"],"names":[],"mappings":"AAKA,4BAA4B;AAC5B,oBAAY,kBAAkB,GAAG;IAC/B,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,YAAY,EAAE,GAAG,CAAC;IAClB,wBAAwB;IACxB,QAAQ,EAAE,GAAG,CAAC;IACd,mCAAmC;IACnC,UAAU,EAAE,GAAG,CAAC;CACjB,CAAC;AAWF,+BAA+B;AAC/B,oBAAY,iBAAiB,GAAG;IAE9B,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,UAAU,CAAC,EAAE,GAAG,CAAC;IAEjB,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAYF,kCAAkC;AAClC,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,KAAK,MAAC;IACN,SAAS,UAAS;IAClB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAA6B;IACzD,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAM;IACtC,OAAO,CAAC,UAAU,CAA4B;IAC9C,OAAO,CAAC,aAAa,CAAQ;IAG7B,UAAU,EAAE,OAAO,CAAgD;IAEnE;;;OAGG;gBACS,KAAK,KAAK;IAItB;;OAEG;IACH;;OAEG;IACF,GAAG,CAAC,SAAS,EAAE,kBAAkB,EAAE,GAAG,IAAI;IAU1C;;OAEG;IACJ,GAAG,CAAC,OAAO,GAAE,MAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BxC,YAAY,CAAC,QAAQ,KAAA;IAYrB,YAAY,CAAC,cAAc,KAAA;IAI3B,MAAM,CAAC,QAAQ,KAAA;IAOf,KAAK,CAAC,MAAM,KAAA;IAKZ,KAAK,CAAC,MAAM,KAAA;IAKZ,KAAK;IAML,SAAS,CAAC,cAAc,KAAA;IAqCxB,aAAa;CAqDd"}
|
package/dist/test-runner.js
CHANGED
|
@@ -24,7 +24,8 @@ export default class TestRunner {
|
|
|
24
24
|
|
|
25
25
|
_defineProperty(this, "isRunning", false);
|
|
26
26
|
|
|
27
|
-
_defineProperty(this, "testOptions",
|
|
27
|
+
_defineProperty(this, "testOptions", { ...DEFAULT_TEST_OPTIONS
|
|
28
|
+
});
|
|
28
29
|
|
|
29
30
|
_defineProperty(this, "_animationProps", {});
|
|
30
31
|
|
|
@@ -32,9 +33,9 @@ export default class TestRunner {
|
|
|
32
33
|
|
|
33
34
|
_defineProperty(this, "_testCaseData", null);
|
|
34
35
|
|
|
36
|
+
_defineProperty(this, "isHeadless", Boolean(window.browserTestDriver_isHeadless));
|
|
37
|
+
|
|
35
38
|
this.props = props;
|
|
36
|
-
this.isHeadless = Boolean(window.browserTestDriver_isHeadless);
|
|
37
|
-
this.testOptions = Object.assign({}, DEFAULT_TEST_OPTIONS);
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
add(testCases) {
|
package/dist/test-runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/test-runner.ts"],"names":["AnimationLoop","pushContextState","popContextState","noop","DEFAULT_TEST_CASE","name","onInitialize","onRender","done","onFinalize","DEFAULT_TEST_OPTIONS","onTestStart","testCase","console","log","onTestPass","onTestFail","timeout","TestRunner","constructor","props","isHeadless","Boolean","window","browserTestDriver_isHeadless","testOptions","Object","assign","add","testCases","Array","isArray","_testCases","push","run","options","Promise","resolve","_animationLoop","_onRender","bind","isRunning","start","isDiffing","_currentTestCase","catch","error","_fail","message","initTestCase","animationLoop","key","shouldRender","animationProps","assert","_pass","_next","result","_nextTestCase","_animationProps","stop","isDone","testCaseAnimationProps","_testCaseData","startTime","_currentTestCaseStartTime","time","tick","_currentTestCaseStartTick","value","delete","gl","shift","then","userData"],"mappings":";AAEA,SAAQA,aAAR,QAA4B,eAA5B;AACA,SAAQC,gBAAR,EAA0BC,eAA1B,QAAgD,gBAAhD;;AASA,SAASC,IAAT,GAAgB,CAAE;;AAElB,MAAMC,iBAAqC,GAAG;AAC5CC,EAAAA,IAAI,EAAE,cADsC;AAE5CC,EAAAA,YAAY,EAAEH,IAF8B;AAG5CI,EAAAA,QAAQ,EAAE,CAAC;AAACC,IAAAA;AAAD,GAAD,KAAYA,IAAI,EAHkB;AAI5CC,EAAAA,UAAU,EAAEN;AAJgC,CAA9C;AAiBA,MAAMO,oBAAiD,GAAG;AAExDC,EAAAA,WAAW,EAAGC,QAAD,IAAcC,OAAO,CAACC,GAAR,aAAiBF,QAAQ,CAACP,IAA1B,EAF6B;AAGxDU,EAAAA,UAAU,EAAGH,QAAD,IAAcC,OAAO,CAACC,GAAR,cAAkBF,QAAQ,CAACP,IAA3B,aAH8B;AAIxDW,EAAAA,UAAU,EAAGJ,QAAD,IAAcC,OAAO,CAACC,GAAR,kBAAsBF,QAAQ,CAACP,IAA/B,aAJ8B;AAOxDY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-nocheck TODO remove\n/* eslint-disable no-console */\nimport {AnimationLoop} from '@luma.gl/core';\nimport {pushContextState, popContextState} from '@luma.gl/webgl';\n\nexport type TestRunnerTestCase = {\n name: string;\n onInitialize: any;\n onRender: any;\n onFinalize: any;\n};\n\nfunction noop() {}\n\nconst DEFAULT_TEST_CASE: TestRunnerTestCase = {\n name: 'Unnamed test',\n onInitialize: noop,\n onRender: ({done}) => done(),\n onFinalize: noop\n};\n\nexport type TestRunnerOptions = {\n // test lifecycle callback\n onTestStart?: any;\n onTestPass?: any;\n onTestFail?: any;\n\n // milliseconds to wait for each test case before aborting\n timeout?: number;\n};\n\nconst DEFAULT_TEST_OPTIONS: Required<TestRunnerOptions> = {\n // test lifecycle callback\n onTestStart: (testCase) => console.log(`# ${testCase.name}`),\n onTestPass: (testCase) => console.log(`ok ${testCase.name} passed`),\n onTestFail: (testCase) => console.log(`not ok ${testCase.name} failed`),\n\n // milliseconds to wait for each test case before aborting\n timeout: 2000\n};\n\nexport default class TestRunner {\n props;\n isRunning = false;\n readonly testOptions: object;\n readonly _animationProps: object = {};\n private _testCases: TestRunnerTestCase[] = [];\n private _testCaseData = null;\n\n /**\n * props\n * AnimationLoop props\n */\n constructor(props = {}) {\n this.props = props;\n\n // @ts-expect-error\n this.isHeadless = Boolean(window.browserTestDriver_isHeadless);\n\n this.testOptions = Object.assign({}, DEFAULT_TEST_OPTIONS);\n }\n\n /**\n * Add testCase(s)\n */\n /**\n * Add testCase(s)\n */\n add(testCases: TestRunnerTestCase[]): this {\n if (!Array.isArray(testCases)) {\n testCases = [testCases];\n }\n for (const testCase of testCases) {\n this._testCases.push(testCase);\n }\n return this;\n }\n\n /**\n * Returns a promise that resolves when all the test cases are done\n */\n run(options: object = {}): Promise<void> {\n Object.assign(this.testOptions, options);\n\n return new Promise<void>(resolve => {\n this._animationLoop = new AnimationLoop(\n // @ts-expect-error TODO\n Object.assign({}, this.props, {\n onRender: this._onRender.bind(this),\n onFinalize: () => {\n this.isRunning = false;\n resolve();\n }\n })\n );\n this._animationLoop.start(this.props);\n\n this.isRunning = true;\n this.isDiffing = false;\n this._currentTestCase = null;\n }).catch((error) => {\n this._fail({error: error.message});\n });\n }\n\n /* Lifecycle methods for subclassing */\n\n initTestCase(testCase) {\n const {animationLoop} = testCase;\n if (animationLoop) {\n testCase.onInitialize = animationLoop.onInitialize.bind(animationLoop);\n testCase.onRender = animationLoop.onRender.bind(animationLoop);\n testCase.onFinalize = animationLoop.onFinalize.bind(animationLoop);\n }\n for (const key in DEFAULT_TEST_CASE) {\n testCase[key] = testCase[key] || DEFAULT_TEST_CASE[key];\n }\n }\n\n shouldRender(animationProps) {\n return true;\n }\n\n assert(testCase) {\n this._pass(testCase);\n this._next();\n }\n\n /* Utilities */\n\n _pass(result) {\n // @ts-expect-error\n this.testOptions.onTestPass(this._currentTestCase, result);\n }\n\n _fail(result) {\n // @ts-expect-error\n this.testOptions.onTestFail(this._currentTestCase, result);\n }\n\n _next() {\n this._nextTestCase();\n }\n\n /* Private methods */\n\n _onRender(animationProps) {\n this._animationProps = animationProps;\n\n const testCase = this._currentTestCase || this._nextTestCase();\n if (!testCase) {\n // all test cases are done\n this._animationLoop.stop();\n return;\n }\n\n let isDone = false;\n const testCaseAnimationProps = Object.assign({}, animationProps, this._testCaseData, {\n // tick/time starts from 0 for each test case\n startTime: this._currentTestCaseStartTime,\n time: animationProps.time - this._currentTestCaseStartTime,\n tick: animationProps.tick - this._currentTestCaseStartTick,\n // called by the test case when it is done rendering and ready for capture and diff\n done: () => {\n isDone = true;\n }\n });\n\n if (this._testCaseData && this.shouldRender(testCaseAnimationProps)) {\n // test case is initialized, render frame\n testCase.onRender(testCaseAnimationProps);\n }\n\n const timeout = testCase.timeout || this.testOptions.timeout;\n if (timeout && testCaseAnimationProps.time > timeout) {\n isDone = true;\n }\n\n if (isDone) {\n this.assert(testCase);\n }\n }\n\n _nextTestCase() {\n const animationProps = this._animationProps;\n\n // finalize the current test case\n if (this._testCaseData) {\n for (const key in this._testCaseData) {\n const value = this._testCaseData[key];\n if (value && value.delete) {\n value.delete();\n }\n }\n this._currentTestCase.onFinalize(Object.assign({}, animationProps, this._testCaseData));\n\n // reset WebGL context\n popContextState(animationProps.gl);\n\n this._currentTestCase = null;\n this._testCaseData = null;\n }\n\n // get the next test case\n const testCase = this._testCases.shift();\n if (testCase) {\n // start new test case\n this._currentTestCase = testCase;\n this._currentTestCaseStartTime = animationProps.time;\n this._currentTestCaseStartTick = animationProps.tick;\n this.initTestCase(testCase);\n\n // initialize test case\n\n // save WebGL context\n pushContextState(animationProps.gl);\n\n // aligned with the behavior of AnimationLoop.onInitialized\n // onInitialized could return a plain object or a promise\n Promise.resolve(\n testCase.onInitialize(\n Object.assign({}, animationProps, {\n // tick/time starts from 0 for each test case\n startTime: animationProps.time,\n time: 0,\n tick: 0\n })\n )\n ).then((userData) => {\n this._testCaseData = userData || {};\n });\n // invoke user callback\n this.testOptions.onTestStart(testCase);\n }\n return testCase;\n }\n}\n"],"file":"test-runner.js"}
|
|
1
|
+
{"version":3,"sources":["../src/test-runner.ts"],"names":["AnimationLoop","pushContextState","popContextState","noop","DEFAULT_TEST_CASE","name","onInitialize","onRender","done","onFinalize","DEFAULT_TEST_OPTIONS","onTestStart","testCase","console","log","onTestPass","onTestFail","timeout","TestRunner","constructor","props","Boolean","window","browserTestDriver_isHeadless","add","testCases","Array","isArray","_testCases","push","run","options","Object","assign","testOptions","Promise","resolve","_animationLoop","_onRender","bind","isRunning","start","isDiffing","_currentTestCase","catch","error","_fail","message","initTestCase","animationLoop","key","shouldRender","animationProps","assert","_pass","_next","result","_nextTestCase","_animationProps","stop","isDone","testCaseAnimationProps","_testCaseData","startTime","_currentTestCaseStartTime","time","tick","_currentTestCaseStartTick","value","delete","gl","shift","then","userData"],"mappings":";AAEA,SAAQA,aAAR,QAA4B,eAA5B;AACA,SAAQC,gBAAR,EAA0BC,eAA1B,QAAgD,gBAAhD;;AAcA,SAASC,IAAT,GAAgB,CAAE;;AAElB,M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AAc,CAACkB,EAAhB,CAAhB;AAIAnC,MAAAA,OAAO,CAACC,OAAR,CACExB,QAAQ,CAACN,YAAT,CACE0B,MAAM,CAACC,MAAP,CAAc,EAAd,EAAkBmB,cAAlB,EAAkC;AAEhCW,QAAAA,SAAS,EAAEX,cAAc,CAACa,IAFM;AAGhCA,QAAAA,IAAI,EAAE,CAH0B;AAIhCC,QAAAA,IAAI,EAAE;AAJ0B,OAAlC,CADF,CADF,EASEM,IATF,CASQC,QAAD,IAAc;AACnB,aAAKX,aAAL,GAAqBW,QAAQ,IAAI,EAAjC;AACD,OAXD;AAaA,WAAKvC,WAAL,CAAiBvB,WAAjB,CAA6BC,QAA7B;AACD;;AACD,WAAOA,QAAP;AACD;;AAhM6B","sourcesContent":["// @ts-nocheck TODO remove\n/* eslint-disable no-console */\nimport {AnimationLoop} from '@luma.gl/core';\nimport {pushContextState, popContextState} from '@luma.gl/webgl';\n\n/** Describes a test case */\nexport type TestRunnerTestCase = {\n /** Name of the test case (for logging) */\n name: string;\n /** Initialize the test case. Can return a promise */\n onInitialize: any;\n /** Perform rendering */\n onRender: any;\n /** Clean up after the test case */\n onFinalize: any;\n};\n\nfunction noop() {}\n\nconst DEFAULT_TEST_CASE: TestRunnerTestCase = {\n name: 'Unnamed test',\n onInitialize: noop,\n onRender: ({done}) => done(),\n onFinalize: noop\n};\n\n/** Options for a TestRunner */\nexport type TestRunnerOptions = {\n // test lifecycle callback\n onTestStart?: any;\n onTestPass?: any;\n onTestFail?: any;\n\n /** milliseconds to wait for each test case before aborting */\n timeout?: number;\n};\n\nconst DEFAULT_TEST_OPTIONS: Required<TestRunnerOptions> = {\n // test lifecycle callback\n onTestStart: (testCase) => console.log(`# ${testCase.name}`),\n onTestPass: (testCase) => console.log(`ok ${testCase.name} passed`),\n onTestFail: (testCase) => console.log(`not ok ${testCase.name} failed`),\n\n // milliseconds to wait for each test case before aborting\n timeout: 2000\n};\n\n/** Runs an array of test cases */\nexport default class TestRunner {\n props;\n isRunning = false;\n readonly testOptions: object = {...DEFAULT_TEST_OPTIONS};\n readonly _animationProps: object = {};\n private _testCases: TestRunnerTestCase[] = [];\n private _testCaseData = null;\n\n // @ts-expect-error\n isHeadless: boolean = Boolean(window.browserTestDriver_isHeadless);\n\n /**\n * props\n * AnimationLoop props\n */\n constructor(props = {}) {\n this.props = props;\n }\n\n /**\n * Add testCase(s)\n */\n /**\n * Add testCase(s)\n */\n add(testCases: TestRunnerTestCase[]): this {\n if (!Array.isArray(testCases)) {\n testCases = [testCases];\n }\n for (const testCase of testCases) {\n this._testCases.push(testCase);\n }\n return this;\n }\n\n /**\n * Returns a promise that resolves when all the test cases are done\n */\n run(options: object = {}): Promise<void> {\n Object.assign(this.testOptions, options);\n\n return new Promise<void>(resolve => {\n this._animationLoop = new AnimationLoop(\n // @ts-expect-error TODO\n Object.assign({}, this.props, {\n onRender: this._onRender.bind(this),\n onFinalize: () => {\n this.isRunning = false;\n resolve();\n }\n })\n );\n this._animationLoop.start(this.props);\n\n this.isRunning = true;\n this.isDiffing = false;\n this._currentTestCase = null;\n }).catch((error) => {\n this._fail({error: error.message});\n });\n }\n\n /* Lifecycle methods for subclassing */\n\n initTestCase(testCase) {\n const {animationLoop} = testCase;\n if (animationLoop) {\n testCase.onInitialize = animationLoop.onInitialize.bind(animationLoop);\n testCase.onRender = animationLoop.onRender.bind(animationLoop);\n testCase.onFinalize = animationLoop.onFinalize.bind(animationLoop);\n }\n for (const key in DEFAULT_TEST_CASE) {\n testCase[key] = testCase[key] || DEFAULT_TEST_CASE[key];\n }\n }\n\n shouldRender(animationProps) {\n return true;\n }\n\n assert(testCase) {\n this._pass(testCase);\n this._next();\n }\n\n /* Utilities */\n\n _pass(result) {\n // @ts-expect-error\n this.testOptions.onTestPass(this._currentTestCase, result);\n }\n\n _fail(result) {\n // @ts-expect-error\n this.testOptions.onTestFail(this._currentTestCase, result);\n }\n\n _next() {\n this._nextTestCase();\n }\n\n /* Private methods */\n\n _onRender(animationProps) {\n this._animationProps = animationProps;\n\n const testCase = this._currentTestCase || this._nextTestCase();\n if (!testCase) {\n // all test cases are done\n this._animationLoop.stop();\n return;\n }\n\n let isDone = false;\n const testCaseAnimationProps = Object.assign({}, animationProps, this._testCaseData, {\n // tick/time starts from 0 for each test case\n startTime: this._currentTestCaseStartTime,\n time: animationProps.time - this._currentTestCaseStartTime,\n tick: animationProps.tick - this._currentTestCaseStartTick,\n // called by the test case when it is done rendering and ready for capture and diff\n done: () => {\n isDone = true;\n }\n });\n\n if (this._testCaseData && this.shouldRender(testCaseAnimationProps)) {\n // test case is initialized, render frame\n testCase.onRender(testCaseAnimationProps);\n }\n\n const timeout = testCase.timeout || this.testOptions.timeout;\n if (timeout && testCaseAnimationProps.time > timeout) {\n isDone = true;\n }\n\n if (isDone) {\n this.assert(testCase);\n }\n }\n\n _nextTestCase() {\n const animationProps = this._animationProps;\n\n // finalize the current test case\n if (this._testCaseData) {\n for (const key in this._testCaseData) {\n const value = this._testCaseData[key];\n if (value && value.delete) {\n value.delete();\n }\n }\n this._currentTestCase.onFinalize(Object.assign({}, animationProps, this._testCaseData));\n\n // reset WebGL context\n popContextState(animationProps.gl);\n\n this._currentTestCase = null;\n this._testCaseData = null;\n }\n\n // get the next test case\n const testCase = this._testCases.shift();\n if (testCase) {\n // start new test case\n this._currentTestCase = testCase;\n this._currentTestCaseStartTime = animationProps.time;\n this._currentTestCaseStartTick = animationProps.tick;\n this.initTestCase(testCase);\n\n // initialize test case\n\n // save WebGL context\n pushContextState(animationProps.gl);\n\n // aligned with the behavior of AnimationLoop.onInitialized\n // onInitialized could return a plain object or a promise\n Promise.resolve(\n testCase.onInitialize(\n Object.assign({}, animationProps, {\n // tick/time starts from 0 for each test case\n startTime: animationProps.time,\n time: 0,\n tick: 0\n })\n )\n ).then((userData) => {\n this._testCaseData = userData || {};\n });\n // invoke user callback\n this.testOptions.onTestStart(testCase);\n }\n return testCase;\n }\n}\n"],"file":"test-runner.js"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export declare function getBoundingBoxInPage(domElement:
|
|
2
|
-
x:
|
|
3
|
-
y:
|
|
4
|
-
width:
|
|
5
|
-
height:
|
|
1
|
+
export declare function getBoundingBoxInPage(domElement: HTMLElement): {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
6
|
};
|
|
7
7
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,wBAAgB,oBAAoB,CAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,WAAW,GAAG;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;CAAC,CAQpH"}
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts"],"names":["getBoundingBoxInPage","domElement","bbox","getBoundingClientRect","x","window","scrollX","y","scrollY","width","height"],"mappings":"AACA,OAAO,SAASA,oBAAT,CAA8BC,UAA9B,
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts"],"names":["getBoundingBoxInPage","domElement","bbox","getBoundingClientRect","x","window","scrollX","y","scrollY","width","height"],"mappings":"AACA,OAAO,SAASA,oBAAT,CAA8BC,UAA9B,EAA+G;AACpH,QAAMC,IAAI,GAAGD,UAAU,CAACE,qBAAX,EAAb;AACA,SAAO;AACLC,IAAAA,CAAC,EAAEC,MAAM,CAACC,OAAP,GAAiBJ,IAAI,CAACE,CADpB;AAELG,IAAAA,CAAC,EAAEF,MAAM,CAACG,OAAP,GAAiBN,IAAI,CAACK,CAFpB;AAGLE,IAAAA,KAAK,EAAEP,IAAI,CAACO,KAHP;AAILC,IAAAA,MAAM,EAAER,IAAI,CAACQ;AAJR,GAAP;AAMD","sourcesContent":["// Get the bounding box of a DOMElement relative to the page\nexport function getBoundingBoxInPage(domElement: HTMLElement): {x: number; y: number; width: number; height: number;} {\n const bbox = domElement.getBoundingClientRect();\n return {\n x: window.scrollX + bbox.x,\n y: window.scrollY + bbox.y,\n width: bbox.width,\n height: bbox.height\n };\n}\n"],"file":"utils.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/test-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0-alpha.10",
|
|
4
4
|
"description": "Automated WebGL testing utilities with Puppeteer and image diffing",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -31,13 +31,16 @@
|
|
|
31
31
|
"pre-build": "echo test utils has no bundle"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@probe.gl/env": "^3.5.0"
|
|
34
|
+
"@probe.gl/env": "^3.5.0",
|
|
35
|
+
"@types/gl": "^6.0.2",
|
|
36
|
+
"gl": "^5.0.3"
|
|
35
37
|
},
|
|
36
38
|
"peerDependencies": {
|
|
37
|
-
"@luma.gl/
|
|
38
|
-
"@luma.gl/
|
|
39
|
-
"@luma.gl/webgl": "
|
|
39
|
+
"@luma.gl/api": "9.0.0-alpha.7",
|
|
40
|
+
"@luma.gl/engine": "9.0.0-alpha.7",
|
|
41
|
+
"@luma.gl/webgl": "9.0.0-alpha.7",
|
|
42
|
+
"@luma.gl/webgpu": "9.0.0-alpha.7",
|
|
40
43
|
"@probe.gl/test-utils": "^3.5.0"
|
|
41
44
|
},
|
|
42
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "eaa912a3f1479a58e6b9915e905a9274e11d9c34"
|
|
43
46
|
}
|
|
@@ -1,31 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
import {WebGLDevice, WebGLDeviceProps} from '@luma.gl/webgl';
|
|
3
|
-
import {createHeadlessContext} from './create-headless-context';
|
|
1
|
+
// luma.gl, MIT license
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import type {Device, DeviceProps} from '@luma.gl/api';
|
|
4
|
+
import {luma} from '@luma.gl/api';
|
|
5
|
+
import {WebGLDevice} from '@luma.gl/webgl';
|
|
6
|
+
import {WebGPUDevice} from '@luma.gl/webgpu';
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
luma.gl: loaded under Node.js without headless gl installed, meaning that WebGL \
|
|
10
|
-
contexts can not be created. This may not be an error. For example, this is a \
|
|
11
|
-
typical configuration for isorender applications running on the server.`;
|
|
12
|
-
|
|
13
|
-
const CONTEXT_DEFAULTS: Partial<WebGLDeviceProps> = {
|
|
8
|
+
const CONTEXT_DEFAULTS: Partial<DeviceProps> = {
|
|
14
9
|
width: 1,
|
|
15
10
|
height: 1,
|
|
16
11
|
debug: true
|
|
17
12
|
};
|
|
18
13
|
|
|
19
|
-
|
|
14
|
+
/** Create a test WebGL context */
|
|
15
|
+
export function createTestContext(opts: Record<string, any> = {}): WebGLRenderingContext | null {
|
|
16
|
+
const device = createTestDevice(opts);
|
|
17
|
+
return device && device.gl;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Create a test WebGLDevice */
|
|
21
|
+
export function createTestDevice(props: DeviceProps = {}): WebGLDevice | null {
|
|
20
22
|
try {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
props = {...CONTEXT_DEFAULTS, ...props, debug: true};
|
|
24
|
+
// We dont use luma.createDevice since this tests current expect this context to be created synchronously
|
|
23
25
|
return new WebGLDevice(props);
|
|
24
26
|
} catch (error) {
|
|
25
|
-
console.error(error.message);
|
|
27
|
+
console.error(`Failed to created device '${props.id}': ${(error as Error).message}`);
|
|
26
28
|
return null;
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
export const
|
|
31
|
-
export const
|
|
32
|
+
export const webgl1Device: WebGLDevice = createTestDevice({id: 'webgl1-test-device', webgl1: true, webgl2: false});
|
|
33
|
+
export const webgl2Device: WebGLDevice = createTestDevice({id: 'webgl2-test-device', webgl1: false, webgl2: true});
|
|
34
|
+
/** Only available after getTestDevices() has completed */
|
|
35
|
+
export let webgpuDevice: WebGPUDevice;
|
|
36
|
+
|
|
37
|
+
let webgpuCreated = false;
|
|
38
|
+
|
|
39
|
+
/** Synchronously get test devices (only WebGLDevices) */
|
|
40
|
+
export function getWebGLTestDevices(): WebGLDevice[] {
|
|
41
|
+
const devices: WebGLDevice[] = [];
|
|
42
|
+
if (webgl2Device) {
|
|
43
|
+
devices.push(webgl2Device);
|
|
44
|
+
}
|
|
45
|
+
if (webgl1Device) {
|
|
46
|
+
devices.push(webgl1Device);
|
|
47
|
+
}
|
|
48
|
+
return devices;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Includes WebGPU device if available */
|
|
52
|
+
export async function getTestDevices() : Promise<Device[]> {
|
|
53
|
+
if (!webgpuCreated) {
|
|
54
|
+
webgpuCreated = true;
|
|
55
|
+
try {
|
|
56
|
+
webgpuDevice = await luma.createDevice({id: 'webgpu-test-device', type: 'webgpu'}) as WebGPUDevice;
|
|
57
|
+
} catch {
|
|
58
|
+
// ignore (assume WebGPU was not available)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const devices: Device[] = getWebGLTestDevices();
|
|
63
|
+
if (webgpuDevice) {
|
|
64
|
+
devices.unshift(webgpuDevice);
|
|
65
|
+
}
|
|
66
|
+
return devices;
|
|
67
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import './register-devices';
|
|
2
|
+
|
|
3
|
+
export type {TestRunnerTestCase} from './test-runner';
|
|
4
|
+
export type {SnapshotTestRunnerTestCase} from './snapshot-test-runner';
|
|
5
|
+
|
|
1
6
|
export {default as SnapshotTestRunner} from './snapshot-test-runner';
|
|
2
7
|
export {default as PerformanceTestRunner} from './performance-test-runner';
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
|
|
8
|
+
export {createTestDevice, createTestContext, webgl1Device, webgl2Device, webgpuDevice} from './create-test-device';
|
|
9
|
+
export {getTestDevices, getWebGLTestDevices} from './create-test-device';
|
|
10
|
+
|
|
11
|
+
export {checkType} from './check-type';
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
// luma.gl, MIT license
|
|
2
|
+
|
|
1
3
|
import {Stats, Stat} from '@probe.gl/stats';
|
|
2
|
-
import TestRunner, {TestRunnerOptions} from './test-runner';
|
|
4
|
+
import TestRunner, {TestRunnerOptions, TestRunnerTestCase} from './test-runner';
|
|
3
5
|
|
|
4
6
|
export default class PerformanceTestRunner extends TestRunner {
|
|
5
|
-
private _stats: Stats;
|
|
6
|
-
private _fps: Stat;
|
|
7
|
+
private _stats: Stats | null = null;
|
|
8
|
+
private _fps: Stat | null = null;
|
|
7
9
|
|
|
8
10
|
constructor(props: TestRunnerOptions) {
|
|
9
11
|
super(props);
|
|
@@ -14,15 +16,15 @@ export default class PerformanceTestRunner extends TestRunner {
|
|
|
14
16
|
});
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
initTestCase(testCase) {
|
|
19
|
+
initTestCase(testCase: TestRunnerTestCase): void {
|
|
18
20
|
super.initTestCase(testCase);
|
|
19
21
|
this._stats = new Stats({id: testCase.name});
|
|
20
22
|
this._fps = this._stats.get('fps');
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
shouldRender(animationProps) {
|
|
24
|
-
this._fps
|
|
25
|
-
this._fps
|
|
25
|
+
shouldRender(animationProps: Record<string, any>): boolean {
|
|
26
|
+
this._fps?.timeEnd();
|
|
27
|
+
this._fps?.timeStart();
|
|
26
28
|
|
|
27
29
|
// @ts-expect-error
|
|
28
30
|
if (this._fps.count > this.testOptions.maxFramesToRender) {
|
|
@@ -32,11 +34,11 @@ export default class PerformanceTestRunner extends TestRunner {
|
|
|
32
34
|
return true;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
assert(testCase) {
|
|
37
|
+
assert(testCase: TestRunnerTestCase): void {
|
|
36
38
|
// @ts-expect-error
|
|
37
39
|
const targetFPS = testCase.targetFPS || this.testOptions.targetFPS;
|
|
38
|
-
const count = this._fps
|
|
39
|
-
const fps = this._fps
|
|
40
|
+
const count = this._fps?.count;
|
|
41
|
+
const fps = this._fps?.getHz() || 0;
|
|
40
42
|
|
|
41
43
|
if (fps >= targetFPS) {
|
|
42
44
|
this._pass({fps, framesRendered: count});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// luma.gl, MIT license
|
|
2
|
+
|
|
3
|
+
import {luma} from '@luma.gl/api';
|
|
4
|
+
import {WebGLDevice, registerHeadlessGL} from '@luma.gl/webgl';
|
|
5
|
+
import {WebGPUDevice} from '@luma.gl/webgpu';
|
|
6
|
+
|
|
7
|
+
import headlessGL from 'gl';
|
|
8
|
+
|
|
9
|
+
registerHeadlessGL(headlessGL);
|
|
10
|
+
luma.registerDevices([WebGLDevice, WebGPUDevice]);
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import TestRunner, {TestRunnerOptions} from './test-runner';
|
|
1
|
+
import TestRunner, {TestRunnerOptions, TestRunnerTestCase} from './test-runner';
|
|
2
2
|
import {getBoundingBoxInPage} from './utils';
|
|
3
3
|
|
|
4
|
+
/** A snapshot test case */
|
|
5
|
+
export type SnapshotTestRunnerTestCase = TestRunnerTestCase & {
|
|
6
|
+
/** URL to golden image */
|
|
7
|
+
goldenImage: string;
|
|
8
|
+
}
|
|
4
9
|
|
|
5
10
|
export default class SnapshotTestRunner extends TestRunner {
|
|
6
11
|
private isDiffing: boolean = false;
|
package/src/test-runner.ts
CHANGED
|
@@ -3,10 +3,15 @@
|
|
|
3
3
|
import {AnimationLoop} from '@luma.gl/core';
|
|
4
4
|
import {pushContextState, popContextState} from '@luma.gl/webgl';
|
|
5
5
|
|
|
6
|
+
/** Describes a test case */
|
|
6
7
|
export type TestRunnerTestCase = {
|
|
8
|
+
/** Name of the test case (for logging) */
|
|
7
9
|
name: string;
|
|
10
|
+
/** Initialize the test case. Can return a promise */
|
|
8
11
|
onInitialize: any;
|
|
12
|
+
/** Perform rendering */
|
|
9
13
|
onRender: any;
|
|
14
|
+
/** Clean up after the test case */
|
|
10
15
|
onFinalize: any;
|
|
11
16
|
};
|
|
12
17
|
|
|
@@ -19,13 +24,14 @@ const DEFAULT_TEST_CASE: TestRunnerTestCase = {
|
|
|
19
24
|
onFinalize: noop
|
|
20
25
|
};
|
|
21
26
|
|
|
27
|
+
/** Options for a TestRunner */
|
|
22
28
|
export type TestRunnerOptions = {
|
|
23
29
|
// test lifecycle callback
|
|
24
30
|
onTestStart?: any;
|
|
25
31
|
onTestPass?: any;
|
|
26
32
|
onTestFail?: any;
|
|
27
33
|
|
|
28
|
-
|
|
34
|
+
/** milliseconds to wait for each test case before aborting */
|
|
29
35
|
timeout?: number;
|
|
30
36
|
};
|
|
31
37
|
|
|
@@ -39,25 +45,24 @@ const DEFAULT_TEST_OPTIONS: Required<TestRunnerOptions> = {
|
|
|
39
45
|
timeout: 2000
|
|
40
46
|
};
|
|
41
47
|
|
|
48
|
+
/** Runs an array of test cases */
|
|
42
49
|
export default class TestRunner {
|
|
43
50
|
props;
|
|
44
51
|
isRunning = false;
|
|
45
|
-
readonly testOptions: object;
|
|
52
|
+
readonly testOptions: object = {...DEFAULT_TEST_OPTIONS};
|
|
46
53
|
readonly _animationProps: object = {};
|
|
47
54
|
private _testCases: TestRunnerTestCase[] = [];
|
|
48
55
|
private _testCaseData = null;
|
|
49
56
|
|
|
57
|
+
// @ts-expect-error
|
|
58
|
+
isHeadless: boolean = Boolean(window.browserTestDriver_isHeadless);
|
|
59
|
+
|
|
50
60
|
/**
|
|
51
61
|
* props
|
|
52
62
|
* AnimationLoop props
|
|
53
63
|
*/
|
|
54
64
|
constructor(props = {}) {
|
|
55
65
|
this.props = props;
|
|
56
|
-
|
|
57
|
-
// @ts-expect-error
|
|
58
|
-
this.isHeadless = Boolean(window.browserTestDriver_isHeadless);
|
|
59
|
-
|
|
60
|
-
this.testOptions = Object.assign({}, DEFAULT_TEST_OPTIONS);
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
/**
|
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,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-headless-context.d.ts","sourceRoot":"","sources":["../src/create-headless-context.ts"],"names":[],"mappings":"AAmBA,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,GAAG,GAAG,qBAAqB,CAgB1E"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import headlessGL from 'gl';
|
|
2
|
-
const ERR_HEADLESSGL_FAILED = 'Failed to create WebGL context in Node.js, headless gl returned null';
|
|
3
|
-
const ERR_HEADLESSGL_LOAD = " luma.gl: loaded under Node.js without headless gl installed, meaning that WebGL contexts can not be created. This may not be an error. For example, this is a typical configuration for isorender applications running on the server.";
|
|
4
|
-
const CONTEXT_DEFAULTS = {
|
|
5
|
-
width: 1,
|
|
6
|
-
height: 1,
|
|
7
|
-
debug: true,
|
|
8
|
-
throwOnError: false
|
|
9
|
-
};
|
|
10
|
-
export function createHeadlessContext(options) {
|
|
11
|
-
options = { ...CONTEXT_DEFAULTS,
|
|
12
|
-
...options
|
|
13
|
-
};
|
|
14
|
-
const {
|
|
15
|
-
width,
|
|
16
|
-
height,
|
|
17
|
-
webgl1,
|
|
18
|
-
webgl2
|
|
19
|
-
} = options;
|
|
20
|
-
|
|
21
|
-
if (webgl2 && !webgl1) {
|
|
22
|
-
throw new Error('headless-gl does not support WebGL2');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (!headlessGL) {
|
|
26
|
-
throw new Error(ERR_HEADLESSGL_LOAD);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const gl = headlessGL(width, height, options);
|
|
30
|
-
|
|
31
|
-
if (!gl) {
|
|
32
|
-
throw new Error(ERR_HEADLESSGL_FAILED);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return gl;
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=create-headless-context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/create-headless-context.ts"],"names":["headlessGL","ERR_HEADLESSGL_FAILED","ERR_HEADLESSGL_LOAD","CONTEXT_DEFAULTS","width","height","debug","throwOnError","createHeadlessContext","options","webgl1","webgl2","Error","gl"],"mappings":"AAAA,OAAOA,UAAP,MAAuB,IAAvB;AAEA,MAAMC,qBAAqB,GACzB,sEADF;AAGA,MAAMC,mBAAmB,gPAAzB;AAKA,MAAMC,gBAAgB,GAAG;AACvBC,EAAAA,KAAK,EAAE,CADgB;AAEvBC,EAAAA,MAAM,EAAE,CAFe;AAGvBC,EAAAA,KAAK,EAAE,IAHgB;AAIvBC,EAAAA,YAAY,EAAE;AAJS,CAAzB;AASA,OAAO,SAASC,qBAAT,CAA+BC,OAA/B,EAAqE;AAC1EA,EAAAA,OAAO,GAAG,EAAC,GAAGN,gBAAJ;AAAsB,OAAGM;AAAzB,GAAV;AAEA,QAAM;AAACL,IAAAA,KAAD;AAAQC,IAAAA,MAAR;AAAgBK,IAAAA,MAAhB;AAAwBC,IAAAA;AAAxB,MAAkCF,OAAxC;;AAEA,MAAIE,MAAM,IAAI,CAACD,MAAf,EAAuB;AACrB,UAAM,IAAIE,KAAJ,CAAU,qCAAV,CAAN;AACD;;AACD,MAAI,CAACZ,UAAL,EAAiB;AACf,UAAM,IAAIY,KAAJ,CAAUV,mBAAV,CAAN;AACD;;AACD,QAAMW,EAAE,GAAGb,UAAU,CAACI,KAAD,EAAQC,MAAR,EAAgBI,OAAhB,CAArB;;AACA,MAAI,CAACI,EAAL,EAAS;AACP,UAAM,IAAID,KAAJ,CAAUX,qBAAV,CAAN;AACD;;AACD,SAAOY,EAAP;AACD","sourcesContent":["import headlessGL from 'gl';\n\nconst ERR_HEADLESSGL_FAILED =\n 'Failed to create WebGL context in Node.js, headless gl returned null';\n\nconst ERR_HEADLESSGL_LOAD = `\\\n luma.gl: loaded under Node.js without headless gl installed, meaning that WebGL \\\n contexts can not be created. This may not be an error. For example, this is a \\\n typical configuration for isorender applications running on the server.`;\n\nconst CONTEXT_DEFAULTS = {\n width: 1,\n height: 1,\n debug: true,\n throwOnError: false\n};\n\n// Create headless gl context (for running under Node.js)\n// Create headless gl context (for running under Node.js)\nexport function createHeadlessContext(options?: any): WebGLRenderingContext {\n options = {...CONTEXT_DEFAULTS, ...options};\n\n const {width, height, webgl1, webgl2} = options;\n\n if (webgl2 && !webgl1) {\n throw new Error('headless-gl does not support WebGL2');\n }\n if (!headlessGL) {\n throw new Error(ERR_HEADLESSGL_LOAD);\n }\n const gl = headlessGL(width, height, options);\n if (!gl) {\n throw new Error(ERR_HEADLESSGL_FAILED);\n }\n return gl;\n}\n"],"file":"create-headless-context.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-test-context.d.ts","sourceRoot":"","sources":["../src/create-test-context.ts"],"names":[],"mappings":"AAEA,wBAAgB,iBAAiB,CAAC,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,qBAAqB,GAAG,IAAI,CAG9F"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/create-test-context.ts"],"names":["createTestDevice","createTestContext","opts","device","gl"],"mappings":"AAAA,SAASA,gBAAT,QAAiC,sBAAjC;AAEA,OAAO,SAASC,iBAAT,CAA2BC,IAAyB,GAAG,EAAvD,EAAyF;AAC9F,QAAMC,MAAM,GAAGH,gBAAgB,CAACE,IAAD,CAA/B;AACA,SAAOC,MAAM,IAAIA,MAAM,CAACC,EAAxB;AACD","sourcesContent":["import { createTestDevice } from \"./create-test-device\";\n\nexport function createTestContext(opts: Record<string, any> = {}): WebGLRenderingContext | null {\n const device = createTestDevice(opts);\n return device && device.gl;\n}\n\n /*\nimport {isBrowser} from 'probe.gl/env';\nimport {createGLContext, instrumentGLContext} from '@luma.gl/gltools';\nimport {createHeadlessContext} from './create-headless-context';\n\nexport function createTestContext(opts: Record<string, any> = {}): WebGLRenderingContext | null {\n // try {\n if (!isBrowser()) {\n if (opts.webgl2 && !opts.webgl1) {\n return null;\n }\n const gl = createHeadlessContext(opts);\n return gl ? instrumentGLContext(gl) : null;\n }\n return createGLContext(opts);\n // } catch {\n // if (opts.webgl2) {\n // return null;\n // }\n // }\n}\n*/\n"],"file":"create-test-context.js"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import headlessGL from 'gl';
|
|
2
|
-
|
|
3
|
-
const ERR_HEADLESSGL_FAILED =
|
|
4
|
-
'Failed to create WebGL context in Node.js, headless gl returned null';
|
|
5
|
-
|
|
6
|
-
const ERR_HEADLESSGL_LOAD = `\
|
|
7
|
-
luma.gl: loaded under Node.js without headless gl installed, meaning that WebGL \
|
|
8
|
-
contexts can not be created. This may not be an error. For example, this is a \
|
|
9
|
-
typical configuration for isorender applications running on the server.`;
|
|
10
|
-
|
|
11
|
-
const CONTEXT_DEFAULTS = {
|
|
12
|
-
width: 1,
|
|
13
|
-
height: 1,
|
|
14
|
-
debug: true,
|
|
15
|
-
throwOnError: false
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// Create headless gl context (for running under Node.js)
|
|
19
|
-
// Create headless gl context (for running under Node.js)
|
|
20
|
-
export function createHeadlessContext(options?: any): WebGLRenderingContext {
|
|
21
|
-
options = {...CONTEXT_DEFAULTS, ...options};
|
|
22
|
-
|
|
23
|
-
const {width, height, webgl1, webgl2} = options;
|
|
24
|
-
|
|
25
|
-
if (webgl2 && !webgl1) {
|
|
26
|
-
throw new Error('headless-gl does not support WebGL2');
|
|
27
|
-
}
|
|
28
|
-
if (!headlessGL) {
|
|
29
|
-
throw new Error(ERR_HEADLESSGL_LOAD);
|
|
30
|
-
}
|
|
31
|
-
const gl = headlessGL(width, height, options);
|
|
32
|
-
if (!gl) {
|
|
33
|
-
throw new Error(ERR_HEADLESSGL_FAILED);
|
|
34
|
-
}
|
|
35
|
-
return gl;
|
|
36
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { createTestDevice } from "./create-test-device";
|
|
2
|
-
|
|
3
|
-
export function createTestContext(opts: Record<string, any> = {}): WebGLRenderingContext | null {
|
|
4
|
-
const device = createTestDevice(opts);
|
|
5
|
-
return device && device.gl;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/*
|
|
9
|
-
import {isBrowser} from 'probe.gl/env';
|
|
10
|
-
import {createGLContext, instrumentGLContext} from '@luma.gl/gltools';
|
|
11
|
-
import {createHeadlessContext} from './create-headless-context';
|
|
12
|
-
|
|
13
|
-
export function createTestContext(opts: Record<string, any> = {}): WebGLRenderingContext | null {
|
|
14
|
-
// try {
|
|
15
|
-
if (!isBrowser()) {
|
|
16
|
-
if (opts.webgl2 && !opts.webgl1) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
const gl = createHeadlessContext(opts);
|
|
20
|
-
return gl ? instrumentGLContext(gl) : null;
|
|
21
|
-
}
|
|
22
|
-
return createGLContext(opts);
|
|
23
|
-
// } catch {
|
|
24
|
-
// if (opts.webgl2) {
|
|
25
|
-
// return null;
|
|
26
|
-
// }
|
|
27
|
-
// }
|
|
28
|
-
}
|
|
29
|
-
*/
|