@luma.gl/test-utils 9.0.0-alpha.4 → 9.0.0-alpha.40

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 (55) hide show
  1. package/LICENSE +3 -1
  2. package/dist/check-type.js +0 -1
  3. package/dist/check-type.js.map +1 -1
  4. package/dist/create-test-device.d.ts +11 -4
  5. package/dist/create-test-device.d.ts.map +1 -1
  6. package/dist/create-test-device.js +29 -18
  7. package/dist/create-test-device.js.map +1 -1
  8. package/dist/engine/classic-animation-loop.d.ts +135 -0
  9. package/dist/engine/classic-animation-loop.d.ts.map +1 -0
  10. package/dist/engine/classic-animation-loop.js +434 -0
  11. package/dist/engine/classic-animation-loop.js.map +1 -0
  12. package/dist/index.cjs +851 -0
  13. package/dist/index.d.ts +4 -5
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +6 -7
  16. package/dist/index.js.map +1 -1
  17. package/dist/performance-test-runner.d.ts +7 -6
  18. package/dist/performance-test-runner.d.ts.map +1 -1
  19. package/dist/performance-test-runner.js +10 -22
  20. package/dist/performance-test-runner.js.map +1 -1
  21. package/dist/register-devices.d.ts +2 -0
  22. package/dist/register-devices.d.ts.map +1 -0
  23. package/dist/register-devices.js +7 -0
  24. package/dist/register-devices.js.map +1 -0
  25. package/dist/snapshot-test-runner.d.ts +11 -7
  26. package/dist/snapshot-test-runner.d.ts.map +1 -1
  27. package/dist/snapshot-test-runner.js +23 -29
  28. package/dist/snapshot-test-runner.js.map +1 -1
  29. package/dist/test-runner.d.ts +35 -23
  30. package/dist/test-runner.d.ts.map +1 -1
  31. package/dist/test-runner.js +62 -81
  32. package/dist/test-runner.js.map +1 -1
  33. package/dist/utils.d.ts +5 -5
  34. package/dist/utils.d.ts.map +1 -1
  35. package/dist/utils.js.map +1 -1
  36. package/package.json +28 -7
  37. package/src/check-type.ts +1 -1
  38. package/src/create-test-device.ts +38 -21
  39. package/src/engine/classic-animation-loop.ts +714 -0
  40. package/src/index.ts +5 -5
  41. package/src/performance-test-runner.ts +17 -13
  42. package/src/register-devices.ts +11 -0
  43. package/src/snapshot-test-runner.ts +33 -31
  44. package/src/test-runner.ts +100 -75
  45. package/src/utils.ts +1 -1
  46. package/dist/create-headless-context.d.ts +0 -2
  47. package/dist/create-headless-context.d.ts.map +0 -1
  48. package/dist/create-headless-context.js +0 -37
  49. package/dist/create-headless-context.js.map +0 -1
  50. package/dist/create-test-context.d.ts +0 -2
  51. package/dist/create-test-context.d.ts.map +0 -1
  52. package/dist/create-test-context.js +0 -6
  53. package/dist/create-test-context.js.map +0 -1
  54. package/src/create-headless-context.ts +0 -36
  55. package/src/create-test-context.ts +0 -29
package/src/index.ts CHANGED
@@ -1,11 +1,11 @@
1
+ import './register-devices';
2
+
1
3
  export type {TestRunnerTestCase} from './test-runner';
2
4
  export type {SnapshotTestRunnerTestCase} from './snapshot-test-runner';
3
5
 
4
- export {default as SnapshotTestRunner} from './snapshot-test-runner';
5
- export {default as PerformanceTestRunner} from './performance-test-runner';
6
- export {createHeadlessContext} from './create-headless-context';
7
- export {createTestContext} from './create-test-context';
8
- export {createTestDevice, webgl1TestDevice, webgl2TestDevice, webgpuTestDevice} from './create-test-device';
6
+ export {SnapshotTestRunner} from './snapshot-test-runner';
7
+ export {PerformanceTestRunner} from './performance-test-runner';
8
+ export {createTestDevice, createTestContext, webgl1Device, webgl2Device, webgpuDevice} from './create-test-device';
9
9
  export {getTestDevices, getWebGLTestDevices} from './create-test-device';
10
10
 
