Socket
Socket
Sign inDemoInstall

@vitest/runner

Package Overview
Dependencies
12
Maintainers
3
Versions
75
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 1.0.2

62

dist/index.js
import limit from 'p-limit';
import { getSafeTimers, format, isObject, objDisplay, objectAttr, noop, toArray, shuffle } from '@vitest/utils';
import { getSafeTimers, createDefer, format, isObject, objDisplay, objectAttr, noop, toArray, shuffle } from '@vitest/utils';
import { processError } from '@vitest/utils/error';

@@ -138,37 +138,27 @@ export { processError } from '@vitest/utils/error';

return fn(context);
let cursor = 0;
return new Promise((resolve, reject) => {
async function use(fixtureValue) {
const fixture = pendingFixtures[cursor++];
context[fixture.prop] = fixtureValue;
if (!fixtureValueMap.has(fixture)) {
fixtureValueMap.set(fixture, fixtureValue);
cleanupFnArray.unshift(() => {
fixtureValueMap.delete(fixture);
});
}
if (cursor < pendingFixtures.length) {
await next();
async function resolveFixtures() {
for (const fixture of pendingFixtures) {
if (fixtureValueMap.has(fixture))
continue;
let resolvedValue;
if (fixture.isFn) {
const useFnArgPromise = createDefer();
fixture.value(context, async (useFnArg) => {
useFnArgPromise.resolve(useFnArg);
const teardownPromise = createDefer();
cleanupFnArray.push(teardownPromise.resolve);
await teardownPromise;
}).catch(useFnArgPromise.reject);
resolvedValue = await useFnArgPromise;
} else {
try {
resolve(await fn(context));
} catch (err) {
reject(err);
}
return new Promise((resolve2) => {
cleanupFnArray.push(resolve2);
});
resolvedValue = fixture.value;
}
context[fixture.prop] = resolvedValue;
fixtureValueMap.set(fixture, resolvedValue);
cleanupFnArray.unshift(() => {
fixtureValueMap.delete(fixture);
});
}
async function next() {
const fixture = pendingFixtures[cursor];
const { isFn, value } = fixture;
if (fixtureValueMap.has(fixture))
return use(fixtureValueMap.get(fixture));
else
return isFn ? value(context, use) : use(value);
}
const setupFixturePromise = next().catch(reject);
cleanupFnArray.unshift(() => setupFixturePromise);
});
}
return resolveFixtures().then(() => fn(context));
};

@@ -185,3 +175,3 @@ }

if (depSet.has(fixture))
throw new Error("circular fixture dependency");
throw new Error(`Circular fixture dependency detected: ${fixture.prop} <- ${[...depSet].reverse().map((d) => d.prop).join(" <- ")}`);
depSet.add(fixture);

@@ -203,3 +193,3 @@ resolveDeps(fixture.deps, depSet, pendingFixtures);

if (!(first.startsWith("{") && first.endsWith("}")))
throw new Error("the first argument must use object destructuring pattern");
throw new Error(`The first argument inside a fixture must use object destructuring pattern, e.g. ({ test } => {}). Instead, received "${first}".`);
const _first = first.slice(1, -1).replace(/\s/g, "");

@@ -211,3 +201,3 @@ const props = splitByComma(_first).map((prop) => {

if (last && last.startsWith("..."))
throw new Error("Rest parameters are not supported");
throw new Error(`Rest parameters are not supported in fixtures, received "${last}".`);
return props;

@@ -214,0 +204,0 @@ }

{
"name": "@vitest/runner",
"type": "module",
"version": "1.0.1",
"version": "1.0.2",
"description": "Vitest test runner",

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

"pathe": "^1.1.1",
"@vitest/utils": "1.0.1"
"@vitest/utils": "1.0.2"
},

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

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