• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

visgl / loaders.gl / 24139120841

08 Apr 2026 01:53PM UTC coverage: 65.319% (+30.2%) from 35.137%
24139120841

push

github

web-flow
chore: Replace puppeteer with playwright (#3350)

14216 of 18890 branches covered (75.26%)

Branch coverage included in aggregate %.

3 of 3 new or added lines in 1 file covered. (100.0%)

3248 existing lines in 369 files now uncovered.

73509 of 115413 relevant lines covered (63.69%)

5763.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

44.12
/modules/loader-utils/src/lib/worker-loader-utils/create-loader-worker.ts
1
/* eslint-disable no-restricted-globals */
1✔
2
import type {LoaderWithParser, LoaderOptions, LoaderContext} from '../../loader-types';
1✔
3
import {WorkerBody} from '@loaders.gl/worker-utils';
1✔
UNCOV
4
// import {validateLoaderVersion} from './validate-loader-version';
×
UNCOV
5

×
UNCOV
6
let requestId = 0;
×
UNCOV
7

×
UNCOV
8
/**
×
UNCOV
9
 * Set up a WebWorkerGlobalScope to talk with the main thread
×
UNCOV
10
 * @param loader
×
UNCOV
11
 */
×
12
export async function createLoaderWorker(loader: LoaderWithParser) {
✔
13
  // Check that we are actually in a worker thread
5✔
14
  if (!(await WorkerBody.inWorkerThread())) {
5!
15
    return;
×
16
  }
×
17

5✔
18
  WorkerBody.onmessage = async (type, payload) => {
5✔
19
    switch (type) {
5✔
20
      case 'process':
5✔
21
        try {
5✔
22
          // validateLoaderVersion(loader, data.source.split('@')[1]);
5✔
23

5✔
24
          const {input, options = {}, context = {}} = payload;
5✔
25

5✔
26
          const result = await parseData({
5✔
27
            loader,
5✔
28
            arrayBuffer: input,
5✔
29
            options,
5✔
30
            // @ts-expect-error fetch missing
5✔
31
            context: {
5✔
32
              ...context,
×
33
              _parse: parseOnMainThread
×
34
            }
×
35
          });
×
36
          WorkerBody.postMessage('done', {result});
×
37
        } catch (error) {
×
38
          const message = error instanceof Error ? error.message : '';
×
39
          WorkerBody.postMessage('error', {error: message});
×
40
        }
×
41
        break;
×
42
      default:
×
43
    }
×
44
  };
×
45
}
×
UNCOV
46

×
47
function parseOnMainThread(
×
48
  arrayBuffer: ArrayBuffer,
×
49
  loader: any,
×
50
  options?: LoaderOptions,
×
51
  context?: LoaderContext
×
52
): Promise<void> {
×
53
  return new Promise((resolve, reject) => {
×
54
    const id = requestId++;
×
55

×
56
    /**
×
57
     */
×
58
    const onMessage = (type, payload) => {
×
59
      if (payload.id !== id) {
×
60
        // not ours
×
61
        return;
×
62
      }
×
63

×
64
      switch (type) {
×
65
        case 'done':
×
66
          WorkerBody.removeEventListener(onMessage);
×
67
          resolve(payload.result);
×
68
          break;
×
69

×
70
        case 'error':
×
71
          WorkerBody.removeEventListener(onMessage);
×
72
          reject(payload.error);
×
73
          break;
×
74

×
75
        default:
×
76
        // ignore
×
77
      }
×
78
    };
×
79

×
80
    WorkerBody.addEventListener(onMessage);
×
81

×
82
    // Ask the main thread to decode data
×
83
    const payload = {id, input: arrayBuffer, options};
×
84
    WorkerBody.postMessage('process', payload);
×
85
  });
×
86
}
×
87

1✔
88
// TODO - Support byteOffset and byteLength (enabling parsing of embedded binaries without copies)
1✔
89
// TODO - Why not support async loader.parse* funcs here?
1✔
90
// TODO - Why not reuse a common function instead of reimplementing loader.parse* selection logic? Keeping loader small?
1✔
91
// TODO - Lack of appropriate parser functions can be detected when we create worker, no need to wait until parse
1✔
92
async function parseData({
5✔
93
  loader,
5✔
94
  arrayBuffer,
5✔
95
  options,
5✔
96
  context
5✔
97
}: {
5✔
98
  loader: LoaderWithParser;
5✔
99
  arrayBuffer: ArrayBuffer;
5✔
100
  options: LoaderOptions;
5✔
101
  context: LoaderContext;
5✔
102
}) {
5✔
103
  let data;
5✔
104
  let parser;
5✔
105
  if (loader.parseSync || loader.parse) {
5✔
106
    data = arrayBuffer;
5✔
107
    parser = loader.parseSync || loader.parse;
5✔
108
  } else if (loader.parseTextSync) {
5!
109
    const textDecoder = new TextDecoder();
×
110
    data = textDecoder.decode(arrayBuffer);
×
111
    parser = loader.parseTextSync;
×
112
  } else {
×
113
    throw new Error(`Could not load data with ${loader.name} loader`);
×
114
  }
×
115

5✔
116
  // TODO - proper merge in of loader options...
5✔
117
  options = {
5✔
118
    ...options,
5✔
119
    modules: (loader && loader.options && loader.options.modules) || {},
5✔
120
    core: {
5✔
121
      ...options.core,
5✔
122
      worker: false
5✔
123
    }
5✔
124
  };
5✔
125

5✔
126
  return await parser(data, {...options}, context, loader);
5✔
127
}
5✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc