@deck.gl/test-utils 9.0.0-alpha.7 → 9.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/generate-layer-tests.d.ts +20 -0
  2. package/dist/generate-layer-tests.d.ts.map +1 -0
  3. package/dist/generate-layer-tests.js +209 -0
  4. package/dist/index.cjs +645 -0
  5. package/dist/index.cjs.map +7 -0
  6. package/dist/index.d.ts +11 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +11 -0
  9. package/dist/interaction-test-runner.d.ts +29 -0
  10. package/dist/interaction-test-runner.d.ts.map +1 -0
  11. package/dist/interaction-test-runner.js +57 -0
  12. package/dist/lifecycle-test.d.ts +119 -0
  13. package/dist/lifecycle-test.d.ts.map +1 -0
  14. package/dist/lifecycle-test.js +232 -0
  15. package/dist/snapshot-test-runner.d.ts +46 -0
  16. package/dist/snapshot-test-runner.d.ts.map +1 -0
  17. package/dist/snapshot-test-runner.js +101 -0
  18. package/dist/test-runner.d.ts +56 -0
  19. package/dist/test-runner.d.ts.map +1 -0
  20. package/dist/test-runner.js +143 -0
  21. package/dist/utils/dom.d.ts +7 -0
  22. package/dist/utils/dom.d.ts.map +1 -0
  23. package/dist/utils/dom.js +11 -0
  24. package/dist/utils/precision.d.ts +4 -0
  25. package/dist/utils/precision.d.ts.map +1 -0
  26. package/dist/utils/precision.js +19 -0
  27. package/dist/utils/setup-gl.d.ts +5 -0
  28. package/dist/utils/setup-gl.d.ts.map +1 -0
  29. package/dist/utils/setup-gl.js +15 -0
  30. package/package.json +17 -8
  31. package/src/generate-layer-tests.ts +55 -15
  32. package/src/index.ts +7 -3
  33. package/src/interaction-test-runner.ts +29 -13
  34. package/src/lifecycle-test.ts +214 -27
  35. package/src/snapshot-test-runner.ts +79 -47
  36. package/src/test-runner.ts +77 -59
  37. package/src/utils/dom.ts +6 -1
  38. package/src/utils/precision.ts +13 -6
  39. package/src/utils/setup-gl.ts +2 -2
  40. package/dist/es5/generate-layer-tests.js +0 -243
  41. package/dist/es5/generate-layer-tests.js.map +0 -1
  42. package/dist/es5/index.js +0 -88
  43. package/dist/es5/index.js.map +0 -1
  44. package/dist/es5/interaction-test-runner.js +0 -119
  45. package/dist/es5/interaction-test-runner.js.map +0 -1
  46. package/dist/es5/lifecycle-test.js +0 -456
  47. package/dist/es5/lifecycle-test.js.map +0 -1
  48. package/dist/es5/snapshot-test-runner.js +0 -145
  49. package/dist/es5/snapshot-test-runner.js.map +0 -1
  50. package/dist/es5/test-runner.js +0 -198
  51. package/dist/es5/test-runner.js.map +0 -1
  52. package/dist/es5/utils/dom.js +0 -17
  53. package/dist/es5/utils/dom.js.map +0 -1
  54. package/dist/es5/utils/precision.js +0 -33
  55. package/dist/es5/utils/precision.js.map +0 -1
  56. package/dist/es5/utils/setup-gl.js +0 -19
  57. package/dist/es5/utils/setup-gl.js.map +0 -1
  58. package/dist/esm/generate-layer-tests.js +0 -216
  59. package/dist/esm/generate-layer-tests.js.map +0 -1
  60. package/dist/esm/index.js +0 -8
  61. package/dist/esm/index.js.map +0 -1
  62. package/dist/esm/interaction-test-runner.js +0 -52
  63. package/dist/esm/interaction-test-runner.js.map +0 -1
  64. package/dist/esm/lifecycle-test.js +0 -282
  65. package/dist/esm/lifecycle-test.js.map +0 -1
  66. package/dist/esm/snapshot-test-runner.js +0 -94
  67. package/dist/esm/snapshot-test-runner.js.map +0 -1
  68. package/dist/esm/test-runner.js +0 -134
  69. package/dist/esm/test-runner.js.map +0 -1
  70. package/dist/esm/utils/dom.js +0 -10
  71. package/dist/esm/utils/dom.js.map +0 -1
  72. package/dist/esm/utils/precision.js +0 -18
  73. package/dist/esm/utils/precision.js.map +0 -1
  74. package/dist/esm/utils/setup-gl.js +0 -9
  75. package/dist/esm/utils/setup-gl.js.map +0 -1
