New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@vitest/web-worker

Package Overview
Dependencies
Maintainers
4
Versions
205
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vitest/web-worker - npm Package Compare versions

Comparing version 2.0.0-beta.10 to 2.0.0-beta.11

83

dist/pure.js

@@ -14,3 +14,5 @@ import { VitestExecutor } from 'vitest/execute';

const importScripts = () => {
throw new Error("[vitest] `importScripts` is not supported in Vite workers. Please, consider using `import` instead.");
throw new Error(
"[vitest] `importScripts` is not supported in Vite workers. Please, consider using `import` instead."
);
};

@@ -288,4 +290,7 @@ return Object.assign(ctx, this.context, {

function assertGlobalExists(name) {
if (!(name in globalThis))
throw new Error(`[@vitest/web-worker] Cannot initiate a custom Web Worker. "${name}" is not supported in this environment. Please, consider using jsdom or happy-dom environment.`);
if (!(name in globalThis)) {
throw new Error(
`[@vitest/web-worker] Cannot initiate a custom Web Worker. "${name}" is not supported in this environment. Please, consider using jsdom or happy-dom environment.`
);
}
}

@@ -357,8 +362,11 @@ function createClonedMessageEvent(data, transferOrOptions, clone) {

function getFileIdFromUrl(url) {
if (typeof self === "undefined")
if (typeof self === "undefined") {
return stripProtocol(url);
if (!(url instanceof URL))
}
if (!(url instanceof URL)) {
url = new URL(url, self.location.origin);
if (url.protocol === "http:" || url.protocol === "https:")
}
if (url.protocol === "http:" || url.protocol === "https:") {
return url.pathname;
}
return stripProtocol(url);

@@ -390,4 +398,5 @@ }

addEventListener: (...args) => {
if (args[1])
if (args[1]) {
this._vw_insideListeners.set(args[0], args[1]);
}
return this._vw_workerTarget.addEventListener(...args);

@@ -397,5 +406,12 @@ },

postMessage: (...args) => {
if (!args.length)
throw new SyntaxError('"postMessage" requires at least one argument.');
debug("posting message %o from the worker %s to the main thread", args[0], this._vw_name);
if (!args.length) {
throw new SyntaxError(
'"postMessage" requires at least one argument.'
);
}
debug(
"posting message %o from the worker %s to the main thread",
args[0],
this._vw_name
);
const event = createMessageEvent(args[0], args[1], cloneType());

@@ -427,7 +443,14 @@ this.dispatchEvent(event);

return runner.executeFile(fsPath).then(() => {
runnerOptions.moduleCache.invalidateSubDepTree([fsPath, runner.mocker.getMockPath(fsPath)]);
runnerOptions.moduleCache.invalidateSubDepTree([
fsPath,
runner.mocker.getMockPath(fsPath)
]);
const q = this._vw_messageQueue;
this._vw_messageQueue = null;
if (q)
q.forEach(([data, transfer]) => this.postMessage(data, transfer), this);
if (q) {
q.forEach(
([data, transfer]) => this.postMessage(data, transfer),
this
);
}
debug("worker %s successfully initialized", this._vw_name);

@@ -448,21 +471,32 @@ });

addEventListener(type, callback, options2) {
if (callback)
if (callback) {
this._vw_outsideListeners.set(type, callback);
}
return super.addEventListener(type, callback, options2);
}
postMessage(...args) {
if (!args.length)
if (!args.length) {
throw new SyntaxError('"postMessage" requires at least one argument.');
}
const [data, transferOrOptions] = args;
if (this._vw_messageQueue != null) {
debug("worker %s is not yet initialized, queue message %s", this._vw_name, data);
debug(
"worker %s is not yet initialized, queue message %s",
this._vw_name,
data
);
this._vw_messageQueue.push([data, transferOrOptions]);
return;
}
debug("posting message %o from the main thread to the worker %s", data, this._vw_name);
debug(
"posting message %o from the main thread to the worker %s",
data,
this._vw_name
);
const event = createMessageEvent(data, transferOrOptions, cloneType());
if (event.type === "messageerror")
if (event.type === "messageerror") {
this.dispatchEvent(event);
else
} else {
this._vw_workerTarget.dispatchEvent(event);
}
}

@@ -504,6 +538,8 @@ terminate() {

value(event) {
if (event.name === "message")
if (event.name === "message") {
port.onmessage?.(event);
if (event.name === "messageerror")
}
if (event.name === "messageerror") {
port.onmessageerror?.(event);
}
return emit(event);

@@ -567,3 +603,6 @@ },

return runner.executeFile(fsPath).then(() => {
runnerOptions.moduleCache.invalidateSubDepTree([fsPath, runner.mocker.getMockPath(fsPath)]);
runnerOptions.moduleCache.invalidateSubDepTree([
fsPath,
runner.mocker.getMockPath(fsPath)
]);
this._vw_workerTarget.dispatchEvent(

@@ -570,0 +609,0 @@ new MessageEvent("connect", {

{
"name": "@vitest/web-worker",
"type": "module",
"version": "2.0.0-beta.10",
"version": "2.0.0-beta.11",
"description": "Web Worker support for testing in Vitest",

@@ -6,0 +6,0 @@ "license": "MIT",

@@ -48,4 +48,5 @@ # @vitest/web-worker

if (process.env.SUPPORT_WORKERS)
if (process.env.SUPPORT_WORKERS) {
defineWebWorkers({ clone: 'none' })
}
```

@@ -52,0 +53,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc