@deck.gl/test-utils 9.0.0-beta.1 → 9.0.0-beta.11
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/generate-layer-tests.d.ts +20 -0
- package/dist/generate-layer-tests.d.ts.map +1 -0
- package/dist/generate-layer-tests.js +209 -0
- package/dist/index.cjs +646 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/interaction-test-runner.d.ts +29 -0
- package/dist/interaction-test-runner.d.ts.map +1 -0
- package/dist/interaction-test-runner.js +57 -0
- package/dist/lifecycle-test.d.ts +119 -0
- package/dist/lifecycle-test.d.ts.map +1 -0
- package/dist/lifecycle-test.js +232 -0
- package/dist/snapshot-test-runner.d.ts +46 -0
- package/dist/snapshot-test-runner.d.ts.map +1 -0
- package/dist/snapshot-test-runner.js +104 -0
- package/dist/test-runner.d.ts +56 -0
- package/dist/test-runner.d.ts.map +1 -0
- package/dist/test-runner.js +143 -0
- package/dist/utils/dom.d.ts +7 -0
- package/dist/utils/dom.d.ts.map +1 -0
- package/dist/utils/dom.js +11 -0
- package/dist/utils/precision.d.ts +4 -0
- package/dist/utils/precision.d.ts.map +1 -0
- package/dist/utils/precision.js +19 -0
- package/dist/utils/setup-gl.d.ts +5 -0
- package/dist/utils/setup-gl.d.ts.map +1 -0
- package/dist/utils/setup-gl.js +15 -0
- package/package.json +18 -10
- package/src/generate-layer-tests.ts +54 -15
- package/src/index.ts +7 -3
- package/src/interaction-test-runner.ts +29 -13
- package/src/lifecycle-test.ts +214 -27
- package/src/snapshot-test-runner.ts +84 -48
- package/src/test-runner.ts +77 -59
- package/src/utils/dom.ts +6 -1
- package/src/utils/precision.ts +13 -6
- package/src/utils/setup-gl.ts +2 -2
- package/dist/es5/generate-layer-tests.js +0 -243
- package/dist/es5/generate-layer-tests.js.map +0 -1
- package/dist/es5/index.js +0 -88
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/interaction-test-runner.js +0 -119
- package/dist/es5/interaction-test-runner.js.map +0 -1
- package/dist/es5/lifecycle-test.js +0 -456
- package/dist/es5/lifecycle-test.js.map +0 -1
- package/dist/es5/snapshot-test-runner.js +0 -145
- package/dist/es5/snapshot-test-runner.js.map +0 -1
- package/dist/es5/test-runner.js +0 -198
- package/dist/es5/test-runner.js.map +0 -1
- package/dist/es5/utils/dom.js +0 -17
- package/dist/es5/utils/dom.js.map +0 -1
- package/dist/es5/utils/precision.js +0 -33
- package/dist/es5/utils/precision.js.map +0 -1
- package/dist/es5/utils/setup-gl.js +0 -19
- package/dist/es5/utils/setup-gl.js.map +0 -1
- package/dist/esm/generate-layer-tests.js +0 -216
- package/dist/esm/generate-layer-tests.js.map +0 -1
- package/dist/esm/index.js +0 -8
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/interaction-test-runner.js +0 -52
- package/dist/esm/interaction-test-runner.js.map +0 -1
- package/dist/esm/lifecycle-test.js +0 -282
- package/dist/esm/lifecycle-test.js.map +0 -1
- package/dist/esm/snapshot-test-runner.js +0 -94
- package/dist/esm/snapshot-test-runner.js.map +0 -1
- package/dist/esm/test-runner.js +0 -134
- package/dist/esm/test-runner.js.map +0 -1
- package/dist/esm/utils/dom.js +0 -10
- package/dist/esm/utils/dom.js.map +0 -1
- package/dist/esm/utils/precision.js +0 -18
- package/dist/esm/utils/precision.js.map +0 -1
- package/dist/esm/utils/setup-gl.js +0 -9
- package/dist/esm/utils/setup-gl.js.map +0 -1
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
// in the Software without restriction, including without limitation the rights
|
|
6
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
// furnished to do so, subject to the following conditions:
|
|
9
|
+
//
|
|
10
|
+
// The above copyright notice and this permission notice shall be included in
|
|
11
|
+
// all copies or substantial portions of the Software.
|
|
12
|
+
//
|
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
// THE SOFTWARE.
|
|
20
|
+
/* global window */
|
|
21
|
+
import { TestRunner } from "./test-runner.js";
|
|
22
|
+
import { getBoundingBoxInPage } from "./utils/dom.js";
|
|
23
|
+
const DEFAULT_TEST_OPTIONS = {
|
|
24
|
+
imageDiffOptions: {}
|
|
25
|
+
};
|
|
26
|
+
const DEFAULT_TEST_CASE = {
|
|
27
|
+
name: 'Unnamed snapshot test',
|
|
28
|
+
props: {},
|
|
29
|
+
onBeforeRender: ({ deck, layers }) => {
|
|
30
|
+
// eslint-disable-line
|
|
31
|
+
},
|
|
32
|
+
onAfterRender: ({ deck, layers, done }) => {
|
|
33
|
+
if (
|
|
34
|
+
// @ts-expect-error accessing private
|
|
35
|
+
!deck.layerManager?.needsUpdate() &&
|
|
36
|
+
layers.every(layer => layer.isLoaded)) {
|
|
37
|
+
done(); // eslint-disable-line
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
goldenImage: ''
|
|
41
|
+
};
|
|
42
|
+
export class SnapshotTestRunner extends TestRunner {
|
|
43
|
+
constructor(props) {
|
|
44
|
+
super(props, DEFAULT_TEST_OPTIONS);
|
|
45
|
+
this._isDiffing = false;
|
|
46
|
+
this._isDiffing = false;
|
|
47
|
+
}
|
|
48
|
+
get defaultTestCase() {
|
|
49
|
+
return DEFAULT_TEST_CASE;
|
|
50
|
+
}
|
|
51
|
+
initTestCase(testCase) {
|
|
52
|
+
super.initTestCase(testCase);
|
|
53
|
+
if (!testCase.goldenImage) {
|
|
54
|
+
throw new Error(`Test case ${testCase.name} does not have golden image`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
runTestCase(testCase) {
|
|
58
|
+
const deck = this.deck;
|
|
59
|
+
return new Promise(resolve => {
|
|
60
|
+
deck.setProps({
|
|
61
|
+
...this.props,
|
|
62
|
+
...testCase,
|
|
63
|
+
onBeforeRender: () => {
|
|
64
|
+
testCase.onBeforeRender({
|
|
65
|
+
deck,
|
|
66
|
+
// @ts-expect-error Accessing protected layerManager
|
|
67
|
+
layers: this.deck.layerManager.getLayers()
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
onAfterRender: () => {
|
|
71
|
+
testCase.onAfterRender({
|
|
72
|
+
deck,
|
|
73
|
+
// @ts-expect-error Accessing protected layerManager
|
|
74
|
+
layers: this.deck.layerManager.getLayers(),
|
|
75
|
+
done: resolve
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async assert(testCase) {
|
|
82
|
+
if (this._isDiffing) {
|
|
83
|
+
// already performing diffing
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this._isDiffing = true;
|
|
87
|
+
const diffOptions = {
|
|
88
|
+
...this.testOptions.imageDiffOptions,
|
|
89
|
+
...testCase.imageDiffOptions,
|
|
90
|
+
goldenImage: testCase.goldenImage,
|
|
91
|
+
region: getBoundingBoxInPage(this.deck.getCanvas())
|
|
92
|
+
};
|
|
93
|
+
// Take screenshot and compare
|
|
94
|
+
const result = await window.browserTestDriver_captureAndDiffScreen(diffOptions);
|
|
95
|
+
// invoke user callback
|
|
96
|
+
if (result.success) {
|
|
97
|
+
this.pass(result);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
this.fail(result);
|
|
101
|
+
}
|
|
102
|
+
this._isDiffing = false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Deck, DeckProps } from '@deck.gl/core';
|
|
2
|
+
export type TestCase = {
|
|
3
|
+
name: string;
|
|
4
|
+
/** milliseconds to wait before aborting */
|
|
5
|
+
timeout?: number;
|
|
6
|
+
};
|
|
7
|
+
type TestOptions<TestCaseT extends TestCase, ResultT> = {
|
|
8
|
+
/** Called when a test case starts */
|
|
9
|
+
onTestStart: (testCase: TestCaseT) => void;
|
|
10
|
+
/** Called when a test case passes */
|
|
11
|
+
onTestPass: (testCase: TestCaseT, result: ResultT) => void;
|
|
12
|
+
/** Called when a test case fails */
|
|
13
|
+
onTestFail: (testCase: TestCaseT, result: ResultT | {
|
|
14
|
+
error: string;
|
|
15
|
+
}) => void;
|
|
16
|
+
/** milliseconds to wait for each test case before aborting */
|
|
17
|
+
timeout: number;
|
|
18
|
+
};
|
|
19
|
+
export declare abstract class TestRunner<TestCaseT extends TestCase, ResultT, ExtraOptions = {}> {
|
|
20
|
+
deck: Deck<any> | null;
|
|
21
|
+
props: DeckProps<any>;
|
|
22
|
+
isHeadless: boolean;
|
|
23
|
+
isRunning: boolean;
|
|
24
|
+
testOptions: TestOptions<TestCaseT, ResultT> & ExtraOptions;
|
|
25
|
+
gpuVendor?: string;
|
|
26
|
+
private _testCases;
|
|
27
|
+
private _currentTestCase;
|
|
28
|
+
private _testCaseData;
|
|
29
|
+
/**
|
|
30
|
+
* props
|
|
31
|
+
* Deck props
|
|
32
|
+
*/
|
|
33
|
+
constructor(props: DeckProps | undefined, options: ExtraOptions);
|
|
34
|
+
get defaultTestCase(): TestCaseT;
|
|
35
|
+
/**
|
|
36
|
+
* Add testCase(s)
|
|
37
|
+
*/
|
|
38
|
+
add(testCases: TestCaseT[]): this;
|
|
39
|
+
/**
|
|
40
|
+
* Returns a promise that resolves when all the test cases are done
|
|
41
|
+
*/
|
|
42
|
+
run(options?: Partial<TestOptions<TestCaseT, ResultT> & ExtraOptions>): Promise<void>;
|
|
43
|
+
initTestCase(testCase: TestCaseT): void;
|
|
44
|
+
/** Execute the test case. Fails if takes longer than options.timeout */
|
|
45
|
+
abstract runTestCase(testCase: TestCaseT): Promise<void>;
|
|
46
|
+
/** Check the result of the test case. Calls pass() or fail() */
|
|
47
|
+
abstract assert(testCase: TestCaseT): Promise<void>;
|
|
48
|
+
protected pass(result: ResultT): void;
|
|
49
|
+
protected fail(result: ResultT | {
|
|
50
|
+
error: string;
|
|
51
|
+
}): void;
|
|
52
|
+
private _onDeviceInitialized;
|
|
53
|
+
private _runTest;
|
|
54
|
+
}
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=test-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-runner.d.ts","sourceRoot":"","sources":["../src/test-runner.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAC,IAAI,EAAE,SAAS,EAAU,MAAM,eAAe,CAAC;AAcvD,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,WAAW,CAAC,SAAS,SAAS,QAAQ,EAAE,OAAO,IAAI;IACtD,qCAAqC;IACrC,WAAW,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,IAAI,CAAC;IAC3C,qCAAqC;IACrC,UAAU,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3D,oCAAoC;IACpC,UAAU,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,GAAG;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,KAAK,IAAI,CAAC;IAE7E,8DAA8D;IAC9D,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAYF,8BAAsB,UAAU,CAAC,SAAS,SAAS,QAAQ,EAAE,OAAO,EAAE,YAAY,GAAG,EAAE;IACrF,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAC9B,KAAK,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC;IACtB,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,OAAO,CAAS;IAC3B,WAAW,EAAE,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,GAAG,YAAY,CAAC;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,OAAO,CAAC,UAAU,CAAmB;IACrC,OAAO,CAAC,gBAAgB,CAA0B;IAClD,OAAO,CAAC,aAAa,CAAiB;IAEtC;;;OAGG;gBACS,KAAK,uBAAgB,EAAE,OAAO,EAAE,YAAY;IASxD,IAAI,eAAe,IAAI,SAAS,CAE/B;IAED;;OAEG;IACH,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,GAAG,IAAI;IAUjC;;OAEG;IACH,GAAG,CAAC,OAAO,GAAE,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,GAAG,YAAY,CAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgCzF,YAAY,CAAC,QAAQ,EAAE,SAAS;IAShC,wEAAwE;IACxE,QAAQ,CAAC,WAAW,CAAC,QAAQ,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IACxD,gEAAgE;IAChE,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAInD,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO;IAI9B,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,GAAG;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC;IAMhD,OAAO,CAAC,oBAAoB;YAId,QAAQ;CAuBvB"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// Copyright (c) 2015 - 2017 Uber Technologies, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
// in the Software without restriction, including without limitation the rights
|
|
6
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
// furnished to do so, subject to the following conditions:
|
|
9
|
+
//
|
|
10
|
+
// The above copyright notice and this permission notice shall be included in
|
|
11
|
+
// all copies or substantial portions of the Software.
|
|
12
|
+
//
|
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
// THE SOFTWARE.
|
|
20
|
+
/* global window, console, setTimeout */
|
|
21
|
+
/* eslint-disable no-console */
|
|
22
|
+
import { Deck, MapView } from '@deck.gl/core';
|
|
23
|
+
const DEFAULT_DECK_PROPS = {
|
|
24
|
+
...Deck.defaultProps,
|
|
25
|
+
id: 'deckgl-render-test',
|
|
26
|
+
width: 800,
|
|
27
|
+
height: 450,
|
|
28
|
+
style: { position: 'absolute', left: '0px', top: '0px' },
|
|
29
|
+
views: [new MapView({})],
|
|
30
|
+
useDevicePixels: false,
|
|
31
|
+
debug: true
|
|
32
|
+
};
|
|
33
|
+
const DEFAULT_TEST_OPTIONS = {
|
|
34
|
+
// test lifecycle callback
|
|
35
|
+
onTestStart: testCase => console.log(`# ${testCase.name}`),
|
|
36
|
+
onTestPass: testCase => console.log(`ok ${testCase.name} passed`),
|
|
37
|
+
onTestFail: testCase => console.log(`not ok ${testCase.name} failed`),
|
|
38
|
+
// milliseconds to wait for each test case before aborting
|
|
39
|
+
timeout: 2000
|
|
40
|
+
};
|
|
41
|
+
export class TestRunner {
|
|
42
|
+
/**
|
|
43
|
+
* props
|
|
44
|
+
* Deck props
|
|
45
|
+
*/
|
|
46
|
+
constructor(props = {}, options) {
|
|
47
|
+
this.deck = null;
|
|
48
|
+
this.isRunning = false;
|
|
49
|
+
this._testCases = [];
|
|
50
|
+
this._currentTestCase = null;
|
|
51
|
+
this._testCaseData = null;
|
|
52
|
+
this.props = { ...DEFAULT_DECK_PROPS, ...props };
|
|
53
|
+
// @ts-ignore browserTestDriver_isHeadless is injected by @probe.gl/test-utils if running in headless browser
|
|
54
|
+
this.isHeadless = Boolean(window.browserTestDriver_isHeadless);
|
|
55
|
+
this.testOptions = { ...DEFAULT_TEST_OPTIONS, ...options };
|
|
56
|
+
}
|
|
57
|
+
get defaultTestCase() {
|
|
58
|
+
throw new Error('Not implemented');
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Add testCase(s)
|
|
62
|
+
*/
|
|
63
|
+
add(testCases) {
|
|
64
|
+
if (!Array.isArray(testCases)) {
|
|
65
|
+
testCases = [testCases];
|
|
66
|
+
}
|
|
67
|
+
for (const testCase of testCases) {
|
|
68
|
+
this._testCases.push(testCase);
|
|
69
|
+
}
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Returns a promise that resolves when all the test cases are done
|
|
74
|
+
*/
|
|
75
|
+
run(options = {}) {
|
|
76
|
+
Object.assign(this.testOptions, options);
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
this.deck = new Deck({
|
|
79
|
+
...this.props,
|
|
80
|
+
onDeviceInitialized: this._onDeviceInitialized.bind(this),
|
|
81
|
+
onLoad: resolve
|
|
82
|
+
});
|
|
83
|
+
this.isRunning = true;
|
|
84
|
+
this._currentTestCase = null;
|
|
85
|
+
})
|
|
86
|
+
.then(() => {
|
|
87
|
+
let promise = Promise.resolve();
|
|
88
|
+
// chain test case promises
|
|
89
|
+
this._testCases.forEach(testCase => {
|
|
90
|
+
promise = promise.then(() => this._runTest(testCase));
|
|
91
|
+
});
|
|
92
|
+
return promise;
|
|
93
|
+
})
|
|
94
|
+
.catch((error) => {
|
|
95
|
+
this.fail({ error: error.message });
|
|
96
|
+
})
|
|
97
|
+
.finally(() => {
|
|
98
|
+
this.deck.finalize();
|
|
99
|
+
this.deck = null;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/* Lifecycle methods for subclassing */
|
|
103
|
+
initTestCase(testCase) {
|
|
104
|
+
for (const key in this.defaultTestCase) {
|
|
105
|
+
if (!(key in testCase)) {
|
|
106
|
+
testCase[key] = this.defaultTestCase[key];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
this.testOptions.onTestStart(testCase);
|
|
110
|
+
}
|
|
111
|
+
/* Utilities */
|
|
112
|
+
pass(result) {
|
|
113
|
+
this.testOptions.onTestPass(this._currentTestCase, result);
|
|
114
|
+
}
|
|
115
|
+
fail(result) {
|
|
116
|
+
this.testOptions.onTestFail(this._currentTestCase, result);
|
|
117
|
+
}
|
|
118
|
+
/* Private Methods */
|
|
119
|
+
_onDeviceInitialized(device) {
|
|
120
|
+
this.gpuVendor = device.info.vendor;
|
|
121
|
+
}
|
|
122
|
+
async _runTest(testCase) {
|
|
123
|
+
this._currentTestCase = testCase;
|
|
124
|
+
// normalize test case
|
|
125
|
+
this.initTestCase(testCase);
|
|
126
|
+
const timeout = testCase.timeout || this.testOptions.timeout;
|
|
127
|
+
const task = this.runTestCase(testCase);
|
|
128
|
+
const timeoutTask = new Promise((_, reject) => {
|
|
129
|
+
setTimeout(() => {
|
|
130
|
+
reject('Timeout');
|
|
131
|
+
}, timeout);
|
|
132
|
+
});
|
|
133
|
+
try {
|
|
134
|
+
await Promise.race([task, timeoutTask]);
|
|
135
|
+
await this.assert(testCase);
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
if (err === 'Timeout') {
|
|
139
|
+
this.fail({ error: 'Timeout' });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../../src/utils/dom.ts"],"names":[],"mappings":"AAEA,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,WAAW,GAAG;IAC7D,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAQA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/* global window */
|
|
2
|
+
// Get the bounding box of a DOMElement relative to the page
|
|
3
|
+
export function getBoundingBoxInPage(domElement) {
|
|
4
|
+
const bbox = domElement.getBoundingClientRect();
|
|
5
|
+
return {
|
|
6
|
+
x: window.scrollX + bbox.x,
|
|
7
|
+
y: window.scrollY + bbox.y,
|
|
8
|
+
width: bbox.width,
|
|
9
|
+
height: bbox.height
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function toLowPrecision(input: number, precision?: number): number;
|
|
2
|
+
export declare function toLowPrecision(input: number[], precision?: number): number[];
|
|
3
|
+
export declare function toLowPrecision(input: Record<string, number>, precision?: number): Record<string, number>;
|
|
4
|
+
//# sourceMappingURL=precision.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"precision.d.ts","sourceRoot":"","sources":["../../src/utils/precision.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;AAC1E,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;AAC9E,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Covert all numbers in a deep structure to a given precision, allowing
|
|
3
|
+
* reliable float comparisons. Converts data in-place.
|
|
4
|
+
*/
|
|
5
|
+
export function toLowPrecision(input, precision = 11) {
|
|
6
|
+
/* eslint-disable guard-for-in */
|
|
7
|
+
if (typeof input === 'number') {
|
|
8
|
+
return Number(input.toPrecision(precision));
|
|
9
|
+
}
|
|
10
|
+
if (Array.isArray(input)) {
|
|
11
|
+
return input.map(item => toLowPrecision(item, precision));
|
|
12
|
+
}
|
|
13
|
+
if (typeof input === 'object') {
|
|
14
|
+
for (const key in input) {
|
|
15
|
+
input[key] = toLowPrecision(input[key], precision);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return input;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-gl.d.ts","sourceRoot":"","sources":["../../src/utils/setup-gl.ts"],"names":[],"mappings":"AAEA,kBAAkB;AAClB,eAAO,MAAM,MAAM,sCAAc,CAAC;AAElC,mBAAmB;AACnB,eAAO,MAAM,EAAE,+BAMb,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createTestContext, webglDevice } from '@luma.gl/test-utils';
|
|
2
|
+
/** Test device */
|
|
3
|
+
export const device = webglDevice;
|
|
4
|
+
/** Test context */
|
|
5
|
+
export const gl = createTestContext({
|
|
6
|
+
width: 1,
|
|
7
|
+
height: 1,
|
|
8
|
+
debug: true
|
|
9
|
+
// throwOnFailure: false,
|
|
10
|
+
// throwOnError: false
|
|
11
|
+
});
|
|
12
|
+
// // TODO - Seems to be an issue in luma.gl
|
|
13
|
+
// (createContext && createContext(100, 100, {}));
|
|
14
|
+
// // console.log('Context', globalThis.glContext);
|
|
15
|
+
globalThis.glContext = globalThis.glContext || gl;
|
package/package.json
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
"name": "@deck.gl/test-utils",
|
|
3
3
|
"description": "Test utilities for deck.gl layers",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"version": "9.0.0-beta.11",
|
|
6
7
|
"publishConfig": {
|
|
7
8
|
"access": "public"
|
|
8
9
|
},
|
|
@@ -16,22 +17,29 @@
|
|
|
16
17
|
"type": "git",
|
|
17
18
|
"url": "https://github.com/visgl/deck.gl.git"
|
|
18
19
|
},
|
|
19
|
-
"
|
|
20
|
-
"
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
21
|
+
"main": "dist/index.cjs",
|
|
22
|
+
"module": "dist/index.js",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js",
|
|
27
|
+
"require": "./dist/index.cjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
21
30
|
"files": [
|
|
22
31
|
"dist",
|
|
23
|
-
"src"
|
|
24
|
-
"typed"
|
|
32
|
+
"src"
|
|
25
33
|
],
|
|
26
34
|
"dependencies": {
|
|
27
|
-
"@
|
|
35
|
+
"@luma.gl/test-utils": "^9.0.11"
|
|
28
36
|
},
|
|
29
37
|
"peerDependencies": {
|
|
30
|
-
"@deck.gl/core": "^9.0.0-
|
|
31
|
-
"@luma.gl/
|
|
32
|
-
"@luma.gl/
|
|
38
|
+
"@deck.gl/core": "^9.0.0-beta",
|
|
39
|
+
"@luma.gl/core": "^9.0.0",
|
|
40
|
+
"@luma.gl/engine": "^9.0.0",
|
|
33
41
|
"@probe.gl/test-utils": "^4.0.0"
|
|
34
42
|
},
|
|
35
43
|
"scripts": {},
|
|
36
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "d8a3f5bdb644f85caba9d5c1e74baff8f8a3d439"
|
|
37
45
|
}
|
|
@@ -17,39 +17,60 @@
|
|
|
17
17
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
18
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
19
|
// THE SOFTWARE.
|
|
20
|
-
import {_count as count} from '@deck.gl/core';
|
|
20
|
+
import {_count as count, Layer} from '@deck.gl/core';
|
|
21
|
+
|
|
22
|
+
import type {DefaultProps} from '@deck.gl/core';
|
|
23
|
+
import type {LayerTestCase, LayerClass} from './lifecycle-test';
|
|
21
24
|
|
|
22
25
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
23
26
|
function noop() {}
|
|
24
27
|
|
|
25
|
-
function defaultAssert(condition, comment) {
|
|
28
|
+
function defaultAssert(condition: any, comment: string): void {
|
|
26
29
|
if (!condition) {
|
|
27
30
|
throw new Error(comment);
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
// Automatically generate testLayer test cases
|
|
32
|
-
export function generateLayerTests({
|
|
35
|
+
export function generateLayerTests<LayerT extends Layer>({
|
|
33
36
|
Layer,
|
|
34
37
|
sampleProps = {},
|
|
35
38
|
assert = defaultAssert,
|
|
36
39
|
onBeforeUpdate = noop,
|
|
37
40
|
onAfterUpdate = noop,
|
|
38
41
|
runDefaultAsserts = true
|
|
39
|
-
}
|
|
42
|
+
}: {
|
|
43
|
+
Layer: LayerClass<LayerT>;
|
|
44
|
+
/**
|
|
45
|
+
* Override default props during the test
|
|
46
|
+
*/
|
|
47
|
+
sampleProps?: Partial<LayerT['props']>;
|
|
48
|
+
assert?: (condition: any, comment: string) => void;
|
|
49
|
+
onBeforeUpdate?: LayerTestCase<LayerT>['onBeforeUpdate'];
|
|
50
|
+
onAfterUpdate?: LayerTestCase<LayerT>['onAfterUpdate'];
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Test some typical assumptions after layer updates
|
|
54
|
+
* For primitive layers, assert that layer has model(s).
|
|
55
|
+
* For composite layers, assert that layer has sublayer(s).
|
|
56
|
+
* @default true
|
|
57
|
+
*/
|
|
58
|
+
runDefaultAsserts?: boolean;
|
|
59
|
+
}): LayerTestCase<LayerT>[] {
|
|
40
60
|
assert(Layer.layerName, 'Layer should have display name');
|
|
41
61
|
|
|
42
|
-
function wrapTestCaseTitle(title) {
|
|
62
|
+
function wrapTestCaseTitle(title: string): string {
|
|
43
63
|
return `${Layer.layerName}#${title}`;
|
|
44
64
|
}
|
|
45
65
|
|
|
46
|
-
const testCases = [
|
|
66
|
+
const testCases: LayerTestCase<LayerT>[] = [
|
|
47
67
|
{
|
|
48
68
|
title: 'Empty props',
|
|
49
69
|
props: {}
|
|
50
70
|
},
|
|
51
71
|
{
|
|
52
72
|
title: 'Null data',
|
|
73
|
+
// @ts-expect-error null may not be an expected data type
|
|
53
74
|
updateProps: {data: null}
|
|
54
75
|
},
|
|
55
76
|
{
|
|
@@ -62,14 +83,15 @@ export function generateLayerTests({
|
|
|
62
83
|
// Calling constructor for the first time resolves default props
|
|
63
84
|
// eslint-disable-next-line
|
|
64
85
|
new Layer({});
|
|
65
|
-
} catch (error) {
|
|
66
|
-
assert(false, `Construct ${Layer.layerName} throws: ${error.message}`);
|
|
86
|
+
} catch (error: unknown) {
|
|
87
|
+
assert(false, `Construct ${Layer.layerName} throws: ${(error as Error).message}`);
|
|
67
88
|
}
|
|
68
89
|
|
|
90
|
+
// @ts-expect-error Access hidden properties
|
|
69
91
|
const {_propTypes: propTypes, _mergedDefaultProps: defaultProps} = Layer;
|
|
70
92
|
|
|
71
93
|
// Test alternative data formats
|
|
72
|
-
testCases.push(...makeAltDataTestCases(sampleProps, propTypes));
|
|
94
|
+
testCases.push(...makeAltDataTestCases<LayerT>(sampleProps, propTypes));
|
|
73
95
|
|
|
74
96
|
for (const propName in Layer.defaultProps) {
|
|
75
97
|
if (!(propName in sampleProps)) {
|
|
@@ -113,7 +135,19 @@ export function generateLayerTests({
|
|
|
113
135
|
return testCases;
|
|
114
136
|
}
|
|
115
137
|
|
|
116
|
-
function makeAltPropTestCase
|
|
138
|
+
function makeAltPropTestCase<LayerT extends Layer>({
|
|
139
|
+
propName,
|
|
140
|
+
propTypes,
|
|
141
|
+
defaultProps,
|
|
142
|
+
sampleProps,
|
|
143
|
+
assert
|
|
144
|
+
}: {
|
|
145
|
+
propName: string;
|
|
146
|
+
propTypes: DefaultProps<LayerT['props']>;
|
|
147
|
+
defaultProps: LayerT['props'];
|
|
148
|
+
sampleProps: Partial<LayerT['props']>;
|
|
149
|
+
assert: (condition: any, comment: string) => void;
|
|
150
|
+
}): LayerTestCase<LayerT>[] | null {
|
|
117
151
|
const newProps = {...sampleProps};
|
|
118
152
|
const propDef = propTypes[propName];
|
|
119
153
|
|
|
@@ -174,7 +208,7 @@ function makeAltPropTestCase({propName, propTypes, defaultProps, sampleProps, as
|
|
|
174
208
|
updateTriggers: {
|
|
175
209
|
[propName]: 'function+trigger'
|
|
176
210
|
}
|
|
177
|
-
}
|
|
211
|
+
} as Partial<Layer['props']>,
|
|
178
212
|
onBeforeUpdate,
|
|
179
213
|
onAfterUpdate
|
|
180
214
|
}
|
|
@@ -186,29 +220,34 @@ function makeAltPropTestCase({propName, propTypes, defaultProps, sampleProps, as
|
|
|
186
220
|
}
|
|
187
221
|
}
|
|
188
222
|
|
|
189
|
-
function makeAltDataTestCases
|
|
223
|
+
function makeAltDataTestCases<LayerT extends Layer>(
|
|
224
|
+
props: Partial<LayerT['props']>,
|
|
225
|
+
propTypes: DefaultProps<LayerT['props']>
|
|
226
|
+
): LayerTestCase<LayerT>[] {
|
|
190
227
|
const originalData = props.data;
|
|
191
228
|
if (!Array.isArray(originalData)) {
|
|
192
229
|
return [];
|
|
193
230
|
}
|
|
194
231
|
// partial update
|
|
195
|
-
const partialUpdateProps = {
|
|
232
|
+
const partialUpdateProps: Partial<Layer['props']> = {
|
|
196
233
|
data: originalData.slice(),
|
|
197
234
|
_dataDiff: () => [{startRow: 0, endRow: 2}]
|
|
198
235
|
};
|
|
199
236
|
// data should support any iterable
|
|
200
|
-
const genIterableProps = {
|
|
237
|
+
const genIterableProps: Partial<Layer['props']> = {
|
|
201
238
|
data: new Set(originalData),
|
|
202
239
|
_dataDiff: null
|
|
203
240
|
};
|
|
204
241
|
// data in non-iterable form
|
|
205
|
-
const nonIterableProps = {
|
|
242
|
+
const nonIterableProps: Partial<Layer['props']> = {
|
|
206
243
|
data: {
|
|
207
244
|
length: originalData.length
|
|
208
245
|
}
|
|
209
246
|
};
|
|
210
247
|
for (const propName in props) {
|
|
248
|
+
// @ts-ignore propName cannot be used as index
|
|
211
249
|
if (propTypes[propName].type === 'accessor') {
|
|
250
|
+
// @ts-ignore propName cannot be used as index
|
|
212
251
|
nonIterableProps[propName] = (_, info) => props[propName](originalData[info.index], info);
|
|
213
252
|
}
|
|
214
253
|
}
|
package/src/index.ts
CHANGED
|
@@ -11,9 +11,13 @@ export {
|
|
|
11
11
|
export {generateLayerTests} from './generate-layer-tests';
|
|
12
12
|
|
|
13
13
|
// Basic utility for rendering multiple scenes (could go into "deck.gl/core")
|
|
14
|
-
export {
|
|
14
|
+
export {TestRunner} from './test-runner';
|
|
15
15
|
|
|
16
16
|
// A utility that renders a list of scenes and compares against golden images
|
|
17
|
-
export {
|
|
17
|
+
export {SnapshotTestRunner} from './snapshot-test-runner';
|
|
18
18
|
// A utility that emulates input events
|
|
19
|
-
export {
|
|
19
|
+
export {InteractionTestRunner} from './interaction-test-runner';
|
|
20
|
+
|
|
21
|
+
export type {LayerTestCase} from './lifecycle-test';
|
|
22
|
+
export type {SnapshotTestCase} from './snapshot-test-runner';
|
|
23
|
+
export type {InteractionTestCase} from './interaction-test-runner';
|