Socket
Socket
Sign inDemoInstall

@vitest/utils

Package Overview
Dependencies
Maintainers
4
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vitest/utils - npm Package Compare versions

Comparing version 2.0.4 to 2.0.5

11

dist/diff.d.ts

@@ -91,4 +91,11 @@ import { D as DiffOptions } from './types-Bxe-2Udy.js';

*/
declare function diff(a: any, b: any, options?: DiffOptions): string | null;
declare function diff(a: any, b: any, options?: DiffOptions): string | undefined;
declare function printDiffOrStringify(expected: unknown, received: unknown, options?: DiffOptions): string | undefined;
declare function replaceAsymmetricMatcher(actual: any, expected: any, actualReplaced?: WeakSet<WeakKey>, expectedReplaced?: WeakSet<WeakKey>): {
replacedActual: any;
replacedExpected: any;
};
type PrintLabel = (string: string) => string;
declare function getLabelPrinter(...strings: Array<string>): PrintLabel;
export { DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, Diff, DiffOptions, diff, diffLinesRaw, diffLinesUnified, diffLinesUnified2, diffStringsRaw, diffStringsUnified };
export { DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, Diff, DiffOptions, diff, diffLinesRaw, diffLinesUnified, diffLinesUnified2, diffStringsRaw, diffStringsUnified, getLabelPrinter, printDiffOrStringify, replaceAsymmetricMatcher };

11

dist/error.d.ts
import { D as DiffOptions } from './types-Bxe-2Udy.js';
import '@vitest/pretty-format';
declare function serializeError(val: any, seen?: WeakMap<WeakKey, any>): any;
declare function processError(err: any, diffOptions?: DiffOptions, seen?: WeakSet<WeakKey>): any;
declare function replaceAsymmetricMatcher(actual: any, expected: any, actualReplaced?: WeakSet<WeakKey>, expectedReplaced?: WeakSet<WeakKey>): {
replacedActual: any;
replacedExpected: any;
};
declare function serializeValue(val: any, seen?: WeakMap<WeakKey, any>): any;
export { processError, replaceAsymmetricMatcher, serializeError };
declare function processError(_err: any, diffOptions?: DiffOptions, seen?: WeakSet<WeakKey>): any;
export { processError, serializeValue as serializeError, serializeValue };

@@ -1,6 +0,6 @@

import { diff } from './diff.js';
import { printDiffOrStringify } from './diff.js';
import { f as format, s as stringify } from './chunk-display.js';
import { deepClone, getOwnProperties, getType } from './helpers.js';
import '@vitest/pretty-format';
import 'tinyrainbow';
import './helpers.js';
import 'loupe';

@@ -23,3 +23,3 @@

}
function serializeError(val, seen = /* @__PURE__ */ new WeakMap()) {
function serializeValue(val, seen = /* @__PURE__ */ new WeakMap()) {
if (!val || typeof val === "string") {

@@ -38,3 +38,3 @@ return val;

if (isImmutable(val)) {
return serializeError(val.toJSON(), seen);
return serializeValue(val.toJSON(), seen);
}

@@ -51,3 +51,3 @@ if (val instanceof Promise || val.constructor && val.constructor.prototype === "AsyncFunction") {

if (typeof val.toJSON === "function") {
return serializeError(val.toJSON(), seen);
return serializeValue(val.toJSON(), seen);
}

@@ -62,3 +62,3 @@ if (seen.has(val)) {

try {
clone[i] = serializeError(e, seen);
clone[i] = serializeValue(e, seen);
} catch (err) {

@@ -79,3 +79,3 @@ clone[i] = getUnserializableMessage(err);

try {
clone[key] = serializeError(val[key], seen);
clone[key] = serializeValue(val[key], seen);
} catch (err) {

@@ -94,6 +94,7 @@ delete clone[key];

}
function processError(err, diffOptions, seen = /* @__PURE__ */ new WeakSet()) {
if (!err || typeof err !== "object") {
return { message: err };
function processError(_err, diffOptions, seen = /* @__PURE__ */ new WeakSet()) {
if (!_err || typeof _err !== "object") {
return { message: String(_err) };
}
const err = _err;
if (err.stack) {

@@ -106,9 +107,3 @@ err.stackStr = String(err.stack);

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, {
err.diff = printDiffOrStringify(err.actual, err.expected, {
...diffOptions,

@@ -138,5 +133,5 @@ ...err.diffOptions

try {
return serializeError(err);
return serializeValue(err);
} catch (e) {
return serializeError(
return serializeValue(
new Error(

@@ -149,48 +144,3 @@ `Failed to fully serialize error: ${e == null ? void 0 : e.message}

}
function isAsymmetricMatcher(data) {
const type = getType(data);
return type === "Object" && typeof data.asymmetricMatch === "function";
}
function isReplaceable(obj1, obj2) {
const obj1Type = getType(obj1);
const obj2Type = getType(obj2);
return obj1Type === obj2Type && (obj1Type === "Object" || obj1Type === "Array");
}
function replaceAsymmetricMatcher(actual, expected, actualReplaced = /* @__PURE__ */ new WeakSet(), expectedReplaced = /* @__PURE__ */ new WeakSet()) {
if (!isReplaceable(actual, expected)) {
return { replacedActual: actual, replacedExpected: expected };
}
if (actualReplaced.has(actual) || expectedReplaced.has(expected)) {
return { replacedActual: actual, replacedExpected: expected };
}
actualReplaced.add(actual);
expectedReplaced.add(expected);
getOwnProperties(expected).forEach((key) => {
const expectedValue = expected[key];
const actualValue = actual[key];
if (isAsymmetricMatcher(expectedValue)) {
if (expectedValue.asymmetricMatch(actualValue)) {
actual[key] = expectedValue;
}
} else if (isAsymmetricMatcher(actualValue)) {
if (actualValue.asymmetricMatch(expectedValue)) {
expected[key] = actualValue;
}
} else if (isReplaceable(actualValue, expectedValue)) {
const replaced = replaceAsymmetricMatcher(
actualValue,
expectedValue,
actualReplaced,
expectedReplaced
);
actual[key] = replaced.replacedActual;
expected[key] = replaced.replacedExpected;
}
});
return {
replacedActual: actual,
replacedExpected: expected
};
}
export { processError, replaceAsymmetricMatcher, serializeError };
export { processError, serializeValue as serializeError, serializeValue };
export { DeferPromise, assertTypes, clone, createDefer, createSimpleStackTrace, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
import { PrettyFormatOptions } from '@vitest/pretty-format';
import { Colors } from 'tinyrainbow';
export { ArgumentsType, Arrayable, Awaitable, Constructable, DeepMerge, ErrorWithDiff, MergeInsertions, MutableArray, Nullable, ParsedStack } from './types.js';
export { ArgumentsType, Arrayable, Awaitable, Constructable, DeepMerge, ErrorWithDiff, MergeInsertions, MutableArray, Nullable, ParsedStack, SerializedError, TestError } from './types.js';

@@ -6,0 +6,0 @@ interface SafeTimers {

@@ -1,2 +0,2 @@

import { ParsedStack, ErrorWithDiff } from './types.js';
import { ErrorWithDiff, ParsedStack } from './types.js';

@@ -108,3 +108,3 @@ type GeneratedColumn = number;

getFileName?: (id: string) => string;
frameFilter?: (error: Error, frame: ParsedStack) => boolean | void;
frameFilter?: (error: ErrorWithDiff, frame: ParsedStack) => boolean | void;
}

@@ -111,0 +111,0 @@ declare function parseSingleFFOrSafariStack(raw: string): ParsedStack | null;

@@ -23,4 +23,23 @@ type Awaitable<T> = T | PromiseLike<T>;

}
interface ErrorWithDiff extends Error {
name: string;
interface SerializedError {
message: string;
stack?: string;
name?: string;
stacks?: ParsedStack[];
cause?: SerializedError;
[key: string]: unknown;
}
interface TestError extends SerializedError {
cause?: TestError;
diff?: string;
actual?: string;
expected?: string;
}
/**
* @deprecated Use `TestError` instead
*/
interface ErrorWithDiff {
message: string;
name?: string;
cause?: unknown;
nameStr?: string;

@@ -40,2 +59,2 @@ stack?: string;

export type { ArgumentsType, Arrayable, Awaitable, Constructable, DeepMerge, ErrorWithDiff, MergeInsertions, MutableArray, Nullable, ParsedStack };
export type { ArgumentsType, Arrayable, Awaitable, Constructable, DeepMerge, ErrorWithDiff, MergeInsertions, MutableArray, Nullable, ParsedStack, SerializedError, TestError };
{
"name": "@vitest/utils",
"type": "module",
"version": "2.0.4",
"version": "2.0.5",
"description": "Shared Vitest utility functions",

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

"tinyrainbow": "^1.2.0",
"@vitest/pretty-format": "2.0.4"
"@vitest/pretty-format": "2.0.5"
},

@@ -69,0 +69,0 @@ "devDependencies": {

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

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