Socket
Socket
Sign inDemoInstall

@vitest/utils

Package Overview
Dependencies
10
Maintainers
4
Versions
79
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

75

dist/ast.js

@@ -17,4 +17,5 @@ import { walk } from 'estree-walker';

let scopeIds = scopeMap.get(node);
if (scopeIds && scopeIds.has(name))
if (scopeIds && scopeIds.has(name)) {
return;
}
if (!scopeIds) {

@@ -39,11 +40,13 @@ scopeIds = /* @__PURE__ */ new Set();

p.properties.forEach((property) => {
if (property.type === "RestElement")
if (property.type === "RestElement") {
setScope(parentScope, property.argument.name);
else
} else {
handlePattern(property.value, parentScope);
}
});
} else if (p.type === "ArrayPattern") {
p.elements.forEach((element) => {
if (element)
if (element) {
handlePattern(element, parentScope);
}
});

@@ -58,15 +61,19 @@ } else if (p.type === "AssignmentPattern") {

enter(node, parent) {
if (node.type === "ImportDeclaration")
if (node.type === "ImportDeclaration") {
return this.skip();
}
if (parent && !(parent.type === "IfStatement" && node === parent.alternate)) {
parentStack.unshift(parent);
}
if (node.type === "VariableDeclaration")
if (node.type === "VariableDeclaration") {
varKindStack.unshift(node.kind);
if (node.type === "CallExpression")
}
if (node.type === "CallExpression") {
onCallExpression == null ? void 0 : onCallExpression(node);
if (node.type === "MetaProperty" && node.meta.name === "import")
}
if (node.type === "MetaProperty" && node.meta.name === "import") {
onImportMeta == null ? void 0 : onImportMeta(node);
else if (node.type === "ImportExpression")
} else if (node.type === "ImportExpression") {
onDynamicImport == null ? void 0 : onDynamicImport(node);
}
if (node.type === "Identifier") {

@@ -79,4 +86,5 @@ if (!isInScope(node.name, parentStack) && isRefIdentifier(node, parent, parentStack)) {

const parentScope = findParentScope(parentStack);
if (parentScope)
if (parentScope) {
setScope(parentScope, node.id.name);
}
}

@@ -93,6 +101,8 @@ node.params.forEach((p) => {

}
if (child.type !== "Identifier")
if (child.type !== "Identifier") {
return;
if (isStaticPropertyKey(child, parent2))
}
if (isStaticPropertyKey(child, parent2)) {
return;
}
if ((parent2 == null ? void 0 : parent2.type) === "TemplateLiteral" && (parent2 == null ? void 0 : parent2.expressions.includes(child)) || (parent2 == null ? void 0 : parent2.type) === "CallExpression" && (parent2 == null ? void 0 : parent2.callee) === child) {

@@ -112,4 +122,5 @@ return;

);
if (parentFunction)
if (parentFunction) {
handlePattern(node.id, parentFunction);
}
} else if (node.type === "CatchClause" && node.param) {

@@ -123,4 +134,5 @@ handlePattern(node.param, node);

}
if (node.type === "VariableDeclaration")
if (node.type === "VariableDeclaration") {
varKindStack.shift();
}
}

@@ -135,7 +147,11 @@ });

const classExpression = parent.type === "ClassExpression" && node === parent.id;
onIdentifier == null ? void 0 : onIdentifier(node, {
hasBindingShortcut,
classDeclaration,
classExpression
}, stack);
onIdentifier == null ? void 0 : onIdentifier(
node,
{
hasBindingShortcut,
classDeclaration,
classExpression
},
stack
);
}

@@ -149,13 +165,18 @@ });

if (isFunctionNode(parent)) {
if (parent.id === id)
if (parent.id === id) {
return false;
if (parent.params.includes(id))
}
if (parent.params.includes(id)) {
return false;
}
}
if (parent.type === "MethodDefinition" && !parent.computed)
if (parent.type === "MethodDefinition" && !parent.computed) {
return false;
if (isStaticPropertyKey(id, parent))
}
if (isStaticPropertyKey(id, parent)) {
return false;
if (isNodeInPattern(parent) && parent.value === id)
}
if (isNodeInPattern(parent) && parent.value === id) {
return false;
}
if (parent.type === "ArrayPattern" && !isInDestructuringAssignment(parent, parentStack)) {

@@ -167,6 +188,8 @@ return false;

}
if (parent.type === "ExportSpecifier")
if (parent.type === "ExportSpecifier") {
return false;
if (id.name === "arguments")
}
if (id.name === "arguments") {
return false;
}
return true;

