@vitest/runner
Advanced tools
Comparing version 0.34.1 to 0.34.2
@@ -22,2 +22,12 @@ import limit from 'p-limit'; | ||
class PendingError extends Error { | ||
constructor(message, task) { | ||
super(message); | ||
this.message = message; | ||
this.taskId = task.id; | ||
} | ||
code = "VITEST_PENDING"; | ||
taskId; | ||
} | ||
const collectorContext = { | ||
@@ -59,2 +69,6 @@ tasks: [], | ||
context.task = test; | ||
context.skip = () => { | ||
test.pending = true; | ||
throw new PendingError("test is skipped; abort execution", test); | ||
}; | ||
context.onTestFailed = (fn) => { | ||
@@ -570,3 +584,3 @@ test.onFailed || (test.onFailed = []); | ||
async function runTest(test, runner) { | ||
var _a, _b, _c, _d, _e, _f; | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
await ((_a = runner.onBeforeRunTest) == null ? void 0 : _a.call(runner, test)); | ||
@@ -620,2 +634,8 @@ if (test.mode !== "run") | ||
} | ||
if (test.pending || ((_e = test.result) == null ? void 0 : _e.state) === "skip") { | ||
test.mode = "skip"; | ||
test.result = { state: "skip" }; | ||
updateTask(test, runner); | ||
return; | ||
} | ||
try { | ||
@@ -637,3 +657,3 @@ await callSuiteHook(test.suite, test, "afterEach", runner, [test.context, test.suite]); | ||
if (test.result.state === "fail") | ||
await Promise.all(((_e = test.onFailed) == null ? void 0 : _e.map((fn) => fn(test.result))) || []); | ||
await Promise.all(((_f = test.onFailed) == null ? void 0 : _f.map((fn) => fn(test.result))) || []); | ||
if (test.fails) { | ||
@@ -653,6 +673,10 @@ if (test.result.state === "pass") { | ||
test.result.duration = now() - start; | ||
await ((_f = runner.onAfterRunTest) == null ? void 0 : _f.call(runner, test)); | ||
await ((_g = runner.onAfterRunTest) == null ? void 0 : _g.call(runner, test)); | ||
updateTask(test, runner); | ||
} | ||
function failTask(result, err) { | ||
if (err instanceof PendingError) { | ||
result.state = "skip"; | ||
return; | ||
} | ||
result.state = "fail"; | ||
@@ -659,0 +683,0 @@ const errors = Array.isArray(err) ? err : [err]; |
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-abce80cc.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-abce80cc.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 { Awaitable } from '@vitest/utils'; | ||
@@ -6,0 +6,0 @@ |
@@ -22,2 +22,12 @@ import limit from 'p-limit'; | ||
class PendingError extends Error { | ||
constructor(message, task) { | ||
super(message); | ||
this.message = message; | ||
this.taskId = task.id; | ||
} | ||
code = "VITEST_PENDING"; | ||
taskId; | ||
} | ||
const collectorContext = { | ||
@@ -59,2 +69,6 @@ tasks: [], | ||
context.task = test; | ||
context.skip = () => { | ||
test.pending = true; | ||
throw new PendingError("test is skipped; abort execution", test); | ||
}; | ||
context.onTestFailed = (fn) => { | ||
@@ -570,3 +584,3 @@ test.onFailed || (test.onFailed = []); | ||
async function runTest(test, runner) { | ||
var _a, _b, _c, _d, _e, _f; | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
await ((_a = runner.onBeforeRunTest) == null ? void 0 : _a.call(runner, test)); | ||
@@ -620,2 +634,8 @@ if (test.mode !== "run") | ||
} | ||
if (test.pending || ((_e = test.result) == null ? void 0 : _e.state) === "skip") { | ||
test.mode = "skip"; | ||
test.result = { state: "skip" }; | ||
updateTask(test, runner); | ||
return; | ||
} | ||
try { | ||
@@ -637,3 +657,3 @@ await callSuiteHook(test.suite, test, "afterEach", runner, [test.context, test.suite]); | ||
if (test.result.state === "fail") | ||
await Promise.all(((_e = test.onFailed) == null ? void 0 : _e.map((fn) => fn(test.result))) || []); | ||
await Promise.all(((_f = test.onFailed) == null ? void 0 : _f.map((fn) => fn(test.result))) || []); | ||
if (test.fails) { | ||
@@ -653,6 +673,10 @@ if (test.result.state === "pass") { | ||
test.result.duration = now() - start; | ||
await ((_f = runner.onAfterRunTest) == null ? void 0 : _f.call(runner, test)); | ||
await ((_g = runner.onAfterRunTest) == null ? void 0 : _g.call(runner, test)); | ||
updateTask(test, runner); | ||
} | ||
function failTask(result, err) { | ||
if (err instanceof PendingError) { | ||
result.state = "skip"; | ||
return; | ||
} | ||
result.state = "fail"; | ||
@@ -659,0 +683,0 @@ const errors = Array.isArray(err) ? err : [err]; |
@@ -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-abce80cc.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-abce80cc.js'; | ||
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 '@vitest/utils'; | ||
@@ -4,0 +4,0 @@ |
@@ -1,3 +0,3 @@ | ||
import { S as Suite, T as Task, a as Test, b as TaskCustom } from './tasks-abce80cc.js'; | ||
export { C as ChainableFunction, c as createChainable } from './tasks-abce80cc.js'; | ||
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 { Arrayable } from '@vitest/utils'; | ||
@@ -4,0 +4,0 @@ |
@@ -127,3 +127,17 @@ import { processError } from '@vitest/utils/error'; | ||
function getTests(suite) { | ||
return toArray(suite).flatMap((s) => isAtomTest(s) ? [s] : s.tasks.flatMap((c) => isAtomTest(c) ? [c] : getTests(c))); | ||
const tests = []; | ||
const suite_arr = toArray(suite); | ||
for (const s of suite_arr) { | ||
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; | ||
} | ||
@@ -130,0 +144,0 @@ function getTasks(tasks = []) { |
{ | ||
"name": "@vitest/runner", | ||
"type": "module", | ||
"version": "0.34.1", | ||
"version": "0.34.2", | ||
"description": "Vitest test runner", | ||
@@ -43,3 +43,3 @@ "license": "MIT", | ||
"pathe": "^1.1.1", | ||
"@vitest/utils": "0.34.1" | ||
"@vitest/utils": "0.34.2" | ||
}, | ||
@@ -46,0 +46,0 @@ "scripts": { |
78290
2154
+ Added@vitest/utils@0.34.2(transitive)
- Removed@vitest/utils@0.34.1(transitive)
Updated@vitest/utils@0.34.2