@vitest/web-worker 3.2.0-beta.2 → 3.2.0

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 +7 -0
  2. package/package.json +3 -3
package/dist/pure.js CHANGED
@@ -5,6 +5,7 @@ import createDebug from 'debug';
5
5
 
6
6
  class InlineWorkerRunner extends VitestExecutor {
7
7
  constructor(options, context) {
8
+ // share the same mocker as main executor
8
9
  const mocker = globalThis.__vitest_mocker__;
9
10
  super(options);
10
11
  this.context = context;
@@ -12,6 +13,7 @@ class InlineWorkerRunner extends VitestExecutor {
12
13
  }
13
14
  prepareContext(context) {
14
15
  const ctx = super.prepareContext(context);
16
+ // not supported for now, we can't synchronously load modules
15
17
  return Object.assign(ctx, this.context, { importScripts });
16
18
  }
17
19
  }
@@ -295,9 +297,11 @@ var ponyfillStructuredClone = typeof structuredClone === "function" ?
295
297
  ) :
296
298
  (any, options) => deserialize(serialize(any, options));
297
299
 
300
+ // keep the reference in case it was mocked
298
301
  const readFileSync = readFileSync$1;
299
302
  const debug = createDebug("vitest:web-worker");
300
303
  function getWorkerState() {
304
+ // @ts-expect-error untyped global
301
305
  return globalThis.__vitest_worker__;
302
306
  }
303
307
  function assertGlobalExists(name) {
@@ -487,6 +491,7 @@ function createSharedWorkerConstructor() {
487
491
  this._vw_name = name ?? fsPath;
488
492
  debug("initialize shared worker %s", this._vw_name);
489
493
  return runner.executeFile(fsPath).then(() => {
494
+ // worker should be new every time, invalidate its sub dependency
490
495
  runnerOptions.moduleCache.invalidateSubDepTree([fsPath, runner.mocker.getMockPath(fsPath)]);
491
496
  this._vw_workerTarget.dispatchEvent(new MessageEvent("connect", { ports: [this._vw_workerPort] }));
492
497
  debug("shared worker %s successfully initialized", this._vw_name);
@@ -522,6 +527,7 @@ function createWorkerConstructor(options) {
522
527
  constructor(url, options) {
523
528
  super();
524
529
  let selfProxy;
530
+ // should be in sync with DedicatedWorkerGlobalScope, but without globalThis
525
531
  const context = {
526
532
  onmessage: null,
527
533
  onmessageerror: null,
@@ -585,6 +591,7 @@ function createWorkerConstructor(options) {
585
591
  this._vw_name = options?.name ?? fsPath;
586
592
  debug("initialize worker %s", this._vw_name);
587
593
  return runner.executeFile(fsPath).then(() => {
594
+ // worker should be new every time, invalidate its sub dependency
588
595
  runnerOptions.moduleCache.invalidateSubDepTree([fsPath, runner.mocker.getMockPath(fsPath)]);
589
596
  const q = this._vw_messageQueue;
590
597
  this._vw_messageQueue = null;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/web-worker",
3
3
  "type": "module",
4
- "version": "3.2.0-beta.2",
4
+ "version": "3.2.0",
5
5
  "description": "Web Worker support for testing in Vitest",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -33,10 +33,10 @@
33
33
  "dist"
34
34
  ],
35
35
  "peerDependencies": {
36
- "vitest": "3.2.0-beta.2"
36
+ "vitest": "3.2.0"
37
37
  },
38
38
  "dependencies": {
39
- "debug": "^4.4.0"
39
+ "debug": "^4.4.1"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/debug": "^4.1.12",