@@ -173,0 +196,0 @@ }

@@ -36,6 +36,9 @@ const SAFE_TIMERS_SYMBOL = Symbol("vitest:SAFE_TIMERS");

string.close = "";
const defaultColors = /* @__PURE__ */ colorsEntries.reduce((acc, [key]) => {
acc[key] = string;
return acc;
}, { isColorSupported: false });
const defaultColors = /* @__PURE__ */ colorsEntries.reduce(
(acc, [key]) => {
acc[key] = string;
return acc;
},
{ isColorSupported: false }
);
function getDefaultColors() {

@@ -42,0 +45,0 @@ return { ...defaultColors };

@@ -48,4 +48,5 @@ import { format as format$1, plugins } from 'pretty-format';

const objects = [];
for (let i2 = 0; i2 < args.length; i2++)
for (let i2 = 0; i2 < args.length; i2++) {
objects.push(inspect(args[i2], { depth: 0, colors: false }));
}
return objects.join(" ");

@@ -57,15 +58,20 @@ }

let str = String(template).replace(formatRegExp, (x) => {
if (x === "%%")
if (x === "%%") {
return "%";
if (i >= len)
}
if (i >= len) {
return x;
}
switch (x) {
case "%s": {
const value = args[i++];
if (typeof value === "bigint")
if (typeof value === "bigint") {
return `${value.toString()}n`;
if (typeof value === "number" && value === 0 && 1 / value < 0)
}
if (typeof value === "number" && value === 0 && 1 / value < 0) {
return "-0";
if (typeof value === "object" && value !== null)
}
if (typeof value === "object" && value !== null) {
return inspect(value, { depth: 0, colors: false });
}
return String(value);

@@ -75,4 +81,5 @@ }

const value = args[i++];
if (typeof value === "bigint")
if (typeof value === "bigint") {
return `${value.toString()}n`;
}
return Number(value).toString();

@@ -82,4 +89,5 @@ }

const value = args[i++];
if (typeof value === "bigint")
if (typeof value === "bigint") {
return `${value.toString()}n`;
}
return Number.parseInt(String(value)).toString();

@@ -115,6 +123,7 @@ }

for (let x = args[i]; i < len; x = args[++i]) {
if (x === null || typeof x !== "object")
if (x === null || typeof x !== "object") {
str += ` ${x}`;
else
} else {
str += ` ${inspect(x)}`;
}
}

@@ -124,9 +133,11 @@ return str;

function inspect(obj, options = {}) {
if (options.truncate === 0)
if (options.truncate === 0) {
options.truncate = Number.POSITIVE_INFINITY;
}
return loupe.inspect(obj, options);
}
function objDisplay(obj, options = {}) {
if (typeof options.truncate === "undefined")
if (typeof options.truncate === "undefined") {
options.truncate = 40;
}
const str = inspect(obj, options);

@@ -133,0 +144,0 @@ const type = Object.prototype.toString.call(obj);

@@ -24,10 +24,11 @@ import { format, plugins } from 'pretty-format';

if (value != null) {
if (value.constructor === RegExp)
if (value.constructor === RegExp) {
return "regexp";
else if (value.constructor === Map)
} else if (value.constructor === Map) {
return "map";
else if (value.constructor === Set)
} else if (value.constructor === Set) {
return "set";
else if (value.constructor === Date)
} else if (value.constructor === Date) {
return "date";
}
}

@@ -53,4 +54,5 @@ return "object";

const diff_commonPrefix = function(text1, text2) {
if (!text1 || !text2 || text1.charAt(0) !== text2.charAt(0))
if (!text1 || !text2 || text1.charAt(0) !== text2.charAt(0)) {
return 0;
}
let pointermin = 0;

@@ -93,11 +95,14 @@ let pointermax = Math.min(text1.length, text2.length);

const text2_length = text2.length;
if (text1_length === 0 || text2_length === 0)
if (text1_length === 0 || text2_length === 0) {
return 0;
if (text1_length > text2_length)
}
if (text1_length > text2_length) {
text1 = text1.substring(text1_length - text2_length);
else if (text1_length < text2_length)
} else if (text1_length < text2_length) {
text2 = text2.substring(0, text1_length);
}
const text_length = Math.min(text1_length, text2_length);
if (text1 === text2)
if (text1 === text2) {
return text_length;
}
let best = 0;

@@ -108,4 +113,5 @@ let length = 1;

const found = text2.indexOf(pattern);
if (found === -1)
if (found === -1) {
return best;
}
length += found;

@@ -137,8 +143,13 @@ if (found === 0 || text1.substring(text_length - length) === text2.substring(0, length)) {

} else {
if (diffs[pointer][0] === DIFF_INSERT)
if (diffs[pointer][0] === DIFF_INSERT) {
length_insertions2 += diffs[pointer][1].length;
else
} else {
length_deletions2 += diffs[pointer][1].length;
}
if (lastEquality && lastEquality.length <= Math.max(length_insertions1, length_deletions1) && lastEquality.length <= Math.max(length_insertions2, length_deletions2)) {
diffs.splice(equalities[equalitiesLength - 1], 0, new Diff(DIFF_DELETE, lastEquality));
diffs.splice(
equalities[equalitiesLength - 1],
0,
new Diff(DIFF_DELETE, lastEquality)
);
diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT;

@@ -158,4 +169,5 @@ equalitiesLength--;

}
if (changes)
if (changes) {
diff_cleanupMerge(diffs);
}
diff_cleanupSemanticLossless(diffs);

@@ -171,4 +183,11 @@ pointer = 1;

if (overlap_length1 >= deletion.length / 2 || overlap_length1 >= insertion.length / 2) {
diffs.splice(pointer, 0, new Diff(DIFF_EQUAL, insertion.substring(0, overlap_length1)));
diffs[pointer - 1][1] = deletion.substring(0, deletion.length - overlap_length1);
diffs.splice(
pointer,
0,
new Diff(DIFF_EQUAL, insertion.substring(0, overlap_length1))
);
diffs[pointer - 1][1] = deletion.substring(
0,
deletion.length - overlap_length1
);
diffs[pointer + 1][1] = insertion.substring(overlap_length1);

@@ -179,5 +198,12 @@ pointer++;

if (overlap_length2 >= deletion.length / 2 || overlap_length2 >= insertion.length / 2) {
diffs.splice(pointer, 0, new Diff(DIFF_EQUAL, deletion.substring(0, overlap_length2)));
diffs.splice(
pointer,
0,
new Diff(DIFF_EQUAL, deletion.substring(0, overlap_length2))
);
diffs[pointer - 1][0] = DIFF_INSERT;
diffs[pointer - 1][1] = insertion.substring(0, insertion.length - overlap_length2);
diffs[pointer - 1][1] = insertion.substring(
0,
insertion.length - overlap_length2
);
diffs[pointer + 1][0] = DIFF_DELETE;

@@ -302,3 +328,7 @@ diffs[pointer + 1][1] = deletion.substring(overlap_length2);

} else {
diffs.splice(0, 0, new Diff(DIFF_EQUAL, text_insert.substring(0, commonlength)));
diffs.splice(
0,
0,
new Diff(DIFF_EQUAL, text_insert.substring(0, commonlength))
);
pointer++;

@@ -312,4 +342,10 @@ }

diffs[pointer][1] = text_insert.substring(text_insert.length - commonlength) + diffs[pointer][1];
text_insert = text_insert.substring(0, text_insert.length - commonlength);
text_delete = text_delete.substring(0, text_delete.length - commonlength);
text_insert = text_insert.substring(
0,
text_insert.length - commonlength
);
text_delete = text_delete.substring(
0,
text_delete.length - commonlength
);
}

@@ -341,4 +377,5 @@ }

}
if (diffs[diffs.length - 1][1] === "")
if (diffs[diffs.length - 1][1] === "") {
diffs.pop();
}
let changes = false;

@@ -348,4 +385,9 @@ pointer = 1;

if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
if (diffs[pointer][1].substring(diffs[pointer][1].length - diffs[pointer - 1][1].length) === diffs[pointer - 1][1]) {
diffs[pointer][1] = diffs[pointer - 1][1] + diffs[pointer][1].substring(0, diffs[pointer][1].length - diffs[pointer - 1][1].length);
if (diffs[pointer][1].substring(
diffs[pointer][1].length - diffs[pointer - 1][1].length
) === diffs[pointer - 1][1]) {
diffs[pointer][1] = diffs[pointer - 1][1] + diffs[pointer][1].substring(
0,
diffs[pointer][1].length - diffs[pointer - 1][1].length
);
diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1];

@@ -363,4 +405,5 @@ diffs.splice(pointer - 1, 1);

}
if (changes)
if (changes) {
diff_cleanupMerge(diffs);
}
}

@@ -439,4 +482,5 @@

const iStart = i;
while (i !== iLength && diffs[i][0] === DIFF_EQUAL)
while (i !== iLength && diffs[i][0] === DIFF_EQUAL) {
i += 1;
}
if (iStart !== i) {

@@ -462,15 +506,18 @@ if (iStart === 0) {

}
while (i !== iLength && diffs[i][0] !== DIFF_EQUAL)
while (i !== iLength && diffs[i][0] !== DIFF_EQUAL) {
i += 1;
}
}
const hasPatch = nExcessesBetweenChanges !== 0 || hasExcessAtStartOrEnd;
if (nExcessesBetweenChanges !== 0)
if (nExcessesBetweenChanges !== 0) {
jLength += nExcessesBetweenChanges + 1;
else if (hasExcessAtStartOrEnd)
} else if (hasExcessAtStartOrEnd) {
jLength += 1;
}
const jLast = jLength - 1;
const lines = [];
let jPatchMark = 0;
if (hasPatch)
if (hasPatch) {
lines.push("");
}
let aStart = 0;

@@ -499,4 +546,5 @@ let bStart = 0;

let iStart = i;
while (i !== iLength && diffs[i][0] === DIFF_EQUAL)
while (i !== iLength && diffs[i][0] === DIFF_EQUAL) {
i += 1;
}
if (iStart !== i) {

@@ -511,8 +559,10 @@ if (iStart === 0) {

}
for (let iCommon = iStart; iCommon !== i; iCommon += 1)
for (let iCommon = iStart; iCommon !== i; iCommon += 1) {
pushCommonLine(diffs[iCommon][1]);
}
} else if (i === iLength) {
const iEnd = i - iStart > nContextLines ? iStart + nContextLines : i;
for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1)
for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1) {
pushCommonLine(diffs[iCommon][1]);
}
} else {

@@ -522,4 +572,5 @@ const nCommon = i - iStart;

const iEnd = iStart + nContextLines;
for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1)
for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1) {
pushCommonLine(diffs[iCommon][1]);
}
lines[jPatchMark] = createPatchMark(

@@ -539,7 +590,9 @@ aStart,

bEnd = bStart;
for (let iCommon = i - nContextLines; iCommon !== i; iCommon += 1)
for (let iCommon = i - nContextLines; iCommon !== i; iCommon += 1) {
pushCommonLine(diffs[iCommon][1]);
}
} else {
for (let iCommon = iStart; iCommon !== i; iCommon += 1)
for (let iCommon = iStart; iCommon !== i; iCommon += 1) {
pushCommonLine(diffs[iCommon][1]);
}
}

@@ -557,4 +610,5 @@ }

}
if (hasPatch)
if (hasPatch) {
lines[jPatchMark] = createPatchMark(aStart, aEnd, bStart, bEnd, options);
}
return lines.join("\n");

@@ -649,4 +703,5 @@ }

}, changeCounts) {
if (omitAnnotationLines)
if (omitAnnotationLines) {
return "";
}
let aRest = "";

@@ -684,7 +739,3 @@ let bRest = "";

);
return printDiffLines(
diffs,
truncated,
normalizedOptions
);
return printDiffLines(diffs, truncated, normalizedOptions);
}

@@ -703,3 +754,7 @@ function diffLinesUnified2(aLinesDisplay, bLinesDisplay, aLinesCompare, bLinesCompare, options) {

}
const [diffs, truncated] = diffLinesRaw(aLinesCompare, bLinesCompare, options);
const [diffs, truncated] = diffLinesRaw(
aLinesCompare,
bLinesCompare,
options
);
let aIndex = 0;

@@ -727,3 +782,6 @@ let bIndex = 0;

const truncate = (options == null ? void 0 : options.truncateThreshold) ?? false;
const truncateThreshold = Math.max(Math.floor((options == null ? void 0 : options.truncateThreshold) ?? 0), 0);
const truncateThreshold = Math.max(
Math.floor((options == null ? void 0 : options.truncateThreshold) ?? 0),
0
);
const aLength = truncate ? Math.min(aLines.length, truncateThreshold) : aLines.length;

@@ -737,15 +795,20 @@ const bLength = truncate ? Math.min(bLines.length, truncateThreshold) : bLines.length;

const foundSubsequence = (nCommon, aCommon, bCommon) => {
for (; aIndex !== aCommon; aIndex += 1)
for (; aIndex !== aCommon; aIndex += 1) {
diffs.push(new Diff(DIFF_DELETE, aLines[aIndex]));
for (; bIndex !== bCommon; bIndex += 1)
}
for (; bIndex !== bCommon; bIndex += 1) {
diffs.push(new Diff(DIFF_INSERT, bLines[bIndex]));
for (; nCommon !== 0; nCommon -= 1, aIndex += 1, bIndex += 1)
}
for (; nCommon !== 0; nCommon -= 1, aIndex += 1, bIndex += 1) {
diffs.push(new Diff(DIFF_EQUAL, bLines[bIndex]));
}
};
const diffSequences = diff$1.default.default || diff$1.default;
diffSequences(aLength, bLength, isCommon, foundSubsequence);
for (; aIndex !== aLength; aIndex += 1)
for (; aIndex !== aLength; aIndex += 1) {
diffs.push(new Diff(DIFF_DELETE, aLines[aIndex]));
for (; bIndex !== bLength; bIndex += 1)
}
for (; bIndex !== bLength; bIndex += 1) {
diffs.push(new Diff(DIFF_INSERT, bLines[bIndex]));
}
return [diffs, truncated];

@@ -759,3 +822,6 @@ }

const truncate = (options == null ? void 0 : options.truncateThreshold) ?? false;
const truncateThreshold = Math.max(Math.floor((options == null ? void 0 : options.truncateThreshold) ?? 0), 0);
const truncateThreshold = Math.max(
Math.floor((options == null ? void 0 : options.truncateThreshold) ?? 0),
0
);
let aLength = a.length;

@@ -781,6 +847,8 @@ let bLength = b.length;

const foundSubsequence = (nCommon, aCommon, bCommon) => {
if (aIndex !== aCommon)
if (aIndex !== aCommon) {
diffs.push(new Diff(DIFF_DELETE, a.slice(aIndex, aCommon)));
if (bIndex !== bCommon)
}
if (bIndex !== bCommon) {
diffs.push(new Diff(DIFF_INSERT, b.slice(bIndex, bCommon)));
}
aIndex = aCommon + nCommon;

@@ -792,6 +860,8 @@ bIndex = bCommon + nCommon;

diffSequences(aLength, bLength, isCommon, foundSubsequence);
if (aIndex !== aLength)
if (aIndex !== aLength) {
diffs.push(new Diff(DIFF_DELETE, a.slice(aIndex)));
if (bIndex !== bLength)
}
if (bIndex !== bLength) {
diffs.push(new Diff(DIFF_INSERT, b.slice(bIndex)));
}
return [diffs, truncated];

@@ -859,4 +929,5 @@ }

moveLinesTo(lines) {
if (!this.isLineEmpty())
if (!this.isLineEmpty()) {
this.pushLine();
}
lines.push(...this.lines);

@@ -880,6 +951,8 @@ this.lines.length = 0;

const isDiffEmpty = diff[1].length === 0;
if (!isDiffEmpty || this.deleteBuffer.isLineEmpty())
if (!isDiffEmpty || this.deleteBuffer.isLineEmpty()) {
this.deleteBuffer.pushDiff(diff);
if (!isDiffEmpty || this.insertBuffer.isLineEmpty())
}
if (!isDiffEmpty || this.insertBuffer.isLineEmpty()) {
this.insertBuffer.pushDiff(diff);
}
}

@@ -973,4 +1046,5 @@ flushChangeLines() {

const [diffs, truncated] = diffStrings(a, b, options);
if (cleanup)
if (cleanup) {
diff_cleanupSemantic(diffs);
}
return [diffs, truncated];

@@ -1008,4 +1082,5 @@ }