11
11
  export {checkType} from './check-type';
@@ -1,11 +1,16 @@
1
+ // luma.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+
1
4
  import {Stats, Stat} from '@probe.gl/stats';
2
- import TestRunner, {TestRunnerOptions} from './test-runner';
5
+ import {TestRunner, TestRunnerProps, TestRunnerTestCase} from './test-runner';
6
+
7
+ export type PerformanceTestRunnerProps = TestRunnerProps;
3
8
 
4
- export default class PerformanceTestRunner extends TestRunner {
5
- private _stats: Stats;
6
- private _fps: Stat;
9
+ export class PerformanceTestRunner extends TestRunner {
10
+ private _stats: Stats | null = null;
11
+ private _fps: Stat | null = null;
7
12
 
8
- constructor(props: TestRunnerOptions) {
13
+ constructor(props: PerformanceTestRunnerProps) {
9
14
  super(props);
10
15
 
11
16
  Object.assign(this.testOptions, {
@@ -14,17 +19,16 @@ export default class PerformanceTestRunner extends TestRunner {
14
19
  });
15
20
  }
16
21
 
17
- initTestCase(testCase) {
22
+ override initTestCase(testCase: TestRunnerTestCase): void {
18
23
  super.initTestCase(testCase);
19
24
  this._stats = new Stats({id: testCase.name});
20
25
  this._fps = this._stats.get('fps');
21
26
  }
22
27
 
23
- shouldRender(animationProps) {
24
- this._fps.timeEnd();
25
- this._fps.timeStart();
28
+ override shouldRender(animationProps: Record<string, any>): boolean {
29
+ this._fps?.timeEnd();
30
+ this._fps?.timeStart();
26
31
 
27
- // @ts-expect-error
28
32
  if (this._fps.count > this.testOptions.maxFramesToRender) {
29
33
  animationProps.done();
30
34
  }
@@ -32,11 +36,11 @@ export default class PerformanceTestRunner extends TestRunner {
32
36
  return true;
33
37
  }
34
38
 
35
- assert(testCase) {
39
+ override assert(testCase: TestRunnerTestCase): void {
36
40
  // @ts-expect-error
37
41
  const targetFPS = testCase.targetFPS || this.testOptions.targetFPS;
38
- const count = this._fps.count;
39
- const fps = this._fps.getHz();
42
+ const count = this._fps?.count;
43
+ const fps = this._fps?.getHz() || 0;
40
44
 
41
45
  if (fps >= targetFPS) {
42
46
  this._pass({fps, framesRendered: count});
@@ -0,0 +1,11 @@
1
+ // luma.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+
4
+ import {luma} from '@luma.gl/core';
5
+ import {WebGLDevice, registerHeadlessGL} from '@luma.gl/webgl';
6
+ import {WebGPUDevice} from '@luma.gl/webgpu';
7
+
8
+ import headlessGL from 'gl';
9
+
10
+ registerHeadlessGL(headlessGL);
11
+ luma.registerDevices([WebGLDevice, WebGPUDevice]);
@@ -1,65 +1,67 @@
1
- import TestRunner, {TestRunnerOptions, TestRunnerTestCase} from './test-runner';
1
+ import {TestRunner, TestRunnerProps, TestRunnerTestCase} from './test-runner';
2
2
  import {getBoundingBoxInPage} from './utils';
3
3
 
4
4
  /** A snapshot test case */
5
5
  export type SnapshotTestRunnerTestCase = TestRunnerTestCase & {
6
6
  /** URL to golden image */
7
7
  goldenImage: string;
8
+ /** Diff options */
9
+ imageDiffOptions?: {[key: string]: any};
8
10
  }
9
11
 
10
- export default class SnapshotTestRunner extends TestRunner {
11
- private isDiffing: boolean = false;
12
+ export type SnapshotTestRunnerProps = TestRunnerProps;
12
13
 
13
- constructor(props: TestRunnerOptions) {
14
- super(props);
14
+ export class SnapshotTestRunner extends TestRunner {
15
+ // should be defined here but hack access in TestRunner
16
+ // private isDiffing: boolean = false;
15
17
 
16
- // @ts-expect-error
18
+ constructor(props: SnapshotTestRunnerProps) {
19
+ super(props);
17
20
  this.testOptions.imageDiffOptions = {};
18
21
  }
19
22
 
20
- initTestCase(testCase) {
23
+ override initTestCase(testCase: SnapshotTestRunnerTestCase): void {
21
24
  super.initTestCase(testCase);
22
25
  if (!testCase.goldenImage) {
23
26
  throw new Error(`Test case ${testCase.name} does not have golden image`);
24
27
  }
25
28
  }
26
29
 
27
- shouldRender() {
30
+ override shouldRender(): boolean {
28
31
  // wait for the current diffing to finish
29
32
  return !this.isDiffing;
30
33
  }
31
34
 
32
- assert(testCase) {
35
+ override async assert(testCase: SnapshotTestRunnerTestCase): Promise<void> {
33
36
  if (this.isDiffing) {
34
37
  // Already performing diffing
35
38
  return;
36
39
  }
37
40
  this.isDiffing = true;
38
41
 
39
- const diffOptions = Object.assign(
40
- {},
41
- // @ts-expect-error
42
- this.testOptions.imageDiffOptions,
43
- testCase.imageDiffOptions,
44
- {
45
- goldenImage: testCase.goldenImage,
46
- // @ts-expect-error
47
- region: getBoundingBoxInPage(this._animationProps.canvas)
48
- }
49
- );
42
+ const canvas = this._animationProps?.canvas;
43
+ if (!(canvas instanceof HTMLCanvasElement)) {
44
+ throw new Error('canvas');
45
+ }
46
+
47
+ const diffOptions = {
48
+ ...this.testOptions.imageDiffOptions,
49
+ ...testCase.imageDiffOptions,
50
+ goldenImage: testCase.goldenImage,
51
+ region: getBoundingBoxInPage(canvas)
52
+ };
50
53
 
51
54
  // Take screenshot and compare
52
- // @ts-expect-error
53
- window.browserTestDriver_captureAndDiffScreen(diffOptions).then((result) => {
54
- // invoke user callback
55
- if (result.success) {
56
- this._pass(result);
57
- } else {
58
- this._fail(result);
59
- }
55
+ const result = await globalThis.browserTestDriver_captureAndDiffScreen(diffOptions);
56
+
57
+ // invoke user callback
58
+ if (result.success) {
59
+ this._pass(result);
60
+ } else {
61
+ this._fail(result);
62
+ }
60
63
 
61
- this.isDiffing = false;
62
- this._next();
63
- });
64
+ this.isDiffing = false;
65
+ this._next();
64
66
  }
65
67
  }
@@ -1,58 +1,78 @@
1
- // @ts-nocheck TODO remove
2
- /* eslint-disable no-console */
3
- import {AnimationLoop} from '@luma.gl/core';
4
- import {pushContextState, popContextState} from '@luma.gl/webgl';
1
+ // @ts-nocheck
2
+ /* eslint-disable */
3
+
4
+ import {AnimationProps} from '@luma.gl/engine';
5
+ import {webglDevice} from './create-test-device';
6
+
7
+ // TODO - Replace with new AnimationLoop from `@luma.gl/engine`
8
+ import {ClassicAnimationLoop as AnimationLoop} from './engine/classic-animation-loop';
5
9
 
6
10
  /** Describes a test case */
7
11
  export type TestRunnerTestCase = {
8
12
  /** Name of the test case (for logging) */
9
13
  name: string;
10
14
  /** Initialize the test case. Can return a promise */
11
- onInitialize: any;
15
+ onInitialize: (props: AnimationProps) => Promise<void | {}>;
12
16
  /** Perform rendering */
13
- onRender: any;
17
+ onRender: (props: AnimationProps & {done}) => void;
14
18
  /** Clean up after the test case */
15
- onFinalize: any;
19
+ onFinalize: (props: AnimationProps) => void;
20
+ animationLoop?: AnimationLoop;
16
21
  };
17
22
 
18
- function noop() {}
19
-
20
23
  const DEFAULT_TEST_CASE: TestRunnerTestCase = {
21
24
  name: 'Unnamed test',
22
- onInitialize: noop,
25
+ onInitialize: async () => {},
23
26
  onRender: ({done}) => done(),
24
- onFinalize: noop
27
+ onFinalize: () => {}
25
28
  };
26
29
 
27
30
  /** Options for a TestRunner */
28
- export type TestRunnerOptions = {
31
+ export type TestRunnerProps = {
32
+ width?: number;
33
+ height?: number;
29
34
  // test lifecycle callback
30
- onTestStart?: any;
31
- onTestPass?: any;
32
- onTestFail?: any;
33
-
35
+ onTestStart?: (testCase: TestRunnerTestCase) => void;
36
+ onTestPass?: (testCase: TestRunnerTestCase, result?: unknown) => void;
37
+ onTestFail?: (testCase: TestRunnerTestCase, error?: unknown) => void;
34
38
  /** milliseconds to wait for each test case before aborting */
35
39
  timeout?: number;
40
+ maxFramesToRender?: number;
41
+ // HACK - this is for the snapshot test runner
42
+ imageDiffOptions?: any;
36
43
  };
37
44
 
38
- const DEFAULT_TEST_OPTIONS: Required<TestRunnerOptions> = {
45
+ const DEFAULT_TEST_PROPS: Required<TestRunnerProps> = {
46
+ width: undefined,
47
+ height: undefined,
48
+
39
49
  // test lifecycle callback
40
- onTestStart: (testCase) => console.log(`# ${testCase.name}`),
41
- onTestPass: (testCase) => console.log(`ok ${testCase.name} passed`),
42
- onTestFail: (testCase) => console.log(`not ok ${testCase.name} failed`),
50
+ onTestStart: (testCase: TestRunnerTestCase) => console.log(`# ${testCase.name}`),
51
+ onTestPass: (testCase: TestRunnerTestCase, result?: unknown) => console.log(`ok ${testCase.name} passed`),
52
+ onTestFail: (testCase: TestRunnerTestCase, error?: unknown) => console.log(`not ok ${testCase.name} failed`),
43
53
 
44
54
  // milliseconds to wait for each test case before aborting
45
- timeout: 2000
55
+ timeout: 2000,
56
+ maxFramesToRender: undefined,
57
+ imageDiffOptions: undefined
46
58
  };
47
59
 
48
60
  /** Runs an array of test cases */
49
- export default class TestRunner {
50
- props;
51
- isRunning = false;
52
- readonly testOptions: object = {...DEFAULT_TEST_OPTIONS};
53
- readonly _animationProps: object = {};
61
+ export class TestRunner {
62
+ device = webglDevice;
63
+ props: Record<string, any>;
64
+ isRunning: boolean = false;
65
+ testOptions: Required<TestRunnerProps> = {...DEFAULT_TEST_PROPS};
66
+ readonly _animationProps?: AnimationProps;
67
+ private _animationLoop: AnimationLoop | null;
54
68
  private _testCases: TestRunnerTestCase[] = [];
55
- private _testCaseData = null;
69
+ private _testCaseData: any = null;
70
+ private _currentTestCase: TestRunnerTestCase | null;
71
+ private _currentTestCaseStartTime: number;
72
+ private _currentTestCaseStartTick: number;
73
+
74
+ // should be defined in snapshot-test-runner
75
+ isDiffing: boolean = false;
56
76
 
57
77
  // @ts-expect-error
58
78
  isHeadless: boolean = Boolean(window.browserTestDriver_isHeadless);
@@ -61,17 +81,14 @@ export default class TestRunner {
61
81
  * props
62
82
  * AnimationLoop props
63
83
  */
64
- constructor(props = {}) {
84
+ constructor(props: Record<string, any> = {}) {
65
85
  this.props = props;
66
86
  }
67
87
 
68
88
  /**
69
89
  * Add testCase(s)
70
90
  */
71
- /**
72
- * Add testCase(s)
73
- */
74
- add(testCases: TestRunnerTestCase[]): this {
91
+ add(testCases: TestRunnerTestCase[]): this {
75
92
  if (!Array.isArray(testCases)) {
76
93
  testCases = [testCases];
77
94
  }
@@ -81,75 +98,75 @@ export default class TestRunner {
81
98
  return this;
82
99
  }
83
100
 
84
- /**
101
+ /**
85
102
  * Returns a promise that resolves when all the test cases are done
86
103
  */
87
104
  run(options: object = {}): Promise<void> {
88
- Object.assign(this.testOptions, options);
89
-
90
- return new Promise<void>(resolve => {
91
- this._animationLoop = new AnimationLoop(
92
- // @ts-expect-error TODO
93
- Object.assign({}, this.props, {
94
- onRender: this._onRender.bind(this),
95
- onFinalize: () => {
96
- this.isRunning = false;
97
- resolve();
98
- }
99
- })
100
- );
105
+ this.testOptions = {...this.testOptions, ...options};
106
+
107
+ return new Promise<void>((resolve, reject) => {
108
+ this._animationLoop = new AnimationLoop({
109
+ ...this.props,
110
+ device: this.device,
111
+ onRender: this._onRender.bind(this),
112
+ onFinalize: () => {
113
+ this.isRunning = false;
114
+ resolve();
115
+ }
116
+ });
101
117
  this._animationLoop.start(this.props);
102
118
 
103
119
  this.isRunning = true;
104
120
  this.isDiffing = false;
105
121
  this._currentTestCase = null;
106
- }).catch((error) => {
122
+ }).catch (error => {
107
123
  this._fail({error: error.message});
124
+ // reject(error);
108
125
  });
109
126
  }
110
127
 
111
128
  /* Lifecycle methods for subclassing */
112
129
 
113
- initTestCase(testCase) {
130
+ initTestCase(testCase: TestRunnerTestCase) {
114
131
  const {animationLoop} = testCase;
115
132
  if (animationLoop) {
116
- testCase.onInitialize = animationLoop.onInitialize.bind(animationLoop);
117
- testCase.onRender = animationLoop.onRender.bind(animationLoop);
118
- testCase.onFinalize = animationLoop.onFinalize.bind(animationLoop);
133
+ testCase.onInitialize = animationLoop.props.onInitialize.bind(animationLoop);
134
+ testCase.onRender = animationLoop.props.onRender.bind(animationLoop);
135
+ testCase.onFinalize = animationLoop.props.onFinalize.bind(animationLoop);
119
136
  }
120
137
  for (const key in DEFAULT_TEST_CASE) {
121
138
  testCase[key] = testCase[key] || DEFAULT_TEST_CASE[key];
122
139
  }
123
140
  }
124
141
 
125
- shouldRender(animationProps) {
142
+ shouldRender(animationProps): boolean {
126
143
  return true;
127
144
  }
128
145
 
129
- assert(testCase) {
146
+ assert(testCase: TestRunnerTestCase): void {
130
147
  this._pass(testCase);
131
148
  this._next();
132
149
  }
133
150
 
134
151
  /* Utilities */
135
152
 
136
- _pass(result) {
137
- // @ts-expect-error
153
+ _pass(result: unknown): void {
138
154
  this.testOptions.onTestPass(this._currentTestCase, result);
155
+ // this._animationLoop?.stop();
139
156
  }
140
157
 
141
- _fail(result) {
142
- // @ts-expect-error
158
+ _fail(result: unknown): void {
143
159
  this.testOptions.onTestFail(this._currentTestCase, result);
160
+ // this._animationLoop?.stop();
144
161
  }
145
162
 
146
- _next() {
163
+ _next(): void {
147
164
  this._nextTestCase();
148
165
  }
149
166
 
150
167
  /* Private methods */
151
168
 
152
- _onRender(animationProps) {
169
+ _onRender(animationProps): void {
153
170
  this._animationProps = animationProps;
154
171
 
155
172
  const testCase = this._currentTestCase || this._nextTestCase();
@@ -160,7 +177,9 @@ export default class TestRunner {
160
177
  }
161
178
 
162
179
  let isDone = false;
163
- const testCaseAnimationProps = Object.assign({}, animationProps, this._testCaseData, {
180
+ const testCaseAnimationProps: AnimationProps = {
181
+ ...animationProps,
182
+ ...this._testCaseData,
164
183
  // tick/time starts from 0 for each test case
165
184
  startTime: this._currentTestCaseStartTime,
166
185
  time: animationProps.time - this._currentTestCaseStartTime,
@@ -169,11 +188,15 @@ export default class TestRunner {
169
188
  done: () => {
170
189
  isDone = true;
171
190
  }
172
- });
191
+ };
173
192
 
174
193
  if (this._testCaseData && this.shouldRender(testCaseAnimationProps)) {
194
+ // try {
175
195
  // test case is initialized, render frame
176
196
  testCase.onRender(testCaseAnimationProps);
197
+ // } catch {
198
+ // isDone = true;
199
+ // }
177
200
  }
178
201
 
179
202
  const timeout = testCase.timeout || this.testOptions.timeout;
@@ -186,7 +209,7 @@ export default class TestRunner {
186
209
  }
187
210
  }
188
211
 
189
- _nextTestCase() {
212
+ _nextTestCase(): Promise<TestRunnerTestCase> {
190
213
  const animationProps = this._animationProps;
191
214
 
192
215
  // finalize the current test case
@@ -194,13 +217,13 @@ export default class TestRunner {
194
217
  for (const key in this._testCaseData) {
195
218
  const value = this._testCaseData[key];
196
219
  if (value && value.delete) {
197
- value.delete();
220
+ value.destroy();
198
221
  }
199
222
  }
200
223
  this._currentTestCase.onFinalize(Object.assign({}, animationProps, this._testCaseData));
201
224
 
202
225
  // reset WebGL context
203
- popContextState(animationProps.gl);
226
+ this.device.popState();
204
227
 
205
228
  this._currentTestCase = null;
206
229
  this._testCaseData = null;
@@ -218,22 +241,24 @@ export default class TestRunner {
218
241
  // initialize test case
219
242
 
220
243
  // save WebGL context
221
- pushContextState(animationProps.gl);
244
+ this.device.pushState();
222
245
 
223
246
  // aligned with the behavior of AnimationLoop.onInitialized
224
247
  // onInitialized could return a plain object or a promise
225
- Promise.resolve(
226
- testCase.onInitialize(
227
- Object.assign({}, animationProps, {
228
- // tick/time starts from 0 for each test case
229
- startTime: animationProps.time,
230
- time: 0,
231
- tick: 0
232
- })
233
- )
234
- ).then((userData) => {
248
+ const initProps = {
249
+ ...animationProps,
250
+ // tick/time starts from 0 for each test case
251
+ startTime: animationProps.time,
252
+ time: 0,
253
+ tick: 0
254
+ };
255
+
256
+ // aligned with the behavior of AnimationLoop.onInitialized
257
+ // onInitialized could return a plain object or a promise
258
+ Promise.resolve(testCase.onInitialize(initProps)).then((userData) => {
235
259
  this._testCaseData = userData || {};
236
260
  });
261
+
237
262
  // invoke user callback
238
263
  this.testOptions.onTestStart(testCase);
239
264
  }
package/src/utils.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // Get the bounding box of a DOMElement relative to the page
2
- export function getBoundingBoxInPage(domElement) {
2
+ export function getBoundingBoxInPage(domElement: HTMLElement): {x: number; y: number; width: number; height: number;} {
3
3
  const bbox = domElement.getBoundingClientRect();
4
4
  return {
5
5
  x: window.scrollX + bbox.x,
@@ -1,2 +0,0 @@
1
- export declare function createHeadlessContext(options?: any): WebGLRenderingContext;
2
- //# sourceMappingURL=create-headless-context.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-headless-context.d.ts","sourceRoot":"","sources":["../src/create-headless-context.ts"],"names":[],"mappings":"AAmBA,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,GAAG,GAAG,qBAAqB,CAgB1E"}
@@ -1,37 +0,0 @@
1
- import headlessGL from 'gl';
2
- const ERR_HEADLESSGL_FAILED = 'Failed to create WebGL context in Node.js, headless gl returned null';
3
- const ERR_HEADLESSGL_LOAD = " luma.gl: loaded under Node.js without headless gl installed, meaning that WebGL contexts can not be created. This may not be an error. For example, this is a typical configuration for isorender applications running on the server.";
4
- const CONTEXT_DEFAULTS = {
5
- width: 1,
6
- height: 1,
7
- debug: true,
8
- throwOnError: false
9
- };
10
- export function createHeadlessContext(options) {
11
- options = { ...CONTEXT_DEFAULTS,
12
- ...options
13
- };
14
- const {
15
- width,
16
- height,
17
- webgl1,
18
- webgl2
19
- } = options;
20
-
21
- if (webgl2 && !webgl1) {
22
- throw new Error('headless-gl does not support WebGL2');
23
- }
24
-
25
- if (!headlessGL) {
26
- throw new Error(ERR_HEADLESSGL_LOAD);
27
- }
28
-
29
- const gl = headlessGL(width, height, options);
30
-
31
- if (!gl) {
32
- throw new Error(ERR_HEADLESSGL_FAILED);
33
- }
34
-
35
- return gl;
36
- }
37
- //# sourceMappingURL=create-headless-context.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/create-headless-context.ts"],"names":["headlessGL","ERR_HEADLESSGL_FAILED","ERR_HEADLESSGL_LOAD","CONTEXT_DEFAULTS","width","height","debug","throwOnError","createHeadlessContext","options","webgl1","webgl2","Error","gl"],"mappings":"AAAA,OAAOA,UAAP,MAAuB,IAAvB;AAEA,MAAMC,qBAAqB,GACzB,sEADF;AAGA,MAAMC,mBAAmB,gPAAzB;AAKA,MAAMC,gBAAgB,GAAG;AACvBC,EAAAA,KAAK,EAAE,CADgB;AAEvBC,EAAAA,MAAM,EAAE,CAFe;AAGvBC,EAAAA,KAAK,EAAE,IAHgB;AAIvBC,EAAAA,YAAY,EAAE;AAJS,CAAzB;AASA,OAAO,SAASC,qBAAT,CAA+BC,OAA/B,EAAqE;AAC1EA,EAAAA,OAAO,GAAG,EAAC,GAAGN,gBAAJ;AAAsB,OAAGM;AAAzB,GAAV;AAEA,QAAM;AAACL,IAAAA,KAAD;AAAQC,IAAAA,MAAR;AAAgBK,IAAAA,MAAhB;AAAwBC,IAAAA;AAAxB,MAAkCF,OAAxC;;AAEA,MAAIE,MAAM,IAAI,CAACD,MAAf,EAAuB;AACrB,UAAM,IAAIE,KAAJ,CAAU,qCAAV,CAAN;AACD;;AACD,MAAI,CAACZ,UAAL,EAAiB;AACf,UAAM,IAAIY,KAAJ,CAAUV,mBAAV,CAAN;AACD;;AACD,QAAMW,EAAE,GAAGb,UAAU,CAACI,KAAD,EAAQC,MAAR,EAAgBI,OAAhB,CAArB;;AACA,MAAI,CAACI,EAAL,EAAS;AACP,UAAM,IAAID,KAAJ,CAAUX,qBAAV,CAAN;AACD;;AACD,SAAOY,EAAP;AACD","sourcesContent":["import headlessGL from 'gl';\n\nconst ERR_HEADLESSGL_FAILED =\n 'Failed to create WebGL context in Node.js, headless gl returned null';\n\nconst ERR_HEADLESSGL_LOAD = `\\\n luma.gl: loaded under Node.js without headless gl installed, meaning that WebGL \\\n contexts can not be created. This may not be an error. For example, this is a \\\n typical configuration for isorender applications running on the server.`;\n\nconst CONTEXT_DEFAULTS = {\n width: 1,\n height: 1,\n debug: true,\n throwOnError: false\n};\n\n// Create headless gl context (for running under Node.js)\n// Create headless gl context (for running under Node.js)\nexport function createHeadlessContext(options?: any): WebGLRenderingContext {\n options = {...CONTEXT_DEFAULTS, ...options};\n\n const {width, height, webgl1, webgl2} = options;\n\n if (webgl2 && !webgl1) {\n throw new Error('headless-gl does not support WebGL2');\n }\n if (!headlessGL) {\n throw new Error(ERR_HEADLESSGL_LOAD);\n }\n const gl = headlessGL(width, height, options);\n if (!gl) {\n throw new Error(ERR_HEADLESSGL_FAILED);\n }\n return gl;\n}\n"],"file":"create-headless-context.js"}
@@ -1,2 +0,0 @@
1
- export declare function createTestContext(opts?: Record<string, any>): WebGLRenderingContext | null;
2
- //# sourceMappingURL=create-test-context.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-test-context.d.ts","sourceRoot":"","sources":["../src/create-test-context.ts"],"names":[],"mappings":"AAEA,wBAAgB,iBAAiB,CAAC,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,qBAAqB,GAAG,IAAI,CAG9F"}
@@ -1,6 +0,0 @@
1
- import { createTestDevice } from "./create-test-device";
2
- export function createTestContext(opts = {}) {
3
- const device = createTestDevice(opts);
4
- return device && device.gl;
5
- }
6
- //# sourceMappingURL=create-test-context.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/create-test-context.ts"],"names":["createTestDevice","createTestContext","opts","device","gl"],"mappings":"AAAA,SAASA,gBAAT,QAAiC,sBAAjC;AAEA,OAAO,SAASC,iBAAT,CAA2BC,IAAyB,GAAG,EAAvD,EAAyF;AAC9F,QAAMC,MAAM,GAAGH,gBAAgB,CAACE,IAAD,CAA/B;AACA,SAAOC,MAAM,IAAIA,MAAM,CAACC,EAAxB;AACD","sourcesContent":["import { createTestDevice } from \"./create-test-device\";\n\nexport function createTestContext(opts: Record<string, any> = {}): WebGLRenderingContext | null {\n const device = createTestDevice(opts);\n return device && device.gl;\n}\n\n /*\nimport {isBrowser} from 'probe.gl/env';\nimport {createGLContext, instrumentGLContext} from '@luma.gl/gltools';\nimport {createHeadlessContext} from './create-headless-context';\n\nexport function createTestContext(opts: Record<string, any> = {}): WebGLRenderingContext | null {\n // try {\n if (!isBrowser()) {\n if (opts.webgl2 && !opts.webgl1) {\n return null;\n }\n const gl = createHeadlessContext(opts);\n return gl ? instrumentGLContext(gl) : null;\n }\n return createGLContext(opts);\n // } catch {\n // if (opts.webgl2) {\n // return null;\n // }\n // }\n}\n*/\n"],"file":"create-test-context.js"}
@@ -1,36 +0,0 @@
1
- import headlessGL from 'gl';
2
-
3
- const ERR_HEADLESSGL_FAILED =
4
- 'Failed to create WebGL context in Node.js, headless gl returned null';
5
-
6
- const ERR_HEADLESSGL_LOAD = `\
7
- luma.gl: loaded under Node.js without headless gl installed, meaning that WebGL \
8
- contexts can not be created. This may not be an error. For example, this is a \
9
- typical configuration for isorender applications running on the server.`;
10
-
11
- const CONTEXT_DEFAULTS = {
12
- width: 1,
13
- height: 1,
14
- debug: true,
15
- throwOnError: false
16
- };
17
-
18
- // Create headless gl context (for running under Node.js)
19
- // Create headless gl context (for running under Node.js)
20
- export function createHeadlessContext(options?: any): WebGLRenderingContext {
21
- options = {...CONTEXT_DEFAULTS, ...options};
22
-
23
- const {width, height, webgl1, webgl2} = options;
24
-
25
- if (webgl2 && !webgl1) {
26
- throw new Error('headless-gl does not support WebGL2');
27
- }
28
- if (!headlessGL) {
29
- throw new Error(ERR_HEADLESSGL_LOAD);
30
- }
31
- const gl = headlessGL(width, height, options);
32
- if (!gl) {
33
- throw new Error(ERR_HEADLESSGL_FAILED);
34
- }
35
- return gl;
36
- }
@@ -1,29 +0,0 @@
1
- import { createTestDevice } from "./create-test-device";
2
-
3
- export function createTestContext(opts: Record<string, any> = {}): WebGLRenderingContext | null {
4
- const device = createTestDevice(opts);
5
- return device && device.gl;
6
- }
7
-
8
- /*
9
- import {isBrowser} from 'probe.gl/env';
10
- import {createGLContext, instrumentGLContext} from '@luma.gl/gltools';
11
- import {createHeadlessContext} from './create-headless-context';
12
-
13
- export function createTestContext(opts: Record<string, any> = {}): WebGLRenderingContext | null {
14
- // try {
15
- if (!isBrowser()) {
16
- if (opts.webgl2 && !opts.webgl1) {
17
- return null;
18
- }
19
- const gl = createHeadlessContext(opts);
20
- return gl ? instrumentGLContext(gl) : null;
21
- }
22
- return createGLContext(opts);
23
- // } catch {
24
- // if (opts.webgl2) {
25
- // return null;
26
- // }
27
- // }
28
- }
29
- */