vitest
Version:
A blazing fast unit test framework powered by Vite
71 lines (66 loc) • 2.09 kB
JavaScript
import { relative } from 'pathe';
import 'std-env';
import '@vitest/runner/utils';
import '@vitest/utils';
var _a;
const isNode = typeof process < "u" && typeof process.stdout < "u" && !((_a = process.versions) == null ? void 0 : _a.deno) && !globalThis.window;
function getWorkerState() {
return globalThis.__vitest_worker__;
}
function getCurrentEnvironment() {
return globalThis.__vitest_environment__;
}
const isWindows = isNode && process.platform === "win32";
const getRunMode = () => getWorkerState().config.mode;
const isRunningInBenchmark = () => getRunMode() === "benchmark";
const relativePath = relative;
function resetModules(modules, resetMocks = false) {
const skipPaths = [
/\/vitest\/dist\//,
/\/vite-node\/dist\//,
/vitest-virtual-\w+\/dist/,
/@vitest\/dist/,
...!resetMocks ? [/^mock:/] : []
];
modules.forEach((mod, path) => {
if (skipPaths.some((re) => re.test(path)))
return;
modules.invalidateModule(mod);
});
}
function removeUndefinedValues(obj) {
for (const key in Object.keys(obj)) {
if (obj[key] === void 0)
delete obj[key];
}
return obj;
}
function getCallLastIndex(code) {
let charIndex = -1;
let inString = null;
let startedBracers = 0;
let endedBracers = 0;
let beforeChar = null;
while (charIndex <= code.length) {
beforeChar = code[charIndex];
charIndex++;
const char = code[charIndex];
const isCharString = char === '"' || char === "'" || char === "`";
if (isCharString && beforeChar !== "\\") {
if (inString === char)
inString = null;
else if (!inString)
inString = char;
}
if (!inString) {
if (char === "(")
startedBracers++;
if (char === ")")
endedBracers++;
}
if (startedBracers && endedBracers && startedBracers === endedBracers)
return charIndex;
}
return null;
}
export { getCallLastIndex as a, getCurrentEnvironment as b, isNode as c, relativePath as d, removeUndefinedValues as e, isWindows as f, getWorkerState as g, isRunningInBenchmark as i, resetModules as r };