@@ -0,0 +1,101 @@
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 (layers.every(layer => layer.isLoaded)) {
34
+ done(); // eslint-disable-line
35
+ }
36
+ },
37
+ goldenImage: ''
38
+ };
39
+ export class SnapshotTestRunner extends TestRunner {
40
+ constructor(props) {
41
+ super(props, DEFAULT_TEST_OPTIONS);
42
+ this._isDiffing = false;
43
+ this._isDiffing = false;
44
+ }
45
+ get defaultTestCase() {
46
+ return DEFAULT_TEST_CASE;
47
+ }
48
+ initTestCase(testCase) {
49
+ super.initTestCase(testCase);
50
+ if (!testCase.goldenImage) {
51
+ throw new Error(`Test case ${testCase.name} does not have golden image`);
52
+ }
53
+ }
54
+ runTestCase(testCase) {
55
+ const deck = this.deck;
56
+ return new Promise(resolve => {
57
+ deck.setProps({
58
+ ...this.props,
59
+ ...testCase,
60
+ onBeforeRender: () => {
61
+ testCase.onBeforeRender({
62
+ deck,
63
+ // @ts-expect-error Accessing protected layerManager
64
+ layers: this.deck.layerManager.getLayers()
65
+ });
66
+ },
67
+ onAfterRender: () => {
68
+ testCase.onAfterRender({
69
+ deck,
70
+ // @ts-expect-error Accessing protected layerManager
71
+ layers: this.deck.layerManager.getLayers(),
72
+ done: resolve
73
+ });
74
+ }
75
+ });
76
+ });
77
+ }
78
+ async assert(testCase) {
79
+ if (this._isDiffing) {
80
+ // already performing diffing
81
+ return;
82
+ }
83
+ this._isDiffing = true;
84
+ const diffOptions = {
85
+ ...this.testOptions.imageDiffOptions,
86
+ ...testCase.imageDiffOptions,
87
+ goldenImage: testCase.goldenImage,
88
+ region: getBoundingBoxInPage(this.deck.getCanvas())
89
+ };
90
+ // Take screenshot and compare
91
+ const result = await window.browserTestDriver_captureAndDiffScreen(diffOptions);
92
+ // invoke user callback
93
+ if (result.success) {
94
+ this.pass(result);
95
+ }
96
+ else {
97
+ this.fail(result);
98
+ }
99
+ this._isDiffing = false;
100
+ }
101
+ }
@@ -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 | null;
21
+ props: DeckProps;
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,GAAG,IAAI,CAAQ;IACzB,KAAK,EAAE,SAAS,CAAC;IACjB,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,7 @@
1
+ export declare function getBoundingBoxInPage(domElement: HTMLElement): {
2
+ x: number;
3
+ y: number;
4
+ width: number;
5
+ height: number;
6
+ };
7
+ //# sourceMappingURL=dom.d.ts.map
@@ -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,5 @@
1
+ /** Test device */
2
+ export declare const device: import("@luma.gl/webgl").WebGLDevice;
3
+ /** Test context */
4
+ export declare const gl: WebGL2RenderingContext | null;
5
+ //# sourceMappingURL=setup-gl.d.ts.map
@@ -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
- "version": "9.0.0-alpha.7",
5
+ "type": "module",
6
+ "version": "9.0.0-beta.10",
6
7
  "publishConfig": {
7
8
  "access": "public"
8
9
  },
@@ -16,22 +17,30 @@
16
17
  "type": "git",
17
18
  "url": "https://github.com/visgl/deck.gl.git"
18
19
  },
19
- "main": "dist/es5/index.js",
20
- "module": "dist/esm/index.js",
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
32
  "src",
24
33
  "typed"
25
34
  ],
26
35
  "dependencies": {
27
- "@babel/runtime": "^7.0.0"
36
+ "@luma.gl/test-utils": "^9.0.4"
28
37
  },
29
38
  "peerDependencies": {
30
- "@deck.gl/core": "^9.0.0-alpha",
31
- "@luma.gl/test-utils": "9.0.0-alpha.53",
32
- "@luma.gl/webgl": "9.0.0-alpha.53",
39
+ "@deck.gl/core": "^9.0.0-beta",
40
+ "@luma.gl/core": "^9.0.4",
41
+ "@luma.gl/engine": "^9.0.4",
33
42
  "@probe.gl/test-utils": "^4.0.0"
34
43
  },
35
44
  "scripts": {},
36
- "gitHead": "de061268077ab74e163792162efbc07be95d10f5"
45
+ "gitHead": "6c44f602069374cd21268ff279c5bf818c905ff7"
37
46
  }
@@ -17,38 +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
21
 
22
+ import type {DefaultProps} from '@deck.gl/core';
23
+ import type {LayerTestCase, LayerClass} from './lifecycle-test';
24
+
25
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
22
26
  function noop() {}
23
27
 
