@luma.gl/test-utils 9.0.0-alpha.2 → 9.0.0-alpha.20
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.js +0 -1
- package/dist/check-type.js.map +1 -1
- package/dist/create-test-device.d.ts +10 -3
- package/dist/create-test-device.d.ts.map +1 -1
- package/dist/create-test-device.js +27 -16
- package/dist/create-test-device.js.map +1 -1
- package/dist/index.cjs +404 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -7
- package/dist/index.js.map +1 -1
- package/dist/performance-test-runner.d.ts +6 -5
- package/dist/performance-test-runner.d.ts.map +1 -1
- package/dist/performance-test-runner.js +9 -20
- 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 +9 -4
- package/dist/snapshot-test-runner.d.ts.map +1 -1
- package/dist/snapshot-test-runner.js +21 -25
- package/dist/snapshot-test-runner.js.map +1 -1
- package/dist/test-runner.d.ts +27 -21
- package/dist/test-runner.d.ts.map +1 -1
- package/dist/test-runner.js +39 -64
- 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 +24 -7
- package/src/check-type.ts +1 -1
- package/src/create-test-device.ts +35 -19
- package/src/index.ts +3 -3
- package/src/performance-test-runner.ts +15 -12
- package/src/register-devices.ts +10 -0
- package/src/snapshot-test-runner.ts +30 -29
- package/src/test-runner.ts +76 -64
- 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
package/dist/check-type.js
CHANGED
package/dist/check-type.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"check-type.js","names":["checkType","value"],"sources":["../src/check-type.ts"],"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"],"mappings":"AAKA,OAAO,SAASA,SAASA,CAAIC,KAAQ,EAAQ,CAAC"}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import type { Device, DeviceProps } from '@luma.gl/api';
|
|
2
2
|
import { WebGLDevice } from '@luma.gl/webgl';
|
|
3
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 */
|
|
4
7
|
export declare function createTestDevice(props?: DeviceProps): WebGLDevice | null;
|
|
5
|
-
|
|
6
|
-
export declare const
|
|
8
|
+
/** A WebGL 1 Device intended for testing */
|
|
9
|
+
export declare const webgl1Device: WebGLDevice;
|
|
10
|
+
/** A WebGL 2 Device intended for testing. Can be null */
|
|
11
|
+
export declare const webgl2Device: WebGLDevice;
|
|
12
|
+
/** A WebGL 2 or WebGL 1 Device intended for testing. Best available. */
|
|
13
|
+
export declare const webglDevice: WebGLDevice;
|
|
7
14
|
/** Only available after getTestDevices() has completed */
|
|
8
|
-
export declare let
|
|
15
|
+
export declare let webgpuDevice: WebGPUDevice;
|
|
9
16
|
/** Synchronously get test devices (only WebGLDevices) */
|
|
10
17
|
export declare function getWebGLTestDevices(): WebGLDevice[];
|
|
11
18
|
/** Includes WebGPU device if available */
|
|
@@ -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,CAU5E;AAED,4CAA4C;AAC5C,eAAO,MAAM,YAAY,EAAE,WAAuF,CAAE;AACpH,yDAAyD;AACzD,eAAO,MAAM,YAAY,EAAE,WAAuF,CAAE;AACpH,wEAAwE;AACxE,eAAO,MAAM,WAAW,EAAE,WAA0C,CAAC;AAErE,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,20 +1,21 @@
|
|
|
1
|
-
import { isBrowser } from 'probe.gl/env';
|
|
2
1
|
import { luma } from '@luma.gl/api';
|
|
3
2
|
import { WebGLDevice } from '@luma.gl/webgl';
|
|
4
|
-
import { createHeadlessContext } from './create-headless-context';
|
|
5
|
-
const ERR_HEADLESSGL_FAILED = 'Failed to create WebGL context in Node.js, headless gl returned null';
|
|
6
|
-
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.";
|
|
7
3
|
const CONTEXT_DEFAULTS = {
|
|
8
4
|
width: 1,
|
|
9
5
|
height: 1,
|
|
10
6
|
debug: true
|
|
11
7
|
};
|
|
12
|
-
export function
|
|
8
|
+
export function createTestContext() {
|
|
9
|
+
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
10
|
+
const device = createTestDevice(opts);
|
|
11
|
+
return device && device.gl;
|
|
12
|
+
}
|
|
13
|
+
export function createTestDevice() {
|
|
14
|
+
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
13
15
|
try {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
props = {
|
|
17
|
+
...CONTEXT_DEFAULTS,
|
|
16
18
|
...props,
|
|
17
|
-
gl,
|
|
18
19
|
debug: true
|
|
19
20
|
};
|
|
20
21
|
return new WebGLDevice(props);
|
|
@@ -23,33 +24,43 @@ export function createTestDevice(props = {}) {
|
|
|
23
24
|
return null;
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
|
-
export const
|
|
27
|
+
export const webgl1Device = createTestDevice({
|
|
27
28
|
id: 'webgl1-test-device',
|
|
28
29
|
webgl1: true,
|
|
29
30
|
webgl2: false
|
|
30
31
|
});
|
|
31
|
-
export const
|
|
32
|
+
export const webgl2Device = createTestDevice({
|
|
32
33
|
id: 'webgl2-test-device',
|
|
33
34
|
webgl1: false,
|
|
34
35
|
webgl2: true
|
|
35
36
|
});
|
|
36
|
-
export
|
|
37
|
+
export const webglDevice = webgl2Device || webgl1Device;
|
|
38
|
+
export let webgpuDevice;
|
|
37
39
|
let webgpuCreated = false;
|
|
38
40
|
export function getWebGLTestDevices() {
|
|
39
|
-
|
|
41
|
+
const devices = [];
|
|
42
|
+
if (webgl2Device) {
|
|
43
|
+
devices.push(webgl2Device);
|
|
44
|
+
}
|
|
45
|
+
if (webgl1Device) {
|
|
46
|
+
devices.push(webgl1Device);
|
|
47
|
+
}
|
|
48
|
+
return devices;
|
|
40
49
|
}
|
|
41
50
|
export async function getTestDevices() {
|
|
42
51
|
if (!webgpuCreated) {
|
|
43
52
|
webgpuCreated = true;
|
|
44
|
-
|
|
45
53
|
try {
|
|
46
|
-
|
|
54
|
+
webgpuDevice = await luma.createDevice({
|
|
47
55
|
id: 'webgpu-test-device',
|
|
48
56
|
type: 'webgpu'
|
|
49
57
|
});
|
|
50
58
|
} catch {}
|
|
51
59
|
}
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
const devices = getWebGLTestDevices();
|
|
61
|
+
if (webgpuDevice) {
|
|
62
|
+
devices.unshift(webgpuDevice);
|
|
63
|
+
}
|
|
64
|
+
return devices;
|
|
54
65
|
}
|
|
55
66
|
//# sourceMappingURL=create-test-device.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"create-test-device.js","names":["luma","WebGLDevice","CONTEXT_DEFAULTS","width","height","debug","createTestContext","opts","arguments","length","undefined","device","createTestDevice","gl","props","error","console","concat","id","message","webgl1Device","webgl1","webgl2","webgl2Device","webglDevice","webgpuDevice","webgpuCreated","getWebGLTestDevices","devices","push","getTestDevices","createDevice","type","unshift"],"sources":["../src/create-test-device.ts"],"sourcesContent":["// luma.gl, 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 // eslint-disable-next-line no-console\n console.error(`Failed to created device '${props.id}': ${(error as Error).message}`);\n return null;\n }\n}\n\n/** A WebGL 1 Device intended for testing */\nexport const webgl1Device: WebGLDevice = createTestDevice({id: 'webgl1-test-device', webgl1: true, webgl2: false}) ;\n/** A WebGL 2 Device intended for testing. Can be null */\nexport const webgl2Device: WebGLDevice = createTestDevice({id: 'webgl2-test-device', webgl1: false, webgl2: true}) ;\n/** A WebGL 2 or WebGL 1 Device intended for testing. Best available. */\nexport const webglDevice: WebGLDevice = webgl2Device || webgl1Device;\n\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"],"mappings":"AAGA,SAAQA,IAAI,QAAO,cAAc;AACjC,SAAQC,WAAW,QAAO,gBAAgB;AAG1C,MAAMC,gBAAsC,GAAG;EAC7CC,KAAK,EAAE,CAAC;EACRC,MAAM,EAAE,CAAC;EACTC,KAAK,EAAE;AACT,CAAC;AAGD,OAAO,SAASC,iBAAiBA,CAAA,EAA+D;EAAA,IAA9DC,IAAyB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAC9D,MAAMG,MAAM,GAAGC,gBAAgB,CAACL,IAAI,CAAC;EACrC,OAAOI,MAAM,IAAIA,MAAM,CAACE,EAAE;AAC5B;AAGA,OAAO,SAASD,gBAAgBA,CAAA,EAA8C;EAAA,IAA7CE,KAAkB,GAAAN,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EACtD,IAAI;IACFM,KAAK,GAAG;MAAC,GAAGZ,gBAAgB;MAAE,GAAGY,KAAK;MAAET,KAAK,EAAE;IAAI,CAAC;IAEpD,OAAO,IAAIJ,WAAW,CAACa,KAAK,CAAC;EAC/B,CAAC,CAAC,OAAOC,KAAK,EAAE;IAEdC,OAAO,CAACD,KAAK,8BAAAE,MAAA,CAA8BH,KAAK,CAACI,EAAE,SAAAD,MAAA,CAAOF,KAAK,CAAWI,OAAO,EAAG;IACpF,OAAO,IAAI;EACb;AACF;AAGA,OAAO,MAAMC,YAAyB,GAAGR,gBAAgB,CAAC;EAACM,EAAE,EAAE,oBAAoB;EAAEG,MAAM,EAAE,IAAI;EAAEC,MAAM,EAAE;AAAK,CAAC,CAAC;AAElH,OAAO,MAAMC,YAAyB,GAAGX,gBAAgB,CAAC;EAACM,EAAE,EAAE,oBAAoB;EAAEG,MAAM,EAAE,KAAK;EAAEC,MAAM,EAAE;AAAI,CAAC,CAAC;AAElH,OAAO,MAAME,WAAwB,GAAGD,YAAY,IAAIH,YAAY;AAGpE,OAAO,IAAIK,YAA0B;AAErC,IAAIC,aAAa,GAAG,KAAK;AAGzB,OAAO,SAASC,mBAAmBA,CAAA,EAAkB;EACnD,MAAMC,OAAsB,GAAG,EAAE;EACjC,IAAIL,YAAY,EAAE;IAChBK,OAAO,CAACC,IAAI,CAACN,YAAY,CAAC;EAC5B;EACA,IAAIH,YAAY,EAAE;IAChBQ,OAAO,CAACC,IAAI,CAACT,YAAY,CAAC;EAC5B;EACA,OAAOQ,OAAO;AAChB;AAGA,OAAO,eAAeE,cAAcA,CAAA,EAAuB;EACzD,IAAI,CAACJ,aAAa,EAAE;IAClBA,aAAa,GAAG,IAAI;IACpB,IAAI;MACFD,YAAY,GAAG,MAAMzB,IAAI,CAAC+B,YAAY,CAAC;QAACb,EAAE,EAAE,oBAAoB;QAAEc,IAAI,EAAE;MAAQ,CAAC,CAAiB;IACpG,CAAC,CAAC,MAAM,CAER;EACF;EAEA,MAAMJ,OAAiB,GAAGD,mBAAmB,EAAE;EAC/C,IAAIF,YAAY,EAAE;IAChBG,OAAO,CAACK,OAAO,CAACR,YAAY,CAAC;EAC/B;EACA,OAAOG,OAAO;AAChB"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
+
};
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
38
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
39
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
40
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
41
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
42
|
+
mod
|
|
43
|
+
));
|
|
44
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
45
|
+
var __async = (__this, __arguments, generator) => {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
var fulfilled = (value) => {
|
|
48
|
+
try {
|
|
49
|
+
step(generator.next(value));
|
|
50
|
+
} catch (e) {
|
|
51
|
+
reject(e);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var rejected = (value) => {
|
|
55
|
+
try {
|
|
56
|
+
step(generator.throw(value));
|
|
57
|
+
} catch (e) {
|
|
58
|
+
reject(e);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
62
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// src/index.ts
|
|
67
|
+
var src_exports = {};
|
|
68
|
+
__export(src_exports, {
|
|
69
|
+
PerformanceTestRunner: () => PerformanceTestRunner,
|
|
70
|
+
SnapshotTestRunner: () => SnapshotTestRunner,
|
|
71
|
+
checkType: () => checkType,
|
|
72
|
+
createTestContext: () => createTestContext,
|
|
73
|
+
createTestDevice: () => createTestDevice,
|
|
74
|
+
getTestDevices: () => getTestDevices,
|
|
75
|
+
getWebGLTestDevices: () => getWebGLTestDevices,
|
|
76
|
+
webgl1Device: () => webgl1Device,
|
|
77
|
+
webgl2Device: () => webgl2Device,
|
|
78
|
+
webgpuDevice: () => webgpuDevice
|
|
79
|
+
});
|
|
80
|
+
module.exports = __toCommonJS(src_exports);
|
|
81
|
+
|
|
82
|
+
// src/register-devices.ts
|
|
83
|
+
var import_api = require("@luma.gl/api");
|
|
84
|
+
var import_webgl = require("@luma.gl/webgl");
|
|
85
|
+
var import_webgpu = require("@luma.gl/webgpu");
|
|
86
|
+
var import_gl = __toESM(require("gl"), 1);
|
|
87
|
+
(0, import_webgl.registerHeadlessGL)(import_gl.default);
|
|
88
|
+
import_api.luma.registerDevices([import_webgl.WebGLDevice, import_webgpu.WebGPUDevice]);
|
|
89
|
+
|
|
90
|
+
// src/test-runner.ts
|
|
91
|
+
var import_webgl_legacy = require("@luma.gl/webgl-legacy");
|
|
92
|
+
|
|
93
|
+
// src/create-test-device.ts
|
|
94
|
+
var import_api2 = require("@luma.gl/api");
|
|
95
|
+
var import_webgl2 = require("@luma.gl/webgl");
|
|
96
|
+
var CONTEXT_DEFAULTS = {
|
|
97
|
+
width: 1,
|
|
98
|
+
height: 1,
|
|
99
|
+
debug: true
|
|
100
|
+
};
|
|
101
|
+
function createTestContext(opts = {}) {
|
|
102
|
+
const device = createTestDevice(opts);
|
|
103
|
+
return device && device.gl;
|
|
104
|
+
}
|
|
105
|
+
function createTestDevice(props = {}) {
|
|
106
|
+
try {
|
|
107
|
+
props = __spreadProps(__spreadValues(__spreadValues({}, CONTEXT_DEFAULTS), props), { debug: true });
|
|
108
|
+
return new import_webgl2.WebGLDevice(props);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error(`Failed to created device '${props.id}': ${error.message}`);
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
var webgl1Device = createTestDevice({ id: "webgl1-test-device", webgl1: true, webgl2: false });
|
|
115
|
+
var webgl2Device = createTestDevice({ id: "webgl2-test-device", webgl1: false, webgl2: true });
|
|
116
|
+
var webglDevice = webgl2Device || webgl1Device;
|
|
117
|
+
var webgpuDevice;
|
|
118
|
+
var webgpuCreated = false;
|
|
119
|
+
function getWebGLTestDevices() {
|
|
120
|
+
const devices = [];
|
|
121
|
+
if (webgl2Device) {
|
|
122
|
+
devices.push(webgl2Device);
|
|
123
|
+
}
|
|
124
|
+
if (webgl1Device) {
|
|
125
|
+
devices.push(webgl1Device);
|
|
126
|
+
}
|
|
127
|
+
return devices;
|
|
128
|
+
}
|
|
129
|
+
function getTestDevices() {
|
|
130
|
+
return __async(this, null, function* () {
|
|
131
|
+
if (!webgpuCreated) {
|
|
132
|
+
webgpuCreated = true;
|
|
133
|
+
try {
|
|
134
|
+
webgpuDevice = yield import_api2.luma.createDevice({ id: "webgpu-test-device", type: "webgpu" });
|
|
135
|
+
} catch (e) {
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const devices = getWebGLTestDevices();
|
|
139
|
+
if (webgpuDevice) {
|
|
140
|
+
devices.unshift(webgpuDevice);
|
|
141
|
+
}
|
|
142
|
+
return devices;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// src/test-runner.ts
|
|
147
|
+
function noop() {
|
|
148
|
+
}
|
|
149
|
+
var DEFAULT_TEST_CASE = {
|
|
150
|
+
name: "Unnamed test",
|
|
151
|
+
onInitialize: noop,
|
|
152
|
+
onRender: ({ done }) => done(),
|
|
153
|
+
onFinalize: noop
|
|
154
|
+
};
|
|
155
|
+
var DEFAULT_TEST_PROPS = {
|
|
156
|
+
// test lifecycle callback
|
|
157
|
+
onTestStart: (testCase) => console.log(`# ${testCase.name}`),
|
|
158
|
+
onTestPass: (testCase) => console.log(`ok ${testCase.name} passed`),
|
|
159
|
+
onTestFail: (testCase) => console.log(`not ok ${testCase.name} failed`),
|
|
160
|
+
// milliseconds to wait for each test case before aborting
|
|
161
|
+
timeout: 2e3
|
|
162
|
+
};
|
|
163
|
+
var TestRunner = class {
|
|
164
|
+
/**
|
|
165
|
+
* props
|
|
166
|
+
* AnimationLoop props
|
|
167
|
+
*/
|
|
168
|
+
constructor(props = {}) {
|
|
169
|
+
this.device = webglDevice;
|
|
170
|
+
this.isRunning = false;
|
|
171
|
+
this.testOptions = __spreadValues({}, DEFAULT_TEST_PROPS);
|
|
172
|
+
this._animationProps = {};
|
|
173
|
+
this._testCases = [];
|
|
174
|
+
this._testCaseData = null;
|
|
175
|
+
// @ts-expect-error
|
|
176
|
+
this.isHeadless = Boolean(window.browserTestDriver_isHeadless);
|
|
177
|
+
this.props = props;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Add testCase(s)
|
|
181
|
+
*/
|
|
182
|
+
add(testCases) {
|
|
183
|
+
if (!Array.isArray(testCases)) {
|
|
184
|
+
testCases = [testCases];
|
|
185
|
+
}
|
|
186
|
+
for (const testCase of testCases) {
|
|
187
|
+
this._testCases.push(testCase);
|
|
188
|
+
}
|
|
189
|
+
return this;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Returns a promise that resolves when all the test cases are done
|
|
193
|
+
*/
|
|
194
|
+
run(options = {}) {
|
|
195
|
+
this.testOptions = __spreadValues(__spreadValues({}, this.testOptions), options);
|
|
196
|
+
return new Promise((resolve, reject) => {
|
|
197
|
+
this._animationLoop = new import_webgl_legacy.AnimationLoop(__spreadProps(__spreadValues({}, this.props), {
|
|
198
|
+
device: this.device,
|
|
199
|
+
onRender: this._onRender.bind(this),
|
|
200
|
+
onFinalize: () => {
|
|
201
|
+
this.isRunning = false;
|
|
202
|
+
resolve();
|
|
203
|
+
}
|
|
204
|
+
}));
|
|
205
|
+
this._animationLoop.start(this.props);
|
|
206
|
+
this.isRunning = true;
|
|
207
|
+
this.isDiffing = false;
|
|
208
|
+
this._currentTestCase = null;
|
|
209
|
+
}).catch((error) => {
|
|
210
|
+
this._fail({ error: error.message });
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
/* Lifecycle methods for subclassing */
|
|
214
|
+
initTestCase(testCase) {
|
|
215
|
+
const { animationLoop } = testCase;
|
|
216
|
+
if (animationLoop) {
|
|
217
|
+
testCase.onInitialize = animationLoop.props.onInitialize.bind(animationLoop);
|
|
218
|
+
testCase.onRender = animationLoop.props.onRender.bind(animationLoop);
|
|
219
|
+
testCase.onFinalize = animationLoop.props.onFinalize.bind(animationLoop);
|
|
220
|
+
}
|
|
221
|
+
for (const key in DEFAULT_TEST_CASE) {
|
|
222
|
+
testCase[key] = testCase[key] || DEFAULT_TEST_CASE[key];
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
shouldRender(animationProps) {
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
assert(testCase) {
|
|
229
|
+
this._pass(testCase);
|
|
230
|
+
this._next();
|
|
231
|
+
}
|
|
232
|
+
/* Utilities */
|
|
233
|
+
_pass(result) {
|
|
234
|
+
this.testOptions.onTestPass(this._currentTestCase, result);
|
|
235
|
+
}
|
|
236
|
+
_fail(result) {
|
|
237
|
+
this.testOptions.onTestFail(this._currentTestCase, result);
|
|
238
|
+
}
|
|
239
|
+
_next() {
|
|
240
|
+
this._nextTestCase();
|
|
241
|
+
}
|
|
242
|
+
/* Private methods */
|
|
243
|
+
_onRender(animationProps) {
|
|
244
|
+
this._animationProps = animationProps;
|
|
245
|
+
const testCase = this._currentTestCase || this._nextTestCase();
|
|
246
|
+
if (!testCase) {
|
|
247
|
+
this._animationLoop.stop();
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
let isDone = false;
|
|
251
|
+
const testCaseAnimationProps = __spreadProps(__spreadValues(__spreadValues({}, animationProps), this._testCaseData), {
|
|
252
|
+
// tick/time starts from 0 for each test case
|
|
253
|
+
startTime: this._currentTestCaseStartTime,
|
|
254
|
+
time: animationProps.time - this._currentTestCaseStartTime,
|
|
255
|
+
tick: animationProps.tick - this._currentTestCaseStartTick,
|
|
256
|
+
// called by the test case when it is done rendering and ready for capture and diff
|
|
257
|
+
done: () => {
|
|
258
|
+
isDone = true;
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
if (this._testCaseData && this.shouldRender(testCaseAnimationProps)) {
|
|
262
|
+
testCase.onRender(testCaseAnimationProps);
|
|
263
|
+
}
|
|
264
|
+
const timeout = testCase.timeout || this.testOptions.timeout;
|
|
265
|
+
if (timeout && testCaseAnimationProps.time > timeout) {
|
|
266
|
+
isDone = true;
|
|
267
|
+
}
|
|
268
|
+
if (isDone) {
|
|
269
|
+
this.assert(testCase);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
_nextTestCase() {
|
|
273
|
+
const animationProps = this._animationProps;
|
|
274
|
+
if (this._testCaseData) {
|
|
275
|
+
for (const key in this._testCaseData) {
|
|
276
|
+
const value = this._testCaseData[key];
|
|
277
|
+
if (value && value.delete) {
|
|
278
|
+
value.delete();
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
this._currentTestCase.onFinalize(Object.assign({}, animationProps, this._testCaseData));
|
|
282
|
+
this.device.popState();
|
|
283
|
+
this._currentTestCase = null;
|
|
284
|
+
this._testCaseData = null;
|
|
285
|
+
}
|
|
286
|
+
const testCase = this._testCases.shift();
|
|
287
|
+
if (testCase) {
|
|
288
|
+
this._currentTestCase = testCase;
|
|
289
|
+
this._currentTestCaseStartTime = animationProps.time;
|
|
290
|
+
this._currentTestCaseStartTick = animationProps.tick;
|
|
291
|
+
this.initTestCase(testCase);
|
|
292
|
+
this.device.pushState();
|
|
293
|
+
const initProps = __spreadProps(__spreadValues({}, animationProps), {
|
|
294
|
+
// tick/time starts from 0 for each test case
|
|
295
|
+
startTime: animationProps.time,
|
|
296
|
+
time: 0,
|
|
297
|
+
tick: 0
|
|
298
|
+
});
|
|
299
|
+
Promise.resolve(testCase.onInitialize(initProps)).then((userData) => {
|
|
300
|
+
this._testCaseData = userData || {};
|
|
301
|
+
});
|
|
302
|
+
this.testOptions.onTestStart(testCase);
|
|
303
|
+
}
|
|
304
|
+
return testCase;
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
// src/utils.ts
|
|
309
|
+
function getBoundingBoxInPage(domElement) {
|
|
310
|
+
const bbox = domElement.getBoundingClientRect();
|
|
311
|
+
return {
|
|
312
|
+
x: window.scrollX + bbox.x,
|
|
313
|
+
y: window.scrollY + bbox.y,
|
|
314
|
+
width: bbox.width,
|
|
315
|
+
height: bbox.height
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// src/snapshot-test-runner.ts
|
|
320
|
+
var SnapshotTestRunner = class extends TestRunner {
|
|
321
|
+
constructor(props) {
|
|
322
|
+
super(props);
|
|
323
|
+
this.isDiffing = false;
|
|
324
|
+
this.testOptions.imageDiffOptions = {};
|
|
325
|
+
}
|
|
326
|
+
initTestCase(testCase) {
|
|
327
|
+
super.initTestCase(testCase);
|
|
328
|
+
if (!testCase.goldenImage) {
|
|
329
|
+
throw new Error(`Test case ${testCase.name} does not have golden image`);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
shouldRender() {
|
|
333
|
+
return !this.isDiffing;
|
|
334
|
+
}
|
|
335
|
+
assert(testCase) {
|
|
336
|
+
return __async(this, null, function* () {
|
|
337
|
+
var _a;
|
|
338
|
+
if (this.isDiffing) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
this.isDiffing = true;
|
|
342
|
+
const canvas = (_a = this._animationProps) == null ? void 0 : _a.canvas;
|
|
343
|
+
if (!(canvas instanceof HTMLCanvasElement)) {
|
|
344
|
+
throw new Error("canvas");
|
|
345
|
+
}
|
|
346
|
+
const diffOptions = __spreadProps(__spreadValues(__spreadValues({}, this.testOptions.imageDiffOptions), testCase.imageDiffOptions), {
|
|
347
|
+
goldenImage: testCase.goldenImage,
|
|
348
|
+
region: getBoundingBoxInPage(canvas)
|
|
349
|
+
});
|
|
350
|
+
const result = yield globalThis.browserTestDriver_captureAndDiffScreen(diffOptions);
|
|
351
|
+
if (result.success) {
|
|
352
|
+
this._pass(result);
|
|
353
|
+
} else {
|
|
354
|
+
this._fail(result);
|
|
355
|
+
}
|
|
356
|
+
this.isDiffing = false;
|
|
357
|
+
this._next();
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
// src/performance-test-runner.ts
|
|
363
|
+
var import_stats = require("@probe.gl/stats");
|
|
364
|
+
var PerformanceTestRunner = class extends TestRunner {
|
|
365
|
+
constructor(props) {
|
|
366
|
+
super(props);
|
|
367
|
+
this._stats = null;
|
|
368
|
+
this._fps = null;
|
|
369
|
+
Object.assign(this.testOptions, {
|
|
370
|
+
maxFramesToRender: 60,
|
|
371
|
+
targetFPS: 50
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
initTestCase(testCase) {
|
|
375
|
+
super.initTestCase(testCase);
|
|
376
|
+
this._stats = new import_stats.Stats({ id: testCase.name });
|
|
377
|
+
this._fps = this._stats.get("fps");
|
|
378
|
+
}
|
|
379
|
+
shouldRender(animationProps) {
|
|
380
|
+
var _a, _b;
|
|
381
|
+
(_a = this._fps) == null ? void 0 : _a.timeEnd();
|
|
382
|
+
(_b = this._fps) == null ? void 0 : _b.timeStart();
|
|
383
|
+
if (this._fps.count > this.testOptions.maxFramesToRender) {
|
|
384
|
+
animationProps.done();
|
|
385
|
+
}
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
assert(testCase) {
|
|
389
|
+
var _a, _b;
|
|
390
|
+
const targetFPS = testCase.targetFPS || this.testOptions.targetFPS;
|
|
391
|
+
const count = (_a = this._fps) == null ? void 0 : _a.count;
|
|
392
|
+
const fps = ((_b = this._fps) == null ? void 0 : _b.getHz()) || 0;
|
|
393
|
+
if (fps >= targetFPS) {
|
|
394
|
+
this._pass({ fps, framesRendered: count });
|
|
395
|
+
} else {
|
|
396
|
+
this._fail({ fps, framesRendered: count });
|
|
397
|
+
}
|
|
398
|
+
this._next();
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
// src/check-type.ts
|
|
403
|
+
function checkType(value) {
|
|
404
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import './register-devices';
|
|
1
2
|
export type { TestRunnerTestCase } from './test-runner';
|
|
2
3
|
export type { SnapshotTestRunnerTestCase } from './snapshot-test-runner';
|
|
3
4
|
export { default as SnapshotTestRunner } from './snapshot-test-runner';
|
|
4
5
|
export { default as PerformanceTestRunner } from './performance-test-runner';
|
|
5
|
-
export {
|
|
6
|
-
export { createTestContext } from './create-test-context';
|
|
7
|
-
export { createTestDevice, webgl1TestDevice, webgl2TestDevice, webgpuTestDevice } from './create-test-device';
|
|
6
|
+
export { createTestDevice, createTestContext, webgl1Device, webgl2Device, webgpuDevice } from './create-test-device';
|
|
8
7
|
export { getTestDevices, getWebGLTestDevices } from './create-test-device';
|
|
9
8
|
export { checkType } from './check-type';
|
|
10
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,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,
|
|
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,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
export { default as
|
|
3
|
-
export {
|
|
4
|
-
export { createTestContext } from
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export { checkType } from './check-type';
|
|
1
|
+
import "./register-devices.js";
|
|
2
|
+
export { default as SnapshotTestRunner } from "./snapshot-test-runner.js";
|
|
3
|
+
export { default as PerformanceTestRunner } from "./performance-test-runner.js";
|
|
4
|
+
export { createTestDevice, createTestContext, webgl1Device, webgl2Device, webgpuDevice } from "./create-test-device.js";
|
|
5
|
+
export { getTestDevices, getWebGLTestDevices } from "./create-test-device.js";
|
|
6
|
+
export { checkType } from "./check-type.js";
|
|
8
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["default","SnapshotTestRunner","PerformanceTestRunner","createTestDevice","createTestContext","webgl1Device","webgl2Device","webgpuDevice","getTestDevices","getWebGLTestDevices","checkType"],"sources":["../src/index.ts"],"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"],"mappings":";SAKQA,OAAO,IAAIC,kBAAkB;AAAA,SAC7BD,OAAO,IAAIE,qBAAqB;AAAA,SAChCC,gBAAgB,EAAEC,iBAAiB,EAAEC,YAAY,EAAEC,YAAY,EAAEC,YAAY;AAAA,SAC7EC,cAAc,EAAEC,mBAAmB;AAAA,SAEnCC,SAAS"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import TestRunner, {
|
|
1
|
+
import TestRunner, { TestRunnerProps, TestRunnerTestCase } from './test-runner';
|
|
2
|
+
export declare type PerformanceTestRunnerProps = TestRunnerProps;
|
|
2
3
|
export default class PerformanceTestRunner extends TestRunner {
|
|
3
4
|
private _stats;
|
|
4
5
|
private _fps;
|
|
5
|
-
constructor(props:
|
|
6
|
-
initTestCase(testCase:
|
|
7
|
-
shouldRender(animationProps: any): boolean;
|
|
8
|
-
assert(testCase:
|
|
6
|
+
constructor(props: PerformanceTestRunnerProps);
|
|
7
|
+
initTestCase(testCase: TestRunnerTestCase): void;
|
|
8
|
+
shouldRender(animationProps: Record<string, any>): boolean;
|
|
9
|
+
assert(testCase: TestRunnerTestCase): void;
|
|
9
10
|
}
|
|
10
11
|
//# 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,eAAe,EAAE,kBAAkB,EAAC,MAAM,eAAe,CAAC;AAE9E,oBAAY,0BAA0B,GAAG,eAAe,CAAC;AAEzD,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAAQ,UAAU;IAC3D,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,IAAI,CAAqB;gBAErB,KAAK,EAAE,0BAA0B;IASpC,YAAY,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI;IAMhD,YAAY,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO;IAW1D,MAAM,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI;CAapD"}
|