@vitest/web-worker 2.0.3 → 2.0.5

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 +58 -13
  2. package/package.json +2 -2
package/dist/pure.js CHANGED
@@ -306,9 +306,11 @@ function createClonedMessageEvent(data, transferOrOptions, clone) {
306
306
  }
307
307
  if (clone !== "none") {
308
308
  debug("create message event, using polyfilled structured clone");
309
- transfer?.length && console.warn(
310
- '[@vitest/web-worker] `structuredClone` is not supported in this environment. Falling back to polyfill, your transferable options will be lost. Set `VITEST_WEB_WORKER_CLONE` environmental variable to "none", if you don\'t want to loose it,or update to Node 17+.'
311
- );
309
+ if (transfer?.length) {
310
+ console.warn(
311
+ '[@vitest/web-worker] `structuredClone` is not supported in this environment. Falling back to polyfill, your transferable options will be lost. Set `VITEST_WEB_WORKER_CLONE` environmental variable to "none", if you don\'t want to loose it,or update to Node 17+.'
312
+ );
313
+ }
312
314
  return new MessageEvent("message", {
313
315
  data: ponyfillStructuredClone(data, { lossy: true }),
314
316
  origin
@@ -385,9 +387,25 @@ function createWorkerConstructor(options) {
385
387
  onerror = null;
386
388
  constructor(url, options2) {
387
389
  super();
390
+ let selfProxy;
388
391
  const context = {
389
392
  onmessage: null,
390
- name: options2?.name,
393
+ onmessageerror: null,
394
+ onerror: null,
395
+ onlanguagechange: null,
396
+ onoffline: null,
397
+ ononline: null,
398
+ onrejectionhandled: null,
399
+ onrtctransform: null,
400
+ onunhandledrejection: null,
401
+ origin: typeof location !== "undefined" ? location.origin : "http://localhost:3000",
402
+ importScripts: () => {
403
+ throw new Error(
404
+ "[vitest] `importScripts` is not supported in Vite workers. Please, consider using `import` instead."
405
+ );
406
+ },
407
+ crossOriginIsolated: false,
408
+ name: options2?.name || "",
391
409
  close: () => this.terminate(),
392
410
  dispatchEvent: (event) => {
393
411
  return this._vw_workerTarget.dispatchEvent(event);
@@ -414,12 +432,17 @@ function createWorkerConstructor(options) {
414
432
  this.dispatchEvent(event);
415
433
  },
416
434
  get self() {
417
- return context;
418
- },
419
- get global() {
420
- return context;
435
+ return selfProxy;
421
436
  }
422
437
  };
438
+ selfProxy = new Proxy(context, {
439
+ get(target, prop, receiver) {
440
+ if (Reflect.has(target, prop)) {
441
+ return Reflect.get(target, prop, receiver);
442
+ }
443
+ return globalThis[prop];
444
+ }
445
+ });
423
446
  this._vw_workerTarget.addEventListener("message", (e) => {
424
447
  context.onmessage?.(e);
425
448
  });
@@ -562,9 +585,26 @@ function createSharedWorkerConstructor() {
562
585
  constructor(url, options) {
563
586
  super();
564
587
  const name = typeof options === "string" ? options : options?.name;
588
+ let selfProxy;
565
589
  const context = {
590
+ onmessage: null,
591
+ onmessageerror: null,
592
+ onerror: null,
593
+ onlanguagechange: null,
594
+ onoffline: null,
595
+ ononline: null,
596
+ onrejectionhandled: null,
597
+ onrtctransform: null,
598
+ onunhandledrejection: null,
599
+ origin: typeof location !== "undefined" ? location.origin : "http://localhost:3000",
600
+ importScripts: () => {
601
+ throw new Error(
602
+ "[vitest] `importScripts` is not supported in Vite workers. Please, consider using `import` instead."
603
+ );
604
+ },
605
+ crossOriginIsolated: false,
566
606
  onconnect: null,
567
- name,
607
+ name: name || "",
568
608
  close: () => this.port.close(),
569
609
  dispatchEvent: (event) => {
570
610
  return this._vw_workerTarget.dispatchEvent(event);
@@ -574,12 +614,17 @@ function createSharedWorkerConstructor() {
574
614
  },
575
615
  removeEventListener: this._vw_workerTarget.removeEventListener,
576
616
  get self() {
577
- return context;
578
- },
579
- get global() {
580
- return context;
617
+ return selfProxy;
581
618
  }
582
619
  };
620
+ selfProxy = new Proxy(context, {
621
+ get(target, prop, receiver) {
622
+ if (Reflect.has(target, prop)) {
623
+ return Reflect.get(target, prop, receiver);
624
+ }
625
+ return Reflect.get(globalThis, prop, receiver);
626
+ }
627
+ });
583
628
  const channel = new MessageChannel();
584
629
  this.port = convertNodePortToWebPort(channel.port1);
585
630
  this._vw_workerPort = convertNodePortToWebPort(channel.port2);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/web-worker",
3
3
  "type": "module",
4
- "version": "2.0.3",
4
+ "version": "2.0.5",
5
5
  "description": "Web Worker support for testing in Vitest",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -33,7 +33,7 @@
33
33
  "dist"
34
34
  ],
35
35
  "peerDependencies": {
36
- "vitest": "2.0.3"
36
+ "vitest": "2.0.5"
37
37
  },
38
38
  "dependencies": {
39
39
  "debug": "^4.3.5"