@luma.gl/test-utils 9.0.0-alpha.21 → 9.0.0-alpha.23
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/engine/classic-animation-loop.d.ts +137 -0
- package/dist/engine/classic-animation-loop.d.ts.map +1 -0
- package/dist/engine/classic-animation-loop.js +435 -0
- package/dist/engine/classic-animation-loop.js.map +1 -0
- package/dist/index.cjs +461 -14
- package/dist/snapshot-test-runner.d.ts +0 -1
- package/dist/snapshot-test-runner.d.ts.map +1 -1
- package/dist/snapshot-test-runner.js +0 -2
- package/dist/snapshot-test-runner.js.map +1 -1
- package/dist/test-runner.d.ts +11 -5
- package/dist/test-runner.d.ts.map +1 -1
- package/dist/test-runner.js +16 -9
- package/dist/test-runner.js.map +1 -1
- package/package.json +9 -5
- package/src/engine/classic-animation-loop.ts +714 -0
- package/src/snapshot-test-runner.ts +2 -1
- package/src/test-runner.ts +30 -17
package/dist/test-runner.js
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
import { AnimationLoop } from '@luma.gl/webgl-legacy';
|
|
3
2
|
import { webglDevice } from "./create-test-device.js";
|
|
4
|
-
|
|
3
|
+
import { ClassicAnimationLoop as AnimationLoop } from "./engine/classic-animation-loop.js";
|
|
5
4
|
const DEFAULT_TEST_CASE = {
|
|
6
5
|
name: 'Unnamed test',
|
|
7
|
-
onInitialize:
|
|
6
|
+
onInitialize: async () => {},
|
|
8
7
|
onRender: _ref => {
|
|
9
8
|
let {
|
|
10
9
|
done
|
|
11
10
|
} = _ref;
|
|
12
11
|
return done();
|
|
13
12
|
},
|
|
14
|
-
onFinalize:
|
|
13
|
+
onFinalize: () => {}
|
|
15
14
|
};
|
|
16
15
|
const DEFAULT_TEST_PROPS = {
|
|
16
|
+
width: undefined,
|
|
17
|
+
height: undefined,
|
|
17
18
|
onTestStart: testCase => console.log("# ".concat(testCase.name)),
|
|
18
|
-
onTestPass: testCase => console.log("ok ".concat(testCase.name, " passed")),
|
|
19
|
-
onTestFail: testCase => console.log("not ok ".concat(testCase.name, " failed")),
|
|
20
|
-
timeout: 2000
|
|
19
|
+
onTestPass: (testCase, result) => console.log("ok ".concat(testCase.name, " passed")),
|
|
20
|
+
onTestFail: (testCase, error) => console.log("not ok ".concat(testCase.name, " failed")),
|
|
21
|
+
timeout: 2000,
|
|
22
|
+
maxFramesToRender: undefined,
|
|
23
|
+
imageDiffOptions: undefined
|
|
21
24
|
};
|
|
22
25
|
export class TestRunner {
|
|
23
26
|
constructor() {
|
|
@@ -28,10 +31,14 @@ export class TestRunner {
|
|
|
28
31
|
_defineProperty(this, "testOptions", {
|
|
29
32
|
...DEFAULT_TEST_PROPS
|
|
30
33
|
});
|
|
31
|
-
_defineProperty(this, "_animationProps",
|
|
34
|
+
_defineProperty(this, "_animationProps", void 0);
|
|
32
35
|
_defineProperty(this, "_animationLoop", void 0);
|
|
33
36
|
_defineProperty(this, "_testCases", []);
|
|
34
37
|
_defineProperty(this, "_testCaseData", null);
|
|
38
|
+
_defineProperty(this, "_currentTestCase", void 0);
|
|
39
|
+
_defineProperty(this, "_currentTestCaseStartTime", void 0);
|
|
40
|
+
_defineProperty(this, "_currentTestCaseStartTick", void 0);
|
|
41
|
+
_defineProperty(this, "isDiffing", false);
|
|
35
42
|
_defineProperty(this, "isHeadless", Boolean(window.browserTestDriver_isHeadless));
|
|
36
43
|
this.props = props;
|
|
37
44
|
}
|
|
@@ -134,7 +141,7 @@ export class TestRunner {
|
|
|
134
141
|
for (const key in this._testCaseData) {
|
|
135
142
|
const value = this._testCaseData[key];
|
|
136
143
|
if (value && value.delete) {
|
|
137
|
-
value.
|
|
144
|
+
value.destroy();
|
|
138
145
|
}
|
|
139
146
|
}
|
|
140
147
|
this._currentTestCase.onFinalize(Object.assign({}, animationProps, this._testCaseData));
|
package/dist/test-runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-runner.js","names":["AnimationLoop","webglDevice","noop","DEFAULT_TEST_CASE","name","onInitialize","onRender","_ref","done","onFinalize","DEFAULT_TEST_PROPS","onTestStart","testCase","console","log","concat","onTestPass","onTestFail","timeout","TestRunner","constructor","props","arguments","length","undefined","_defineProperty","Boolean","window","browserTestDriver_isHeadless","add","testCases","Array","isArray","_testCases","push","run","options","testOptions","Promise","resolve","reject","_animationLoop","device","_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","Object","assign","popState","shift","pushState","initProps","then","userData"],"sources":["../src/test-runner.ts"],"sourcesContent":["// @ts-nocheck TODO remove\n/* eslint-disable no-console */\nimport {AnimationLoop, AnimationProps} from '@luma.gl/webgl-legacy';\nimport {webglDevice} from './create-test-device';\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: (props: AnimationProps) => Promise<unknown>;\n /** Perform rendering */\n onRender: (props: AnimationProps & {done}) => void;\n /** Clean up after the test case */\n onFinalize: (props: AnimationProps) => void;\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 TestRunnerProps = {\n width?: number;\n height?: number;\n // test lifecycle callback\n onTestStart?: (testCase: TestRunnerTestCase) => void;\n onTestPass?: (testCase: TestRunnerTestCase) => void;\n onTestFail?: (testCase: TestRunnerTestCase) => void;\n /** milliseconds to wait for each test case before aborting */\n timeout?: number;\n maxFramesToRender?: number;\n // HACK - this is for the snapshot test runner\n imageDiffOptions?: any;\n};\n\nconst DEFAULT_TEST_PROPS: Required<TestRunnerProps> = {\n // test lifecycle callback\n onTestStart: (testCase: TestRunnerTestCase) => console.log(`# ${testCase.name}`),\n onTestPass: (testCase: TestRunnerTestCase) => console.log(`ok ${testCase.name} passed`),\n onTestFail: (testCase: TestRunnerTestCase) => 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 class TestRunner {\n device = webglDevice;\n props: Record<string, any>;\n isRunning: boolean = false;\n readonly testOptions: Required<TestRunnerProps> = {...DEFAULT_TEST_PROPS};\n readonly _animationProps?: AnimationProps = {};\n private _animationLoop: AnimationLoop | null;\n private _testCases: TestRunnerTestCase[] = [];\n private _testCaseData: any = null;\n\n // @ts-expect-error\n isHeadless: boolean = Boolean(window.browserTestDriver_isHeadless);\n\n /**\n * props\n * AnimationLoop props\n */\n constructor(props: Record<string, any> = {}) {\n this.props = props;\n }\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 this.testOptions = {...this.testOptions, ...options};\n\n return new Promise<void>((resolve, reject) => {\n this._animationLoop = new AnimationLoop({\n // @ts-expect-error TODO\n ...this.props,\n device: this.device,\n onRender: this._onRender.bind(this),\n onFinalize: () => {\n this.isRunning = false;\n resolve();\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 // reject(error);\n });\n }\n\n /* Lifecycle methods for subclassing */\n\n initTestCase(testCase: TestRunnerTestCase) {\n const {animationLoop} = testCase;\n if (animationLoop) {\n testCase.onInitialize = animationLoop.props.onInitialize.bind(animationLoop);\n testCase.onRender = animationLoop.props.onRender.bind(animationLoop);\n testCase.onFinalize = animationLoop.props.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): boolean {\n return true;\n }\n\n assert(testCase: TestRunnerTestCase): void {\n this._pass(testCase);\n this._next();\n }\n\n /* Utilities */\n\n _pass(result: unknown): void {\n this.testOptions.onTestPass(this._currentTestCase, result);\n // this._animationLoop?.stop();\n }\n\n _fail(result: unknown): void {\n this.testOptions.onTestFail(this._currentTestCase, result);\n // this._animationLoop?.stop();\n }\n\n _next(): void {\n this._nextTestCase();\n }\n\n /* Private methods */\n\n _onRender(animationProps): void {\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: AnimationProps = {\n ...animationProps, \n ...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 // try {\n // test case is initialized, render frame\n testCase.onRender(testCaseAnimationProps);\n // } catch {\n // isDone = true;\n // }\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(): Promise<TestRunnerTestCase> {\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 this.device.popState();\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 this.device.pushState();\n\n // aligned with the behavior of AnimationLoop.onInitialized\n // onInitialized could return a plain object or a promise\n const initProps = {\n ...animationProps,\n // tick/time starts from 0 for each test case\n startTime: animationProps.time,\n time: 0,\n tick: 0\n };\n\n // aligned with the behavior of AnimationLoop.onInitialized\n // onInitialized could return a plain object or a promise\n Promise.resolve(testCase.onInitialize(initProps)).then((userData) => {\n this._testCaseData = userData || {};\n });\n\n // invoke user callback\n this.testOptions.onTestStart(testCase);\n }\n return testCase;\n }\n}\n"],"mappings":";AAEA,SAAQA,aAAa,QAAuB,uBAAuB;AAAC,SAC5DC,WAAW;AAcnB,SAASC,IAAIA,CAAA,EAAG,CAAC;AAEjB,MAAMC,iBAAqC,GAAG;EAC5CC,IAAI,EAAE,cAAc;EACpBC,YAAY,EAAEH,IAAI;EAClBI,QAAQ,EAAEC,IAAA;IAAA,IAAC;MAACC;IAAI,CAAC,GAAAD,IAAA;IAAA,OAAKC,IAAI,EAAE;EAAA;EAC5BC,UAAU,EAAEP;AACd,CAAC;AAiBD,MAAMQ,kBAA6C,GAAG;EAEpDC,WAAW,EAAGC,QAA4B,IAAKC,OAAO,CAACC,GAAG,MAAAC,MAAA,CAAMH,QAAQ,CAACR,IAAI,EAAG;EAChFY,UAAU,EAAGJ,QAA4B,IAAKC,OAAO,CAACC,GAAG,OAAAC,MAAA,CAAOH,QAAQ,CAACR,IAAI,aAAU;EACvFa,UAAU,EAAGL,QAA4B,IAAKC,OAAO,CAACC,GAAG,WAAAC,MAAA,CAAWH,QAAQ,CAACR,IAAI,aAAU;EAG3Fc,OAAO,EAAE;AACX,CAAC;AAGD,OAAO,MAAMC,UAAU,CAAC;EAiBtBC,WAAWA,CAAA,EAAkC;IAAA,IAAjCC,KAA0B,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ACrC,CAAC,CAAC;MAGF,IAAI,CAAC7C,WAAW,CAAC1B,WAAW,CAACC,QAAQ,CAAC;IACxC;IACA,OAAOA,QAAQ;EACjB;AACF"}
|
|
1
|
+
{"version":3,"file":"test-runner.js","names":["webglDevice","ClassicAnimationLoop","AnimationLoop","DEFAULT_TEST_CASE","name","onInitialize","onRender","_ref","done","onFinalize","DEFAULT_TEST_PROPS","width","undefined","height","onTestStart","testCase","console","log","concat","onTestPass","result","onTestFail","error","timeout","maxFramesToRender","imageDiffOptions","TestRunner","constructor","props","arguments","length","_defineProperty","Boolean","window","browserTestDriver_isHeadless","add","testCases","Array","isArray","_testCases","push","run","options","testOptions","Promise","resolve","reject","_animationLoop","device","_onRender","bind","isRunning","start","isDiffing","_currentTestCase","catch","_fail","message","initTestCase","animationLoop","key","shouldRender","animationProps","assert","_pass","_next","_nextTestCase","_animationProps","stop","isDone","testCaseAnimationProps","_testCaseData","startTime","_currentTestCaseStartTime","time","tick","_currentTestCaseStartTick","value","delete","destroy","Object","assign","popState","shift","pushState","initProps","then","userData"],"sources":["../src/test-runner.ts"],"sourcesContent":["// @ts-nocheck\n/* eslint-disable */\n\nimport {AnimationProps} from '@luma.gl/engine';\nimport {webglDevice} from './create-test-device';\n\n// TODO - Replace with new AnimationLoop from `@luma.gl/engine`\nimport {ClassicAnimationLoop as AnimationLoop} from './engine/classic-animation-loop';\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: (props: AnimationProps) => Promise<void | {}>;\n /** Perform rendering */\n onRender: (props: AnimationProps & {done}) => void;\n /** Clean up after the test case */\n onFinalize: (props: AnimationProps) => void;\n animationLoop?: AnimationLoop;\n};\n\nconst DEFAULT_TEST_CASE: TestRunnerTestCase = {\n name: 'Unnamed test',\n onInitialize: async () => {},\n onRender: ({done}) => done(),\n onFinalize: () => {}\n};\n\n/** Options for a TestRunner */\nexport type TestRunnerProps = {\n width?: number;\n height?: number;\n // test lifecycle callback\n onTestStart?: (testCase: TestRunnerTestCase) => void;\n onTestPass?: (testCase: TestRunnerTestCase, result?: unknown) => void;\n onTestFail?: (testCase: TestRunnerTestCase, error?: unknown) => void;\n /** milliseconds to wait for each test case before aborting */\n timeout?: number;\n maxFramesToRender?: number;\n // HACK - this is for the snapshot test runner\n imageDiffOptions?: any;\n};\n\nconst DEFAULT_TEST_PROPS: Required<TestRunnerProps> = {\n width: undefined,\n height: undefined,\n\n // test lifecycle callback\n onTestStart: (testCase: TestRunnerTestCase) => console.log(`# ${testCase.name}`),\n onTestPass: (testCase: TestRunnerTestCase, result?: unknown) => console.log(`ok ${testCase.name} passed`),\n onTestFail: (testCase: TestRunnerTestCase, error?: unknown) => console.log(`not ok ${testCase.name} failed`),\n\n // milliseconds to wait for each test case before aborting\n timeout: 2000,\n maxFramesToRender: undefined,\n imageDiffOptions: undefined\n};\n\n/** Runs an array of test cases */\nexport class TestRunner {\n device = webglDevice;\n props: Record<string, any>;\n isRunning: boolean = false;\n testOptions: Required<TestRunnerProps> = {...DEFAULT_TEST_PROPS};\n readonly _animationProps?: AnimationProps;\n private _animationLoop: AnimationLoop | null;\n private _testCases: TestRunnerTestCase[] = [];\n private _testCaseData: any = null;\n private _currentTestCase: TestRunnerTestCase | null;\n private _currentTestCaseStartTime: number;\n private _currentTestCaseStartTick: number;\n\n // should be defined in snapshot-test-runner\n isDiffing: boolean = false;\n\n // @ts-expect-error\n isHeadless: boolean = Boolean(window.browserTestDriver_isHeadless);\n\n /**\n * props\n * AnimationLoop props\n */\n constructor(props: Record<string, any> = {}) {\n this.props = props;\n }\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 this.testOptions = {...this.testOptions, ...options};\n\n return new Promise<void>((resolve, reject) => {\n this._animationLoop = new AnimationLoop({\n ...this.props,\n device: this.device,\n onRender: this._onRender.bind(this),\n onFinalize: () => {\n this.isRunning = false;\n resolve();\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 // reject(error);\n });\n }\n\n /* Lifecycle methods for subclassing */\n\n initTestCase(testCase: TestRunnerTestCase) {\n const {animationLoop} = testCase;\n if (animationLoop) {\n testCase.onInitialize = animationLoop.props.onInitialize.bind(animationLoop);\n testCase.onRender = animationLoop.props.onRender.bind(animationLoop);\n testCase.onFinalize = animationLoop.props.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): boolean {\n return true;\n }\n\n assert(testCase: TestRunnerTestCase): void {\n this._pass(testCase);\n this._next();\n }\n\n /* Utilities */\n\n _pass(result: unknown): void {\n this.testOptions.onTestPass(this._currentTestCase, result);\n // this._animationLoop?.stop();\n }\n\n _fail(result: unknown): void {\n this.testOptions.onTestFail(this._currentTestCase, result);\n // this._animationLoop?.stop();\n }\n\n _next(): void {\n this._nextTestCase();\n }\n\n /* Private methods */\n\n _onRender(animationProps): void {\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: AnimationProps = {\n ...animationProps, \n ...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 // try {\n // test case is initialized, render frame\n testCase.onRender(testCaseAnimationProps);\n // } catch {\n // isDone = true;\n // }\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(): Promise<TestRunnerTestCase> {\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.destroy();\n }\n }\n this._currentTestCase.onFinalize(Object.assign({}, animationProps, this._testCaseData));\n\n // reset WebGL context\n this.device.popState();\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 this.device.pushState();\n\n // aligned with the behavior of AnimationLoop.onInitialized\n // onInitialized could return a plain object or a promise\n const initProps = {\n ...animationProps,\n // tick/time starts from 0 for each test case\n startTime: animationProps.time,\n time: 0,\n tick: 0\n };\n\n // aligned with the behavior of AnimationLoop.onInitialized\n // onInitialized could return a plain object or a promise\n Promise.resolve(testCase.onInitialize(initProps)).then((userData) => {\n this._testCaseData = userData || {};\n });\n\n // invoke user callback\n this.testOptions.onTestStart(testCase);\n }\n return testCase;\n }\n}\n"],"mappings":";SAIQA,WAAW;AAAA,SAGXC,oBAAoB,IAAIC,aAAa;AAe7C,MAAMC,iBAAqC,GAAG;EAC5CC,IAAI,EAAE,cAAc;EACpBC,YAAY,EAAE,MAAAA,CAAA,KAAY,CAAC,CAAC;EAC5BC,QAAQ,EAAEC,IAAA;IAAA,IAAC;MAACC;IAAI,CAAC,GAAAD,IAAA;IAAA,OAAKC,IAAI,EAAE;EAAA;EAC5BC,UAAU,EAAEA,CAAA,KAAM,CAAC;AACrB,CAAC;AAiBD,MAAMC,kBAA6C,GA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xD,QAAQ,GAAG,IAAI,CAACwB,UAAU,CAAC4C,KAAK,EAAE;IACxC,IAAIpE,QAAQ,EAAE;MAEZ,IAAI,CAACuC,gBAAgB,GAAGvC,QAAQ;MAChC,IAAI,CAAC0D,yBAAyB,GAAGX,cAAc,CAACY,IAAI;MACpD,IAAI,CAACE,yBAAyB,GAAGd,cAAc,CAACa,IAAI;MACpD,IAAI,CAACjB,YAAY,CAAC3C,QAAQ,CAAC;MAK3B,IAAI,CAACiC,MAAM,CAACoC,SAAS,EAAE;MAIvB,MAAMC,SAAS,GAAG;QAChB,GAAGvB,cAAc;QAEjBU,SAAS,EAAEV,cAAc,CAACY,IAAI;QAC9BA,IAAI,EAAE,CAAC;QACPC,IAAI,EAAE;MACR,CAAC;MAID/B,OAAO,CAACC,OAAO,CAAC9B,QAAQ,CAACV,YAAY,CAACgF,SAAS,CAAC,CAAC,CAACC,IAAI,CAAEC,QAAQ,IAAK;QACnE,IAAI,CAAChB,aAAa,GAAGgB,QAAQ,IAAI,CAAC,CAAC;MACrC,CAAC,CAAC;MAGF,IAAI,CAAC5C,WAAW,CAAC7B,WAAW,CAACC,QAAQ,CAAC;IACxC;IACA,OAAOA,QAAQ;EACjB;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/test-utils",
|
|
3
|
-
"version": "9.0.0-alpha.
|
|
3
|
+
"version": "9.0.0-alpha.23",
|
|
4
4
|
"description": "Automated WebGL testing utilities with Puppeteer and image diffing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,14 +39,18 @@
|
|
|
39
39
|
"pre-build": "echo test utils has no bundle"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
+
"@luma.gl/api": "9.0.0-alpha.23",
|
|
43
|
+
"@luma.gl/engine": "9.0.0-alpha.23",
|
|
44
|
+
"@luma.gl/webgl": "9.0.0-alpha.23",
|
|
45
|
+
"@luma.gl/webgpu": "9.0.0-alpha.23",
|
|
42
46
|
"@probe.gl/env": "^4.0.2",
|
|
43
47
|
"@types/gl": "^6.0.2",
|
|
44
48
|
"gl": "^6.0.1"
|
|
45
49
|
},
|
|
46
50
|
"peerDependencies": {
|
|
47
|
-
"@luma.gl/api": "9.0.0-alpha.
|
|
48
|
-
"@luma.gl/webgl": "9.0.0-alpha.
|
|
49
|
-
"@luma.gl/webgpu": "9.0.0-alpha.
|
|
51
|
+
"@luma.gl/api": "9.0.0-alpha.21",
|
|
52
|
+
"@luma.gl/webgl": "9.0.0-alpha.21",
|
|
53
|
+
"@luma.gl/webgpu": "9.0.0-alpha.21",
|
|
50
54
|
"@probe.gl/test-utils": "^4.0.2"
|
|
51
55
|
},
|
|
52
56
|
"engines_comment": [
|
|
@@ -55,5 +59,5 @@
|
|
|
55
59
|
"engines": {
|
|
56
60
|
"node": ">=16.18.0"
|
|
57
61
|
},
|
|
58
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "5e4a30497333bea4be8f2b3f3db33c0b67931b9c"
|
|
59
63
|
}
|