@vitest/web-worker
Advanced tools
Comparing version 2.0.4 to 2.0.5
@@ -390,5 +390,21 @@ import { VitestExecutor } from 'vitest/execute'; | ||
super(); | ||
let selfProxy; | ||
const context = { | ||
onmessage: null, | ||
name: options2?.name, | ||
onmessageerror: null, | ||
onerror: null, | ||
onlanguagechange: null, | ||
onoffline: null, | ||
ononline: null, | ||
onrejectionhandled: null, | ||
onrtctransform: null, | ||
onunhandledrejection: null, | ||
origin: typeof location !== "undefined" ? location.origin : "http://localhost:3000", | ||
importScripts: () => { | ||
throw new Error( | ||
"[vitest] `importScripts` is not supported in Vite workers. Please, consider using `import` instead." | ||
); | ||
}, | ||
crossOriginIsolated: false, | ||
name: options2?.name || "", | ||
close: () => this.terminate(), | ||
@@ -420,8 +436,13 @@ dispatchEvent: (event) => { | ||
get self() { | ||
return context; | ||
}, | ||
get global() { | ||
return context; | ||
return selfProxy; | ||
} | ||
}; | ||
selfProxy = new Proxy(context, { | ||
get(target, prop, receiver) { | ||
if (Reflect.has(target, prop)) { | ||
return Reflect.get(target, prop, receiver); | ||
} | ||
return globalThis[prop]; | ||
} | ||
}); | ||
this._vw_workerTarget.addEventListener("message", (e) => { | ||
@@ -569,5 +590,22 @@ context.onmessage?.(e); | ||
const name = typeof options === "string" ? options : options?.name; | ||
let selfProxy; | ||
const context = { | ||
onmessage: null, | ||
onmessageerror: null, | ||
onerror: null, | ||
onlanguagechange: null, | ||
onoffline: null, | ||
ononline: null, | ||
onrejectionhandled: null, | ||
onrtctransform: null, | ||
onunhandledrejection: null, | ||
origin: typeof location !== "undefined" ? location.origin : "http://localhost:3000", | ||
importScripts: () => { | ||
throw new Error( | ||
"[vitest] `importScripts` is not supported in Vite workers. Please, consider using `import` instead." | ||
); | ||
}, | ||
crossOriginIsolated: false, | ||
onconnect: null, | ||
name, | ||
name: name || "", | ||
close: () => this.port.close(), | ||
@@ -582,8 +620,13 @@ dispatchEvent: (event) => { | ||
get self() { | ||
return context; | ||
}, | ||
get global() { | ||
return context; | ||
return selfProxy; | ||
} | ||
}; | ||
selfProxy = new Proxy(context, { | ||
get(target, prop, receiver) { | ||
if (Reflect.has(target, prop)) { | ||
return Reflect.get(target, prop, receiver); | ||
} | ||
return Reflect.get(globalThis, prop, receiver); | ||
} | ||
}); | ||
const channel = new MessageChannel(); | ||
@@ -590,0 +633,0 @@ this.port = convertNodePortToWebPort(channel.port1); |
{ | ||
"name": "@vitest/web-worker", | ||
"type": "module", | ||
"version": "2.0.4", | ||
"version": "2.0.5", | ||
"description": "Web Worker support for testing in Vitest", | ||
@@ -36,3 +36,3 @@ "license": "MIT", | ||
"peerDependencies": { | ||
"vitest": "2.0.4" | ||
"vitest": "2.0.5" | ||
}, | ||
@@ -39,0 +39,0 @@ "dependencies": { |
25679
657