Time slots app prototype
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

2595 lines
82 KiB

import util$1 from 'util';
import * as chai$2 from 'chai';
import { AssertionError, util, expect } from 'chai';
import { i as isObject$1, b as getCallLastIndex, s as slash, g as getWorkerState, c as getNames, d as getCurrentEnvironment, e as getFullName, o as objectAttr, n as noop, f as isRunningInTest, h as isRunningInBenchmark } from './chunk-mock-date.a1c85759.js';
import { c as commonjsGlobal } from './vendor-_commonjsHelpers.addc3445.js';
import c from 'picocolors';
import { c as createPatch, a as stringify, p as plugins_1, f as format_1, s as safeSetTimeout, b as safeClearTimeout } from './chunk-utils-timers.52534f96.js';
import { i as isMockFunction } from './vendor-index.723a074f.js';
import { c as cliTruncate, a as positionToOffset, o as offsetToLineNumber, l as lineSplitRE, b as parseStacktrace } from './chunk-utils-source-map.60562959.js';
import { r as rpc } from './chunk-runtime-rpc.7f83c8a9.js';
import fs from 'node:fs';
import { j as join, d as dirname } from './chunk-utils-env.b861e3a0.js';
import { promises } from 'fs';
function createChainable(keys, fn) {
function create(context) {
const chain2 = function(...args) {
return fn.apply(context, args);
};
Object.assign(chain2, fn);
chain2.withContext = () => chain2.bind(context);
for (const key of keys) {
Object.defineProperty(chain2, key, {
get() {
return create({ ...context, [key]: true });
}
});
}
return chain2;
}
const chain = create({});
chain.fn = fn;
return chain;
}
function commonjsRequire(path) {
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
}
var chaiSubset = {exports: {}};
(function (module, exports) {
(function() {
(function(chaiSubset) {
if (typeof commonjsRequire === 'function' && 'object' === 'object' && 'object' === 'object') {
return module.exports = chaiSubset;
} else {
return chai.use(chaiSubset);
}
})(function(chai, utils) {
var Assertion = chai.Assertion;
var assertionPrototype = Assertion.prototype;
Assertion.addMethod('containSubset', function (expected) {
var actual = utils.flag(this, 'object');
var showDiff = chai.config.showDiff;
assertionPrototype.assert.call(this,
compare(expected, actual),
'expected #{act} to contain subset #{exp}',
'expected #{act} to not contain subset #{exp}',
expected,
actual,
showDiff
);
});
chai.assert.containSubset = function(val, exp, msg) {
new chai.Assertion(val, msg).to.be.containSubset(exp);
};
function compare(expected, actual) {
if (expected === actual) {
return true;
}
if (typeof(actual) !== typeof(expected)) {
return false;
}
if (typeof(expected) !== 'object' || expected === null) {
return expected === actual;
}
if (!!expected && !actual) {
return false;
}
if (Array.isArray(expected)) {
if (typeof(actual.length) !== 'number') {
return false;
}
var aa = Array.prototype.slice.call(actual);
return expected.every(function (exp) {
return aa.some(function (act) {
return compare(exp, act);
});
});
}
if (expected instanceof Date) {
if (actual instanceof Date) {
return expected.getTime() === actual.getTime();
} else {
return false;
}
}
return Object.keys(expected).every(function (key) {
var eo = expected[key];
var ao = actual[key];
if (typeof(eo) === 'object' && eo !== null && ao !== null) {
return compare(eo, ao);
}
if (typeof(eo) === 'function') {
return eo(ao);
}
return ao === eo;
});
}
});
}).call(commonjsGlobal);
} (chaiSubset));
var Subset = chaiSubset.exports;
function formatLine(line, outputTruncateLength) {
var _a;
return cliTruncate(line, (outputTruncateLength ?? (((_a = process.stdout) == null ? void 0 : _a.columns) || 80)) - 4);
}
function unifiedDiff(actual, expected, options = {}) {
if (actual === expected)
return "";
const { outputTruncateLength, outputDiffLines, outputDiffMaxLines, noColor, showLegend = true } = options;
const indent = " ";
const diffLimit = outputDiffLines || 15;
const diffMaxLines = outputDiffMaxLines || 50;
const counts = {
"+": 0,
"-": 0
};
let previousState = null;
let previousCount = 0;
const str = (str2) => str2;
const dim = noColor ? str : c.dim;
const green = noColor ? str : c.green;
const red = noColor ? str : c.red;
function preprocess(line) {
if (!line || line.match(/\\ No newline/))
return;
const char = line[0];
if ("-+".includes(char)) {
if (previousState !== char) {
previousState = char;
previousCount = 0;
}
previousCount++;
counts[char]++;
if (previousCount === diffLimit)
return dim(`${char} ...`);
else if (previousCount > diffLimit)
return;
}
return line;
}
const msg = createPatch("string", expected, actual);
let lines = msg.split("\n").slice(5).map(preprocess).filter(Boolean);
let moreLines = 0;
const isCompact = counts["+"] === 1 && counts["-"] === 1 && lines.length === 2;
if (lines.length > diffMaxLines) {
const firstDiff = lines.findIndex((line) => line[0] === "-" || line[0] === "+");
const displayLines = lines.slice(firstDiff - 2, diffMaxLines);
const lastDisplayedIndex = firstDiff - 2 + diffMaxLines;
if (lastDisplayedIndex < lines.length)
moreLines = lines.length - lastDisplayedIndex;
lines = displayLines;
}
let formatted = lines.map((line) => {
line = line.replace(/\\"/g, '"');
if (line[0] === "-") {
line = formatLine(line.slice(1), outputTruncateLength);
if (isCompact)
return green(line);
return green(`- ${formatLine(line, outputTruncateLength)}`);
}
if (line[0] === "+") {
line = formatLine(line.slice(1), outputTruncateLength);
if (isCompact)
return red(line);
return red(`+ ${formatLine(line, outputTruncateLength)}`);
}
if (line.match(/@@/))
return "--";
return ` ${line}`;
});
if (moreLines)
formatted.push(dim(`... ${moreLines} more lines`));
if (showLegend) {
if (isCompact) {
formatted = [
`${green("- Expected")} ${formatted[0]}`,
`${red("+ Received")} ${formatted[1]}`
];
} else {
if (formatted[0].includes('"'))
formatted[0] = formatted[0].replace('"', "");
const last = formatted.length - 1;
if (formatted[last].endsWith('"'))
formatted[last] = formatted[last].slice(0, formatted[last].length - 1);
formatted.unshift(
green(`- Expected - ${counts["-"]}`),
red(`+ Received + ${counts["+"]}`),
""
);
}
}
return formatted.map((i) => i ? indent + i : i).join("\n");
}
function assertTypes(value, name, types) {
const receivedType = typeof value;
const pass = types.includes(receivedType);
if (!pass)
throw new TypeError(`${name} value must be ${types.join(" or ")}, received "${receivedType}"`);
}
function isObject(item) {
return item != null && typeof item === "object" && !Array.isArray(item);
}
const MATCHERS_OBJECT = Symbol.for("matchers-object");
const JEST_MATCHERS_OBJECT = Symbol.for("$$jest-matchers-object");
const GLOBAL_EXPECT = Symbol.for("expect-global");
if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
const globalState = /* @__PURE__ */ new WeakMap();
const matchers = /* @__PURE__ */ Object.create(null);
Object.defineProperty(globalThis, MATCHERS_OBJECT, {
get: () => globalState
});
Object.defineProperty(globalThis, JEST_MATCHERS_OBJECT, {
configurable: true,
get: () => ({
state: globalState.get(globalThis[GLOBAL_EXPECT]),
matchers
})
});
}
const getState = (expect) => globalThis[MATCHERS_OBJECT].get(expect);
const setState = (state, expect) => {
const map = globalThis[MATCHERS_OBJECT];
const current = map.get(expect) || {};
Object.assign(current, state);
map.set(expect, current);
};
const EXPECTED_COLOR = c.green;
const RECEIVED_COLOR = c.red;
const INVERTED_COLOR = c.inverse;
const BOLD_WEIGHT = c.bold;
const DIM_COLOR = c.dim;
function matcherHint(matcherName, received = "received", expected = "expected", options = {}) {
const {
comment = "",
isDirectExpectCall = false,
isNot = false,
promise = "",
secondArgument = "",
expectedColor = EXPECTED_COLOR,
receivedColor = RECEIVED_COLOR,
secondArgumentColor = EXPECTED_COLOR
} = options;
let hint = "";
let dimString = "expect";
if (!isDirectExpectCall && received !== "") {
hint += DIM_COLOR(`${dimString}(`) + receivedColor(received);
dimString = ")";
}
if (promise !== "") {
hint += DIM_COLOR(`${dimString}.`) + promise;
dimString = "";
}
if (isNot) {
hint += `${DIM_COLOR(`${dimString}.`)}not`;
dimString = "";
}
if (matcherName.includes(".")) {
dimString += matcherName;
} else {
hint += DIM_COLOR(`${dimString}.`) + matcherName;
dimString = "";
}
if (expected === "") {
dimString += "()";
} else {
hint += DIM_COLOR(`${dimString}(`) + expectedColor(expected);
if (secondArgument)
hint += DIM_COLOR(", ") + secondArgumentColor(secondArgument);
dimString = ")";
}
if (comment !== "")
dimString += ` // ${comment}`;
if (dimString !== "")
hint += DIM_COLOR(dimString);
return hint;
}
const SPACE_SYMBOL = "\xB7";
const replaceTrailingSpaces = (text) => text.replace(/\s+$/gm, (spaces) => SPACE_SYMBOL.repeat(spaces.length));
const printReceived = (object) => RECEIVED_COLOR(replaceTrailingSpaces(stringify(object)));
const printExpected = (value) => EXPECTED_COLOR(replaceTrailingSpaces(stringify(value)));
function diff(a, b, options) {
return unifiedDiff(stringify(b), stringify(a));
}
var matcherUtils = /* @__PURE__ */ Object.freeze({
__proto__: null,
stringify,
EXPECTED_COLOR,
RECEIVED_COLOR,
INVERTED_COLOR,
BOLD_WEIGHT,
DIM_COLOR,
matcherHint,
printReceived,
printExpected,
diff
});
function equals(a, b, customTesters, strictCheck) {
customTesters = customTesters || [];
return eq(a, b, [], [], customTesters, strictCheck ? hasKey : hasDefinedKey);
}
function isAsymmetric(obj) {
return !!obj && typeof obj === "object" && "asymmetricMatch" in obj && isA("Function", obj.asymmetricMatch);
}
function asymmetricMatch(a, b) {
const asymmetricA = isAsymmetric(a);
const asymmetricB = isAsymmetric(b);
if (asymmetricA && asymmetricB)
return void 0;
if (asymmetricA)
return a.asymmetricMatch(b);
if (asymmetricB)
return b.asymmetricMatch(a);
}
function eq(a, b, aStack, bStack, customTesters, hasKey2) {
let result = true;
const asymmetricResult = asymmetricMatch(a, b);
if (asymmetricResult !== void 0)
return asymmetricResult;
for (let i = 0; i < customTesters.length; i++) {
const customTesterResult = customTesters[i](a, b);
if (customTesterResult !== void 0)
return customTesterResult;
}
if (a instanceof Error && b instanceof Error)
return a.message === b.message;
if (Object.is(a, b))
return true;
if (a === null || b === null)
return a === b;
const className = Object.prototype.toString.call(a);
if (className !== Object.prototype.toString.call(b))
return false;
switch (className) {
case "[object Boolean]":
case "[object String]":
case "[object Number]":
if (typeof a !== typeof b) {
return false;
} else if (typeof a !== "object" && typeof b !== "object") {
return Object.is(a, b);
} else {
return Object.is(a.valueOf(), b.valueOf());
}
case "[object Date]":
return isNaN(a) && isNaN(b) || +a === +b;
case "[object RegExp]":
return a.source === b.source && a.flags === b.flags;
}
if (typeof a !== "object" || typeof b !== "object")
return false;
if (isDomNode(a) && isDomNode(b))
return a.isEqualNode(b);
let length = aStack.length;
while (length--) {
if (aStack[length] === a)
return bStack[length] === b;
else if (bStack[length] === b)
return false;
}
aStack.push(a);
bStack.push(b);
if (className === "[object Array]" && a.length !== b.length)
return false;
const aKeys = keys(a, hasKey2);
let key;
let size = aKeys.length;
if (keys(b, hasKey2).length !== size)
return false;
while (size--) {
key = aKeys[size];
result = hasKey2(b, key) && eq(a[key], b[key], aStack, bStack, customTesters, hasKey2);
if (!result)
return false;
}
aStack.pop();
bStack.pop();
return result;
}
function keys(obj, hasKey2) {
const keys2 = [];
for (const key in obj) {
if (hasKey2(obj, key))
keys2.push(key);
}
return keys2.concat(
Object.getOwnPropertySymbols(obj).filter(
(symbol) => Object.getOwnPropertyDescriptor(obj, symbol).enumerable
)
);
}
function hasDefinedKey(obj, key) {
return hasKey(obj, key) && obj[key] !== void 0;
}
function hasKey(obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key);
}
function isA(typeName, value) {
return Object.prototype.toString.apply(value) === `[object ${typeName}]`;
}
function isDomNode(obj) {
return obj !== null && typeof obj === "object" && typeof obj.nodeType === "number" && typeof obj.nodeName === "string" && typeof obj.isEqualNode === "function";
}
const IS_KEYED_SENTINEL = "@@__IMMUTABLE_KEYED__@@";
const IS_SET_SENTINEL = "@@__IMMUTABLE_SET__@@";
const IS_ORDERED_SENTINEL = "@@__IMMUTABLE_ORDERED__@@";
function isImmutableUnorderedKeyed(maybeKeyed) {
return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL] && !maybeKeyed[IS_ORDERED_SENTINEL]);
}
function isImmutableUnorderedSet(maybeSet) {
return !!(maybeSet && maybeSet[IS_SET_SENTINEL] && !maybeSet[IS_ORDERED_SENTINEL]);
}
const IteratorSymbol = Symbol.iterator;
const hasIterator = (object) => !!(object != null && object[IteratorSymbol]);
const iterableEquality = (a, b, aStack = [], bStack = []) => {
if (typeof a !== "object" || typeof b !== "object" || Array.isArray(a) || Array.isArray(b) || !hasIterator(a) || !hasIterator(b))
return void 0;
if (a.constructor !== b.constructor)
return false;
let length = aStack.length;
while (length--) {
if (aStack[length] === a)
return bStack[length] === b;
}
aStack.push(a);
bStack.push(b);
const iterableEqualityWithStack = (a2, b2) => iterableEquality(a2, b2, [...aStack], [...bStack]);
if (a.size !== void 0) {
if (a.size !== b.size) {
return false;
} else if (isA("Set", a) || isImmutableUnorderedSet(a)) {
let allFound = true;
for (const aValue of a) {
if (!b.has(aValue)) {
let has = false;
for (const bValue of b) {
const isEqual = equals(aValue, bValue, [iterableEqualityWithStack]);
if (isEqual === true)
has = true;
}
if (has === false) {
allFound = false;
break;
}
}
}
aStack.pop();
bStack.pop();
return allFound;
} else if (isA("Map", a) || isImmutableUnorderedKeyed(a)) {
let allFound = true;
for (const aEntry of a) {
if (!b.has(aEntry[0]) || !equals(aEntry[1], b.get(aEntry[0]), [iterableEqualityWithStack])) {
let has = false;
for (const bEntry of b) {
const matchedKey = equals(aEntry[0], bEntry[0], [
iterableEqualityWithStack
]);
let matchedValue = false;
if (matchedKey === true) {
matchedValue = equals(aEntry[1], bEntry[1], [
iterableEqualityWithStack
]);
}
if (matchedValue === true)
has = true;
}
if (has === false) {
allFound = false;
break;
}
}
}
aStack.pop();
bStack.pop();
return allFound;
}
}
const bIterator = b[IteratorSymbol]();
for (const aValue of a) {
const nextB = bIterator.next();
if (nextB.done || !equals(aValue, nextB.value, [iterableEqualityWithStack]))
return false;
}
if (!bIterator.next().done)
return false;
aStack.pop();
bStack.pop();
return true;
};
const hasPropertyInObject = (object, key) => {
const shouldTerminate = !object || typeof object !== "object" || object === Object.prototype;
if (shouldTerminate)
return false;
return Object.prototype.hasOwnProperty.call(object, key) || hasPropertyInObject(Object.getPrototypeOf(object), key);
};
const isObjectWithKeys = (a) => isObject(a) && !(a instanceof Error) && !Array.isArray(a) && !(a instanceof Date);
const subsetEquality = (object, subset) => {
const subsetEqualityWithContext = (seenReferences = /* @__PURE__ */ new WeakMap()) => (object2, subset2) => {
if (!isObjectWithKeys(subset2))
return void 0;
return Object.keys(subset2).every((key) => {
if (isObjectWithKeys(subset2[key])) {
if (seenReferences.has(subset2[key]))
return equals(object2[key], subset2[key], [iterableEquality]);
seenReferences.set(subset2[key], true);
}
const result = object2 != null && hasPropertyInObject(object2, key) && equals(object2[key], subset2[key], [
iterableEquality,
subsetEqualityWithContext(seenReferences)
]);
seenReferences.delete(subset2[key]);
return result;
});
};
return subsetEqualityWithContext()(object, subset);
};
const typeEquality = (a, b) => {
if (a == null || b == null || a.constructor === b.constructor)
return void 0;
return false;
};
const arrayBufferEquality = (a, b) => {
if (!(a instanceof ArrayBuffer) || !(b instanceof ArrayBuffer))
return void 0;
const dataViewA = new DataView(a);
const dataViewB = new DataView(b);
if (dataViewA.byteLength !== dataViewB.byteLength)
return false;
for (let i = 0; i < dataViewA.byteLength; i++) {
if (dataViewA.getUint8(i) !== dataViewB.getUint8(i))
return false;
}
return true;
};
const sparseArrayEquality = (a, b) => {
if (!Array.isArray(a) || !Array.isArray(b))
return void 0;
const aKeys = Object.keys(a);
const bKeys = Object.keys(b);
return equals(a, b, [iterableEquality, typeEquality], true) && equals(aKeys, bKeys);
};
const generateToBeMessage = (deepEqualityName, expected = "#{this}", actual = "#{exp}") => {
const toBeMessage = `expected ${expected} to be ${actual} // Object.is equality`;
if (["toStrictEqual", "toEqual"].includes(deepEqualityName))
return `${toBeMessage}
If it should pass with deep equality, replace "toBe" with "${deepEqualityName}"
Expected: ${expected}
Received: serializes to the same string
`;
return toBeMessage;
};
class AsymmetricMatcher$1 {
constructor(sample, inverse = false) {
this.sample = sample;
this.inverse = inverse;
this.$$typeof = Symbol.for("jest.asymmetricMatcher");
}
getMatcherContext(expect) {
return {
...getState(expect || globalThis[GLOBAL_EXPECT]),
equals,
isNot: this.inverse,
utils: matcherUtils
};
}
}
class StringContaining extends AsymmetricMatcher$1 {
constructor(sample, inverse = false) {
if (!isA("String", sample))
throw new Error("Expected is not a string");
super(sample, inverse);
}
asymmetricMatch(other) {
const result = isA("String", other) && other.includes(this.sample);
return this.inverse ? !result : result;
}
toString() {
return `String${this.inverse ? "Not" : ""}Containing`;
}
getExpectedType() {
return "string";
}
}
class Anything extends AsymmetricMatcher$1 {
asymmetricMatch(other) {
return other != null;
}
toString() {
return "Anything";
}
toAsymmetricMatcher() {
return "Anything";
}
}
class ObjectContaining extends AsymmetricMatcher$1 {
constructor(sample, inverse = false) {
super(sample, inverse);
}
getPrototype(obj) {
if (Object.getPrototypeOf)
return Object.getPrototypeOf(obj);
if (obj.constructor.prototype === obj)
return null;
return obj.constructor.prototype;
}
hasProperty(obj, property) {
if (!obj)
return false;
if (Object.prototype.hasOwnProperty.call(obj, property))
return true;
return this.hasProperty(this.getPrototype(obj), property);
}
asymmetricMatch(other) {
if (typeof this.sample !== "object") {
throw new TypeError(
`You must provide an object to ${this.toString()}, not '${typeof this.sample}'.`
);
}
let result = true;
for (const property in this.sample) {
if (!this.hasProperty(other, property) || !equals(this.sample[property], other[property])) {
result = false;
break;
}
}
return this.inverse ? !result : result;
}
toString() {
return `Object${this.inverse ? "Not" : ""}Containing`;
}
getExpectedType() {
return "object";
}
}
class ArrayContaining extends AsymmetricMatcher$1 {
constructor(sample, inverse = false) {
super(sample, inverse);
}
asymmetricMatch(other) {
if (!Array.isArray(this.sample)) {
throw new TypeError(
`You must provide an array to ${this.toString()}, not '${typeof this.sample}'.`
);
}
const result = this.sample.length === 0 || Array.isArray(other) && this.sample.every(
(item) => other.some((another) => equals(item, another))
);
return this.inverse ? !result : result;
}
toString() {
return `Array${this.inverse ? "Not" : ""}Containing`;
}
getExpectedType() {
return "array";
}
}
class Any extends AsymmetricMatcher$1 {
constructor(sample) {
if (typeof sample === "undefined") {
throw new TypeError(
"any() expects to be passed a constructor function. Please pass one or use anything() to match any object."
);
}
super(sample);
}
fnNameFor(func) {
if (func.name)
return func.name;
const functionToString2 = Function.prototype.toString;
const matches = functionToString2.call(func).match(/^(?:async)?\s*function\s*\*?\s*([\w$]+)\s*\(/);
return matches ? matches[1] : "<anonymous>";
}
asymmetricMatch(other) {
if (this.sample === String)
return typeof other == "string" || other instanceof String;
if (this.sample === Number)
return typeof other == "number" || other instanceof Number;
if (this.sample === Function)
return typeof other == "function" || other instanceof Function;
if (this.sample === Boolean)
return typeof other == "boolean" || other instanceof Boolean;
if (this.sample === BigInt)
return typeof other == "bigint" || other instanceof BigInt;
if (this.sample === Symbol)
return typeof other == "symbol" || other instanceof Symbol;
if (this.sample === Object)
return typeof other == "object";
return other instanceof this.sample;
}
toString() {
return "Any";
}
getExpectedType() {
if (this.sample === String)
return "string";
if (this.sample === Number)
return "number";
if (this.sample === Function)
return "function";
if (this.sample === Object)
return "object";
if (this.sample === Boolean)
return "boolean";
return this.fnNameFor(this.sample);
}
toAsymmetricMatcher() {
return `Any<${this.fnNameFor(this.sample)}>`;
}
}
class StringMatching extends AsymmetricMatcher$1 {
constructor(sample, inverse = false) {
if (!isA("String", sample) && !isA("RegExp", sample))
throw new Error("Expected is not a String or a RegExp");
super(new RegExp(sample), inverse);
}
asymmetricMatch(other) {
const result = isA("String", other) && this.sample.test(other);
return this.inverse ? !result : result;
}
toString() {
return `String${this.inverse ? "Not" : ""}Matching`;
}
getExpectedType() {
return "string";
}
}
const JestAsymmetricMatchers = (chai, utils) => {
utils.addMethod(
chai.expect,
"anything",
() => new Anything()
);
utils.addMethod(
chai.expect,
"any",
(expected) => new Any(expected)
);
utils.addMethod(
chai.expect,
"stringContaining",
(expected) => new StringContaining(expected)
);
utils.addMethod(
chai.expect,
"objectContaining",
(expected) => new ObjectContaining(expected)
);
utils.addMethod(
chai.expect,
"arrayContaining",
(expected) => new ArrayContaining(expected)
);
utils.addMethod(
chai.expect,
"stringMatching",
(expected) => new StringMatching(expected)
);
chai.expect.not = {
stringContaining: (expected) => new StringContaining(expected, true),
objectContaining: (expected) => new ObjectContaining(expected, true),
arrayContaining: (expected) => new ArrayContaining(expected, true),
stringMatching: (expected) => new StringMatching(expected, true)
};
};
const JestChaiExpect = (chai, utils) => {
function def(name, fn) {
const addMethod = (n) => {
utils.addMethod(chai.Assertion.prototype, n, fn);
utils.addMethod(globalThis[JEST_MATCHERS_OBJECT].matchers, n, fn);
};
if (Array.isArray(name))
name.forEach((n) => addMethod(n));
else
addMethod(name);
}
["throw", "throws", "Throw"].forEach((m) => {
utils.overwriteMethod(chai.Assertion.prototype, m, (_super) => {
return function(...args) {
const promise = utils.flag(this, "promise");
const object = utils.flag(this, "object");
const isNot = utils.flag(this, "negate");
if (promise === "rejects") {
utils.flag(this, "object", () => {
throw object;
});
} else if (promise === "resolves" && typeof object !== "function") {
if (!isNot) {
const message = utils.flag(this, "message") || "expected promise to throw an error, but it didn't";
const error = {
showDiff: false
};
throw new AssertionError(message, error, utils.flag(this, "ssfi"));
} else {
return;
}
}
_super.apply(this, args);
};
});
});
def("withTest", function(test) {
utils.flag(this, "vitest-test", test);
return this;
});
def("toEqual", function(expected) {
const actual = utils.flag(this, "object");
const equal = equals(
actual,
expected,
[iterableEquality]
);
return this.assert(
equal,
"expected #{this} to deeply equal #{exp}",
"expected #{this} to not deeply equal #{exp}",
expected,
actual
);
});
def("toStrictEqual", function(expected) {
const obj = utils.flag(this, "object");
const equal = equals(
obj,
expected,
[
iterableEquality,
typeEquality,
sparseArrayEquality,
arrayBufferEquality
],
true
);
return this.assert(
equal,
"expected #{this} to strictly equal #{exp}",
"expected #{this} to not strictly equal #{exp}",
expected,
obj
);
});
def("toBe", function(expected) {
const actual = this._obj;
const pass = Object.is(actual, expected);
let deepEqualityName = "";
if (!pass) {
const toStrictEqualPass = equals(
actual,
expected,
[
iterableEquality,
typeEquality,
sparseArrayEquality,
arrayBufferEquality
],
true
);
if (toStrictEqualPass) {
deepEqualityName = "toStrictEqual";
} else {
const toEqualPass = equals(
actual,
expected,
[iterableEquality]
);
if (toEqualPass)
deepEqualityName = "toEqual";
}
}
return this.assert(
pass,
generateToBeMessage(deepEqualityName),
"expected #{this} not to be #{exp} // Object.is equality",
expected,
actual
);
});
def("toMatchObject", function(expected) {
const actual = this._obj;
return this.assert(
equals(actual, expected, [iterableEquality, subsetEquality]),
"expected #{this} to match object #{exp}",
"expected #{this} to not match object #{exp}",
expected,
actual
);
});
def("toMatch", function(expected) {
if (typeof expected === "string")
return this.include(expected);
else
return this.match(expected);
});
def("toContain", function(item) {
return this.contain(item);
});
def("toContainEqual", function(expected) {
const obj = utils.flag(this, "object");
const index = Array.from(obj).findIndex((item) => {
return equals(item, expected);
});
this.assert(
index !== -1,
"expected #{this} to deep equally contain #{exp}",
"expected #{this} to not deep equally contain #{exp}",
expected
);
});
def("toBeTruthy", function() {
const obj = utils.flag(this, "object");
this.assert(
Boolean(obj),
"expected #{this} to be truthy",
"expected #{this} to not be truthy",
obj
);
});
def("toBeFalsy", function() {
const obj = utils.flag(this, "object");
this.assert(
!obj,
"expected #{this} to be falsy",
"expected #{this} to not be falsy",
obj
);
});
def("toBeGreaterThan", function(expected) {
const actual = this._obj;
assertTypes(actual, "actual", ["number", "bigint"]);
assertTypes(expected, "expected", ["number", "bigint"]);
return this.assert(
actual > expected,
`expected ${actual} to be greater than ${expected}`,
`expected ${actual} to be not greater than ${expected}`,
actual,
expected
);
});
def("toBeGreaterThanOrEqual", function(expected) {
const actual = this._obj;
assertTypes(actual, "actual", ["number", "bigint"]);
assertTypes(expected, "expected", ["number", "bigint"]);
return this.assert(
actual >= expected,
`expected ${actual} to be greater than or equal to ${expected}`,
`expected ${actual} to be not greater than or equal to ${expected}`,
actual,
expected
);
});
def("toBeLessThan", function(expected) {
const actual = this._obj;
assertTypes(actual, "actual", ["number", "bigint"]);
assertTypes(expected, "expected", ["number", "bigint"]);
return this.assert(
actual < expected,
`expected ${actual} to be less than ${expected}`,
`expected ${actual} to be not less than ${expected}`,
actual,
expected
);
});
def("toBeLessThanOrEqual", function(expected) {
const actual = this._obj;
assertTypes(actual, "actual", ["number", "bigint"]);
assertTypes(expected, "expected", ["number", "bigint"]);
return this.assert(
actual <= expected,
`expected ${actual} to be less than or equal to ${expected}`,
`expected ${actual} to be not less than or equal to ${expected}`,
actual,
expected
);
});
def("toBeNaN", function() {
return this.be.NaN;
});
def("toBeUndefined", function() {
return this.be.undefined;
});
def("toBeNull", function() {
return this.be.null;
});
def("toBeDefined", function() {
const negate = utils.flag(this, "negate");
utils.flag(this, "negate", false);
if (negate)
return this.be.undefined;
return this.not.be.undefined;
});
def("toBeTypeOf", function(expected) {
const actual = typeof this._obj;
const equal = expected === actual;
return this.assert(
equal,
"expected #{this} to be type of #{exp}",
"expected #{this} not to be type of #{exp}",
expected,
actual
);
});
def("toBeInstanceOf", function(obj) {
return this.instanceOf(obj);
});
def("toHaveLength", function(length) {
return this.have.length(length);
});
def("toHaveProperty", function(...args) {
if (Array.isArray(args[0]))
args[0] = args[0].map((key) => key.replace(/([.[\]])/g, "\\$1")).join(".");
const actual = this._obj;
const [propertyName, expected] = args;
const getValue = () => {
const hasOwn = Object.prototype.hasOwnProperty.call(actual, propertyName);
if (hasOwn)
return { value: actual[propertyName], exists: true };
return utils.getPathInfo(actual, propertyName);
};
const { value, exists } = getValue();
const pass = exists && (args.length === 1 || equals(expected, value));
const valueString = args.length === 1 ? "" : ` with value ${utils.objDisplay(expected)}`;
return this.assert(
pass,
`expected #{this} to have property "${propertyName}"${valueString}`,
`expected #{this} to not have property "${propertyName}"${valueString}`,
actual
);
});
def("toBeCloseTo", function(received, precision = 2) {
const expected = this._obj;
let pass = false;
let expectedDiff = 0;
let receivedDiff = 0;
if (received === Infinity && expected === Infinity) {
pass = true;
} else if (received === -Infinity && expected === -Infinity) {
pass = true;
} else {
expectedDiff = 10 ** -precision / 2;
receivedDiff = Math.abs(expected - received);
pass = receivedDiff < expectedDiff;
}
return this.assert(
pass,
`expected #{this} to be close to #{exp}, received difference is ${receivedDiff}, but expected ${expectedDiff}`,
`expected #{this} to not be close to #{exp}, received difference is ${receivedDiff}, but expected ${expectedDiff}`,
received,
expected
);
});
const assertIsMock = (assertion) => {
if (!isMockFunction(assertion._obj))
throw new TypeError(`${utils.inspect(assertion._obj)} is not a spy or a call to a spy!`);
};
const getSpy = (assertion) => {
assertIsMock(assertion);
return assertion._obj;
};
const ordinalOf = (i) => {
const j = i % 10;
const k = i % 100;
if (j === 1 && k !== 11)
return `${i}st`;
if (j === 2 && k !== 12)
return `${i}nd`;
if (j === 3 && k !== 13)
return `${i}rd`;
return `${i}th`;
};
const formatCalls = (spy, msg, actualCall) => {
msg += c.gray(`
Received:
${spy.mock.calls.map((callArg, i) => {
let methodCall = c.bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call:
`);
if (actualCall)
methodCall += unifiedDiff(stringify(callArg), stringify(actualCall), { showLegend: false });
else
methodCall += stringify(callArg).split("\n").map((line) => ` ${line}`).join("\n");
methodCall += "\n";
return methodCall;
}).join("\n")}`);
msg += c.gray(`
Number of calls: ${c.bold(spy.mock.calls.length)}
`);
return msg;
};
const formatReturns = (spy, msg, actualReturn) => {
msg += c.gray(`
Received:
${spy.mock.results.map((callReturn, i) => {
let methodCall = c.bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call return:
`);
if (actualReturn)
methodCall += unifiedDiff(stringify(callReturn.value), stringify(actualReturn), { showLegend: false });
else
methodCall += stringify(callReturn).split("\n").map((line) => ` ${line}`).join("\n");
methodCall += "\n";
return methodCall;
}).join("\n")}`);
msg += c.gray(`
Number of calls: ${c.bold(spy.mock.calls.length)}
`);
return msg;
};
def(["toHaveBeenCalledTimes", "toBeCalledTimes"], function(number) {
const spy = getSpy(this);
const spyName = spy.getMockName();
const callCount = spy.mock.calls.length;
return this.assert(
callCount === number,
`expected "${spyName}" to be called #{exp} times`,
`expected "${spyName}" to not be called #{exp} times`,
number,
callCount
);
});
def("toHaveBeenCalledOnce", function() {
const spy = getSpy(this);
const spyName = spy.getMockName();
const callCount = spy.mock.calls.length;
return this.assert(
callCount === 1,
`expected "${spyName}" to be called once`,
`expected "${spyName}" to not be called once`,
1,
callCount
);
});
def(["toHaveBeenCalled", "toBeCalled"], function() {
const spy = getSpy(this);
const spyName = spy.getMockName();
const called = spy.mock.calls.length > 0;
const isNot = utils.flag(this, "negate");
let msg = utils.getMessage(
this,
[
called,
`expected "${spyName}" to be called at least once`,
`expected "${spyName}" to not be called at all`,
true,
called
]
);
if (called && isNot)
msg += formatCalls(spy, msg);
if (called && isNot || !called && !isNot) {
const err = new Error(msg);
err.name = "AssertionError";
throw err;
}
});
def(["toHaveBeenCalledWith", "toBeCalledWith"], function(...args) {
const spy = getSpy(this);
const spyName = spy.getMockName();
const pass = spy.mock.calls.some((callArg) => equals(callArg, args, [iterableEquality]));
const isNot = utils.flag(this, "negate");
let msg = utils.getMessage(
this,
[
pass,
`expected "${spyName}" to be called with arguments: #{exp}`,
`expected "${spyName}" to not be called with arguments: #{exp}`,
args
]
);
if (pass && isNot || !pass && !isNot) {
msg += formatCalls(spy, msg, args);
const err = new Error(msg);
err.name = "AssertionError";
throw err;
}
});
def(["toHaveBeenNthCalledWith", "nthCalledWith"], function(times, ...args) {
const spy = getSpy(this);
const spyName = spy.getMockName();
const nthCall = spy.mock.calls[times - 1];
this.assert(
equals(nthCall, args, [iterableEquality]),
`expected ${ordinalOf(times)} "${spyName}" call to have been called with #{exp}`,
`expected ${ordinalOf(times)} "${spyName}" call to not have been called with #{exp}`,
args,
nthCall
);
});
def(["toHaveBeenLastCalledWith", "lastCalledWith"], function(...args) {
const spy = getSpy(this);
const spyName = spy.getMockName();
const lastCall = spy.mock.calls[spy.calls.length - 1];
this.assert(
equals(lastCall, args, [iterableEquality]),
`expected last "${spyName}" call to have been called with #{exp}`,
`expected last "${spyName}" call to not have been called with #{exp}`,
args,
lastCall
);
});
def(["toThrow", "toThrowError"], function(expected) {
if (typeof expected === "string" || typeof expected === "undefined" || expected instanceof RegExp)
return this.throws(expected);
const obj = this._obj;
const promise = utils.flag(this, "promise");
const isNot = utils.flag(this, "negate");
let thrown = null;
if (promise === "rejects") {
thrown = obj;
} else if (promise === "resolves" && typeof obj !== "function") {
if (!isNot) {
const message = utils.flag(this, "message") || "expected promise to throw an error, but it didn't";
const error = {
showDiff: false
};
throw new AssertionError(message, error, utils.flag(this, "ssfi"));
} else {
return;
}
} else {
try {
obj();
} catch (err) {
thrown = err;
}
}
if (typeof expected === "function") {
const name = expected.name || expected.prototype.constructor.name;
return this.assert(
thrown && thrown instanceof expected,
`expected error to be instance of ${name}`,
`expected error not to be instance of ${name}`,
expected,
thrown
);
}
if (expected instanceof Error) {
return this.assert(
thrown && expected.message === thrown.message,
`expected error to have message: ${expected.message}`,
`expected error not to have message: ${expected.message}`,
expected.message,
thrown && thrown.message
);
}
if (typeof expected === "object" && "asymmetricMatch" in expected && typeof expected.asymmetricMatch === "function") {
const matcher = expected;
return this.assert(
thrown && matcher.asymmetricMatch(thrown),
"expected error to match asymmetric matcher",
"expected error not to match asymmetric matcher",
matcher.toString(),
thrown
);
}
throw new Error(`"toThrow" expects string, RegExp, function, Error instance or asymmetric matcher, got "${typeof expected}"`);
});
def(["toHaveReturned", "toReturn"], function() {
const spy = getSpy(this);
const spyName = spy.getMockName();
const calledAndNotThrew = spy.mock.calls.length > 0 && !spy.mock.results.some(({ type }) => type === "throw");
this.assert(
calledAndNotThrew,
`expected "${spyName}" to be successfully called at least once`,
`expected "${spyName}" to not be successfully called`,
calledAndNotThrew,
!calledAndNotThrew
);
});
def(["toHaveReturnedTimes", "toReturnTimes"], function(times) {
const spy = getSpy(this);
const spyName = spy.getMockName();
const successfulReturns = spy.mock.results.reduce((success, { type }) => type === "throw" ? success : ++success, 0);
this.assert(
successfulReturns === times,
`expected "${spyName}" to be successfully called ${times} times`,
`expected "${spyName}" to not be successfully called ${times} times`,
`expected number of returns: ${times}`,
`received number of returns: ${successfulReturns}`
);
});
def(["toHaveReturnedWith", "toReturnWith"], function(value) {
const spy = getSpy(this);
const spyName = spy.getMockName();
const pass = spy.mock.results.some(({ type, value: result }) => type === "return" && equals(value, result));
const isNot = utils.flag(this, "negate");
let msg = utils.getMessage(
this,
[
pass,
`expected "${spyName}" to return with: #{exp} at least once`,
`expected "${spyName}" to not return with: #{exp}`,
value
]
);
if (pass && isNot || !pass && !isNot) {
msg = formatReturns(spy, msg, value);
const err = new Error(msg);
err.name = "AssertionError";
throw err;
}
});
def(["toHaveLastReturnedWith", "lastReturnedWith"], function(value) {
const spy = getSpy(this);
const spyName = spy.getMockName();
const { value: lastResult } = spy.mock.results[spy.returns.length - 1];
const pass = equals(lastResult, value);
this.assert(
pass,
`expected last "${spyName}" call to return #{exp}`,
`expected last "${spyName}" call to not return #{exp}`,
value,
lastResult
);
});
def(["toHaveNthReturnedWith", "nthReturnedWith"], function(nthCall, value) {
const spy = getSpy(this);
const spyName = spy.getMockName();
const isNot = utils.flag(this, "negate");
const { type: callType, value: callResult } = spy.mock.results[nthCall - 1];
const ordinalCall = `${ordinalOf(nthCall)} call`;
if (!isNot && callType === "throw")
chai.assert.fail(`expected ${ordinalCall} to return #{exp}, but instead it threw an error`);
const nthCallReturn = equals(callResult, value);
this.assert(
nthCallReturn,
`expected ${ordinalCall} "${spyName}" call to return #{exp}`,
`expected ${ordinalCall} "${spyName}" call to not return #{exp}`,
value,
callResult
);
});
def("toSatisfy", function(matcher, message) {
return this.be.satisfy(matcher, message);
});
utils.addProperty(chai.Assertion.prototype, "resolves", function __VITEST_RESOLVES__() {
utils.flag(this, "promise", "resolves");
utils.flag(this, "error", new Error("resolves"));
const obj = utils.flag(this, "object");
if (typeof (obj == null ? void 0 : obj.then) !== "function")
throw new TypeError(`You must provide a Promise to expect() when using .resolves, not '${typeof obj}'.`);
const proxy = new Proxy(this, {
get: (target, key, receiver) => {
const result = Reflect.get(target, key, receiver);
if (typeof result !== "function")
return result instanceof chai.Assertion ? proxy : result;
return async (...args) => {
return obj.then(
(value) => {
utils.flag(this, "object", value);
return result.call(this, ...args);
},
(err) => {
throw new Error(`promise rejected "${String(err)}" instead of resolving`);
}
);
};
}
});
return proxy;
});
utils.addProperty(chai.Assertion.prototype, "rejects", function __VITEST_REJECTS__() {
utils.flag(this, "promise", "rejects");
utils.flag(this, "error", new Error("rejects"));
const obj = utils.flag(this, "object");
const wrapper = typeof obj === "function" ? obj() : obj;
if (typeof (wrapper == null ? void 0 : wrapper.then) !== "function")
throw new TypeError(`You must provide a Promise to expect() when using .rejects, not '${typeof wrapper}'.`);
const proxy = new Proxy(this, {
get: (target, key, receiver) => {
const result = Reflect.get(target, key, receiver);
if (typeof result !== "function")
return result instanceof chai.Assertion ? proxy : result;
return async (...args) => {
return wrapper.then(
(value) => {
throw new Error(`promise resolved "${String(value)}" instead of rejecting`);
},
(err) => {
utils.flag(this, "object", err);
return result.call(this, ...args);
}
);
};
}
});
return proxy;
});
};
const isAsyncFunction = (fn) => typeof fn === "function" && fn[Symbol.toStringTag] === "AsyncFunction";
const getMatcherState = (assertion, expect) => {
const obj = assertion._obj;
const isNot = util.flag(assertion, "negate");
const promise = util.flag(assertion, "promise") || "";
const jestUtils = {
...matcherUtils,
iterableEquality,
subsetEquality
};
const matcherState = {
...getState(expect),
isNot,
utils: jestUtils,
promise,
equals,
suppressedErrors: []
};
return {
state: matcherState,
isNot,
obj
};
};
class JestExtendError extends Error {
constructor(message, actual, expected) {
super(message);
this.actual = actual;
this.expected = expected;
}
}
function JestExtendPlugin(expect, matchers) {
return (c2, utils) => {
Object.entries(matchers).forEach(([expectAssertionName, expectAssertion]) => {
function expectSyncWrapper(...args) {
const { state, isNot, obj } = getMatcherState(this, expect);
const { pass, message, actual, expected } = expectAssertion.call(state, obj, ...args);
if (pass && isNot || !pass && !isNot)
throw new JestExtendError(message(), actual, expected);
}
async function expectAsyncWrapper(...args) {
const { state, isNot, obj } = getMatcherState(this, expect);
const { pass, message, actual, expected } = await expectAssertion.call(state, obj, ...args);
if (pass && isNot || !pass && !isNot)
throw new JestExtendError(message(), actual, expected);
}
const expectAssertionWrapper = isAsyncFunction(expectAssertion) ? expectAsyncWrapper : expectSyncWrapper;
utils.addMethod(globalThis[JEST_MATCHERS_OBJECT].matchers, expectAssertionName, expectAssertionWrapper);
utils.addMethod(c2.Assertion.prototype, expectAssertionName, expectAssertionWrapper);
class CustomMatcher extends AsymmetricMatcher$1 {
constructor(inverse = false, ...sample) {
super(sample, inverse);
}
asymmetricMatch(other) {
const { pass } = expectAssertion.call(
this.getMatcherContext(expect),
other,
...this.sample
);
return this.inverse ? !pass : pass;
}
toString() {
return `${this.inverse ? "not." : ""}${expectAssertionName}`;
}
getExpectedType() {
return "any";
}
toAsymmetricMatcher() {
return `${this.toString()}<${this.sample.map(String).join(", ")}>`;
}
}
Object.defineProperty(expect, expectAssertionName, {
configurable: true,
enumerable: true,
value: (...sample) => new CustomMatcher(false, ...sample),
writable: true
});
Object.defineProperty(expect.not, expectAssertionName, {
configurable: true,
enumerable: true,
value: (...sample) => new CustomMatcher(true, ...sample),
writable: true
});
});
};
}
const JestExtend = (chai, utils) => {
utils.addMethod(chai.expect, "extend", (expect, expects) => {
chai.use(JestExtendPlugin(expect, expects));
});
};
var naturalCompare$1 = {exports: {}};
/*
* @version 1.4.0
* @date 2015-10-26
* @stability 3 - Stable
* @author Lauri Rooden (https://github.com/litejs/natural-compare-lite)
* @license MIT License
*/
var naturalCompare = function(a, b) {
var i, codeA
, codeB = 1
, posA = 0
, posB = 0
, alphabet = String.alphabet;
function getCode(str, pos, code) {
if (code) {
for (i = pos; code = getCode(str, i), code < 76 && code > 65;) ++i;
return +str.slice(pos - 1, i)
}
code = alphabet && alphabet.indexOf(str.charAt(pos));
return code > -1 ? code + 76 : ((code = str.charCodeAt(pos) || 0), code < 45 || code > 127) ? code
: code < 46 ? 65 // -
: code < 48 ? code - 1
: code < 58 ? code + 18 // 0-9
: code < 65 ? code - 11
: code < 91 ? code + 11 // A-Z
: code < 97 ? code - 37
: code < 123 ? code + 5 // a-z
: code - 63
}
if ((a+="") != (b+="")) for (;codeB;) {
codeA = getCode(a, posA++);
codeB = getCode(b, posB++);
if (codeA < 76 && codeB < 76 && codeA > 66 && codeB > 66) {
codeA = getCode(a, posA, posA);
codeB = getCode(b, posB, posA = i);
posB = i;
}
if (codeA != codeB) return (codeA < codeB) ? -1 : 1
}
return 0
};
try {
naturalCompare$1.exports = naturalCompare;
} catch (e) {
String.naturalCompare = naturalCompare;
}
const serialize$1 = (val, config, indentation, depth, refs, printer) => {
const name = val.getMockName();
const nameString = name === "vi.fn()" ? "" : ` ${name}`;
let callsString = "";
if (val.mock.calls.length !== 0) {
const indentationNext = indentation + config.indent;
callsString = ` {${config.spacingOuter}${indentationNext}"calls": ${printer(val.mock.calls, config, indentationNext, depth, refs)}${config.min ? ", " : ","}${config.spacingOuter}${indentationNext}"results": ${printer(val.mock.results, config, indentationNext, depth, refs)}${config.min ? "" : ","}${config.spacingOuter}${indentation}}`;
}
return `[MockFunction${nameString}]${callsString}`;
};
const test$1 = (val) => val && !!val._isMockFunction;
const plugin = { serialize: serialize$1, test: test$1 };
const {
DOMCollection,
DOMElement,
Immutable,
ReactElement,
ReactTestComponent,
AsymmetricMatcher
} = plugins_1;
let PLUGINS = [
ReactTestComponent,
ReactElement,
DOMElement,
DOMCollection,
Immutable,
AsymmetricMatcher,
plugin
];
const addSerializer = (plugin) => {
PLUGINS = [plugin].concat(PLUGINS);
};
const getSerializers = () => PLUGINS;
const SNAPSHOT_VERSION = "1";
const writeSnapshotVersion = () => `// Vitest Snapshot v${SNAPSHOT_VERSION}`;
const testNameToKey = (testName, count) => `${testName} ${count}`;
const keyToTestName = (key) => {
if (!/ \d+$/.test(key))
throw new Error("Snapshot keys must end with a number.");
return key.replace(/ \d+$/, "");
};
const getSnapshotData = (snapshotPath, update) => {
const data = /* @__PURE__ */ Object.create(null);
let snapshotContents = "";
let dirty = false;
if (fs.existsSync(snapshotPath)) {
try {
snapshotContents = fs.readFileSync(snapshotPath, "utf8");
const populate = new Function("exports", snapshotContents);
populate(data);
} catch {
}
}
const isInvalid = snapshotContents;
if ((update === "all" || update === "new") && isInvalid)
dirty = true;
return { data, dirty };
};
const addExtraLineBreaks = (string) => string.includes("\n") ? `
${string}
` : string;
const removeExtraLineBreaks = (string) => string.length > 2 && string.startsWith("\n") && string.endsWith("\n") ? string.slice(1, -1) : string;
const escapeRegex = true;
const printFunctionName = false;
function serialize(val, indent = 2, formatOverrides = {}) {
return normalizeNewlines(
format_1(val, {
escapeRegex,
indent,
plugins: getSerializers(),
printFunctionName,
...formatOverrides
})
);
}
function escapeBacktickString(str) {
return str.replace(/`|\\|\${/g, "\\$&");
}
function printBacktickString(str) {
return `\`${escapeBacktickString(str)}\``;
}
function ensureDirectoryExists(filePath) {
try {
fs.mkdirSync(join(dirname(filePath)), { recursive: true });
} catch {
}
}
function normalizeNewlines(string) {
return string.replace(/\r\n|\r/g, "\n");
}
async function saveSnapshotFile(snapshotData, snapshotPath) {
var _a, _b;
const snapshots = Object.keys(snapshotData).sort(naturalCompare$1.exports).map(
(key) => `exports[${printBacktickString(key)}] = ${printBacktickString(normalizeNewlines(snapshotData[key]))};`
);
const content = `${writeSnapshotVersion()}
${snapshots.join("\n\n")}
`;
const skipWriting = fs.existsSync(snapshotPath) && await ((_a = fs) == null ? void 0 : _a.promises.readFile(snapshotPath, "utf8")) === content;
if (skipWriting)
return;
ensureDirectoryExists(snapshotPath);
await ((_b = fs) == null ? void 0 : _b.promises.writeFile(
snapshotPath,
content,
"utf-8"
));
}
function prepareExpected(expected) {
function findStartIndent() {
var _a, _b;
const matchObject = /^( +)}\s+$/m.exec(expected || "");
const objectIndent = (_a = matchObject == null ? void 0 : matchObject[1]) == null ? void 0 : _a.length;
if (objectIndent)
return objectIndent;
const matchText = /^\n( +)"/.exec(expected || "");
return ((_b = matchText == null ? void 0 : matchText[1]) == null ? void 0 : _b.length) || 0;
}
const startIndent = findStartIndent();
let expectedTrimmed = expected == null ? void 0 : expected.trim();
if (startIndent) {
expectedTrimmed = expectedTrimmed == null ? void 0 : expectedTrimmed.replace(new RegExp(`^${" ".repeat(startIndent)}`, "gm"), "").replace(/ +}$/, "}");
}
return expectedTrimmed;
}
function deepMergeArray(target = [], source = []) {
const mergedOutput = Array.from(target);
source.forEach((sourceElement, index) => {
const targetElement = mergedOutput[index];
if (Array.isArray(target[index])) {
mergedOutput[index] = deepMergeArray(target[index], sourceElement);
} else if (isObject$1(targetElement)) {
mergedOutput[index] = deepMergeSnapshot(target[index], sourceElement);
} else {
mergedOutput[index] = sourceElement;
}
});
return mergedOutput;
}
function deepMergeSnapshot(target, source) {
if (isObject$1(target) && isObject$1(source)) {
const mergedOutput = { ...target };
Object.keys(source).forEach((key) => {
if (isObject$1(source[key]) && !source[key].$$typeof) {
if (!(key in target))
Object.assign(mergedOutput, { [key]: source[key] });
else
mergedOutput[key] = deepMergeSnapshot(target[key], source[key]);
} else if (Array.isArray(source[key])) {
mergedOutput[key] = deepMergeArray(target[key], source[key]);
} else {
Object.assign(mergedOutput, { [key]: source[key] });
}
});
return mergedOutput;
} else if (Array.isArray(target) && Array.isArray(source)) {
return deepMergeArray(target, source);
}
return target;
}
async function saveInlineSnapshots(snapshots) {
const MagicString = (await import('./chunk-magic-string.3a794426.js')).default;
const files = new Set(snapshots.map((i) => i.file));
await Promise.all(Array.from(files).map(async (file) => {
const snaps = snapshots.filter((i) => i.file === file);
const code = await promises.readFile(file, "utf8");
const s = new MagicString(code);
for (const snap of snaps) {
const index = positionToOffset(code, snap.line, snap.column);
replaceInlineSnap(code, s, index, snap.snapshot);
}
const transformed = s.toString();
if (transformed !== code)
await promises.writeFile(file, transformed, "utf-8");
}));
}
const startObjectRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\S\s]*\*\/\s*|\/\/.*\s+)*\s*({)/m;
function replaceObjectSnap(code, s, index, newSnap) {
code = code.slice(index);
const startMatch = startObjectRegex.exec(code);
if (!startMatch)
return false;
code = code.slice(startMatch.index);
const charIndex = getCallLastIndex(code);
if (charIndex === null)
return false;
s.appendLeft(index + startMatch.index + charIndex, `, ${prepareSnapString(newSnap, code, index)}`);
return true;
}
function prepareSnapString(snap, source, index) {
const lineNumber = offsetToLineNumber(source, index);
const line = source.split(lineSplitRE)[lineNumber - 1];
const indent = line.match(/^\s*/)[0] || "";
const indentNext = indent.includes(" ") ? `${indent} ` : `${indent} `;
const lines = snap.trim().replace(/\\/g, "\\\\").split(/\n/g);
const isOneline = lines.length <= 1;
const quote = isOneline ? "'" : "`";
if (isOneline)
return `'${lines.join("\n").replace(/'/g, "\\'")}'`;
else
return `${quote}
${lines.map((i) => i ? indentNext + i : "").join("\n").replace(/`/g, "\\`").replace(/\${/g, "\\${")}
${indent}${quote}`;
}
const startRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\S\s]*\*\/\s*|\/\/.*\s+)*\s*[\w_$]*(['"`\)])/m;
function replaceInlineSnap(code, s, index, newSnap) {
const startMatch = startRegex.exec(code.slice(index));
if (!startMatch)
return replaceObjectSnap(code, s, index, newSnap);
const quote = startMatch[1];
const startIndex = index + startMatch.index + startMatch[0].length;
const snapString = prepareSnapString(newSnap, code, index);
if (quote === ")") {
s.appendRight(startIndex - 1, snapString);
return true;
}
const quoteEndRE = new RegExp(`(?:^|[^\\\\])${quote}`);
const endMatch = quoteEndRE.exec(code.slice(startIndex));
if (!endMatch)
return false;
const endIndex = startIndex + endMatch.index + endMatch[0].length;
s.overwrite(startIndex - 1, endIndex, snapString);
return true;
}
const INDENTATION_REGEX = /^([^\S\n]*)\S/m;
function stripSnapshotIndentation(inlineSnapshot) {
const match = inlineSnapshot.match(INDENTATION_REGEX);
if (!match || !match[1]) {
return inlineSnapshot;
}
const indentation = match[1];
const lines = inlineSnapshot.split(/\n/g);
if (lines.length <= 2) {
return inlineSnapshot;
}
if (lines[0].trim() !== "" || lines[lines.length - 1].trim() !== "") {
return inlineSnapshot;
}
for (let i = 1; i < lines.length - 1; i++) {
if (lines[i] !== "") {
if (lines[i].indexOf(indentation) !== 0) {
return inlineSnapshot;
}
lines[i] = lines[i].substring(indentation.length);
}
}
lines[lines.length - 1] = "";
inlineSnapshot = lines.join("\n");
return inlineSnapshot;
}
class SnapshotState {
constructor(testFilePath, snapshotPath, options) {
this.testFilePath = testFilePath;
this.snapshotPath = snapshotPath;
const { data, dirty } = getSnapshotData(
this.snapshotPath,
options.updateSnapshot
);
this._initialData = data;
this._snapshotData = data;
this._dirty = dirty;
this._inlineSnapshots = [];
this._uncheckedKeys = new Set(Object.keys(this._snapshotData));
this._counters = /* @__PURE__ */ new Map();
this.expand = options.expand || false;
this.added = 0;
this.matched = 0;
this.unmatched = 0;
this._updateSnapshot = options.updateSnapshot;
this.updated = 0;
this._snapshotFormat = {
printBasicPrototype: false,
...options.snapshotFormat
};
}
markSnapshotsAsCheckedForTest(testName) {
this._uncheckedKeys.forEach((uncheckedKey) => {
if (keyToTestName(uncheckedKey) === testName)
this._uncheckedKeys.delete(uncheckedKey);
});
}
_inferInlineSnapshotStack(stacks) {
const promiseIndex = stacks.findIndex((i) => i.method.match(/__VITEST_(RESOLVES|REJECTS)__/));
if (promiseIndex !== -1)
return stacks[promiseIndex + 3];
const stackIndex = stacks.findIndex((i) => i.method.includes("__VITEST_INLINE_SNAPSHOT__"));
return stackIndex !== -1 ? stacks[stackIndex + 2] : null;
}
_addSnapshot(key, receivedSerialized, options) {
this._dirty = true;
if (options.isInline) {
const error = options.error || new Error("Unknown error");
const stacks = parseStacktrace(error, true);
stacks.forEach((i) => i.file = slash(i.file));
const stack = this._inferInlineSnapshotStack(stacks);
if (!stack) {
throw new Error(
`Vitest: Couldn't infer stack frame for inline snapshot.
${JSON.stringify(stacks)}`
);
}
stack.column--;
this._inlineSnapshots.push({
snapshot: receivedSerialized,
...stack
});
} else {
this._snapshotData[key] = receivedSerialized;
}
}
clear() {
this._snapshotData = this._initialData;
this._counters = /* @__PURE__ */ new Map();
this.added = 0;
this.matched = 0;
this.unmatched = 0;
this.updated = 0;
this._dirty = false;
}
async save() {
const hasExternalSnapshots = Object.keys(this._snapshotData).length;
const hasInlineSnapshots = this._inlineSnapshots.length;
const isEmpty = !hasExternalSnapshots && !hasInlineSnapshots;
const status = {
deleted: false,
saved: false
};
if ((this._dirty || this._uncheckedKeys.size) && !isEmpty) {
if (hasExternalSnapshots)
await saveSnapshotFile(this._snapshotData, this.snapshotPath);
if (hasInlineSnapshots)
await saveInlineSnapshots(this._inlineSnapshots);
status.saved = true;
} else if (!hasExternalSnapshots && fs.existsSync(this.snapshotPath)) {
if (this._updateSnapshot === "all")
fs.unlinkSync(this.snapshotPath);
status.deleted = true;
}
return status;
}
getUncheckedCount() {
return this._uncheckedKeys.size || 0;
}
getUncheckedKeys() {
return Array.from(this._uncheckedKeys);
}
removeUncheckedKeys() {
if (this._updateSnapshot === "all" && this._uncheckedKeys.size) {
this._dirty = true;
this._uncheckedKeys.forEach((key) => delete this._snapshotData[key]);
this._uncheckedKeys.clear();
}
}
match({
testName,
received,
key,
inlineSnapshot,
isInline,
error
}) {
this._counters.set(testName, (this._counters.get(testName) || 0) + 1);
const count = Number(this._counters.get(testName));
if (!key)
key = testNameToKey(testName, count);
if (!(isInline && this._snapshotData[key] !== void 0))
this._uncheckedKeys.delete(key);
const receivedSerialized = addExtraLineBreaks(serialize(received, void 0, this._snapshotFormat));
const expected = isInline ? inlineSnapshot : this._snapshotData[key];
const expectedTrimmed = prepareExpected(expected);
const pass = expectedTrimmed === prepareExpected(receivedSerialized);
const hasSnapshot = expected !== void 0;
const snapshotIsPersisted = isInline || fs.existsSync(this.snapshotPath);
if (pass && !isInline) {
this._snapshotData[key] = receivedSerialized;
}
if (hasSnapshot && this._updateSnapshot === "all" || (!hasSnapshot || !snapshotIsPersisted) && (this._updateSnapshot === "new" || this._updateSnapshot === "all")) {
if (this._updateSnapshot === "all") {
if (!pass) {
if (hasSnapshot)
this.updated++;
else
this.added++;
this._addSnapshot(key, receivedSerialized, { error, isInline });
} else {
this.matched++;
}
} else {
this._addSnapshot(key, receivedSerialized, { error, isInline });
this.added++;
}
return {
actual: "",
count,
expected: "",
key,
pass: true
};
} else {
if (!pass) {
this.unmatched++;
return {
actual: removeExtraLineBreaks(receivedSerialized),
count,
expected: expectedTrimmed !== void 0 ? removeExtraLineBreaks(expectedTrimmed) : void 0,
key,
pass: false
};
} else {
this.matched++;
return {
actual: "",
count,
expected: "",
key,
pass: true
};
}
}
}
async pack() {
const snapshot = {
filepath: this.testFilePath,
added: 0,
fileDeleted: false,
matched: 0,
unchecked: 0,
uncheckedKeys: [],
unmatched: 0,
updated: 0
};
const uncheckedCount = this.getUncheckedCount();
const uncheckedKeys = this.getUncheckedKeys();
if (uncheckedCount)
this.removeUncheckedKeys();
const status = await this.save();
snapshot.fileDeleted = status.deleted;
snapshot.added = this.added;
snapshot.matched = this.matched;
snapshot.unmatched = this.unmatched;
snapshot.updated = this.updated;
snapshot.unchecked = !status.deleted ? uncheckedCount : 0;
snapshot.uncheckedKeys = Array.from(uncheckedKeys);
return snapshot;
}
}
class SnapshotClient {
constructor() {
this.snapshotStateMap = /* @__PURE__ */ new Map();
}
async setTest(test) {
var _a;
this.test = test;
if (((_a = this.snapshotState) == null ? void 0 : _a.testFilePath) !== this.test.file.filepath) {
this.saveCurrent();
const filePath = this.test.file.filepath;
if (!this.getSnapshotState(test)) {
this.snapshotStateMap.set(
filePath,
new SnapshotState(
filePath,
await rpc().resolveSnapshotPath(filePath),
getWorkerState().config.snapshotOptions
)
);
}
this.snapshotState = this.getSnapshotState(test);
}
}
getSnapshotState(test) {
return this.snapshotStateMap.get(test.file.filepath);
}
clearTest() {
this.test = void 0;
}
skipTestSnapshots(test) {
var _a;
(_a = this.snapshotState) == null ? void 0 : _a.markSnapshotsAsCheckedForTest(test.name);
}
assert(options) {
const {
test = this.test,
message,
isInline = false,
properties,
inlineSnapshot,
error,
errorMessage
} = options;
let { received } = options;
if (!test)
throw new Error("Snapshot cannot be used outside of test");
if (typeof properties === "object") {
if (typeof received !== "object" || !received)
throw new Error("Received value must be an object when the matcher has properties");
try {
const pass2 = equals(received, properties, [iterableEquality, subsetEquality]);
if (!pass2)
expect(received).equals(properties);
else
received = deepMergeSnapshot(received, properties);
} catch (err) {
err.message = errorMessage || "Snapshot mismatched";
throw err;
}
}
const testName = [
...getNames(test).slice(1),
...message ? [message] : []
].join(" > ");
const snapshotState = this.getSnapshotState(test);
const { actual, expected, key, pass } = snapshotState.match({
testName,
received,
isInline,
error,
inlineSnapshot
});
if (!pass) {
try {
expect(actual.trim()).equals(expected ? expected.trim() : "");
} catch (error2) {
error2.message = errorMessage || `Snapshot \`${key || "unknown"}\` mismatched`;
throw error2;
}
}
}
async saveCurrent() {
if (!this.snapshotState)
return;
const result = await this.snapshotState.pack();
await rpc().snapshotSaved(result);
this.snapshotState = void 0;
}
clear() {
this.snapshotStateMap.clear();
}
}
let _client;
function getSnapshotClient() {
if (!_client)
_client = new SnapshotClient();
return _client;
}
const getErrorMessage = (err) => {
if (err instanceof Error)
return err.message;
return err;
};
const getErrorString = (expected, promise) => {
if (typeof expected !== "function") {
if (!promise)
throw new Error(`expected must be a function, received ${typeof expected}`);
return getErrorMessage(expected);
}
try {
expected();
} catch (e) {
return getErrorMessage(e);
}
throw new Error("snapshot function didn't throw");
};
const SnapshotPlugin = (chai, utils) => {
for (const key of ["matchSnapshot", "toMatchSnapshot"]) {
utils.addMethod(
chai.Assertion.prototype,
key,
function(properties, message) {
const expected = utils.flag(this, "object");
const test = utils.flag(this, "vitest-test");
if (typeof properties === "string" && typeof message === "undefined") {
message = properties;
properties = void 0;
}
const errorMessage = utils.flag(this, "message");
getSnapshotClient().assert({
received: expected,
test,
message,
isInline: false,
properties,
errorMessage
});
}
);
}
utils.addMethod(
chai.Assertion.prototype,
"toMatchInlineSnapshot",
function __VITEST_INLINE_SNAPSHOT__(properties, inlineSnapshot, message) {
const expected = utils.flag(this, "object");
const error = utils.flag(this, "error");
const test = utils.flag(this, "vitest-test");
if (typeof properties === "string") {
message = inlineSnapshot;
inlineSnapshot = properties;
properties = void 0;
}
if (inlineSnapshot)
inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
const errorMessage = utils.flag(this, "message");
getSnapshotClient().assert({
received: expected,
test,
message,
isInline: true,
properties,
inlineSnapshot,
error,
errorMessage
});
}
);
utils.addMethod(
chai.Assertion.prototype,
"toThrowErrorMatchingSnapshot",
function(message) {
const expected = utils.flag(this, "object");
const test = utils.flag(this, "vitest-test");
const promise = utils.flag(this, "promise");
const errorMessage = utils.flag(this, "message");
getSnapshotClient().assert({
received: getErrorString(expected, promise),
test,
message,
errorMessage
});
}
);
utils.addMethod(
chai.Assertion.prototype,
"toThrowErrorMatchingInlineSnapshot",
function __VITEST_INLINE_SNAPSHOT__(inlineSnapshot, message) {
const expected = utils.flag(this, "object");
const error = utils.flag(this, "error");
const test = utils.flag(this, "vitest-test");
const promise = utils.flag(this, "promise");
const errorMessage = utils.flag(this, "message");
getSnapshotClient().assert({
received: getErrorString(expected, promise),
test,
message,
inlineSnapshot,
isInline: true,
error,
errorMessage
});
}
);
utils.addMethod(
chai.expect,
"addSnapshotSerializer",
addSerializer
);
};
var chai$1 = /*#__PURE__*/Object.freeze({
__proto__: null,
getSnapshotClient: getSnapshotClient,
SnapshotPlugin: SnapshotPlugin
});
chai$2.use(JestExtend);
chai$2.use(JestChaiExpect);
chai$2.use(Subset);
chai$2.use(SnapshotPlugin);
chai$2.use(JestAsymmetricMatchers);
function createExpect(test) {
var _a;
const expect = (value, message) => {
const { assertionCalls } = getState(expect);
setState({ assertionCalls: assertionCalls + 1 }, expect);
const assert2 = chai$2.expect(value, message);
if (test)
return assert2.withTest(test);
else
return assert2;
};
Object.assign(expect, chai$2.expect);
expect.getState = () => getState(expect);
expect.setState = (state) => setState(state, expect);
const globalState = getState(globalThis[GLOBAL_EXPECT]) || {};
setState({
...globalState,
assertionCalls: 0,
isExpectingAssertions: false,
isExpectingAssertionsError: null,
expectedAssertionsNumber: null,
expectedAssertionsNumberErrorGen: null,
environment: getCurrentEnvironment(),
testPath: test ? (_a = test.suite.file) == null ? void 0 : _a.filepath : globalState.testPath,
currentTestName: test ? getFullName(test) : globalState.currentTestName
}, expect);
expect.extend = (matchers) => chai$2.expect.extend(expect, matchers);
function assertions(expected) {
const errorGen = () => new Error(`expected number of assertions to be ${expected}, but got ${expect.getState().assertionCalls}`);
if (Error.captureStackTrace)
Error.captureStackTrace(errorGen(), assertions);
expect.setState({
expectedAssertionsNumber: expected,
expectedAssertionsNumberErrorGen: errorGen
});
}
function hasAssertions() {
const error = new Error("expected any number of assertion, but got none");
if (Error.captureStackTrace)
Error.captureStackTrace(error, hasAssertions);
expect.setState({
isExpectingAssertions: true,
isExpectingAssertionsError: error
});
}
chai$2.util.addMethod(expect, "assertions", assertions);
chai$2.util.addMethod(expect, "hasAssertions", hasAssertions);
return expect;
}
const globalExpect = createExpect();
Object.defineProperty(globalThis, GLOBAL_EXPECT, {
value: globalExpect,
writable: true,
configurable: true
});
const collectorContext = {
tasks: [],
currentSuite: null
};
function collectTask(task) {
var _a;
(_a = collectorContext.currentSuite) == null ? void 0 : _a.tasks.push(task);
}
async function runWithSuite(suite, fn) {
const prev = collectorContext.currentSuite;
collectorContext.currentSuite = suite;
await fn();
collectorContext.currentSuite = prev;
}
function getDefaultTestTimeout() {
return getWorkerState().config.testTimeout;
}
function getDefaultHookTimeout() {
return getWorkerState().config.hookTimeout;
}
function withTimeout(fn, timeout = getDefaultTestTimeout(), isHook = false) {
if (timeout <= 0 || timeout === Infinity)
return fn;
return (...args) => {
return Promise.race([fn(...args), new Promise((resolve, reject) => {
var _a;
const timer = safeSetTimeout(() => {
safeClearTimeout(timer);
reject(new Error(makeTimeoutMsg(isHook, timeout)));
}, timeout);
(_a = timer.unref) == null ? void 0 : _a.call(timer);
})]);
};
}
function createTestContext(test) {
const context = function() {
throw new Error("done() callback is deprecated, use promise instead");
};
context.meta = test;
let _expect;
Object.defineProperty(context, "expect", {
get() {
if (!_expect)
_expect = createExpect(test);
return _expect;
}
});
Object.defineProperty(context, "_local", {
get() {
return _expect != null;
}
});
context.onTestFailed = (fn) => {
test.onFailed || (test.onFailed = []);
test.onFailed.push(fn);
};
return context;
}
function makeTimeoutMsg(isHook, timeout) {
return `${isHook ? "Hook" : "Test"} timed out in ${timeout}ms.
If this is a long-running ${isHook ? "hook" : "test"}, pass a timeout value as the last argument or configure it globally with "${isHook ? "hookTimeout" : "testTimeout"}".`;
}
const fnMap = /* @__PURE__ */ new WeakMap();
const hooksMap = /* @__PURE__ */ new WeakMap();
const benchOptsMap = /* @__PURE__ */ new WeakMap();
function setFn(key, fn) {
fnMap.set(key, fn);
}
function getFn(key) {
return fnMap.get(key);
}
function setHooks(key, hooks) {
hooksMap.set(key, hooks);
}
function getHooks(key) {
return hooksMap.get(key);
}
function setBenchOptions(key, val) {
benchOptsMap.set(key, val);
}
function getBenchOptions(key) {
return benchOptsMap.get(key);
}
const suite = createSuite();
const test = createTest(
function(name, fn, options) {
getCurrentSuite().test.fn.call(this, name, fn, options);
}
);
const bench = createBenchmark(
function(name, fn = noop, options = {}) {
getCurrentSuite().benchmark.fn.call(this, name, fn, options);
}
);
const describe = suite;
const it = test;
const workerState = getWorkerState();
const defaultSuite = workerState.config.sequence.shuffle ? suite.shuffle("") : suite("");
function clearCollectorContext() {
collectorContext.tasks.length = 0;
defaultSuite.clear();
collectorContext.currentSuite = defaultSuite;
}
function getCurrentSuite() {
return collectorContext.currentSuite || defaultSuite;
}
function createSuiteHooks() {
return {
beforeAll: [],
afterAll: [],
beforeEach: [],
afterEach: []
};
}
function createSuiteCollector(name, factory = () => {
}, mode, concurrent, shuffle, suiteOptions) {
const tasks = [];
const factoryQueue = [];
let suite2;
initSuite();
const test2 = createTest(function(name2, fn = noop, options = suiteOptions) {
if (!isRunningInTest())
throw new Error("`test()` and `it()` is only available in test mode.");
const mode2 = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
if (typeof options === "number")
options = { timeout: options };
const test3 = {
id: "",
type: "test",
name: name2,
mode: mode2,
suite: void 0,
fails: this.fails,
retry: options == null ? void 0 : options.retry
};
if (this.concurrent || concurrent)
test3.concurrent = true;
if (shuffle)
test3.shuffle = true;
const context = createTestContext(test3);
Object.defineProperty(test3, "context", {
value: context,
enumerable: false
});
setFn(test3, withTimeout(
() => fn(context),
options == null ? void 0 : options.timeout
));
tasks.push(test3);
});
const benchmark = createBenchmark(function(name2, fn = noop, options = {}) {
const mode2 = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
if (!isRunningInBenchmark())
throw new Error("`bench()` is only available in benchmark mode. Run with `vitest bench` instead.");
const benchmark2 = {
type: "benchmark",
id: "",
name: name2,
mode: mode2,
suite: void 0
};
setFn(benchmark2, fn);
setBenchOptions(benchmark2, options);
tasks.push(benchmark2);
});
const collector = {
type: "collector",
name,
mode,
test: test2,
tasks,
benchmark,
collect,
clear,
on: addHook
};
function addHook(name2, ...fn) {
getHooks(suite2)[name2].push(...fn);
}
function initSuite() {
suite2 = {
id: "",
type: "suite",
name,
mode,
shuffle,
tasks: []
};
setHooks(suite2, createSuiteHooks());
}
function clear() {
tasks.length = 0;
factoryQueue.length = 0;
initSuite();
}
async function collect(file) {
factoryQueue.length = 0;
if (factory)
await runWithSuite(collector, () => factory(test2));
const allChildren = [];
for (const i of [...factoryQueue, ...tasks])
allChildren.push(i.type === "collector" ? await i.collect(file) : i);
suite2.file = file;
suite2.tasks = allChildren;
allChildren.forEach((task) => {
task.suite = suite2;
if (file)
task.file = file;
});
return suite2;
}
collectTask(collector);
return collector;
}
function createSuite() {
function suiteFn(name, factory, options) {
const mode = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
return createSuiteCollector(name, factory, mode, this.concurrent, this.shuffle, options);
}
suiteFn.each = function(cases, ...args) {
const suite2 = this.withContext();
if (Array.isArray(cases) && args.length)
cases = formatTemplateString(cases, args);
return (name, fn, options) => {
const arrayOnlyCases = cases.every(Array.isArray);
cases.forEach((i, idx) => {
const items = Array.isArray(i) ? i : [i];
arrayOnlyCases ? suite2(formatTitle(name, items, idx), () => fn(...items), options) : suite2(formatTitle(name, items, idx), () => fn(i), options);
});
};
};
suiteFn.skipIf = (condition) => condition ? suite.skip : suite;
suiteFn.runIf = (condition) => condition ? suite : suite.skip;
return createChainable(
["concurrent", "shuffle", "skip", "only", "todo"],
suiteFn
);
}
function createTest(fn) {
const testFn = fn;
testFn.each = function(cases, ...args) {
const test2 = this.withContext();
if (Array.isArray(cases) && args.length)
cases = formatTemplateString(cases, args);
return (name, fn2, options) => {
const arrayOnlyCases = cases.every(Array.isArray);
cases.forEach((i, idx) => {
const items = Array.isArray(i) ? i : [i];
arrayOnlyCases ? test2(formatTitle(name, items, idx), () => fn2(...items), options) : test2(formatTitle(name, items, idx), () => fn2(i), options);
});
};
};
testFn.skipIf = (condition) => condition ? test.skip : test;
testFn.runIf = (condition) => condition ? test : test.skip;
return createChainable(
["concurrent", "skip", "only", "todo", "fails"],
testFn
);
}
function createBenchmark(fn) {
const benchmark = createChainable(
["skip", "only", "todo"],
fn
);
benchmark.skipIf = (condition) => condition ? benchmark.skip : benchmark;
benchmark.runIf = (condition) => condition ? benchmark : benchmark.skip;
return benchmark;
}
function formatTitle(template, items, idx) {
if (template.includes("%#")) {
template = template.replace(/%%/g, "__vitest_escaped_%__").replace(/%#/g, `${idx}`).replace(/__vitest_escaped_%__/g, "%%");
}
const count = template.split("%").length - 1;
let formatted = util$1.format(template, ...items.slice(0, count));
if (isObject$1(items[0])) {
formatted = formatted.replace(
/\$([$\w_.]+)/g,
(_, key) => util.objDisplay(objectAttr(items[0], key))
);
}
return formatted;
}
function formatTemplateString(cases, args) {
const header = cases.join("").trim().replace(/ /g, "").split("\n").map((i) => i.split("|"))[0];
const res = [];
for (let i = 0; i < Math.floor(args.length / header.length); i++) {
const oneCase = {};
for (let j = 0; j < header.length; j++)
oneCase[header[j]] = args[i * header.length + j];
res.push(oneCase);
}
return res;
}
export { GLOBAL_EXPECT as G, getDefaultHookTimeout as a, bench as b, createExpect as c, describe as d, globalExpect as e, clearCollectorContext as f, getCurrentSuite as g, defaultSuite as h, it as i, setHooks as j, getHooks as k, collectorContext as l, getBenchOptions as m, getFn as n, setState as o, getSnapshotClient as p, getState as q, createSuiteHooks as r, suite as s, test as t, chai$1 as u, withTimeout as w };