* Helper function for executing scripts in a webworker. We use * webworkers to get isolated contexts for tests for custom bundles. * * @param programUrl url to script to run in worker * @param debug debug mode
(
programUrl: string, opts: {debug?: boolean, workerParams?: {}})
| 312 | * @param debug debug mode |
| 313 | */ |
| 314 | async function executeInWorker( |
| 315 | programUrl: string, opts: {debug?: boolean, workerParams?: {}}) { |
| 316 | return new Promise((resolve, reject) => { |
| 317 | const debug = opts.debug || false; |
| 318 | const workerParams = opts.workerParams || {}; |
| 319 | const worker = new Worker(programUrl); |
| 320 | |
| 321 | worker.addEventListener('message', (evt) => { |
| 322 | if (evt.data.error) { |
| 323 | reject(evt.data.payload); |
| 324 | } |
| 325 | |
| 326 | if (debug && evt.data.msg) { |
| 327 | console.log('msg from worker: ', evt.data); |
| 328 | } |
| 329 | |
| 330 | if (evt.data.result) { |
| 331 | if (debug) { |
| 332 | console.log('result from worker: ', evt.data.result); |
| 333 | } |
| 334 | resolve(evt.data.payload); |
| 335 | } |
| 336 | }, false); |
| 337 | |
| 338 | worker.postMessage(workerParams); // Send data to our worker. |
| 339 | }); |
| 340 | } |
no test coverage detected
searching dependent graphs…