24
- function defaultAssert(condition, comment) {
28
+ function defaultAssert(condition: any, comment: string): void {
25
29
  if (!condition) {
26
30
  throw new Error(comment);
27
31
  }
28
32
  }
29
33
 
30
34
  // Automatically generate testLayer test cases
31
- export function generateLayerTests({
35
+ export function generateLayerTests<LayerT extends Layer>({
32
36
  Layer,
33
37
  sampleProps = {},
34
38
  assert = defaultAssert,
35
39
  onBeforeUpdate = noop,
36
40
  onAfterUpdate = noop,
37
41
  runDefaultAsserts = true
38
- }) {
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>[] {
39
60
  assert(Layer.layerName, 'Layer should have display name');
40
61
 
41
- function wrapTestCaseTitle(title) {
62
+ function wrapTestCaseTitle(title: string): string {
42
63
  return `${Layer.layerName}#${title}`;
43
64
  }
44
65
 
45
- const testCases = [
66
+ const testCases: LayerTestCase<LayerT>[] = [
46
67
  {
47
68
  title: 'Empty props',
48
69
  props: {}
49
70
  },
50
71
  {
51
72
  title: 'Null data',
73
+ // @ts-expect-error null may not be an expected data type
52
74
  updateProps: {data: null}
53
75
  },
54
76
  {
@@ -61,14 +83,15 @@ export function generateLayerTests({
61
83
  // Calling constructor for the first time resolves default props
62
84
  // eslint-disable-next-line
63
85
  new Layer({});
64
- } catch (error) {
65
- assert(false, `Construct ${Layer.layerName} throws: ${error.message}`);
86
+ } catch (error: unknown) {
87
+ assert(false, `Construct ${Layer.layerName} throws: ${(error as Error).message}`);
66
88
  }
67
89
 
90
+ // @ts-expect-error Access hidden properties
68
91
  const {_propTypes: propTypes, _mergedDefaultProps: defaultProps} = Layer;
69
92
 
70
93
  // Test alternative data formats
71
- testCases.push(...makeAltDataTestCases(sampleProps, propTypes));
94
+ testCases.push(...makeAltDataTestCases<LayerT>(sampleProps, propTypes));
72
95
 
73
96
  for (const propName in Layer.defaultProps) {
74
97
  if (!(propName in sampleProps)) {
@@ -112,7 +135,19 @@ export function generateLayerTests({
112
135
  return testCases;
113
136
  }
114
137
 
115
- function makeAltPropTestCase({propName, propTypes, defaultProps, sampleProps, assert}) {
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 {
116
151
  const newProps = {...sampleProps};
117
152
  const propDef = propTypes[propName];
118
153
 
@@ -173,7 +208,7 @@ function makeAltPropTestCase({propName, propTypes, defaultProps, sampleProps, as
173
208
  updateTriggers: {
174
209
  [propName]: 'function+trigger'
175
210
  }
176
- },
211
+ } as Partial<Layer['props']>,
177
212
  onBeforeUpdate,
178
213
  onAfterUpdate
179
214
  }
@@ -185,29 +220,34 @@ function makeAltPropTestCase({propName, propTypes, defaultProps, sampleProps, as
185
220
  }
186
221
  }
187
222
 
188
- function makeAltDataTestCases(props, propTypes) {
223
+ function makeAltDataTestCases<LayerT extends Layer>(
224
+ props: Partial<LayerT['props']>,
225
+ propTypes: DefaultProps<LayerT['props']>
226
+ ): LayerTestCase<LayerT>[] {
189
227
  const originalData = props.data;
190
228
  if (!Array.isArray(originalData)) {
191
229
  return [];
192
230
  }
193
231
  // partial update
194
- const partialUpdateProps = {
232
+ const partialUpdateProps: Partial<Layer['props']> = {
195
233
  data: originalData.slice(),
196
234
  _dataDiff: () => [{startRow: 0, endRow: 2}]
197
235
  };
198
236
  // data should support any iterable
199
- const genIterableProps = {
237
+ const genIterableProps: Partial<Layer['props']> = {
200
238
  data: new Set(originalData),
201
239
  _dataDiff: null
202
240
  };
203
241
  // data in non-iterable form
204
- const nonIterableProps = {
242
+ const nonIterableProps: Partial<Layer['props']> = {
205
243
  data: {
206
244
  length: originalData.length
207
245
  }
208
246
  };
209
247
  for (const propName in props) {
248
+ // @ts-ignore propName cannot be used as index
210
249
  if (propTypes[propName].type === 'accessor') {
250
+ // @ts-ignore propName cannot be used as index
211
251
  nonIterableProps[propName] = (_, info) => props[propName](originalData[info.index], info);
212
252
  }
213
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 {default as TestRunner} from './test-runner';
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 {default as SnapshotTestRunner} from './snapshot-test-runner';
17
+ export {SnapshotTestRunner} from './snapshot-test-runner';
18
18
  // A utility that emulates input events
19
- export {default as InteractionTestRunner} from './interaction-test-runner';
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';