@vitest/runner
Advanced tools
Comparing version 1.2.2 to 1.3.0
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 CustomAPI, h as SuiteHooks, O as OnTestFailedHandler, a as Test, C as Custom, S as Suite } from './tasks-rsXe_qLO.js'; | ||
export { D as DoneCallback, E as ExtendedContext, r as Fixture, q as FixtureFn, s as Fixtures, t as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, R as RunMode, w as RuntimeContext, z as SequenceHooks, A as SequenceSetupFiles, v as SuiteFactory, j as TaskBase, y as TaskContext, u as TaskCustomOptions, l as TaskMeta, k as TaskPopulated, m as TaskResult, n as TaskResultPack, i as TaskState, x as TestContext, o as TestFunction, p as TestOptions, U as Use } from './tasks-rsXe_qLO.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, i as OnTestFinishedHandler, a as Test, C as Custom, S as Suite } from './tasks-_kyNRBhz.js'; | ||
export { D as DoneCallback, E as ExtendedContext, t as Fixture, s as FixtureFn, r as FixtureOptions, u as Fixtures, v as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, R as RunMode, y as RuntimeContext, B as SequenceHooks, G as SequenceSetupFiles, x as SuiteFactory, k as TaskBase, A as TaskContext, w as TaskCustomOptions, m as TaskMeta, l as TaskPopulated, n as TaskResult, o as TaskResultPack, j as TaskState, z as TestContext, p as TestFunction, q as TestOptions, U as Use } from './tasks-_kyNRBhz.js'; | ||
import { Awaitable } from '@vitest/utils'; | ||
@@ -24,2 +24,3 @@ export { processError } from '@vitest/utils/error'; | ||
declare const onTestFailed: (fn: OnTestFailedHandler) => void; | ||
declare const onTestFinished: (fn: OnTestFinishedHandler) => void; | ||
@@ -33,2 +34,2 @@ declare function setFn(key: Test | Custom, fn: (() => Awaitable<void>)): void; | ||
export { Custom, CustomAPI, File, OnTestFailedHandler, Suite, SuiteAPI, SuiteCollector, SuiteHooks, Task, Test, TestAPI, VitestRunner, afterAll, afterEach, beforeAll, beforeEach, createTaskCollector, describe, getCurrentSuite, getCurrentTest, getFn, getHooks, it, onTestFailed, setFn, setHooks, startTests, suite, test, updateTask }; | ||
export { Custom, CustomAPI, File, OnTestFailedHandler, OnTestFinishedHandler, Suite, SuiteAPI, SuiteCollector, SuiteHooks, Task, Test, TestAPI, VitestRunner, afterAll, afterEach, beforeAll, beforeEach, createTaskCollector, describe, getCurrentSuite, getCurrentTest, getFn, getHooks, it, onTestFailed, onTestFinished, setFn, setHooks, startTests, suite, test, updateTask }; |
import limit from 'p-limit'; | ||
import { getSafeTimers, createDefer, format, isObject, objDisplay, objectAttr, noop, toArray, shuffle } from '@vitest/utils'; | ||
import { getSafeTimers, isObject, createDefer, format, objDisplay, objectAttr, toArray, shuffle } from '@vitest/utils'; | ||
import { processError } from '@vitest/utils/error'; | ||
export { processError } from '@vitest/utils/error'; | ||
import { createChainable, generateHash, calculateSuiteHash, someTasksAreOnly, interpretTaskModes, partitionSuiteChildren, hasTests, hasFailed } from './utils.js'; | ||
import { j as createChainable, g as generateHash, c as calculateSuiteHash, s as someTasksAreOnly, i as interpretTaskModes, p as partitionSuiteChildren, h as hasTests, e as hasFailed } from './chunk-tasks.js'; | ||
import { relative } from 'pathe'; | ||
@@ -83,2 +83,6 @@ | ||
}; | ||
context.onTestFinished = (fn) => { | ||
test.onFinished || (test.onFinished = []); | ||
test.onFinished.push(fn); | ||
}; | ||
return ((_a = runner.extendTaskContext) == null ? void 0 : _a.call(runner, context)) || context; | ||
@@ -92,10 +96,12 @@ } | ||
function mergeContextFixtures(fixtures, context = {}) { | ||
const fixtureArray = Object.entries(fixtures).map(([prop, value], index) => { | ||
const isFn = typeof value === "function"; | ||
return { | ||
prop, | ||
value, | ||
index, | ||
isFn | ||
}; | ||
const fixtureOptionKeys = ["auto"]; | ||
const fixtureArray = Object.entries(fixtures).map(([prop, value]) => { | ||
const fixtureItem = { value }; | ||
if (Array.isArray(value) && value.length >= 2 && isObject(value[1]) && Object.keys(value[1]).some((key) => fixtureOptionKeys.includes(key))) { | ||
Object.assign(fixtureItem, value[1]); | ||
fixtureItem.value = value[0]; | ||
} | ||
fixtureItem.prop = prop; | ||
fixtureItem.isFn = typeof fixtureItem.value === "function"; | ||
return fixtureItem; | ||
}); | ||
@@ -132,3 +138,4 @@ if (Array.isArray(context.fixtures)) | ||
const usedProps = getUsedProps(fn); | ||
if (!usedProps.length) | ||
const hasAutoFixture = fixtures.some(({ auto }) => auto); | ||
if (!usedProps.length && !hasAutoFixture) | ||
return fn(context); | ||
@@ -141,3 +148,3 @@ if (!fixtureValueMaps.get(context)) | ||
const cleanupFnArray = cleanupFnArrayMap.get(context); | ||
const usedFixtures = fixtures.filter(({ prop }) => usedProps.includes(prop)); | ||
const usedFixtures = fixtures.filter(({ prop, auto }) => auto || usedProps.includes(prop)); | ||
const pendingFixtures = resolveDeps(usedFixtures); | ||
@@ -250,6 +257,6 @@ if (!pendingFixtures.length) | ||
const test = createTest( | ||
function(name, fn, options) { | ||
function(name, optionsOrFn, optionsOrTest) { | ||
if (getCurrentTest()) | ||
throw new Error('Calling the test function inside another test function is not allowed. Please put it inside "describe" or "suite" so it can be properly collected.'); | ||
getCurrentSuite().test.fn.call(this, formatName(name), fn, options); | ||
getCurrentSuite().test.fn.call(this, formatName(name), optionsOrFn, optionsOrTest); | ||
} | ||
@@ -286,4 +293,29 @@ ); | ||
} | ||
function parseArguments(optionsOrFn, optionsOrTest) { | ||
let options = {}; | ||
let fn = () => { | ||
}; | ||
if (typeof optionsOrTest === "object") { | ||
if (typeof optionsOrFn === "object") | ||
throw new TypeError("Cannot use two objects as arguments. Please provide options and a function callback in that order."); | ||
options = optionsOrTest; | ||
} else if (typeof optionsOrTest === "number") { | ||
options = { timeout: optionsOrTest }; | ||
} else if (typeof optionsOrFn === "object") { | ||
options = optionsOrFn; | ||
} | ||
if (typeof optionsOrFn === "function") { | ||
if (typeof optionsOrTest === "function") | ||
throw new TypeError("Cannot use two functions as arguments. Please use the second argument for options."); | ||
fn = optionsOrFn; | ||
} else if (typeof optionsOrTest === "function") { | ||
fn = optionsOrTest; | ||
} | ||
return { | ||
options, | ||
handler: fn | ||
}; | ||
} | ||
function createSuiteCollector(name, factory = () => { | ||
}, mode, concurrent, sequential, shuffle, each, suiteOptions) { | ||
}, mode, shuffle, each, suiteOptions) { | ||
const tasks = []; | ||
@@ -327,5 +359,7 @@ const factoryQueue = []; | ||
}; | ||
const test2 = createTest(function(name2, fn = noop, options = {}) { | ||
if (typeof options === "number") | ||
options = { timeout: options }; | ||
const test2 = createTest(function(name2, optionsOrFn, optionsOrTest) { | ||
let { options, handler } = parseArguments( | ||
optionsOrFn, | ||
optionsOrTest | ||
); | ||
if (typeof suiteOptions === "object") | ||
@@ -337,3 +371,3 @@ options = Object.assign({}, suiteOptions, options); | ||
formatName(name2), | ||
{ ...this, ...options, handler: fn } | ||
{ ...this, ...options, handler } | ||
); | ||
@@ -398,7 +432,9 @@ test3.type = "test"; | ||
function createSuite() { | ||
function suiteFn(name, factory, options = {}) { | ||
function suiteFn(name, factoryOrOptions, optionsOrFactory = {}) { | ||
const mode = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run"; | ||
const currentSuite = getCurrentSuite(); | ||
if (typeof options === "number") | ||
options = { timeout: options }; | ||
let { options, handler: factory } = parseArguments( | ||
factoryOrOptions, | ||
optionsOrFactory | ||
); | ||
if (currentSuite == null ? void 0 : currentSuite.options) | ||
@@ -408,3 +444,3 @@ options = { ...currentSuite.options, ...options }; | ||
options.sequential = this.sequential || !this.concurrent && (options == null ? void 0 : options.sequential); | ||
return createSuiteCollector(formatName(name), factory, mode, this.concurrent, this.sequential, this.shuffle, this.each, options); | ||
return createSuiteCollector(formatName(name), factory, mode, this.shuffle, this.each, options); | ||
} | ||
@@ -416,8 +452,12 @@ suiteFn.each = function(cases, ...args) { | ||
cases = formatTemplateString(cases, args); | ||
return (name, fn, options) => { | ||
return (name, optionsOrFn, fnOrOptions) => { | ||
const _name = formatName(name); | ||
const arrayOnlyCases = cases.every(Array.isArray); | ||
const { options, handler } = parseArguments( | ||
optionsOrFn, | ||
fnOrOptions | ||
); | ||
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); | ||
arrayOnlyCases ? suite2(formatTitle(_name, items, idx), options, () => handler(...items)) : suite2(formatTitle(_name, items, idx), options, () => handler(i)); | ||
}); | ||
@@ -441,8 +481,12 @@ this.setContext("each", void 0); | ||
cases = formatTemplateString(cases, args); | ||
return (name, fn2, options) => { | ||
return (name, optionsOrFn, fnOrOptions) => { | ||
const _name = formatName(name); | ||
const arrayOnlyCases = cases.every(Array.isArray); | ||
const { options, handler } = parseArguments( | ||
optionsOrFn, | ||
fnOrOptions | ||
); | ||
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); | ||
arrayOnlyCases ? test2(formatTitle(_name, items, idx), options, () => handler(...items)) : test2(formatTitle(_name, items, idx), options, () => handler(i)); | ||
}); | ||
@@ -460,4 +504,4 @@ this.setContext("each", void 0); | ||
const _context = mergeContextFixtures(fixtures, context); | ||
return createTest(function fn2(name, fn2, options) { | ||
getCurrentSuite().test.fn.call(this, formatName(name), fn2, options); | ||
return createTest(function fn2(name, optionsOrFn, optionsOrTest) { | ||
getCurrentSuite().test.fn.call(this, formatName(name), optionsOrFn, optionsOrTest); | ||
}, _context); | ||
@@ -657,3 +701,3 @@ }; | ||
async function runTest(test, runner) { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
await ((_a = runner.onBeforeRunTask) == null ? void 0 : _a.call(runner, test)); | ||
@@ -730,4 +774,14 @@ if (test.mode !== "run") | ||
} | ||
if (test.result.state === "fail") | ||
await Promise.all(((_f = test.onFailed) == null ? void 0 : _f.map((fn) => fn(test.result))) || []); | ||
try { | ||
await Promise.all(((_f = test.onFinished) == null ? void 0 : _f.map((fn) => fn(test.result))) || []); | ||
} catch (e) { | ||
failTask(test.result, e, runner.config.diffOptions); | ||
} | ||
if (test.result.state === "fail") { | ||
try { | ||
await Promise.all(((_g = test.onFailed) == null ? void 0 : _g.map((fn) => fn(test.result))) || []); | ||
} catch (e) { | ||
failTask(test.result, e, runner.config.diffOptions); | ||
} | ||
} | ||
if (test.fails) { | ||
@@ -745,3 +799,3 @@ if (test.result.state === "pass") { | ||
test.result.duration = now() - start; | ||
await ((_g = runner.onAfterRunTask) == null ? void 0 : _g.call(runner, test)); | ||
await ((_h = runner.onAfterRunTask) == null ? void 0 : _h.call(runner, test)); | ||
updateTask(test, runner); | ||
@@ -892,2 +946,6 @@ } | ||
}); | ||
const onTestFinished = createTestHook("onTestFinished", (test, handler) => { | ||
test.onFinished || (test.onFinished = []); | ||
test.onFinished.push(handler); | ||
}); | ||
function createTestHook(name, handler) { | ||
@@ -898,6 +956,6 @@ return (fn) => { | ||
throw new Error(`Hook ${name}() can only be called inside a test`); | ||
handler(current, fn); | ||
return handler(current, fn); | ||
}; | ||
} | ||
export { afterAll, afterEach, beforeAll, beforeEach, createTaskCollector, describe, getCurrentSuite, getCurrentTest, getFn, getHooks, it, onTestFailed, setFn, setHooks, startTests, suite, test, updateTask }; | ||
export { afterAll, afterEach, beforeAll, beforeEach, createTaskCollector, describe, getCurrentSuite, getCurrentTest, getFn, getHooks, it, onTestFailed, onTestFinished, setFn, setHooks, startTests, suite, test, updateTask }; |
@@ -1,3 +0,3 @@ | ||
import { z as SequenceHooks, A as SequenceSetupFiles, F as File, k as TaskPopulated, S as Suite, n as TaskResultPack, a as Test, C as Custom, y as TaskContext, E as ExtendedContext } from './tasks-rsXe_qLO.js'; | ||
export { g as CustomAPI, D as DoneCallback, r as Fixture, q as FixtureFn, s as Fixtures, t as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, R as RunMode, w as RuntimeContext, d as SuiteAPI, f as SuiteCollector, v as SuiteFactory, h as SuiteHooks, T as Task, j as TaskBase, u as TaskCustomOptions, l as TaskMeta, m as TaskResult, i as TaskState, e as TestAPI, x as TestContext, o as TestFunction, p as TestOptions, U as Use } from './tasks-rsXe_qLO.js'; | ||
import { B as SequenceHooks, G as SequenceSetupFiles, F as File, T as Task, S as Suite, o as TaskResultPack, a as Test, C as Custom, A as TaskContext, E as ExtendedContext } from './tasks-_kyNRBhz.js'; | ||
export { g as CustomAPI, D as DoneCallback, t as Fixture, s as FixtureFn, r as FixtureOptions, u as Fixtures, v as HookCleanupCallback, H as HookListener, I as InferFixturesTypes, O as OnTestFailedHandler, i as OnTestFinishedHandler, R as RunMode, y as RuntimeContext, d as SuiteAPI, f as SuiteCollector, x as SuiteFactory, h as SuiteHooks, k as TaskBase, w as TaskCustomOptions, m as TaskMeta, l as TaskPopulated, n as TaskResult, j as TaskState, e as TestAPI, z as TestContext, p as TestFunction, q as TestOptions, U as Use } from './tasks-_kyNRBhz.js'; | ||
import { DiffOptions } from '@vitest/utils/diff'; | ||
@@ -38,7 +38,7 @@ import '@vitest/utils'; | ||
*/ | ||
onBeforeCollect?(paths: string[]): unknown; | ||
onBeforeCollect?: (paths: string[]) => unknown; | ||
/** | ||
* Called after collecting tests and before "onBeforeRun". | ||
*/ | ||
onCollected?(files: File[]): unknown; | ||
onCollected?: (files: File[]) => unknown; | ||
/** | ||
@@ -49,33 +49,33 @@ * Called when test runner should cancel next test runs. | ||
*/ | ||
onCancel?(reason: CancelReason): unknown; | ||
onCancel?: (reason: CancelReason) => unknown; | ||
/** | ||
* Called before running a single test. Doesn't have "result" yet. | ||
*/ | ||
onBeforeRunTask?(test: TaskPopulated): unknown; | ||
onBeforeRunTask?: (test: Task) => unknown; | ||
/** | ||
* Called before actually running the test function. Already has "result" with "state" and "startTime". | ||
*/ | ||
onBeforeTryTask?(test: TaskPopulated, options: { | ||
onBeforeTryTask?: (test: Task, options: { | ||
retry: number; | ||
repeats: number; | ||
}): unknown; | ||
}) => unknown; | ||
/** | ||
* Called after result and state are set. | ||
*/ | ||
onAfterRunTask?(test: TaskPopulated): unknown; | ||
onAfterRunTask?: (test: Task) => unknown; | ||
/** | ||
* Called right after running the test function. Doesn't have new state yet. Will not be called, if the test function throws. | ||
*/ | ||
onAfterTryTask?(test: TaskPopulated, options: { | ||
onAfterTryTask?: (test: Task, options: { | ||
retry: number; | ||
repeats: number; | ||
}): unknown; | ||
}) => unknown; | ||
/** | ||
* Called before running a single suite. Doesn't have "result" yet. | ||
*/ | ||
onBeforeRunSuite?(suite: Suite): unknown; | ||
onBeforeRunSuite?: (suite: Suite) => unknown; | ||
/** | ||
* Called after running a single suite. Has state and result. | ||
*/ | ||
onAfterRunSuite?(suite: Suite): unknown; | ||
onAfterRunSuite?: (suite: Suite) => unknown; | ||
/** | ||
@@ -85,3 +85,3 @@ * If defined, will be called instead of usual Vitest suite partition and handling. | ||
*/ | ||
runSuite?(suite: Suite): Promise<void>; | ||
runSuite?: (suite: Suite) => Promise<void>; | ||
/** | ||
@@ -91,15 +91,15 @@ * If defined, will be called instead of usual Vitest handling. Useful, if you have your custom test function. | ||
*/ | ||
runTask?(test: TaskPopulated): Promise<void>; | ||
runTask?: (test: Task) => Promise<void>; | ||
/** | ||
* Called, when a task is updated. The same as "onTaskUpdate" in a reporter, but this is running in the same thread as tests. | ||
*/ | ||
onTaskUpdate?(task: TaskResultPack[]): Promise<void>; | ||
onTaskUpdate?: (task: TaskResultPack[]) => Promise<void>; | ||
/** | ||
* Called before running all tests in collected paths. | ||
*/ | ||
onBeforeRunFiles?(files: File[]): unknown; | ||
onBeforeRunFiles?: (files: File[]) => unknown; | ||
/** | ||
* Called right after running all tests in collected paths. | ||
*/ | ||
onAfterRunFiles?(files: File[]): unknown; | ||
onAfterRunFiles?: (files: File[]) => unknown; | ||
/** | ||
@@ -113,7 +113,7 @@ * Called when new context for a test is defined. Useful, if you want to add custom properties to the context. | ||
*/ | ||
extendTaskContext?<T extends Test | Custom>(context: TaskContext<T>): ExtendedContext<T>; | ||
extendTaskContext?: <T extends Test | Custom>(context: TaskContext<T>) => ExtendedContext<T>; | ||
/** | ||
* Called, when files are imported. Can be called in two situations: when collecting tests and when importing setup files. | ||
*/ | ||
importFile(filepath: string, source: VitestRunnerImportSource): unknown; | ||
importFile: (filepath: string, source: VitestRunnerImportSource) => unknown; | ||
/** | ||
@@ -125,2 +125,2 @@ * Publicly available configuration. | ||
export { type CancelReason, Custom, ExtendedContext, File, SequenceHooks, SequenceSetupFiles, Suite, TaskContext, TaskPopulated, TaskResultPack, Test, type VitestRunner, type VitestRunnerConfig, type VitestRunnerConstructor, type VitestRunnerImportSource }; | ||
export { type CancelReason, Custom, ExtendedContext, File, SequenceHooks, SequenceSetupFiles, Suite, Task, TaskContext, TaskResultPack, Test, type VitestRunner, type VitestRunnerConfig, type VitestRunnerConstructor, type VitestRunnerImportSource }; |
@@ -1,3 +0,3 @@ | ||
import { S as Suite, T as Task, a as Test, C as Custom } from './tasks-rsXe_qLO.js'; | ||
export { b as ChainableFunction, c as createChainable } from './tasks-rsXe_qLO.js'; | ||
import { S as Suite, T as Task, a as Test, C as Custom } from './tasks-_kyNRBhz.js'; | ||
export { b as ChainableFunction, c as createChainable } from './tasks-_kyNRBhz.js'; | ||
import { Arrayable } from '@vitest/utils'; | ||
@@ -4,0 +4,0 @@ |
@@ -1,168 +0,3 @@ | ||
import { processError } from '@vitest/utils/error'; | ||
import { toArray } from '@vitest/utils'; | ||
function partitionSuiteChildren(suite) { | ||
let tasksGroup = []; | ||
const tasksGroups = []; | ||
for (const c of suite.tasks) { | ||
if (tasksGroup.length === 0 || c.concurrent === tasksGroup[0].concurrent) { | ||
tasksGroup.push(c); | ||
} else { | ||
tasksGroups.push(tasksGroup); | ||
tasksGroup = [c]; | ||
} | ||
} | ||
if (tasksGroup.length > 0) | ||
tasksGroups.push(tasksGroup); | ||
return tasksGroups; | ||
} | ||
function interpretTaskModes(suite, namePattern, onlyMode, parentIsOnly, allowOnly) { | ||
const suiteIsOnly = parentIsOnly || suite.mode === "only"; | ||
suite.tasks.forEach((t) => { | ||
const includeTask = suiteIsOnly || t.mode === "only"; | ||
if (onlyMode) { | ||
if (t.type === "suite" && (includeTask || someTasksAreOnly(t))) { | ||
if (t.mode === "only") { | ||
checkAllowOnly(t, allowOnly); | ||
t.mode = "run"; | ||
} | ||
} else if (t.mode === "run" && !includeTask) { | ||
t.mode = "skip"; | ||
} else if (t.mode === "only") { | ||
checkAllowOnly(t, allowOnly); | ||
t.mode = "run"; | ||
} | ||
} | ||
if (t.type === "test") { | ||
if (namePattern && !getTaskFullName(t).match(namePattern)) | ||
t.mode = "skip"; | ||
} else if (t.type === "suite") { | ||
if (t.mode === "skip") | ||
skipAllTasks(t); | ||
else | ||
interpretTaskModes(t, namePattern, onlyMode, includeTask, allowOnly); | ||
} | ||
}); | ||
if (suite.mode === "run") { | ||
if (suite.tasks.length && suite.tasks.every((i) => i.mode !== "run")) | ||
suite.mode = "skip"; | ||
} | ||
} | ||
function getTaskFullName(task) { | ||
return `${task.suite ? `${getTaskFullName(task.suite)} ` : ""}${task.name}`; | ||
} | ||
function someTasksAreOnly(suite) { | ||
return suite.tasks.some((t) => t.mode === "only" || t.type === "suite" && someTasksAreOnly(t)); | ||
} | ||
function skipAllTasks(suite) { | ||
suite.tasks.forEach((t) => { | ||
if (t.mode === "run") { | ||
t.mode = "skip"; | ||
if (t.type === "suite") | ||
skipAllTasks(t); | ||
} | ||
}); | ||
} | ||
function checkAllowOnly(task, allowOnly) { | ||
if (allowOnly) | ||
return; | ||
const error = processError(new Error("[Vitest] Unexpected .only modifier. Remove it or pass --allowOnly argument to bypass this error")); | ||
task.result = { | ||
state: "fail", | ||
errors: [error] | ||
}; | ||
} | ||
function generateHash(str) { | ||
let hash = 0; | ||
if (str.length === 0) | ||
return `${hash}`; | ||
for (let i = 0; i < str.length; i++) { | ||
const char = str.charCodeAt(i); | ||
hash = (hash << 5) - hash + char; | ||
hash = hash & hash; | ||
} | ||
return `${hash}`; | ||
} | ||
function calculateSuiteHash(parent) { | ||
parent.tasks.forEach((t, idx) => { | ||
t.id = `${parent.id}_${idx}`; | ||
if (t.type === "suite") | ||
calculateSuiteHash(t); | ||
}); | ||
} | ||
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); | ||
chain2.setContext = (key, value) => { | ||
context[key] = value; | ||
}; | ||
chain2.mergeContext = (ctx) => { | ||
Object.assign(context, ctx); | ||
}; | ||
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 isAtomTest(s) { | ||
return s.type === "test" || s.type === "custom"; | ||
} | ||
function getTests(suite) { | ||
const tests = []; | ||
const arraySuites = toArray(suite); | ||
for (const s of arraySuites) { | ||
if (isAtomTest(s)) { | ||
tests.push(s); | ||
} else { | ||
for (const task of s.tasks) { | ||
if (isAtomTest(task)) | ||
tests.push(task); | ||
else | ||
tests.push(...getTests(task)); | ||
} | ||
} | ||
} | ||
return tests; | ||
} | ||
function getTasks(tasks = []) { | ||
return toArray(tasks).flatMap((s) => isAtomTest(s) ? [s] : [s, ...getTasks(s.tasks)]); | ||
} | ||
function getSuites(suite) { | ||
return toArray(suite).flatMap((s) => s.type === "suite" ? [s, ...getSuites(s.tasks)] : []); | ||
} | ||
function hasTests(suite) { | ||
return toArray(suite).some((s) => s.tasks.some((c) => isAtomTest(c) || hasTests(c))); | ||
} | ||
function hasFailed(suite) { | ||
return toArray(suite).some((s) => { | ||
var _a; | ||
return ((_a = s.result) == null ? void 0 : _a.state) === "fail" || s.type === "suite" && hasFailed(s.tasks); | ||
}); | ||
} | ||
function getNames(task) { | ||
const names = [task.name]; | ||
let current = task; | ||
while ((current == null ? void 0 : current.suite) || (current == null ? void 0 : current.file)) { | ||
current = current.suite || current.file; | ||
if (current == null ? void 0 : current.name) | ||
names.unshift(current.name); | ||
} | ||
return names; | ||
} | ||
export { calculateSuiteHash, createChainable, generateHash, getNames, getSuites, getTasks, getTests, hasFailed, hasTests, interpretTaskModes, partitionSuiteChildren, someTasksAreOnly }; | ||
export { c as calculateSuiteHash, j as createChainable, g as generateHash, f as getNames, d as getSuites, b as getTasks, a as getTests, e as hasFailed, h as hasTests, i as interpretTaskModes, p as partitionSuiteChildren, s as someTasksAreOnly } from './chunk-tasks.js'; | ||
import '@vitest/utils/error'; | ||
import '@vitest/utils'; |
{ | ||
"name": "@vitest/runner", | ||
"type": "module", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"description": "Vitest test runner", | ||
@@ -43,3 +43,3 @@ "license": "MIT", | ||
"pathe": "^1.1.1", | ||
"@vitest/utils": "1.2.2" | ||
"@vitest/utils": "1.3.0" | ||
}, | ||
@@ -46,0 +46,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61594
13
1545
1
+ Added@vitest/utils@1.3.0(transitive)
- Removed@vitest/utils@1.2.2(transitive)
Updated@vitest/utils@1.3.0