@vitest/web-worker 2.0.4 → 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 +53 -10
  2. package/package.json +2 -2
package/dist/pure.js CHANGED
@@ -387,9 +387,25 @@ function createWorkerConstructor(options) {
387
387
  onerror = null;
388
388
  constructor(url, options2) {
389
389
  super();
390
+ let selfProxy;
390
391
  const context = {
391
392
  onmessage: null,
392
- 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 || "",
393
409
  close: () => this.terminate(),
394
410
  dispatchEvent: (event) => {
395
411
  return this._vw_workerTarget.dispatchEvent(event);
@@ -416,12 +432,17 @@ function createWorkerConstructor(options) {
416
432
  this.dispatchEvent(event);
417
433
  },
418
434
  get self() {
419
- return context;
420
- },
421
- get global() {
422
- return context;
435
+ return selfProxy;
423
436
  }
424
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
+ });
425
446
  this._vw_workerTarget.addEventListener("message", (e) => {
426
447
  context.onmessage?.(e);
427
448
  });
@@ -564,9 +585,26 @@ function createSharedWorkerConstructor() {
564
585
  constructor(url, options) {
565
586
  super();
566
587
  const name = typeof options === "string" ? options : options?.name;
588
+ let selfProxy;
567
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,
568
606
  onconnect: null,
569
- name,
607
+ name: name || "",
570
608
  close: () => this.port.close(),
571
609
  dispatchEvent: (event) => {
572
610
  return this._vw_workerTarget.dispatchEvent(event);
@@ -576,12 +614,17 @@ function createSharedWorkerConstructor() {
576
614
  },
577
615
  removeEventListener: this._vw_workerTarget.removeEventListener,
578
616
  get self() {
579
- return context;
580
- },
581
- get global() {
582
- return context;
617
+ return selfProxy;
583
618
  }
584
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
+ });
585
628
  const channel = new MessageChannel();
586
629
  this.port = convertNodePortToWebPort(channel.port1);
587
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.4",
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.4"
36
+ "vitest": "2.0.5"
37
37
  },
38
38
  "dependencies": {
39
39
  "debug": "^4.3.5"