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

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,20 @@
1
+ import { Layer } from '@deck.gl/core';
2
+ import type { LayerTestCase, LayerClass } from './lifecycle-test';
3
+ export declare function generateLayerTests<LayerT extends Layer>({ Layer, sampleProps, assert, onBeforeUpdate, onAfterUpdate, runDefaultAsserts }: {
4
+ Layer: LayerClass<LayerT>;
5
+ /**
6
+ * Override default props during the test
7
+ */
8
+ sampleProps?: Partial<LayerT['props']>;
9
+ assert?: (condition: any, comment: string) => void;
10
+ onBeforeUpdate: LayerTestCase<LayerT>['onBeforeUpdate'];
11
+ onAfterUpdate: LayerTestCase<LayerT>['onAfterUpdate'];
12
+ /**
13
+ * Test some typical assumptions after layer updates
14
+ * For primitive layers, assert that layer has model(s).
15
+ * For composite layers, assert that layer has sublayer(s).
16
+ * @default true
17
+ */
18
+ runDefaultAsserts?: boolean;
19
+ }): LayerTestCase<LayerT>[];
20
+ //# sourceMappingURL=generate-layer-tests.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-layer-tests.d.ts","sourceRoot":"","sources":["../src/generate-layer-tests.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAkB,KAAK,EAAC,MAAM,eAAe,CAAC;AAGrD,OAAO,KAAK,EAAC,aAAa,EAAE,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAYhE,wBAAgB,kBAAkB,CAAC,MAAM,SAAS,KAAK,EAAE,EACvD,KAAK,EACL,WAAgB,EAChB,MAAsB,EACtB,cAAqB,EACrB,aAAoB,EACpB,iBAAwB,EACzB,EAAE;IACD,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IAC1B;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IACvC,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD,cAAc,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,gBAAgB,CAAC,CAAC;IACxD,aAAa,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC;IAEtD;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,GAAG,aAAa,CAAC,MAAM,CAAC,EAAE,CA6E1B"}
@@ -0,0 +1,209 @@
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
+ import { _count as count } from '@deck.gl/core';
21
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
22
+ function noop() { }
23
+ function defaultAssert(condition, comment) {
24
+ if (!condition) {
25
+ throw new Error(comment);
26
+ }
27
+ }
28
+ // Automatically generate testLayer test cases
29
+ export function generateLayerTests({ Layer, sampleProps = {}, assert = defaultAssert, onBeforeUpdate = noop, onAfterUpdate = noop, runDefaultAsserts = true }) {
30
+ assert(Layer.layerName, 'Layer should have display name');
31
+ function wrapTestCaseTitle(title) {
32
+ return `${Layer.layerName}#${title}`;
33
+ }
34
+ const testCases = [
35
+ {
36
+ title: 'Empty props',
37
+ props: {}
38
+ },
39
+ {
40
+ title: 'Null data',
41
+ // @ts-expect-error null may not be an expected data type
42
+ updateProps: { data: null }
43
+ },
44
+ {
45
+ title: 'Sample data',
46
+ updateProps: sampleProps
47
+ }
48
+ ];
49
+ try {
50
+ // Calling constructor for the first time resolves default props
51
+ // eslint-disable-next-line
52
+ new Layer({});
53
+ }
54
+ catch (error) {
55
+ assert(false, `Construct ${Layer.layerName} throws: ${error.message}`);
56
+ }
57
+ // @ts-expect-error Access hidden properties
58
+ const { _propTypes: propTypes, _mergedDefaultProps: defaultProps } = Layer;
59
+ // Test alternative data formats
60
+ testCases.push(...makeAltDataTestCases(sampleProps, propTypes));
61
+ for (const propName in Layer.defaultProps) {
62
+ if (!(propName in sampleProps)) {
63
+ // Do not override user provided props - they may be layer-specific
64
+ const newTestCase = makeAltPropTestCase({ propName, propTypes, defaultProps, sampleProps, assert }) || [];
65
+ testCases.push(...newTestCase);
66
+ }
67
+ }
68
+ testCases.forEach(testCase => {
69
+ testCase.title = wrapTestCaseTitle(testCase.title);
70
+ const beforeFunc = testCase.onBeforeUpdate || noop;
71
+ const afterFunc = testCase.onAfterUpdate || noop;
72
+ testCase.onBeforeUpdate = params => {
73
+ // Generated callback
74
+ beforeFunc(params);
75
+ // User callback
76
+ onBeforeUpdate(params);
77
+ };
78
+ testCase.onAfterUpdate = params => {
79
+ // Generated callback
80
+ afterFunc(params);
81
+ // User callback
82
+ onAfterUpdate(params);
83
+ // Default assert
84
+ if (runDefaultAsserts) {
85
+ if (params.layer.isComposite) {
86
+ const { data } = params.layer.props;
87
+ if (data && typeof data === 'object' && count(data)) {
88
+ assert(params.subLayers.length, 'Layer should have sublayers');
89
+ }
90
+ }
91
+ else {
92
+ assert(params.layer.getModels().length, 'Layer should have models');
93
+ }
94
+ }
95
+ };
96
+ });
97
+ return testCases;
98
+ }
99
+ function makeAltPropTestCase({ propName, propTypes, defaultProps, sampleProps, assert }) {
100
+ const newProps = { ...sampleProps };
101
+ const propDef = propTypes[propName];
102
+ if (!propDef) {
103
+ return null;
104
+ }
105
+ switch (propDef.type) {
106
+ case 'boolean':
107
+ newProps[propName] = !defaultProps[propName];
108
+ return [
109
+ {
110
+ title: `${propName}: ${String(newProps[propName])}`,
111
+ props: newProps
112
+ }
113
+ ];
114
+ case 'number':
115
+ if ('max' in propDef) {
116
+ newProps[propName] = propDef.max;
117
+ }
118
+ else if ('min' in propDef) {
119
+ newProps[propName] = propDef.min;
120
+ }
121
+ else {
122
+ newProps[propName] = defaultProps[propName] + 1;
123
+ }
124
+ return [
125
+ {
126
+ title: `${propName}: ${String(newProps[propName])}`,
127
+ props: newProps
128
+ }
129
+ ];
130
+ case 'accessor': {
131
+ if (typeof defaultProps[propName] === 'function') {
132
+ return null;
133
+ }
134
+ let callCount = 0;
135
+ newProps[propName] = () => {
136
+ callCount++;
137
+ return defaultProps[propName];
138
+ };
139
+ newProps.updateTriggers = {
140
+ [propName]: 'function'
141
+ };
142
+ const onBeforeUpdate = () => (callCount = 0);
143
+ const onAfterUpdate = () => assert(callCount > 0, 'accessor function is called');
144
+ return [
145
+ {
146
+ title: `${propName}: () => ${defaultProps[propName]}`,
147
+ props: newProps,
148
+ onBeforeUpdate,
149
+ onAfterUpdate
150
+ },
151
+ {
152
+ title: `${propName}: updateTrigger`,
153
+ updateProps: {
154
+ updateTriggers: {
155
+ [propName]: 'function+trigger'
156
+ }
157
+ },
158
+ onBeforeUpdate,
159
+ onAfterUpdate
160
+ }
161
+ ];
162
+ }
163
+ default:
164
+ return null;
165
+ }
166
+ }
167
+ function makeAltDataTestCases(props, propTypes) {
168
+ const originalData = props.data;
169
+ if (!Array.isArray(originalData)) {
170
+ return [];
171
+ }
172
+ // partial update
173
+ const partialUpdateProps = {
174
+ data: originalData.slice(),
175
+ _dataDiff: () => [{ startRow: 0, endRow: 2 }]
176
+ };
177
+ // data should support any iterable
178
+ const genIterableProps = {
179
+ data: new Set(originalData),
180
+ _dataDiff: null
181
+ };
182
+ // data in non-iterable form
183
+ const nonIterableProps = {
184
+ data: {
185
+ length: originalData.length
186
+ }
187
+ };
188
+ for (const propName in props) {
189
+ // @ts-ignore propName cannot be used as index
190
+ if (propTypes[propName].type === 'accessor') {
191
+ // @ts-ignore propName cannot be used as index
192
+ nonIterableProps[propName] = (_, info) => props[propName](originalData[info.index], info);
193
+ }
194
+ }
195
+ return [
196
+ {
197
+ title: 'Partial update',
198
+ updateProps: partialUpdateProps
199
+ },
200
+ {
201
+ title: 'Generic iterable data',
202
+ updateProps: genIterableProps
203
+ },
204
+ {
205
+ title: 'non-iterable data',
206
+ updateProps: nonIterableProps
207
+ }
208
+ ];
209
+ }