@vitest/web-worker 0.32.2 → 0.32.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 (2) hide show
  1. package/dist/pure.js +56 -30
  2. package/package.json +3 -3
package/dist/pure.js CHANGED
@@ -92,9 +92,14 @@ const deserializer = ($, _) => {
92
92
  return unpair;
93
93
  };
94
94
 
95
+ /**
96
+ * @typedef {Array<string,any>} Record a type representation
97
+ */
98
+
95
99
  /**
96
100
  * Returns a deserialized value from a serialized array of Records.
97
- * @param serialized - a previously serialized value.
101
+ * @param {Record[]} serialized a previously serialized value.
102
+ * @returns {any}
98
103
  */
99
104
  const deserialize = serialized => deserializer(new Map, serialized)(0);
100
105
 
@@ -236,18 +241,35 @@ const serializer = (strict, json, $, _) => {
236
241
  return pair;
237
242
  };
238
243
 
244
+ /**
245
+ * @typedef {Array<string,any>} Record a type representation
246
+ */
247
+
239
248
  /**
240
249
  * Returns an array of serialized Records.
241
- * @param value - a serializable value.
242
- * @param options - an object with a `lossy` property that,
250
+ * @param {any} value a serializable value.
251
+ * @param {{json?: boolean, lossy?: boolean}?} options an object with a `lossy` or `json` property that,
243
252
  * if `true`, will not throw errors on incompatible types, and behave more
244
253
  * like JSON stringify would behave. Symbol and Function will be discarded.
254
+ * @returns {Record[]}
245
255
  */
246
256
  const serialize = (value, {json, lossy} = {}) => {
247
257
  const _ = [];
248
258
  return serializer(!(json || lossy), !!json, new Map, _)(value), _;
249
259
  };
250
260
 
261
+ /**
262
+ * @typedef {Array<string,any>} Record a type representation
263
+ */
264
+
265
+ /**
266
+ * Returns an array of serialized Records.
267
+ * @param {any} any a serializable value.
268
+ * @param {{transfer?: any[], json?: boolean, lossy?: boolean}?} options an object with
269
+ * a transfer option (ignored when polyfilled) and/or non standard fields that
270
+ * fallback to the polyfill if present.
271
+ * @returns {Record[]}
272
+ */
251
273
  var ponyfillStructuredClone = typeof structuredClone === "function" ?
252
274
  /* c8 ignore start */
253
275
  (any, options) => (
@@ -320,19 +342,20 @@ function getRunnerOptions() {
320
342
  }
321
343
 
322
344
  function createWorkerConstructor(options) {
323
- var _a;
324
345
  const runnerOptions = getRunnerOptions();
325
346
  const cloneType = () => (options == null ? void 0 : options.clone) ?? process.env.VITEST_WEB_WORKER_CLONE ?? "native";
326
- return _a = class extends EventTarget {
347
+ return class Worker extends EventTarget {
348
+ static __VITEST_WEB_WORKER__ = true;
349
+ _vw_workerTarget = new EventTarget();
350
+ _vw_insideListeners = /* @__PURE__ */ new Map();
351
+ _vw_outsideListeners = /* @__PURE__ */ new Map();
352
+ _vw_name;
353
+ _vw_messageQueue = [];
354
+ onmessage = null;
355
+ onmessageerror = null;
356
+ onerror = null;
327
357
  constructor(url, options2) {
328
358
  super();
329
- this._vw_workerTarget = new EventTarget();
330
- this._vw_insideListeners = /* @__PURE__ */ new Map();
331
- this._vw_outsideListeners = /* @__PURE__ */ new Map();
332
- this._vw_messageQueue = [];
333
- this.onmessage = null;
334
- this.onmessageerror = null;
335
- this.onerror = null;
336
359
  const context = {
337
360
  onmessage: null,
338
361
  name: options2 == null ? void 0 : options2.name,
@@ -361,16 +384,16 @@ function createWorkerConstructor(options) {
361
384
  }
362
385
  };
363
386
  this._vw_workerTarget.addEventListener("message", (e) => {
364
- var _a2;
365
- (_a2 = context.onmessage) == null ? void 0 : _a2.call(context, e);
387
+ var _a;
388
+ (_a = context.onmessage) == null ? void 0 : _a.call(context, e);
366
389
  });
367
390
  this.addEventListener("message", (e) => {
368
- var _a2;
369
- (_a2 = this.onmessage) == null ? void 0 : _a2.call(this, e);
391
+ var _a;
392
+ (_a = this.onmessage) == null ? void 0 : _a.call(this, e);
370
393
  });
371
394
  this.addEventListener("messageerror", (e) => {
372
- var _a2;
373
- (_a2 = this.onmessageerror) == null ? void 0 : _a2.call(this, e);
395
+ var _a;
396
+ (_a = this.onmessageerror) == null ? void 0 : _a.call(this, e);
374
397
  });
375
398
  const runner = new InlineWorkerRunner(runnerOptions, context);
376
399
  const id = (url instanceof URL ? url.toString() : url).replace(/^file:\/+/, "/");
@@ -387,7 +410,7 @@ function createWorkerConstructor(options) {
387
410
  debug("worker %s successfully initialized", this._vw_name);
388
411
  });
389
412
  }).catch((e) => {
390
- var _a2;
413
+ var _a;
391
414
  debug("worker %s failed to initialize: %o", this._vw_name, e);
392
415
  const EventConstructor = globalThis.ErrorEvent || globalThis.Event;
393
416
  const error = new EventConstructor("error", {
@@ -395,7 +418,7 @@ function createWorkerConstructor(options) {
395
418
  message: e.message
396
419
  });
397
420
  this.dispatchEvent(error);
398
- (_a2 = this.onerror) == null ? void 0 : _a2.call(this, error);
421
+ (_a = this.onerror) == null ? void 0 : _a.call(this, error);
399
422
  console.error(e);
400
423
  });
401
424
  }
@@ -429,7 +452,7 @@ function createWorkerConstructor(options) {
429
452
  this._vw_workerTarget.removeEventListener(type, fn);
430
453
  });
431
454
  }
432
- }, _a.__VITEST_WEB_WORKER__ = true, _a;
455
+ };
433
456
  }
434
457
 
435
458
  function convertNodePortToWebPort(port) {
@@ -476,13 +499,16 @@ function convertNodePortToWebPort(port) {
476
499
  return port;
477
500
  }
478
501
  function createSharedWorkerConstructor() {
479
- var _a;
480
502
  const runnerOptions = getRunnerOptions();
481
- return _a = class extends EventTarget {
503
+ return class SharedWorker extends EventTarget {
504
+ static __VITEST_WEB_WORKER__ = true;
505
+ _vw_workerTarget = new EventTarget();
506
+ _vw_name;
507
+ _vw_workerPort;
508
+ onerror = null;
509
+ port;
482
510
  constructor(url, options) {
483
511
  super();
484
- this._vw_workerTarget = new EventTarget();
485
- this.onerror = null;
486
512
  const name = typeof options === "string" ? options : options == null ? void 0 : options.name;
487
513
  const context = {
488
514
  onconnect: null,
@@ -506,8 +532,8 @@ function createSharedWorkerConstructor() {
506
532
  this.port = convertNodePortToWebPort(channel.port1);
507
533
  this._vw_workerPort = convertNodePortToWebPort(channel.port2);
508
534
  this._vw_workerTarget.addEventListener("connect", (e) => {
509
- var _a2;
510
- (_a2 = context.onconnect) == null ? void 0 : _a2.call(context, e);
535
+ var _a;
536
+ (_a = context.onconnect) == null ? void 0 : _a.call(context, e);
511
537
  });
512
538
  const runner = new InlineWorkerRunner(runnerOptions, context);
513
539
  const id = (url instanceof URL ? url.toString() : url).replace(/^file:\/+/, "/");
@@ -525,7 +551,7 @@ function createSharedWorkerConstructor() {
525
551
  debug("shared worker %s successfully initialized", this._vw_name);
526
552
  });
527
553
  }).catch((e) => {
528
- var _a2;
554
+ var _a;
529
555
  debug("shared worker %s failed to initialize: %o", this._vw_name, e);
530
556
  const EventConstructor = globalThis.ErrorEvent || globalThis.Event;
531
557
  const error = new EventConstructor("error", {
@@ -533,11 +559,11 @@ function createSharedWorkerConstructor() {
533
559
  message: e.message
534
560
  });
535
561
  this.dispatchEvent(error);
536
- (_a2 = this.onerror) == null ? void 0 : _a2.call(this, error);
562
+ (_a = this.onerror) == null ? void 0 : _a.call(this, error);
537
563
  console.error(e);
538
564
  });
539
565
  }
540
- }, _a.__VITEST_WEB_WORKER__ = true, _a;
566
+ };
541
567
  }
542
568
 
543
569
  function defineWebWorkers(options) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/web-worker",
3
3
  "type": "module",
4
- "version": "0.32.2",
4
+ "version": "0.32.4",
5
5
  "description": "Web Worker support for testing in Vitest",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -41,9 +41,9 @@
41
41
  "debug": "^4.3.4"
42
42
  },
43
43
  "devDependencies": {
44
- "@types/debug": "^4.1.7",
44
+ "@types/debug": "^4.1.8",
45
45
  "@types/ungap__structured-clone": "^0.3.0",
46
- "@ungap/structured-clone": "^1.1.0"
46
+ "@ungap/structured-clone": "^1.2.0"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "rimraf dist && rollup -c",