@deck.gl/test-utils 9.0.0-beta.2 → 9.0.0-beta.4

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 (74) 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 +10 -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 +15 -6
  31. package/src/generate-layer-tests.ts +54 -15
  32. package/src/index.ts +6 -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 +76 -58
  37. package/src/utils/dom.ts +6 -1
  38. package/src/utils/precision.ts +13 -6
  39. package/dist/es5/generate-layer-tests.js +0 -243
  40. package/dist/es5/generate-layer-tests.js.map +0 -1
  41. package/dist/es5/index.js +0 -88
  42. package/dist/es5/index.js.map +0 -1
  43. package/dist/es5/interaction-test-runner.js +0 -119
  44. package/dist/es5/interaction-test-runner.js.map +0 -1
  45. package/dist/es5/lifecycle-test.js +0 -456
  46. package/dist/es5/lifecycle-test.js.map +0 -1
  47. package/dist/es5/snapshot-test-runner.js +0 -145
  48. package/dist/es5/snapshot-test-runner.js.map +0 -1
  49. package/dist/es5/test-runner.js +0 -198
  50. package/dist/es5/test-runner.js.map +0 -1
  51. package/dist/es5/utils/dom.js +0 -17
  52. package/dist/es5/utils/dom.js.map +0 -1
  53. package/dist/es5/utils/precision.js +0 -33
  54. package/dist/es5/utils/precision.js.map +0 -1
  55. package/dist/es5/utils/setup-gl.js +0 -19
  56. package/dist/es5/utils/setup-gl.js.map +0 -1
  57. package/dist/esm/generate-layer-tests.js +0 -216
  58. package/dist/esm/generate-layer-tests.js.map +0 -1
  59. package/dist/esm/index.js +0 -8
  60. package/dist/esm/index.js.map +0 -1
  61. package/dist/esm/interaction-test-runner.js +0 -52
  62. package/dist/esm/interaction-test-runner.js.map +0 -1
  63. package/dist/esm/lifecycle-test.js +0 -282
  64. package/dist/esm/lifecycle-test.js.map +0 -1
  65. package/dist/esm/snapshot-test-runner.js +0 -94
  66. package/dist/esm/snapshot-test-runner.js.map +0 -1
  67. package/dist/esm/test-runner.js +0 -134
  68. package/dist/esm/test-runner.js.map +0 -1
  69. package/dist/esm/utils/dom.js +0 -10
  70. package/dist/esm/utils/dom.js.map +0 -1
  71. package/dist/esm/utils/precision.js +0 -18
  72. package/dist/esm/utils/precision.js.map +0 -1
  73. package/dist/esm/utils/setup-gl.js +0 -9
  74. 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 */
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: WebGLRenderingContext | 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,sCAA+B,CAAC;AAEnD,mBAAmB;AACnB,eAAO,MAAM,EAAE,8BAMb,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { createTestContext, webgl1Device, webgl2Device } from '@luma.gl/test-utils';
2
+ /** Test device */
3
+ export const device = webgl2Device || webgl1Device;
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-beta.2",
5
+ "type": "module",
6
+ "version": "9.0.0-beta.4",
6
7
  "publishConfig": {
7
8
  "access": "public"
8
9
  },
@@ -16,8 +17,16 @@
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",
@@ -28,10 +37,10 @@
28
37
  },
29
38
  "peerDependencies": {
30
39
  "@deck.gl/core": "^9.0.0-alpha",
31
- "@luma.gl/test-utils": "9.0.0-beta.1",
32
- "@luma.gl/webgl": "9.0.0-beta.1",
40
+ "@luma.gl/test-utils": "9.0.0-beta.4",
41
+ "@luma.gl/webgl": "9.0.0-beta.4",
33
42
  "@probe.gl/test-utils": "^4.0.0"
34
43
  },
35
44
  "scripts": {},
36
- "gitHead": "ed132efaf84a75ea71c89dd8555b6ffc1fe839d5"
45
+ "gitHead": "7063cbec75a5fbcefc51f33f6e2488134533d34a"
37
46
  }
@@ -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({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 {
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(props, propTypes) {
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,12 @@ 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 {SnapshotTestCase} from './snapshot-test-runner';
22
+ export type {InteractionTestCase} from './interaction-test-runner';