@luma.gl/test-utils 8.6.0-alpha.4 → 9.0.0-alpha.2
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 +10 -2
- package/dist/create-test-device.d.ts.map +1 -1
- package/dist/create-test-device.js +25 -2
- package/dist/create-test-device.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- 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/package.json +2 -3
- package/src/check-type.ts +6 -0
- package/src/create-test-device.ts +33 -7
- package/src/index.ts +7 -1
- package/src/snapshot-test-runner.ts +6 -1
- package/src/test-runner.ts +12 -7
|
@@ -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,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { Device, DeviceProps } from '@luma.gl/api';
|
|
2
|
+
import { WebGLDevice } from '@luma.gl/webgl';
|
|
3
|
+
import { WebGPUDevice } from '@luma.gl/webgpu';
|
|
4
|
+
export declare function createTestDevice(props?: DeviceProps): WebGLDevice | null;
|
|
3
5
|
export declare const webgl1TestDevice: WebGLDevice;
|
|
4
6
|
export declare const webgl2TestDevice: WebGLDevice;
|
|
7
|
+
/** Only available after getTestDevices() has completed */
|
|
8
|
+
export declare let webgpuTestDevice: WebGPUDevice;
|
|
9
|
+
/** Synchronously get test devices (only WebGLDevices) */
|
|
10
|
+
export declare function getWebGLTestDevices(): WebGLDevice[];
|
|
11
|
+
/** Includes WebGPU device if available */
|
|
12
|
+
export declare function getTestDevices(): Promise<Device[]>;
|
|
5
13
|
//# 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":"AACA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"create-test-device.d.ts","sourceRoot":"","sources":["../src/create-test-device.ts"],"names":[],"mappings":"AACA,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;AAiB7C,wBAAgB,gBAAgB,CAAC,KAAK,GAAE,WAAgB,GAAG,WAAW,GAAG,IAAI,CAU5E;AAED,eAAO,MAAM,gBAAgB,EAAE,WAAuF,CAAC;AACvH,eAAO,MAAM,gBAAgB,EAAE,WAAuF,CAAC;AACvH,0DAA0D;AAC1D,eAAO,IAAI,gBAAgB,EAAE,YAAY,CAAC;AAI1C,yDAAyD;AACzD,wBAAgB,mBAAmB,IAAI,WAAW,EAAE,CAEnD;AAED,0CAA0C;AAC1C,wBAAsB,cAAc,IAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAUzD"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isBrowser } from 'probe.gl/env';
|
|
2
|
+
import { luma } from '@luma.gl/api';
|
|
2
3
|
import { WebGLDevice } from '@luma.gl/webgl';
|
|
3
4
|
import { createHeadlessContext } from './create-headless-context';
|
|
4
5
|
const ERR_HEADLESSGL_FAILED = 'Failed to create WebGL context in Node.js, headless gl returned null';
|
|
@@ -13,20 +14,42 @@ export function createTestDevice(props = {}) {
|
|
|
13
14
|
const gl = !isBrowser() ? createHeadlessContext(props) : undefined;
|
|
14
15
|
props = { ...CONTEXT_DEFAULTS,
|
|
15
16
|
...props,
|
|
16
|
-
gl
|
|
17
|
+
gl,
|
|
18
|
+
debug: true
|
|
17
19
|
};
|
|
18
20
|
return new WebGLDevice(props);
|
|
19
21
|
} catch (error) {
|
|
20
|
-
console.error(error.message);
|
|
22
|
+
console.error("Failed to created device '".concat(props.id, "': ").concat(error.message));
|
|
21
23
|
return null;
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
export const webgl1TestDevice = createTestDevice({
|
|
27
|
+
id: 'webgl1-test-device',
|
|
25
28
|
webgl1: true,
|
|
26
29
|
webgl2: false
|
|
27
30
|
});
|
|
28
31
|
export const webgl2TestDevice = createTestDevice({
|
|
32
|
+
id: 'webgl2-test-device',
|
|
29
33
|
webgl1: false,
|
|
30
34
|
webgl2: true
|
|
31
35
|
});
|
|
36
|
+
export let webgpuTestDevice;
|
|
37
|
+
let webgpuCreated = false;
|
|
38
|
+
export function getWebGLTestDevices() {
|
|
39
|
+
return [webgl2TestDevice, webgl1TestDevice].filter(Boolean);
|
|
40
|
+
}
|
|
41
|
+
export async function getTestDevices() {
|
|
42
|
+
if (!webgpuCreated) {
|
|
43
|
+
webgpuCreated = true;
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
webgpuTestDevice = await luma.createDevice({
|
|
47
|
+
id: 'webgpu-test-device',
|
|
48
|
+
type: 'webgpu'
|
|
49
|
+
});
|
|
50
|
+
} catch {}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return [webgpuTestDevice, webgl2TestDevice, webgl1TestDevice].filter(Boolean);
|
|
54
|
+
}
|
|
32
55
|
//# sourceMappingURL=create-test-device.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/create-test-device.ts"],"names":["isBrowser","WebGLDevice","createHeadlessContext","ERR_HEADLESSGL_FAILED","ERR_HEADLESSGL_LOAD","CONTEXT_DEFAULTS","width","height","debug","createTestDevice","props","gl","undefined","error","console","message","webgl1TestDevice","webgl1","webgl2","webgl2TestDevice"],"mappings":"AAAA,SAAQA,SAAR,QAAwB,cAAxB;AACA,SAAQC,WAAR,
|
|
1
|
+
{"version":3,"sources":["../src/create-test-device.ts"],"names":["isBrowser","luma","WebGLDevice","createHeadlessContext","ERR_HEADLESSGL_FAILED","ERR_HEADLESSGL_LOAD","CONTEXT_DEFAULTS","width","height","debug","createTestDevice","props","gl","undefined","error","console","id","message","webgl1TestDevice","webgl1","webgl2","webgl2TestDevice","webgpuTestDevice","webgpuCreated","getWebGLTestDevices","filter","Boolean","getTestDevices","createDevice","type"],"mappings":"AAAA,SAAQA,SAAR,QAAwB,cAAxB;AAEA,SAAQC,IAAR,QAAmB,cAAnB;AACA,SAAQC,WAAR,QAA0B,gBAA1B;AAEA,SAAQC,qBAAR,QAAoC,2BAApC;AAEA,MAAMC,qBAAqB,GACzB,sEADF;AAGA,MAAMC,mBAAmB,gPAAzB;AAKA,MAAMC,gBAAsC,GAAG;AAC7CC,EAAAA,KAAK,EAAE,CADsC;AAE7CC,EAAAA,MAAM,EAAE,CAFqC;AAG7CC,EAAAA,KAAK,EAAE;AAHsC,CAA/C;AAMA,OAAO,SAASC,gBAAT,CAA0BC,KAAkB,GAAG,EAA/C,EAAuE;AAC5E,MAAI;AACF,UAAMC,EAAE,GAAG,CAACZ,SAAS,EAAV,GAAeG,qBAAqB,CAACQ,KAAD,CAAp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CAAP;AACD","sourcesContent":["import {isBrowser} from 'probe.gl/env';\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';\nimport {createHeadlessContext} from './create-headless-context';\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: Partial<DeviceProps> = {\n width: 1,\n height: 1,\n debug: true\n};\n\nexport function createTestDevice(props: DeviceProps = {}): WebGLDevice | null {\n try {\n const gl = !isBrowser() ? createHeadlessContext(props) : undefined;\n props = {...CONTEXT_DEFAULTS, ...props, gl, 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.message}`);\n return null;\n }\n}\n\nexport const webgl1TestDevice: WebGLDevice = createTestDevice({id: 'webgl1-test-device', webgl1: true, webgl2: false});\nexport const webgl2TestDevice: WebGLDevice = createTestDevice({id: 'webgl2-test-device', webgl1: false, webgl2: true});\n/** Only available after getTestDevices() has completed */\nexport let webgpuTestDevice: WebGPUDevice;\n\nlet webgpuCreated = false;\n\n/** Synchronously get test devices (only WebGLDevices) */\nexport function getWebGLTestDevices(): WebGLDevice[] {\n return [webgl2TestDevice, webgl1TestDevice].filter(Boolean);\n}\n\n/** Includes WebGPU device if available */\nexport async function getTestDevices() : Promise<Device[]> {\n if (!webgpuCreated) {\n webgpuCreated = true;\n try {\n webgpuTestDevice = await luma.createDevice({id: 'webgpu-test-device', type: 'webgpu'}) as WebGPUDevice;\n } catch {\n // ignore (assume WebGPU was not available)\n }\n }\n return [webgpuTestDevice, webgl2TestDevice, webgl1TestDevice].filter(Boolean);\n}\n"],"file":"create-test-device.js"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
export type { TestRunnerTestCase } from './test-runner';
|
|
2
|
+
export type { SnapshotTestRunnerTestCase } from './snapshot-test-runner';
|
|
1
3
|
export { default as SnapshotTestRunner } from './snapshot-test-runner';
|
|
2
4
|
export { default as PerformanceTestRunner } from './performance-test-runner';
|
|
3
5
|
export { createHeadlessContext } from './create-headless-context';
|
|
4
6
|
export { createTestContext } from './create-test-context';
|
|
5
|
-
export { createTestDevice, webgl1TestDevice, webgl2TestDevice } from './create-test-device';
|
|
7
|
+
export { createTestDevice, webgl1TestDevice, webgl2TestDevice, webgpuTestDevice } from './create-test-device';
|
|
8
|
+
export { getTestDevices, getWebGLTestDevices } from './create-test-device';
|
|
9
|
+
export { checkType } from './check-type';
|
|
6
10
|
//# 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,EAAC,OAAO,IAAI,kBAAkB,EAAC,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAC,OAAO,IAAI,qBAAqB,EAAC,MAAM,2BAA2B,CAAC;AAC3E,OAAO,EAAC,qBAAqB,EAAC,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAC,iBAAiB,EAAC,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAC,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,EAAC,MAAM,sBAAsB,CAAC"}
|
|
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,qBAAqB,EAAC,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAC,iBAAiB,EAAC,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAC,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,EAAC,MAAM,sBAAsB,CAAC;AAC5G,OAAO,EAAC,cAAc,EAAE,mBAAmB,EAAC,MAAM,sBAAsB,CAAC;AAEzE,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,5 +2,7 @@ export { default as SnapshotTestRunner } from './snapshot-test-runner';
|
|
|
2
2
|
export { default as PerformanceTestRunner } from './performance-test-runner';
|
|
3
3
|
export { createHeadlessContext } from './create-headless-context';
|
|
4
4
|
export { createTestContext } from './create-test-context';
|
|
5
|
-
export { createTestDevice, webgl1TestDevice, webgl2TestDevice } from './create-test-device';
|
|
5
|
+
export { createTestDevice, webgl1TestDevice, webgl2TestDevice, webgpuTestDevice } from './create-test-device';
|
|
6
|
+
export { getTestDevices, getWebGLTestDevices } from './create-test-device';
|
|
7
|
+
export { checkType } from './check-type';
|
|
6
8
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["default","SnapshotTestRunner","PerformanceTestRunner","createHeadlessContext","createTestContext","createTestDevice","webgl1TestDevice","webgl2TestDevice"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["default","SnapshotTestRunner","PerformanceTestRunner","createHeadlessContext","createTestContext","createTestDevice","webgl1TestDevice","webgl2TestDevice","webgpuTestDevice","getTestDevices","getWebGLTestDevices","checkType"],"mappings":"AAGA,SAAQA,OAAO,IAAIC,kBAAnB,QAA4C,wBAA5C;AACA,SAAQD,OAAO,IAAIE,qBAAnB,QAA+C,2BAA/C;AACA,SAAQC,qBAAR,QAAoC,2BAApC;AACA,SAAQC,iBAAR,QAAgC,uBAAhC;AACA,SAAQC,gBAAR,EAA0BC,gBAA1B,EAA4CC,gBAA5C,EAA8DC,gBAA9D,QAAqF,sBAArF;AACA,SAAQC,cAAR,EAAwBC,mBAAxB,QAAkD,sBAAlD;AAEA,SAAQC,SAAR,QAAwB,cAAxB","sourcesContent":["export 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 {createHeadlessContext} from './create-headless-context';\nexport {createTestContext} from './create-test-context';\nexport {createTestDevice, webgl1TestDevice, webgl2TestDevice, webgpuTestDevice} from './create-test-device';\nexport {getTestDevices, getWebGLTestDevices} from './create-test-device';\n\nexport {checkType} from './check-type';\n"],"file":"index.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,EAAAA,OAAO,EAAE;AAP+C,CAA1D;AAUA,eAAe,MAAMC,UAAN,CAAiB;AAY9BC,EAAAA,WAAW,CAACC,KAAK,GAAG,EAAT,EAAa;AAAA;;AAAA,uCAVZ,KAUY;;AAAA;;AAAA,6CARW,EAQX;;AAAA,wCAPmB,EAOnB;;AAAA,2CANA,IAMA;;AAC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gBAAL,CAAsBnC,UAAtB,CAAiCiB,MAAM,CAACC,MAAP,CAAc,EAAd,EAAkB0B,cAAlB,EAAkC,KAAKU,aAAvC,CAAjC;;AAGA7D,MAAAA,eAAe,CAACmD,cAAc,CAACkB,EAAhB,CAAf;AAEA,WAAK3B,gBAAL,GAAwB,IAAxB;AACA,WAAKmB,aAAL,GAAqB,IAArB;AACD;;AAGD,UAAMnD,QAAQ,GAAG,KAAKoB,UAAL,CAAgBwC,KAAhB,EAAjB;;AACA,QAAI5D,QAAJ,EAAc;AAEZ,WAAKgC,gBAAL,GAAwBhC,QAAxB;AACA,WAAKqD,yBAAL,GAAiCZ,cAAc,CAACa,IAAhD;AACA,WAAKE,yBAAL,GAAiCf,cAAc,CAACc,IAAhD;AACA,WAAKlB,YAAL,CAAkBrC,QAAlB;AAKAX,MAAAA,gBAAgB,CAACoD,cAAc,CAACkB,EAAhB,CAAhB;AAIAnC,MAAAA,OAAO,CAACC,OAAR,CACEzB,QAAQ,CAACN,YAAT,CACEoB,MAAM,CAACC,MAAP,CAAc,EAAd,EAAkB0B,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,WAAKjD,WAAL,CAAiBd,WAAjB,CAA6BC,QAA7B;AACD;;AACD,WAAOA,QAAP;AACD;;AAlM6B","sourcesContent":["// @ts-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,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;AAkB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E,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/test-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0-alpha.2",
|
|
4
4
|
"description": "Automated WebGL testing utilities with Puppeteer and image diffing",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -35,9 +35,8 @@
|
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@luma.gl/core": "8.6.0-alpha.1",
|
|
38
|
-
"@luma.gl/debug": "8.6.0-alpha.1",
|
|
39
38
|
"@luma.gl/webgl": "8.6.0-alpha.1",
|
|
40
39
|
"@probe.gl/test-utils": "^3.5.0"
|
|
41
40
|
},
|
|
42
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "81e93840f31f0e32f86dfea6b576acf2c2d9caec"
|
|
43
42
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import {isBrowser} from 'probe.gl/env';
|
|
2
|
-
import {
|
|
2
|
+
import type {Device, DeviceProps} from '@luma.gl/api';
|
|
3
|
+
import {luma} from '@luma.gl/api';
|
|
4
|
+
import {WebGLDevice} from '@luma.gl/webgl';
|
|
5
|
+
import {WebGPUDevice} from '@luma.gl/webgpu';
|
|
3
6
|
import {createHeadlessContext} from './create-headless-context';
|
|
4
7
|
|
|
5
8
|
const ERR_HEADLESSGL_FAILED =
|
|
@@ -10,22 +13,45 @@ const ERR_HEADLESSGL_LOAD = `\
|
|
|
10
13
|
contexts can not be created. This may not be an error. For example, this is a \
|
|
11
14
|
typical configuration for isorender applications running on the server.`;
|
|
12
15
|
|
|
13
|
-
const CONTEXT_DEFAULTS: Partial<
|
|
16
|
+
const CONTEXT_DEFAULTS: Partial<DeviceProps> = {
|
|
14
17
|
width: 1,
|
|
15
18
|
height: 1,
|
|
16
19
|
debug: true
|
|
17
20
|
};
|
|
18
21
|
|
|
19
|
-
export function createTestDevice(props:
|
|
22
|
+
export function createTestDevice(props: DeviceProps = {}): WebGLDevice | null {
|
|
20
23
|
try {
|
|
21
24
|
const gl = !isBrowser() ? createHeadlessContext(props) : undefined;
|
|
22
|
-
props = {...CONTEXT_DEFAULTS, ...props, gl};
|
|
25
|
+
props = {...CONTEXT_DEFAULTS, ...props, gl, debug: true};
|
|
26
|
+
// We dont use luma.createDevice since this tests current expect this context to be created synchronously
|
|
23
27
|
return new WebGLDevice(props);
|
|
24
28
|
} catch (error) {
|
|
25
|
-
console.error(error.message);
|
|
29
|
+
console.error(`Failed to created device '${props.id}': ${error.message}`);
|
|
26
30
|
return null;
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
export const webgl1TestDevice: WebGLDevice = createTestDevice({webgl1: true, webgl2: false});
|
|
31
|
-
export const webgl2TestDevice: WebGLDevice = createTestDevice({webgl1: false, webgl2: true});
|
|
34
|
+
export const webgl1TestDevice: WebGLDevice = createTestDevice({id: 'webgl1-test-device', webgl1: true, webgl2: false});
|
|
35
|
+
export const webgl2TestDevice: WebGLDevice = createTestDevice({id: 'webgl2-test-device', webgl1: false, webgl2: true});
|
|
36
|
+
/** Only available after getTestDevices() has completed */
|
|
37
|
+
export let webgpuTestDevice: WebGPUDevice;
|
|
38
|
+
|
|
39
|
+
let webgpuCreated = false;
|
|
40
|
+
|
|
41
|
+
/** Synchronously get test devices (only WebGLDevices) */
|
|
42
|
+
export function getWebGLTestDevices(): WebGLDevice[] {
|
|
43
|
+
return [webgl2TestDevice, webgl1TestDevice].filter(Boolean);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Includes WebGPU device if available */
|
|
47
|
+
export async function getTestDevices() : Promise<Device[]> {
|
|
48
|
+
if (!webgpuCreated) {
|
|
49
|
+
webgpuCreated = true;
|
|
50
|
+
try {
|
|
51
|
+
webgpuTestDevice = await luma.createDevice({id: 'webgpu-test-device', type: 'webgpu'}) as WebGPUDevice;
|
|
52
|
+
} catch {
|
|
53
|
+
// ignore (assume WebGPU was not available)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return [webgpuTestDevice, webgl2TestDevice, webgl1TestDevice].filter(Boolean);
|
|
57
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
export type {TestRunnerTestCase} from './test-runner';
|
|
2
|
+
export type {SnapshotTestRunnerTestCase} from './snapshot-test-runner';
|
|
3
|
+
|
|
1
4
|
export {default as SnapshotTestRunner} from './snapshot-test-runner';
|
|
2
5
|
export {default as PerformanceTestRunner} from './performance-test-runner';
|
|
3
6
|
export {createHeadlessContext} from './create-headless-context';
|
|
4
7
|
export {createTestContext} from './create-test-context';
|
|
5
|
-
export {createTestDevice, webgl1TestDevice, webgl2TestDevice} from './create-test-device';
|
|
8
|
+
export {createTestDevice, webgl1TestDevice, webgl2TestDevice, webgpuTestDevice} from './create-test-device';
|
|
9
|
+
export {getTestDevices, getWebGLTestDevices} from './create-test-device';
|
|
10
|
+
|
|
11
|
+
export {checkType} from './check-type';
|
|
@@ -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
|
/**
|