@vitest/runner 0.30.0 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import { V as VitestRunner } from './runner-
|
2
|
-
export { a as VitestRunnerConfig, c as VitestRunnerConstructor, b as VitestRunnerImportSource } from './runner-
|
3
|
-
import { T as Task, F as File, S as SuiteAPI, a as TestAPI, b as SuiteCollector, c as SuiteHooks, O as OnTestFailedHandler, d as Test } from './tasks-
|
4
|
-
export { D as DoneCallback, m as HookCleanupCallback, H as HookListener, R as RunMode, o as RuntimeContext, q as SequenceHooks, r as SequenceSetupFiles, j as Suite, n as SuiteFactory, f as TaskBase, g as TaskCustom, h as TaskResult, i as TaskResultPack, e as TaskState, p as TestContext, k as TestFunction, l as TestOptions } from './tasks-
|
1
|
+
import { V as VitestRunner } from './runner-7aa38127.js';
|
2
|
+
export { C as CancelReason, a as VitestRunnerConfig, c as VitestRunnerConstructor, b as VitestRunnerImportSource } from './runner-7aa38127.js';
|
3
|
+
import { T as Task, F as File, S as SuiteAPI, a as TestAPI, b as SuiteCollector, c as SuiteHooks, O as OnTestFailedHandler, d as Test } from './tasks-2a410173.js';
|
4
|
+
export { D as DoneCallback, m as HookCleanupCallback, H as HookListener, R as RunMode, o as RuntimeContext, q as SequenceHooks, r as SequenceSetupFiles, j as Suite, n as SuiteFactory, f as TaskBase, g as TaskCustom, h as TaskResult, i as TaskResultPack, e as TaskState, p as TestContext, k as TestFunction, l as TestOptions } from './tasks-2a410173.js';
|
5
5
|
import { Awaitable } from '@vitest/utils';
|
6
6
|
|
7
7
|
declare function updateTask(task: Task, runner: VitestRunner): void;
|
package/dist/index.js
CHANGED
@@ -110,6 +110,12 @@ function createSuiteCollector(name, factory = () => {
|
|
110
110
|
const mode2 = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
|
111
111
|
if (typeof options === "number")
|
112
112
|
options = { timeout: options };
|
113
|
+
if (typeof suiteOptions === "object") {
|
114
|
+
options = {
|
115
|
+
...suiteOptions,
|
116
|
+
...options
|
117
|
+
};
|
118
|
+
}
|
113
119
|
const test3 = {
|
114
120
|
id: "",
|
115
121
|
type: "test",
|
@@ -117,7 +123,8 @@ function createSuiteCollector(name, factory = () => {
|
|
117
123
|
mode: mode2,
|
118
124
|
suite: void 0,
|
119
125
|
fails: this.fails,
|
120
|
-
retry: options == null ? void 0 : options.retry
|
126
|
+
retry: options == null ? void 0 : options.retry,
|
127
|
+
repeats: options == null ? void 0 : options.repeats
|
121
128
|
};
|
122
129
|
if (this.concurrent || concurrent)
|
123
130
|
test3.concurrent = true;
|
@@ -160,6 +167,8 @@ function createSuiteCollector(name, factory = () => {
|
|
160
167
|
getHooks(suite2)[name2].push(...fn);
|
161
168
|
}
|
162
169
|
function initSuite() {
|
170
|
+
if (typeof suiteOptions === "number")
|
171
|
+
suiteOptions = { timeout: suiteOptions };
|
163
172
|
suite2 = {
|
164
173
|
id: "",
|
165
174
|
type: "suite",
|
@@ -248,7 +257,10 @@ function formatTitle(template, items, idx) {
|
|
248
257
|
if (isObject(items[0])) {
|
249
258
|
formatted = formatted.replace(
|
250
259
|
/\$([$\w_.]+)/g,
|
251
|
-
(_, key) =>
|
260
|
+
(_, key) => {
|
261
|
+
var _a;
|
262
|
+
return objDisplay(objectAttr(items[0], key), (_a = runner == null ? void 0 : runner.config) == null ? void 0 : _a.chaiConfig);
|
263
|
+
}
|
252
264
|
// https://github.com/chaijs/chai/pull/1490
|
253
265
|
);
|
254
266
|
}
|
@@ -430,41 +442,48 @@ async function runTest(test, runner) {
|
|
430
442
|
};
|
431
443
|
updateTask(test, runner);
|
432
444
|
setCurrentTest(test);
|
433
|
-
const
|
434
|
-
for (let
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
445
|
+
const repeats = typeof test.repeats === "number" ? test.repeats : 1;
|
446
|
+
for (let repeatCount = 0; repeatCount < repeats; repeatCount++) {
|
447
|
+
const retry = test.retry || 1;
|
448
|
+
for (let retryCount = 0; retryCount < retry; retryCount++) {
|
449
|
+
let beforeEachCleanups = [];
|
450
|
+
try {
|
451
|
+
await ((_c = runner.onBeforeTryTest) == null ? void 0 : _c.call(runner, test, { retry: retryCount, repeats: repeatCount }));
|
452
|
+
test.result.retryCount = retryCount;
|
453
|
+
test.result.repeatCount = repeatCount;
|
454
|
+
beforeEachCleanups = await callSuiteHook(test.suite, test, "beforeEach", runner, [test.context, test.suite]);
|
455
|
+
if (runner.runTest) {
|
456
|
+
await runner.runTest(test);
|
457
|
+
} else {
|
458
|
+
const fn = getFn(test);
|
459
|
+
if (!fn)
|
460
|
+
throw new Error("Test function is not found. Did you add it using `setFn`?");
|
461
|
+
await fn();
|
462
|
+
}
|
463
|
+
if (test.promises) {
|
464
|
+
const result = await Promise.allSettled(test.promises);
|
465
|
+
const errors = result.map((r) => r.status === "rejected" ? r.reason : void 0).filter(Boolean);
|
466
|
+
if (errors.length)
|
467
|
+
throw errors;
|
468
|
+
}
|
469
|
+
await ((_d = runner.onAfterTryTest) == null ? void 0 : _d.call(runner, test, { retry: retryCount, repeats: repeatCount }));
|
470
|
+
if (!test.repeats)
|
471
|
+
test.result.state = "pass";
|
472
|
+
else if (test.repeats && retry === retryCount)
|
473
|
+
test.result.state = "pass";
|
474
|
+
} catch (e) {
|
475
|
+
failTask(test.result, e);
|
447
476
|
}
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
477
|
+
try {
|
478
|
+
await callSuiteHook(test.suite, test, "afterEach", runner, [test.context, test.suite]);
|
479
|
+
await callCleanupHooks(beforeEachCleanups);
|
480
|
+
} catch (e) {
|
481
|
+
failTask(test.result, e);
|
453
482
|
}
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
failTask(test.result, e);
|
483
|
+
if (test.result.state === "pass")
|
484
|
+
break;
|
485
|
+
updateTask(test, runner);
|
458
486
|
}
|
459
|
-
try {
|
460
|
-
await callSuiteHook(test.suite, test, "afterEach", runner, [test.context, test.suite]);
|
461
|
-
await callCleanupHooks(beforeEachCleanups);
|
462
|
-
} catch (e) {
|
463
|
-
failTask(test.result, e);
|
464
|
-
}
|
465
|
-
if (test.result.state === "pass")
|
466
|
-
break;
|
467
|
-
updateTask(test, runner);
|
468
487
|
}
|
469
488
|
if (test.result.state === "fail")
|
470
489
|
await Promise.all(((_e = test.onFailed) == null ? void 0 : _e.map((fn) => fn(test.result))) || []);
|
@@ -555,24 +574,24 @@ async function runSuite(suite, runner) {
|
|
555
574
|
} catch (e) {
|
556
575
|
failTask(suite.result, e);
|
557
576
|
}
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
577
|
+
if (suite.mode === "run") {
|
578
|
+
if (!hasTests(suite)) {
|
579
|
+
suite.result.state = "fail";
|
580
|
+
if (!suite.result.error) {
|
581
|
+
const error = processError(new Error(`No test found in suite ${suite.name}`));
|
582
|
+
suite.result.error = error;
|
583
|
+
suite.result.errors = [error];
|
584
|
+
}
|
585
|
+
} else if (hasFailed(suite)) {
|
586
|
+
suite.result.state = "fail";
|
587
|
+
} else {
|
588
|
+
suite.result.state = "pass";
|
567
589
|
}
|
568
|
-
} else if (hasFailed(suite)) {
|
569
|
-
suite.result.state = "fail";
|
570
|
-
} else {
|
571
|
-
suite.result.state = "pass";
|
572
590
|
}
|
591
|
+
updateTask(suite, runner);
|
592
|
+
suite.result.duration = now() - start;
|
593
|
+
await ((_c = runner.onAfterRunSuite) == null ? void 0 : _c.call(runner, suite));
|
573
594
|
}
|
574
|
-
await ((_c = runner.onAfterRunSuite) == null ? void 0 : _c.call(runner, suite));
|
575
|
-
updateTask(suite, runner);
|
576
595
|
}
|
577
596
|
async function runSuiteChild(c, runner) {
|
578
597
|
if (c.type === "test")
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { q as SequenceHooks, r as SequenceSetupFiles, F as File, d as Test, j as Suite, h as TaskResult, p as TestContext } from './tasks-
|
1
|
+
import { q as SequenceHooks, r as SequenceSetupFiles, F as File, d as Test, j as Suite, h as TaskResult, p as TestContext } from './tasks-2a410173.js';
|
2
2
|
|
3
3
|
interface VitestRunnerConfig {
|
4
4
|
root: string;
|
@@ -13,6 +13,9 @@ interface VitestRunnerConfig {
|
|
13
13
|
hooks: SequenceHooks;
|
14
14
|
setupFiles: SequenceSetupFiles;
|
15
15
|
};
|
16
|
+
chaiConfig?: {
|
17
|
+
truncateThreshold?: number;
|
18
|
+
};
|
16
19
|
maxConcurrency: number;
|
17
20
|
testTimeout: number;
|
18
21
|
hookTimeout: number;
|
@@ -21,6 +24,7 @@ type VitestRunnerImportSource = 'collect' | 'setup';
|
|
21
24
|
interface VitestRunnerConstructor {
|
22
25
|
new (config: VitestRunnerConfig): VitestRunner;
|
23
26
|
}
|
27
|
+
type CancelReason = 'keyboard-input' | 'test-failure' | string & {};
|
24
28
|
interface VitestRunner {
|
25
29
|
/**
|
26
30
|
* First thing that's getting called before actually collecting and running tests.
|
@@ -30,6 +34,12 @@ interface VitestRunner {
|
|
30
34
|
* Called after collecting tests and before "onBeforeRun".
|
31
35
|
*/
|
32
36
|
onCollected?(files: File[]): unknown;
|
37
|
+
/**
|
38
|
+
* Called when test runner should cancel next test runs.
|
39
|
+
* Runner should listen for this method and mark tests and suites as skipped in
|
40
|
+
* "onBeforeRunSuite" and "onBeforeRunTest" when called.
|
41
|
+
*/
|
42
|
+
onCancel?(reason: CancelReason): unknown;
|
33
43
|
/**
|
34
44
|
* Called before running a single test. Doesn't have "result" yet.
|
35
45
|
*/
|
@@ -37,7 +47,10 @@ interface VitestRunner {
|
|
37
47
|
/**
|
38
48
|
* Called before actually running the test function. Already has "result" with "state" and "startTime".
|
39
49
|
*/
|
40
|
-
onBeforeTryTest?(test: Test,
|
50
|
+
onBeforeTryTest?(test: Test, options: {
|
51
|
+
retry: number;
|
52
|
+
repeats: number;
|
53
|
+
}): unknown;
|
41
54
|
/**
|
42
55
|
* Called after result and state are set.
|
43
56
|
*/
|
@@ -45,7 +58,10 @@ interface VitestRunner {
|
|
45
58
|
/**
|
46
59
|
* Called right after running the test function. Doesn't have new state yet. Will not be called, if the test function throws.
|
47
60
|
*/
|
48
|
-
onAfterTryTest?(test: Test,
|
61
|
+
onAfterTryTest?(test: Test, options: {
|
62
|
+
retry: number;
|
63
|
+
repeats: number;
|
64
|
+
}): unknown;
|
49
65
|
/**
|
50
66
|
* Called before running a single suite. Doesn't have "result" yet.
|
51
67
|
*/
|
@@ -91,4 +107,4 @@ interface VitestRunner {
|
|
91
107
|
config: VitestRunnerConfig;
|
92
108
|
}
|
93
109
|
|
94
|
-
export { VitestRunner as V, VitestRunnerConfig as a, VitestRunnerImportSource as b, VitestRunnerConstructor as c };
|
110
|
+
export { CancelReason as C, VitestRunner as V, VitestRunnerConfig as a, VitestRunnerImportSource as b, VitestRunnerConstructor as c };
|
@@ -22,6 +22,7 @@ interface TaskBase {
|
|
22
22
|
result?: TaskResult;
|
23
23
|
retry?: number;
|
24
24
|
meta?: any;
|
25
|
+
repeats?: number;
|
25
26
|
}
|
26
27
|
interface TaskCustom extends TaskBase {
|
27
28
|
type: 'custom';
|
@@ -39,6 +40,7 @@ interface TaskResult {
|
|
39
40
|
htmlError?: string;
|
40
41
|
hooks?: Partial<Record<keyof SuiteHooks, TaskState>>;
|
41
42
|
retryCount?: number;
|
43
|
+
repeatCount?: number;
|
42
44
|
}
|
43
45
|
type TaskResultPack = [id: string, result: TaskResult | undefined];
|
44
46
|
interface Suite extends TaskBase {
|
@@ -111,6 +113,12 @@ interface TestOptions {
|
|
111
113
|
* @default 1
|
112
114
|
*/
|
113
115
|
retry?: number;
|
116
|
+
/**
|
117
|
+
* How many times the test will repeat.
|
118
|
+
*
|
119
|
+
* @default 5
|
120
|
+
*/
|
121
|
+
repeats?: number;
|
114
122
|
}
|
115
123
|
type TestAPI<ExtraContext = {}> = ChainableTestAPI<ExtraContext> & {
|
116
124
|
each: TestEachFunction;
|
package/dist/types.d.ts
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
export { D as DoneCallback, F as File, m as HookCleanupCallback, H as HookListener, O as OnTestFailedHandler, R as RunMode, o as RuntimeContext, q as SequenceHooks, r as SequenceSetupFiles, j as Suite, S as SuiteAPI, b as SuiteCollector, n as SuiteFactory, c as SuiteHooks, T as Task, f as TaskBase, g as TaskCustom, h as TaskResult, i as TaskResultPack, e as TaskState, d as Test, a as TestAPI, p as TestContext, k as TestFunction, l as TestOptions } from './tasks-
|
2
|
-
export { V as VitestRunner, a as VitestRunnerConfig, c as VitestRunnerConstructor, b as VitestRunnerImportSource } from './runner-
|
1
|
+
export { D as DoneCallback, F as File, m as HookCleanupCallback, H as HookListener, O as OnTestFailedHandler, R as RunMode, o as RuntimeContext, q as SequenceHooks, r as SequenceSetupFiles, j as Suite, S as SuiteAPI, b as SuiteCollector, n as SuiteFactory, c as SuiteHooks, T as Task, f as TaskBase, g as TaskCustom, h as TaskResult, i as TaskResultPack, e as TaskState, d as Test, a as TestAPI, p as TestContext, k as TestFunction, l as TestOptions } from './tasks-2a410173.js';
|
2
|
+
export { C as CancelReason, V as VitestRunner, a as VitestRunnerConfig, c as VitestRunnerConstructor, b as VitestRunnerImportSource } from './runner-7aa38127.js';
|
3
3
|
import '@vitest/utils';
|
package/dist/utils.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { j as Suite, T as Task, d as Test, g as TaskCustom } from './tasks-
|
2
|
-
export { C as ChainableFunction, s as createChainable } from './tasks-
|
1
|
+
import { j as Suite, T as Task, d as Test, g as TaskCustom } from './tasks-2a410173.js';
|
2
|
+
export { C as ChainableFunction, s as createChainable } from './tasks-2a410173.js';
|
3
3
|
import { Arrayable } from '@vitest/utils';
|
4
4
|
export { ErrorWithDiff, ParsedStack } from '@vitest/utils';
|
5
5
|
import { DiffOptions } from '@vitest/utils/diff';
|
package/package.json
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/runner",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.31.0",
|
5
5
|
"description": "Vitest test runner",
|
6
6
|
"license": "MIT",
|
7
|
+
"funding": "https://opencollective.com/vitest",
|
8
|
+
"homepage": "https://github.com/vitest-dev/vitest/tree/main/packages/runner#readme",
|
7
9
|
"repository": {
|
8
10
|
"type": "git",
|
9
11
|
"url": "git+https://github.com/vitest-dev/vitest.git",
|
10
12
|
"directory": "packages/runner"
|
11
13
|
},
|
14
|
+
"bugs": {
|
15
|
+
"url": "https://github.com/vitest-dev/vitest/issues"
|
16
|
+
},
|
12
17
|
"sideEffects": true,
|
13
18
|
"exports": {
|
14
19
|
".": {
|
@@ -36,7 +41,7 @@
|
|
36
41
|
"concordance": "^5.0.4",
|
37
42
|
"p-limit": "^4.0.0",
|
38
43
|
"pathe": "^1.1.0",
|
39
|
-
"@vitest/utils": "0.
|
44
|
+
"@vitest/utils": "0.31.0"
|
40
45
|
},
|
41
46
|
"scripts": {
|
42
47
|
"build": "rimraf dist && rollup -c",
|