Launch Week Day 3: Introducing Organization Notifications in Socket.Learn More
Socket
Book a DemoSign in
Socket

@vitest/mocker

Package Overview
Dependencies
Maintainers
5
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vitest/mocker - npm Package Compare versions

Comparing version
4.1.0-beta.3
to
4.1.0-beta.4
+10
-15
dist/chunk-hoistMocks.js

@@ -321,3 +321,2 @@ import MagicString from 'magic-string';

function hoistMocks(code, id, parse, options = {}) {
var _options$magicString, _hashbangRE$exec;
const needHoisting = (options.regexpHoistable || regexpHoistable).test(code);

@@ -327,3 +326,3 @@ if (!needHoisting) {

}
const s = ((_options$magicString = options.magicString) === null || _options$magicString === void 0 ? void 0 : _options$magicString.call(options)) || new MagicString(code);
const s = options.magicString?.() || new MagicString(code);
let ast;

@@ -343,3 +342,3 @@ try {

// hoist at the start of the file, after the hashbang
const hashbangEnd = ((_hashbangRE$exec = hashbangRE.exec(code)) === null || _hashbangRE$exec === void 0 ? void 0 : _hashbangRE$exec[0].length) ?? 0;
const hashbangEnd = hashbangRE.exec(code)?.[0].length ?? 0;
let hoistIndex = hashbangEnd;

@@ -411,5 +410,4 @@ let hoistedModuleImported = false;

function assertNotDefaultExport(node, error) {
var _findNodeAround;
const defaultExport = (_findNodeAround = findNodeAround(ast, node.start, "ExportDefaultDeclaration")) === null || _findNodeAround === void 0 ? void 0 : _findNodeAround.node;
if ((defaultExport === null || defaultExport === void 0 ? void 0 : defaultExport.declaration) === node || (defaultExport === null || defaultExport === void 0 ? void 0 : defaultExport.declaration.type) === "AwaitExpression" && defaultExport.declaration.argument === node) {
const defaultExport = findNodeAround(ast, node.start, "ExportDefaultDeclaration")?.node;
if (defaultExport?.declaration === node || defaultExport?.declaration.type === "AwaitExpression" && defaultExport.declaration.argument === node) {
throw createSyntaxError(defaultExport, error);

@@ -419,5 +417,4 @@ }

function assertNotNamedExport(node, error) {
var _findNodeAround2;
const nodeExported = (_findNodeAround2 = findNodeAround(ast, node.start, "ExportNamedDeclaration")) === null || _findNodeAround2 === void 0 ? void 0 : _findNodeAround2.node;
if ((nodeExported === null || nodeExported === void 0 ? void 0 : nodeExported.declaration) === node) {
const nodeExported = findNodeAround(ast, node.start, "ExportNamedDeclaration")?.node;
if (nodeExported?.declaration === node) {
throw createSyntaxError(nodeExported, error);

@@ -427,5 +424,4 @@ }

function getVariableDeclaration(node) {
var _findNodeAround3, _declarationNode$decl;
const declarationNode = (_findNodeAround3 = findNodeAround(ast, node.start, "VariableDeclaration")) === null || _findNodeAround3 === void 0 ? void 0 : _findNodeAround3.node;
const init = declarationNode === null || declarationNode === void 0 || (_declarationNode$decl = declarationNode.declarations[0]) === null || _declarationNode$decl === void 0 ? void 0 : _declarationNode$decl.init;
const declarationNode = findNodeAround(ast, node.start, "VariableDeclaration")?.node;
const init = declarationNode?.declarations[0]?.init;
if (init && (init === node || init.type === "AwaitExpression" && init.argument === node)) {

@@ -527,6 +523,5 @@ return declarationNode;

} else {
var _findNodeAround4;
const awaitedExpression = (_findNodeAround4 = findNodeAround(ast, node.start, "AwaitExpression")) === null || _findNodeAround4 === void 0 ? void 0 : _findNodeAround4.node;
const awaitedExpression = findNodeAround(ast, node.start, "AwaitExpression")?.node;
// hoist "await vi.hoisted(async () => {})" or "vi.hoisted(() => {})"
const moveNode = (awaitedExpression === null || awaitedExpression === void 0 ? void 0 : awaitedExpression.argument) === node ? awaitedExpression : node;
const moveNode = awaitedExpression?.argument === node ? awaitedExpression : node;
hoistedNodes.add(moveNode);

@@ -533,0 +528,0 @@ }

+4
-4

@@ -245,3 +245,3 @@ import { c as createSimpleStackTrace } from './chunk-helpers.js';

function createCompilerHints(options) {
const globalThisAccessor = (options === null || options === void 0 ? void 0 : options.globalThisKey) || "__vitest_mocker__";
const globalThisAccessor = options?.globalThisKey || "__vitest_mocker__";
function _mocker() {

@@ -302,3 +302,3 @@ // @ts-expect-error injected by the plugin

const stack = /* @__PURE__ */ parseSingleStack(stackArray[importerStackIndex + 1]);
return (stack === null || stack === void 0 ? void 0 : stack.file) || "";
return stack?.file || "";
}

@@ -390,3 +390,3 @@

const m = mod.default;
return (m === null || m === void 0 ? void 0 : m.__esModule) ? m : {
return m?.__esModule ? m : {
...typeof m === "object" && !Array.isArray(m) || typeof m === "function" ? m : {},

@@ -448,3 +448,3 @@ default: m

queueMock(rawId, importer, factoryOrOptions) {
const promise = this.rpc.resolveMock(rawId, importer, { mock: typeof factoryOrOptions === "function" ? "factory" : (factoryOrOptions === null || factoryOrOptions === void 0 ? void 0 : factoryOrOptions.spy) ? "spy" : "auto" }).then(async ({ redirectUrl, resolvedId, resolvedUrl, needsInterop, mockType }) => {
const promise = this.rpc.resolveMock(rawId, importer, { mock: typeof factoryOrOptions === "function" ? "factory" : factoryOrOptions?.spy ? "spy" : "auto" }).then(async ({ redirectUrl, resolvedId, resolvedUrl, needsInterop, mockType }) => {
const mockUrl = this.resolveMockPath(cleanVersion(resolvedUrl));

@@ -451,0 +451,0 @@ this.mockedIds.add(resolvedId);

@@ -165,3 +165,3 @@ class MockerRegistry {

}
if (typeof exports$1 === "object" && typeof (exports$1 === null || exports$1 === void 0 ? void 0 : exports$1.then) === "function") {
if (typeof exports$1 === "object" && typeof exports$1?.then === "function") {
return exports$1.then((result) => {

@@ -168,0 +168,0 @@ assertValidExports(this.raw, result);

@@ -240,5 +240,4 @@ import { a as cleanUrl, c as createManualModuleSource } from './chunk-utils.js';

if (options.mock === "factory") {
var _manifest$fsPath;
const manifest = getViteDepsManifest(this.server.config);
const needsInterop = (manifest === null || manifest === void 0 || (_manifest$fsPath = manifest[fsPath]) === null || _manifest$fsPath === void 0 ? void 0 : _manifest$fsPath.needsInterop) ?? false;
const needsInterop = manifest?.[fsPath]?.needsInterop ?? false;
return {

@@ -312,3 +311,3 @@ mockType: "manual",

resolveModule(rawId, resolved) {
const id = (resolved === null || resolved === void 0 ? void 0 : resolved.id) || rawId;
const id = resolved?.id || rawId;
const external = !isAbsolute(id) || isModuleDirectory(this.options, id) ? rawId : null;

@@ -315,0 +314,0 @@ return {

{
"name": "@vitest/mocker",
"type": "module",
"version": "4.1.0-beta.3",
"version": "4.1.0-beta.4",
"description": "Vitest module mocker implementation",

@@ -75,3 +75,3 @@ "license": "MIT",

"magic-string": "^0.30.21",
"@vitest/spy": "4.1.0-beta.3"
"@vitest/spy": "4.1.0-beta.4"
},

@@ -86,4 +86,4 @@ "devDependencies": {

"vite": "^6.3.5",
"@vitest/spy": "4.1.0-beta.3",
"@vitest/utils": "4.1.0-beta.3"
"@vitest/spy": "4.1.0-beta.4",
"@vitest/utils": "4.1.0-beta.4"
},

@@ -90,0 +90,0 @@ "scripts": {

Sorry, the diff of this file is too big to display