Socket
Socket
Sign inDemoInstall

@vitest/runner

Package Overview
Dependencies
Maintainers
3
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vitest/runner - npm Package Compare versions

Comparing version 0.34.6 to 1.0.0-beta.0

dist/tasks-b31a73cb.d.ts

123

./dist/index.js

@@ -73,3 +73,2 @@ import limit from 'p-limit';

};
context.meta = test;
context.task = test;

@@ -84,3 +83,3 @@ context.skip = () => {

};
return ((_a = runner.extendTestContext) == null ? void 0 : _a.call(runner, context)) || context;
return ((_a = runner.extendTaskContext) == null ? void 0 : _a.call(runner, context)) || context;
}

@@ -279,48 +278,47 @@ function makeTimeoutMsg(isHook, timeout) {

initSuite();
const test2 = createTest(function(name2, fn = noop, options) {
const mode2 = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
if (typeof options === "number")
options = { timeout: options };
if (typeof suiteOptions === "object")
options = Object.assign({}, suiteOptions, options);
const test3 = {
const task = function(name2 = "", options = {}) {
const task2 = {
id: "",
type: "test",
name: formatName(name2),
each: this.each,
mode: mode2,
name: name2,
suite: void 0,
fails: this.fails,
retry: (options == null ? void 0 : options.retry) ?? runner.config.retry,
repeats: options == null ? void 0 : options.repeats,
meta: /* @__PURE__ */ Object.create(null)
each: options.each,
fails: options.fails,
context: void 0,
type: "custom",
retry: options.retry ?? runner.config.retry,
repeats: options.repeats,
mode: options.only ? "only" : options.skip ? "skip" : options.todo ? "todo" : "run",
meta: options.meta ?? /* @__PURE__ */ Object.create(null)
};
if (this.concurrent || !sequential && (concurrent || runner.config.sequence.concurrent))
test3.concurrent = true;
const handler = options.handler;
if (options.concurrent || !sequential && (concurrent || runner.config.sequence.concurrent))
task2.concurrent = true;
if (shuffle)
test3.shuffle = true;
const context = createTestContext(test3, runner);
Object.defineProperty(test3, "context", {
task2.shuffle = true;
const context = createTestContext(task2, runner);
Object.defineProperty(task2, "context", {
value: context,
enumerable: false
});
setFixture(context, this.fixtures);
setFn(test3, withTimeout(
withFixtures(fn, context),
(options == null ? void 0 : options.timeout) ?? runner.config.testTimeout
));
tasks.push(test3);
setFixture(context, options.fixtures);
if (handler) {
setFn(task2, withTimeout(
withFixtures(handler, context),
(options == null ? void 0 : options.timeout) ?? runner.config.testTimeout
));
}
tasks.push(task2);
return task2;
};
const test2 = createTest(function(name2, fn = noop, options) {
if (typeof options === "number")
options = { timeout: options };
if (typeof suiteOptions === "object")
options = Object.assign({}, suiteOptions, options);
const test3 = task(
formatName(name2),
{ ...this, ...options, handler: fn }
);
test3.type = "test";
});
const custom = function(name2 = "") {
const self = this || {};
const task = {
id: "",
name: name2,
type: "custom",
mode: self.only ? "only" : self.skip ? "skip" : self.todo ? "todo" : "run",
meta: /* @__PURE__ */ Object.create(null)
};
tasks.push(task);
return task;
};
const collector = {

@@ -334,3 +332,3 @@ type: "collector",

collect,
custom,
task,
clear,

@@ -371,6 +369,6 @@ on: addHook

suite2.tasks = allChildren;
allChildren.forEach((task) => {
task.suite = suite2;
allChildren.forEach((task2) => {
task2.suite = suite2;
if (file)
task.file = file;
task2.file = file;
});

@@ -414,5 +412,5 @@ return suite2;

}
function createTest(fn, context) {
const testFn = fn;
testFn.each = function(cases, ...args) {
function createTaskCollector(fn, context) {
const taskFn = fn;
taskFn.each = function(cases, ...args) {
const test2 = this.withContext();

@@ -432,5 +430,5 @@ this.setContext("each", true);

};
testFn.skipIf = (condition) => condition ? test.skip : test;
testFn.runIf = (condition) => condition ? test : test.skip;
testFn.extend = function(fixtures) {
taskFn.skipIf = (condition) => condition ? test.skip : test;
taskFn.runIf = (condition) => condition ? test : test.skip;
taskFn.extend = function(fixtures) {
const _context = mergeContextFixtures(fixtures, context);

@@ -443,3 +441,3 @@ return createTest(function fn2(name, fn2, options) {

["concurrent", "skip", "only", "todo", "fails"],
testFn
taskFn
);

@@ -450,2 +448,5 @@ if (context)

}
function createTest(fn, context) {
return createTaskCollector(fn, context);
}
function formatName(name) {

@@ -642,3 +643,3 @@ return typeof name === "string" ? name : name instanceof Function ? name.name || "<anonymous>" : String(name);

var _a, _b, _c, _d, _e, _f, _g;
await ((_a = runner.onBeforeRunTest) == null ? void 0 : _a.call(runner, test));
await ((_a = runner.onBeforeRunTask) == null ? void 0 : _a.call(runner, test));
if (test.mode !== "run")

@@ -664,7 +665,7 @@ return;

try {
await ((_c = runner.onBeforeTryTest) == null ? void 0 : _c.call(runner, test, { retry: retryCount, repeats: repeatCount }));
await ((_c = runner.onBeforeTryTask) == null ? void 0 : _c.call(runner, test, { retry: retryCount, repeats: repeatCount }));
test.result.repeatCount = repeatCount;
beforeEachCleanups = await callSuiteHook(test.suite, test, "beforeEach", runner, [test.context, test.suite]);
if (runner.runTest) {
await runner.runTest(test);
if (runner.runTask) {
await runner.runTask(test);
} else {

@@ -682,3 +683,3 @@ const fn = getFn(test);

}
await ((_d = runner.onAfterTryTest) == null ? void 0 : _d.call(runner, test, { retry: retryCount, repeats: repeatCount }));
await ((_d = runner.onAfterTryTask) == null ? void 0 : _d.call(runner, test, { retry: retryCount, repeats: repeatCount }));
if (test.result.state !== "fail") {

@@ -730,3 +731,3 @@ if (!test.repeats)

test.result.duration = now() - start;
await ((_g = runner.onAfterRunTest) == null ? void 0 : _g.call(runner, test));
await ((_g = runner.onAfterRunTask) == null ? void 0 : _g.call(runner, test));
updateTask(test, runner);

@@ -829,3 +830,3 @@ }

async function runSuiteChild(c, runner) {
if (c.type === "test")
if (c.type === "test" || c.type === "custom")
return runTest(c, runner);

@@ -856,5 +857,5 @@ else if (c.type === "suite")

(_b = runner.onCollected) == null ? void 0 : _b.call(runner, files);
await ((_c = runner.onBeforeRun) == null ? void 0 : _c.call(runner, files));
await ((_c = runner.onBeforeRunFiles) == null ? void 0 : _c.call(runner, files));
await runFiles(files, runner);
await ((_d = runner.onAfterRun) == null ? void 0 : _d.call(runner, files));
await ((_d = runner.onAfterRunFiles) == null ? void 0 : _d.call(runner, files));
await sendTasksUpdate(runner);

@@ -892,2 +893,2 @@ return files;

export { afterAll, afterEach, beforeAll, beforeEach, describe, getCurrentSuite, getCurrentTest, getFn, it, onTestFailed, setFn, startTests, suite, test, updateTask };
export { afterAll, afterEach, beforeAll, beforeEach, createTaskCollector, describe, getCurrentSuite, getCurrentTest, getFn, it, onTestFailed, setFn, startTests, suite, test, updateTask };
import { VitestRunner } from './types.js';
export { CancelReason, VitestRunnerConfig, VitestRunnerConstructor, VitestRunnerImportSource } from './types.js';
import { T as Task, F as File, d as SuiteAPI, e as TestAPI, f as SuiteCollector, g as SuiteHooks, O as OnTestFailedHandler, a as Test } from './tasks-e594cd24.js';
export { D as DoneCallback, o as Fixtures, p as HookCleanupCallback, H as HookListener, R as RunMode, r as RuntimeContext, t as SequenceHooks, u as SequenceSetupFiles, S as Suite, q as SuiteFactory, i as TaskBase, b as TaskCustom, j as TaskMeta, k as TaskResult, l as TaskResultPack, h as TaskState, s as TestContext, m as TestFunction, n as TestOptions } from './tasks-e594cd24.js';
import { T as Task, F as File, d as SuiteAPI, e as TestAPI, f as SuiteCollector, g as CustomAPI, h as SuiteHooks, O as OnTestFailedHandler, a as Test, C as Custom } from './tasks-b31a73cb.js';
export { D as DoneCallback, E as ExtendedContext, q as Fixture, r as Fixtures, s as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, R as RunMode, v as RuntimeContext, y as SequenceHooks, z as SequenceSetupFiles, S as Suite, u as SuiteFactory, j as TaskBase, x as TaskContext, t as TaskCustomOptions, l as TaskMeta, k as TaskPopulated, m as TaskResult, n as TaskResultPack, i as TaskState, w as TestContext, o as TestFunction, p as TestOptions } from './tasks-b31a73cb.js';
import { Awaitable } from '@vitest/utils';

@@ -15,2 +15,3 @@

declare function getCurrentSuite<ExtraContext = {}>(): SuiteCollector<ExtraContext>;
declare function createTaskCollector(fn: (...args: any[]) => any, context?: Record<string, unknown>): CustomAPI;

@@ -23,7 +24,7 @@ declare function beforeAll(fn: SuiteHooks['beforeAll'][0], timeout?: number): void;

declare function setFn(key: Test, fn: (() => Awaitable<void>)): void;
declare function getFn<Task = Test>(key: Task): (() => Awaitable<void>);
declare function setFn(key: Test | Custom, fn: (() => Awaitable<void>)): void;
declare function getFn<Task = Test | Custom>(key: Task): (() => Awaitable<void>);
declare function getCurrentTest(): Test<{}> | undefined;
declare function getCurrentTest<T extends Test | Custom | undefined>(): T;
export { File, OnTestFailedHandler, SuiteAPI, SuiteCollector, SuiteHooks, Task, Test, TestAPI, VitestRunner, afterAll, afterEach, beforeAll, beforeEach, describe, getCurrentSuite, getCurrentTest, getFn, it, onTestFailed, setFn, startTests, suite, test, updateTask };
export { Custom, CustomAPI, File, OnTestFailedHandler, SuiteAPI, SuiteCollector, SuiteHooks, Task, Test, TestAPI, VitestRunner, afterAll, afterEach, beforeAll, beforeEach, createTaskCollector, describe, getCurrentSuite, getCurrentTest, getFn, it, onTestFailed, setFn, startTests, suite, test, updateTask };

@@ -73,3 +73,2 @@ import limit from 'p-limit';

};
context.meta = test;
context.task = test;

@@ -84,3 +83,3 @@ context.skip = () => {

};
return ((_a = runner.extendTestContext) == null ? void 0 : _a.call(runner, context)) || context;
return ((_a = runner.extendTaskContext) == null ? void 0 : _a.call(runner, context)) || context;
}

@@ -279,48 +278,47 @@ function makeTimeoutMsg(isHook, timeout) {

initSuite();
const test2 = createTest(function(name2, fn = noop, options) {
const mode2 = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
if (typeof options === "number")
options = { timeout: options };
if (typeof suiteOptions === "object")
options = Object.assign({}, suiteOptions, options);
const test3 = {
const task = function(name2 = "", options = {}) {
const task2 = {
id: "",
type: "test",
name: formatName(name2),
each: this.each,
mode: mode2,
name: name2,
suite: void 0,
fails: this.fails,
retry: (options == null ? void 0 : options.retry) ?? runner.config.retry,
repeats: options == null ? void 0 : options.repeats,
meta: /* @__PURE__ */ Object.create(null)
each: options.each,
fails: options.fails,
context: void 0,
type: "custom",
retry: options.retry ?? runner.config.retry,
repeats: options.repeats,
mode: options.only ? "only" : options.skip ? "skip" : options.todo ? "todo" : "run",
meta: options.meta ?? /* @__PURE__ */ Object.create(null)
};
if (this.concurrent || !sequential && (concurrent || runner.config.sequence.concurrent))
test3.concurrent = true;
const handler = options.handler;
if (options.concurrent || !sequential && (concurrent || runner.config.sequence.concurrent))
task2.concurrent = true;
if (shuffle)
test3.shuffle = true;
const context = createTestContext(test3, runner);
Object.defineProperty(test3, "context", {
task2.shuffle = true;
const context = createTestContext(task2, runner);
Object.defineProperty(task2, "context", {
value: context,
enumerable: false
});
setFixture(context, this.fixtures);
setFn(test3, withTimeout(
withFixtures(fn, context),
(options == null ? void 0 : options.timeout) ?? runner.config.testTimeout
));
tasks.push(test3);
setFixture(context, options.fixtures);
if (handler) {
setFn(task2, withTimeout(
withFixtures(handler, context),
(options == null ? void 0 : options.timeout) ?? runner.config.testTimeout
));
}
tasks.push(task2);
return task2;
};
const test2 = createTest(function(name2, fn = noop, options) {
if (typeof options === "number")
options = { timeout: options };
if (typeof suiteOptions === "object")
options = Object.assign({}, suiteOptions, options);
const test3 = task(
formatName(name2),
{ ...this, ...options, handler: fn }
);
test3.type = "test";
});
const custom = function(name2 = "") {
const self = this || {};
const task = {
id: "",
name: name2,
type: "custom",
mode: self.only ? "only" : self.skip ? "skip" : self.todo ? "todo" : "run",
meta: /* @__PURE__ */ Object.create(null)
};
tasks.push(task);
return task;
};
const collector = {

@@ -334,3 +332,3 @@ type: "collector",

collect,
custom,
task,
clear,

@@ -371,6 +369,6 @@ on: addHook

suite2.tasks = allChildren;
allChildren.forEach((task) => {
task.suite = suite2;
allChildren.forEach((task2) => {
task2.suite = suite2;
if (file)
task.file = file;
task2.file = file;
});

@@ -414,5 +412,5 @@ return suite2;

}
function createTest(fn, context) {
const testFn = fn;
testFn.each = function(cases, ...args) {
function createTaskCollector(fn, context) {
const taskFn = fn;
taskFn.each = function(cases, ...args) {
const test2 = this.withContext();

@@ -432,5 +430,5 @@ this.setContext("each", true);

};
testFn.skipIf = (condition) => condition ? test.skip : test;
testFn.runIf = (condition) => condition ? test : test.skip;
testFn.extend = function(fixtures) {
taskFn.skipIf = (condition) => condition ? test.skip : test;
taskFn.runIf = (condition) => condition ? test : test.skip;
taskFn.extend = function(fixtures) {
const _context = mergeContextFixtures(fixtures, context);

@@ -443,3 +441,3 @@ return createTest(function fn2(name, fn2, options) {

["concurrent", "skip", "only", "todo", "fails"],
testFn
taskFn
);

@@ -450,2 +448,5 @@ if (context)

}
function createTest(fn, context) {
return createTaskCollector(fn, context);
}
function formatName(name) {

@@ -642,3 +643,3 @@ return typeof name === "string" ? name : name instanceof Function ? name.name || "<anonymous>" : String(name);

var _a, _b, _c, _d, _e, _f, _g;
await ((_a = runner.onBeforeRunTest) == null ? void 0 : _a.call(runner, test));
await ((_a = runner.onBeforeRunTask) == null ? void 0 : _a.call(runner, test));
if (test.mode !== "run")

@@ -664,7 +665,7 @@ return;

try {
await ((_c = runner.onBeforeTryTest) == null ? void 0 : _c.call(runner, test, { retry: retryCount, repeats: repeatCount }));
await ((_c = runner.onBeforeTryTask) == null ? void 0 : _c.call(runner, test, { retry: retryCount, repeats: repeatCount }));
test.result.repeatCount = repeatCount;
beforeEachCleanups = await callSuiteHook(test.suite, test, "beforeEach", runner, [test.context, test.suite]);
if (runner.runTest) {
await runner.runTest(test);
if (runner.runTask) {
await runner.runTask(test);
} else {

@@ -682,3 +683,3 @@ const fn = getFn(test);

}
await ((_d = runner.onAfterTryTest) == null ? void 0 : _d.call(runner, test, { retry: retryCount, repeats: repeatCount }));
await ((_d = runner.onAfterTryTask) == null ? void 0 : _d.call(runner, test, { retry: retryCount, repeats: repeatCount }));
if (test.result.state !== "fail") {

@@ -730,3 +731,3 @@ if (!test.repeats)

test.result.duration = now() - start;
await ((_g = runner.onAfterRunTest) == null ? void 0 : _g.call(runner, test));
await ((_g = runner.onAfterRunTask) == null ? void 0 : _g.call(runner, test));
updateTask(test, runner);

@@ -829,3 +830,3 @@ }

async function runSuiteChild(c, runner) {
if (c.type === "test")
if (c.type === "test" || c.type === "custom")
return runTest(c, runner);

@@ -856,5 +857,5 @@ else if (c.type === "suite")

(_b = runner.onCollected) == null ? void 0 : _b.call(runner, files);
await ((_c = runner.onBeforeRun) == null ? void 0 : _c.call(runner, files));
await ((_c = runner.onBeforeRunFiles) == null ? void 0 : _c.call(runner, files));
await runFiles(files, runner);
await ((_d = runner.onAfterRun) == null ? void 0 : _d.call(runner, files));
await ((_d = runner.onAfterRunFiles) == null ? void 0 : _d.call(runner, files));
await sendTasksUpdate(runner);

@@ -892,2 +893,2 @@ return files;

export { afterAll, afterEach, beforeAll, beforeEach, describe, getCurrentSuite, getCurrentTest, getFn, it, onTestFailed, setFn, startTests, suite, test, updateTask };
export { afterAll, afterEach, beforeAll, beforeEach, createTaskCollector, describe, getCurrentSuite, getCurrentTest, getFn, it, onTestFailed, setFn, startTests, suite, test, updateTask };

@@ -1,3 +0,3 @@

import { t as SequenceHooks, u as SequenceSetupFiles, F as File, a as Test, S as Suite, l as TaskResultPack, s as TestContext } from './tasks-e594cd24.js';
export { D as DoneCallback, o as Fixtures, p as HookCleanupCallback, H as HookListener, O as OnTestFailedHandler, R as RunMode, r as RuntimeContext, d as SuiteAPI, f as SuiteCollector, q as SuiteFactory, g as SuiteHooks, T as Task, i as TaskBase, b as TaskCustom, j as TaskMeta, k as TaskResult, h as TaskState, e as TestAPI, m as TestFunction, n as TestOptions } from './tasks-e594cd24.js';
import { y as SequenceHooks, z as SequenceSetupFiles, F as File, k as TaskPopulated, S as Suite, n as TaskResultPack, a as Test, C as Custom, x as TaskContext, E as ExtendedContext } from './tasks-b31a73cb.js';
export { g as CustomAPI, D as DoneCallback, q as Fixture, r as Fixtures, s as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, R as RunMode, v as RuntimeContext, d as SuiteAPI, f as SuiteCollector, u as SuiteFactory, h as SuiteHooks, T as Task, j as TaskBase, t as TaskCustomOptions, l as TaskMeta, m as TaskResult, i as TaskState, e as TestAPI, w as TestContext, o as TestFunction, p as TestOptions } from './tasks-b31a73cb.js';
import '@vitest/utils';

@@ -87,3 +87,3 @@

* Runner should listen for this method and mark tests and suites as skipped in
* "onBeforeRunSuite" and "onBeforeRunTest" when called.
* "onBeforeRunSuite" and "onBeforeRunTask" when called.
*/

@@ -94,7 +94,7 @@ onCancel?(reason: CancelReason): unknown;

*/
onBeforeRunTest?(test: Test): unknown;
onBeforeRunTask?(test: TaskPopulated): unknown;
/**
* Called before actually running the test function. Already has "result" with "state" and "startTime".
*/
onBeforeTryTest?(test: Test, options: {
onBeforeTryTask?(test: TaskPopulated, options: {
retry: number;

@@ -106,7 +106,7 @@ repeats: number;

*/
onAfterRunTest?(test: Test): unknown;
onAfterRunTask?(test: TaskPopulated): unknown;
/**
* Called right after running the test function. Doesn't have new state yet. Will not be called, if the test function throws.
*/
onAfterTryTest?(test: Test, options: {
onAfterTryTask?(test: TaskPopulated, options: {
retry: number;

@@ -132,3 +132,3 @@ repeats: number;

*/
runTest?(test: Test): Promise<void>;
runTask?(test: TaskPopulated): Promise<void>;
/**

@@ -141,12 +141,16 @@ * Called, when a task is updated. The same as "onTaskUpdate" in a reporter, but this is running in the same thread as tests.

*/
onBeforeRun?(files: File[]): unknown;
onBeforeRunFiles?(files: File[]): unknown;
/**
* Called right after running all tests in collected paths.
*/
onAfterRun?(files: File[]): unknown;
onAfterRunFiles?(files: File[]): unknown;
/**
* Called when new context for a test is defined. Useful, if you want to add custom properties to the context.
* If you only want to define custom context, consider using "beforeAll" in "setupFiles" instead.
*
* This method is called for both "test" and "custom" handlers.
*
* @see https://vitest.dev/advanced/runner.html#your-task-function
*/
extendTestContext?(context: TestContext): TestContext;
extendTaskContext?<T extends Test | Custom>(context: TaskContext<T>): ExtendedContext<T>;
/**

@@ -162,2 +166,2 @@ * Called, when files are imported. Can be called in two situations: when collecting tests and when importing setup files.

export { CancelReason, File, SequenceHooks, SequenceSetupFiles, Suite, TaskResultPack, Test, TestContext, VitestRunner, VitestRunnerConfig, VitestRunnerConstructor, VitestRunnerImportSource };
export { CancelReason, Custom, ExtendedContext, File, SequenceHooks, SequenceSetupFiles, Suite, TaskContext, TaskPopulated, TaskResultPack, Test, VitestRunner, VitestRunnerConfig, VitestRunnerConstructor, VitestRunnerImportSource };

@@ -1,3 +0,3 @@

import { S as Suite, T as Task, a as Test, b as TaskCustom } from './tasks-e594cd24.js';
export { C as ChainableFunction, c as createChainable } from './tasks-e594cd24.js';
import { S as Suite, T as Task, a as Test, C as Custom } from './tasks-b31a73cb.js';
export { b as ChainableFunction, c as createChainable } from './tasks-b31a73cb.js';
import { Arrayable } from '@vitest/utils';

@@ -18,3 +18,3 @@

declare function getTests(suite: Arrayable<Task>): (Test | TaskCustom)[];
declare function getTests(suite: Arrayable<Task>): (Test | Custom)[];
declare function getTasks(tasks?: Arrayable<Task>): Task[];

@@ -21,0 +21,0 @@ declare function getSuites(suite: Arrayable<Task>): Suite[];

{
"name": "@vitest/runner",
"type": "module",
"version": "0.34.6",
"version": "1.0.0-beta.0",
"description": "Vitest test runner",

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

"pathe": "^1.1.1",
"@vitest/utils": "0.34.6"
"@vitest/utils": "1.0.0-beta.0"
},

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

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