function diff(a, b, options) {
if (Object.is(a, b))
if (Object.is(a, b)) {
return "";
}
const aType = getType(a);

@@ -1037,4 +1112,5 @@ let expectedType = aType;

}
if (omitDifference)
if (omitDifference) {
return null;
}
switch (aType) {

@@ -1041,0 +1117,0 @@ case "string":

@@ -16,29 +16,41 @@ import { diff } from './diff.js';

function getUnserializableMessage(err) {
if (err instanceof Error)
if (err instanceof Error) {
return `<unserializable>: ${err.message}`;
if (typeof err === "string")
}
if (typeof err === "string") {
return `<unserializable>: ${err}`;
}
return "<unserializable>";
}
function serializeError(val, seen = /* @__PURE__ */ new WeakMap()) {
if (!val || typeof val === "string")
if (!val || typeof val === "string") {
return val;
if (typeof val === "function")
}
if (typeof val === "function") {
return `Function<${val.name || "anonymous"}>`;
if (typeof val === "symbol")
}
if (typeof val === "symbol") {
return val.toString();
if (typeof val !== "object")
}
if (typeof val !== "object") {
return val;
if (isImmutable(val))
}
if (isImmutable(val)) {
return serializeError(val.toJSON(), seen);
if (val instanceof Promise || val.constructor && val.constructor.prototype === "AsyncFunction")
}
if (val instanceof Promise || val.constructor && val.constructor.prototype === "AsyncFunction") {
return "Promise";
if (typeof Element !== "undefined" && val instanceof Element)
}
if (typeof Element !== "undefined" && val instanceof Element) {
return val.tagName;
if (typeof val.asymmetricMatch === "function")
}
if (typeof val.asymmetricMatch === "function") {
return `${val.toString()} ${format(val.sample)}`;
if (typeof val.toJSON === "function")
return val.toJSON();
if (seen.has(val))
}
if (typeof val.toJSON === "function") {
return serializeError(val.toJSON(), seen);
}
if (seen.has(val)) {
return seen.get(val);
}
if (Array.isArray(val)) {

@@ -61,4 +73,5 @@ const clone = new Array(val.length);

Object.getOwnPropertyNames(obj).forEach((key) => {
if (key in clone)
if (key in clone) {
return;
}
try {

@@ -80,21 +93,33 @@ clone[key] = serializeError(val[key], seen);

function processError(err, diffOptions, seen = /* @__PURE__ */ new WeakSet()) {
if (!err || typeof err !== "object")
if (!err || typeof err !== "object") {
return { message: err };
if (err.stack)
}
if (err.stack) {
err.stackStr = String(err.stack);
if (err.name)
}
if (err.name) {
err.nameStr = String(err.name);
}
if (err.showDiff || err.showDiff === void 0 && err.expected !== void 0 && err.actual !== void 0) {
const clonedActual = deepClone(err.actual, { forceWritable: true });
const clonedExpected = deepClone(err.expected, { forceWritable: true });
const { replacedActual, replacedExpected } = replaceAsymmetricMatcher(clonedActual, clonedExpected);
err.diff = diff(replacedExpected, replacedActual, { ...diffOptions, ...err.diffOptions });
const { replacedActual, replacedExpected } = replaceAsymmetricMatcher(
clonedActual,
clonedExpected
);
err.diff = diff(replacedExpected, replacedActual, {
...diffOptions,
...err.diffOptions
});
}
if (typeof err.expected !== "string")
if (typeof err.expected !== "string") {
err.expected = stringify(err.expected, 10);
if (typeof err.actual !== "string")
}
if (typeof err.actual !== "string") {
err.actual = stringify(err.actual, 10);
}
try {
if (typeof err.message === "string")
if (typeof err.message === "string") {
err.message = normalizeErrorMessage(err.message);
}
} catch {

@@ -112,4 +137,8 @@ }

} catch (e) {
return serializeError(new Error(`Failed to fully serialize error: ${e == null ? void 0 : e.message}
Inner error message: ${err == null ? void 0 : err.message}`));
return serializeError(
new Error(
`Failed to fully serialize error: ${e == null ? void 0 : e.message}
Inner error message: ${err == null ? void 0 : err.message}`
)
);
}

@@ -127,6 +156,8 @@ }

function replaceAsymmetricMatcher(actual, expected, actualReplaced = /* @__PURE__ */ new WeakSet(), expectedReplaced = /* @__PURE__ */ new WeakSet()) {
if (!isReplaceable(actual, expected))
if (!isReplaceable(actual, expected)) {
return { replacedActual: actual, replacedExpected: expected };
if (actualReplaced.has(actual) || expectedReplaced.has(expected))
}
if (actualReplaced.has(actual) || expectedReplaced.has(expected)) {
return { replacedActual: actual, replacedExpected: expected };
}
actualReplaced.add(actual);

@@ -138,7 +169,9 @@ expectedReplaced.add(expected);

if (isAsymmetricMatcher(expectedValue)) {
if (expectedValue.asymmetricMatch(actualValue))
if (expectedValue.asymmetricMatch(actualValue)) {
actual[key] = expectedValue;
}
} else if (isAsymmetricMatcher(actualValue)) {
if (actualValue.asymmetricMatch(expectedValue))
if (actualValue.asymmetricMatch(expectedValue)) {
expected[key] = actualValue;
}
} else if (isReplaceable(actualValue, expectedValue)) {

@@ -145,0 +178,0 @@ const replaced = replaceAsymmetricMatcher(

@@ -7,4 +7,7 @@ function notNullish(v) {

const pass = types.includes(receivedType);
if (!pass)
throw new TypeError(`${name} value must be ${types.join(" or ")}, received "${receivedType}"`);
if (!pass) {
throw new TypeError(
`${name} value must be ${types.join(" or ")}, received "${receivedType}"`
);
}
}

@@ -19,13 +22,17 @@ function isPrimitive(value) {

const m = input.match(/(\/?)(.+)\1([a-z]*)/i);
if (!m)
if (!m) {
return /$^/;
if (m[3] && !/^(?!.*?(.).*?\1)[gmixXsuUAJ]+$/.test(m[3]))
}
if (m[3] && !/^(?!.*?(.).*?\1)[gmixXsuUAJ]+$/.test(m[3])) {
return RegExp(input);
}
return new RegExp(m[2], m[3]);
}
function toArray(array) {
if (array === null || array === void 0)
if (array === null || array === void 0) {
array = [];
if (Array.isArray(array))
}
if (Array.isArray(array)) {
return array;
}
return [array];

@@ -49,4 +56,5 @@ }

const ownProps = /* @__PURE__ */ new Set();
if (isFinalObj(obj))
if (isFinalObj(obj)) {
return [];
}
collectOwnProperties(obj, ownProps);

@@ -62,8 +70,11 @@ return Array.from(ownProps);

let k, out;
if (seen.has(val))
if (seen.has(val)) {
return seen.get(val);
}
if (Array.isArray(val)) {
out = Array(k = val.length);
seen.set(val, out);
while (k--) out[k] = clone(val[k], seen, options);
while (k--) {
out[k] = clone(val[k], seen, options);
}
return out;

@@ -77,4 +88,5 @@ }

const descriptor = Object.getOwnPropertyDescriptor(val, k2);
if (!descriptor)
if (!descriptor) {
continue;
}
const cloned = clone(val[k2], seen, options);

@@ -113,4 +125,5 @@ if (options.forceWritable) {

result = Object(result)[p];
if (result === void 0)
if (result === void 0) {
return defaultValue;
}
}

@@ -142,15 +155,19 @@ return result;

if (isCharString && beforeChar !== "\\") {
if (inString === char)
if (inString === char) {
inString = null;
else if (!inString)
} else if (!inString) {
inString = char;
}
}
if (!inString) {
if (char === "(")
if (char === "(") {
startedBracers++;
if (char === ")")
}
if (char === ")") {
endedBracers++;
}
}
if (startedBracers && endedBracers && startedBracers === endedBracers)
if (startedBracers && endedBracers && startedBracers === endedBracers) {
return charIndex;
}
}

@@ -160,4 +177,5 @@ return null;

function isNegativeNaN(val) {
if (!Number.isNaN(val))
if (!Number.isNaN(val)) {
return false;
}
const f64 = new Float64Array(1);

@@ -164,0 +182,0 @@ f64[0] = val;

@@ -17,5 +17,3 @@ export { assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';

} = globalThis[SAFE_TIMERS_SYMBOL] || globalThis;
const {
nextTick: safeNextTick
} = globalThis[SAFE_TIMERS_SYMBOL] || globalThis.process || { nextTick: (cb) => cb() };
const { nextTick: safeNextTick } = globalThis[SAFE_TIMERS_SYMBOL] || globalThis.process || { nextTick: (cb) => cb() };
return {

@@ -40,5 +38,5 @@ nextTick: safeNextTick,

} = globalThis;
const {
nextTick: safeNextTick
} = globalThis.process || { nextTick: (cb) => cb() };
const { nextTick: safeNextTick } = globalThis.process || {
nextTick: (cb) => cb()
};
const timers = {

@@ -91,6 +89,8 @@ nextTick: safeNextTick,

let start = 0;
if (lineNumber > lines.length)
if (lineNumber > lines.length) {
return source.length;
for (let i = 0; i < lineNumber - 1; i++)
}
for (let i = 0; i < lineNumber - 1; i++) {
start += lines[i].length + nl;
}
return start + columnNumber;

@@ -110,4 +110,5 @@ }

const lineLength = lines[line].length + nl;
if (counted + lineLength >= offset)
if (counted + lineLength >= offset) {
break;
}
counted += lineLength;

@@ -114,0 +115,0 @@ }

@@ -777,5 +777,3 @@ import { notNullish, isPrimitive } from './helpers.js';

// browser related deps
"/deps/chai.js",
"/deps/vitest___chai.js",
"/deps/p-limit.js",
"/deps/",
/node:\w+/,

@@ -787,11 +785,14 @@ /__vitest_test__/,

function extractLocation(urlLike) {
if (!urlLike.includes(":"))
if (!urlLike.includes(":")) {
return [urlLike];
}
const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
const parts = regExp.exec(urlLike.replace(/^\(|\)$/g, ""));
if (!parts)
if (!parts) {
return [urlLike];
}
let url = parts[1];
if (url.startsWith("async "))
if (url.startsWith("async ")) {
url = url.slice(6);
}
if (url.startsWith("http:") || url.startsWith("https:")) {

@@ -809,14 +810,23 @@ const urlObj = new URL(url);

let line = raw.trim();
if (SAFARI_NATIVE_CODE_REGEXP.test(line))
if (SAFARI_NATIVE_CODE_REGEXP.test(line)) {
return null;
if (line.includes(" > eval"))
line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g, ":$1");
if (!line.includes("@") && !line.includes(":"))
}
if (line.includes(" > eval")) {
line = line.replace(
/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,
":$1"
);
}
if (!line.includes("@") && !line.includes(":")) {
return null;
}
const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(@)/;
const matches = line.match(functionNameRegex);
const functionName = matches && matches[1] ? matches[1] : void 0;
const [url, lineNumber, columnNumber] = extractLocation(line.replace(functionNameRegex, ""));
if (!url || !lineNumber || !columnNumber)
const [url, lineNumber, columnNumber] = extractLocation(
line.replace(functionNameRegex, "")
);
if (!url || !lineNumber || !columnNumber) {
return null;
}
return {

@@ -831,4 +841,5 @@ file: url,

const line = raw.trim();
if (!CHROME_IE_STACK_REGEXP.test(line))
if (!CHROME_IE_STACK_REGEXP.test(line)) {
return parseSingleFFOrSafariStack(line);
}
return parseSingleV8Stack(line);

@@ -838,21 +849,29 @@ }

let line = raw.trim();
if (!CHROME_IE_STACK_REGEXP.test(line))
if (!CHROME_IE_STACK_REGEXP.test(line)) {
return null;
if (line.includes("(eval "))
}
if (line.includes("(eval ")) {
line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
}
let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
const location = sanitizedLine.match(/ (\(.+\)$)/);
sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
const [url, lineNumber, columnNumber] = extractLocation(location ? location[1] : sanitizedLine);
const [url, lineNumber, columnNumber] = extractLocation(
location ? location[1] : sanitizedLine
);
let method = location && sanitizedLine || "";
let file = url && ["eval", "<anonymous>"].includes(url) ? void 0 : url;
if (!file || !lineNumber || !columnNumber)
if (!file || !lineNumber || !columnNumber) {
return null;
if (method.startsWith("async "))
}
if (method.startsWith("async ")) {
method = method.slice(6);
if (file.startsWith("file://"))
}
if (file.startsWith("file://")) {
file = file.slice(7);
}
file = resolve$2(file);
if (method)
if (method) {
method = method.replace(/__vite_ssr_import_\d+__\./g, "");
}
return {

@@ -868,13 +887,18 @@ method,

let stacks = !CHROME_IE_STACK_REGEXP.test(stack) ? parseFFOrSafariStackTrace(stack) : parseV8Stacktrace(stack);
if (ignoreStackEntries.length)
stacks = stacks.filter((stack2) => !ignoreStackEntries.some((p) => stack2.file.match(p)));
if (ignoreStackEntries.length) {
stacks = stacks.filter(
(stack2) => !ignoreStackEntries.some((p) => stack2.file.match(p))
);
}
return stacks.map((stack2) => {
var _a;
const map = (_a = options.getSourceMap) == null ? void 0 : _a.call(options, stack2.file);
if (!map || typeof map !== "object" || !map.version)
if (!map || typeof map !== "object" || !map.version) {
return stack2;
}
const traceMap = new TraceMap(map);
const { line, column } = originalPositionFor(traceMap, stack2);
if (line != null && column != null)
if (line != null && column != null) {
return { ...stack2, line, column };
}
return stack2;

@@ -890,10 +914,15 @@ });

function parseErrorStacktrace(e, options = {}) {
if (!e || isPrimitive(e))
if (!e || isPrimitive(e)) {
return [];
if (e.stacks)
}
if (e.stacks) {
return e.stacks;
}
const stackStr = e.stack || e.stackStr || "";
let stackFrames = parseStacktrace(stackStr, options);
if (options.frameFilter)
stackFrames = stackFrames.filter((f) => options.frameFilter(e, f) !== false);
if (options.frameFilter) {
stackFrames = stackFrames.filter(
(f) => options.frameFilter(e, f) !== false
);
}
e.stacks = stackFrames;

@@ -900,0 +929,0 @@ return stackFrames;

{
"name": "@vitest/utils",
"type": "module",
"version": "2.0.0-beta.10",
"version": "2.0.0-beta.11",
"description": "Shared Vitest utility functions",

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

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc