@vitest/runner 0.34.6 → 1.0.0-beta.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 +7 -6
- package/dist/index.js +62 -61
- package/dist/{tasks-e594cd24.d.ts → tasks-b31a73cb.d.ts} +70 -32
- package/dist/types.d.ts +16 -12
- package/dist/utils.d.ts +3 -3
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { VitestRunner } from './types.js';
|
2
2
|
export { CancelReason, VitestRunnerConfig, VitestRunnerConstructor, VitestRunnerImportSource } from './types.js';
|
3
|
-
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-
|
4
|
-
export { D as DoneCallback,
|
3
|
+
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';
|
4
|
+
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';
|
5
5
|
import { Awaitable } from '@vitest/utils';
|
6
6
|
|
7
7
|
declare function updateTask(task: Task, runner: VitestRunner): void;
|
@@ -12,6 +12,7 @@ declare const test: TestAPI;
|
|
12
12
|
declare const describe: SuiteAPI;
|
13
13
|
declare const it: TestAPI;
|
14
14
|
declare function getCurrentSuite<ExtraContext = {}>(): SuiteCollector<ExtraContext>;
|
15
|
+
declare function createTaskCollector(fn: (...args: any[]) => any, context?: Record<string, unknown>): CustomAPI;
|
15
16
|
|
16
17
|
declare function beforeAll(fn: SuiteHooks['beforeAll'][0], timeout?: number): void;
|
17
18
|
declare function afterAll(fn: SuiteHooks['afterAll'][0], timeout?: number): void;
|
@@ -19,9 +20,9 @@ declare function beforeEach<ExtraContext = {}>(fn: SuiteHooks<ExtraContext>['bef
|
|
19
20
|
declare function afterEach<ExtraContext = {}>(fn: SuiteHooks<ExtraContext>['afterEach'][0], timeout?: number): void;
|
20
21
|
declare const onTestFailed: (fn: OnTestFailedHandler) => void;
|
21
22
|
|
22
|
-
declare function setFn(key: Test, fn: (() => Awaitable<void>)): void;
|
23
|
-
declare function getFn<Task = Test>(key: Task): (() => Awaitable<void>);
|
23
|
+
declare function setFn(key: Test | Custom, fn: (() => Awaitable<void>)): void;
|
24
|
+
declare function getFn<Task = Test | Custom>(key: Task): (() => Awaitable<void>);
|
24
25
|
|
25
|
-
declare function getCurrentTest
|
26
|
+
declare function getCurrentTest<T extends Test | Custom | undefined>(): T;
|
26
27
|
|
27
|
-
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 };
|
28
|
+
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 };
|
package/dist/index.js
CHANGED
@@ -70,7 +70,6 @@ function createTestContext(test, runner) {
|
|
70
70
|
const context = function() {
|
71
71
|
throw new Error("done() callback is deprecated, use promise instead");
|
72
72
|
};
|
73
|
-
context.meta = test;
|
74
73
|
context.task = test;
|
75
74
|
context.skip = () => {
|
76
75
|
test.pending = true;
|
@@ -80,7 +79,7 @@ function createTestContext(test, runner) {
|
|
80
79
|
test.onFailed || (test.onFailed = []);
|
81
80
|
test.onFailed.push(fn);
|
82
81
|
};
|
83
|
-
return ((_a = runner.
|
82
|
+
return ((_a = runner.extendTaskContext) == null ? void 0 : _a.call(runner, context)) || context;
|
84
83
|
}
|
85
84
|
function makeTimeoutMsg(isHook, timeout) {
|
86
85
|
return `${isHook ? "Hook" : "Test"} timed out in ${timeout}ms.
|
@@ -274,52 +273,51 @@ function createSuiteCollector(name, factory = () => {
|
|
274
273
|
const factoryQueue = [];
|
275
274
|
let suite2;
|
276
275
|
initSuite();
|
277
|
-
const
|
278
|
-
const
|
279
|
-
if (typeof options === "number")
|
280
|
-
options = { timeout: options };
|
281
|
-
if (typeof suiteOptions === "object")
|
282
|
-
options = Object.assign({}, suiteOptions, options);
|
283
|
-
const test3 = {
|
276
|
+
const task = function(name2 = "", options = {}) {
|
277
|
+
const task2 = {
|
284
278
|
id: "",
|
285
|
-
|
286
|
-
name: formatName(name2),
|
287
|
-
each: this.each,
|
288
|
-
mode: mode2,
|
279
|
+
name: name2,
|
289
280
|
suite: void 0,
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
281
|
+
each: options.each,
|
282
|
+
fails: options.fails,
|
283
|
+
context: void 0,
|
284
|
+
type: "custom",
|
285
|
+
retry: options.retry ?? runner.config.retry,
|
286
|
+
repeats: options.repeats,
|
287
|
+
mode: options.only ? "only" : options.skip ? "skip" : options.todo ? "todo" : "run",
|
288
|
+
meta: options.meta ?? /* @__PURE__ */ Object.create(null)
|
294
289
|
};
|
295
|
-
|
296
|
-
|
290
|
+
const handler = options.handler;
|
291
|
+
if (options.concurrent || !sequential && (concurrent || runner.config.sequence.concurrent))
|
292
|
+
task2.concurrent = true;
|
297
293
|
if (shuffle)
|
298
|
-
|
299
|
-
const context = createTestContext(
|
300
|
-
Object.defineProperty(
|
294
|
+
task2.shuffle = true;
|
295
|
+
const context = createTestContext(task2, runner);
|
296
|
+
Object.defineProperty(task2, "context", {
|
301
297
|
value: context,
|
302
298
|
enumerable: false
|
303
299
|
});
|
304
|
-
setFixture(context,
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
const task = {
|
314
|
-
id: "",
|
315
|
-
name: name2,
|
316
|
-
type: "custom",
|
317
|
-
mode: self.only ? "only" : self.skip ? "skip" : self.todo ? "todo" : "run",
|
318
|
-
meta: /* @__PURE__ */ Object.create(null)
|
319
|
-
};
|
320
|
-
tasks.push(task);
|
321
|
-
return task;
|
300
|
+
setFixture(context, options.fixtures);
|
301
|
+
if (handler) {
|
302
|
+
setFn(task2, withTimeout(
|
303
|
+
withFixtures(handler, context),
|
304
|
+
(options == null ? void 0 : options.timeout) ?? runner.config.testTimeout
|
305
|
+
));
|
306
|
+
}
|
307
|
+
tasks.push(task2);
|
308
|
+
return task2;
|
322
309
|
};
|
310
|
+
const test2 = createTest(function(name2, fn = noop, options) {
|
311
|
+
if (typeof options === "number")
|
312
|
+
options = { timeout: options };
|
313
|
+
if (typeof suiteOptions === "object")
|
314
|
+
options = Object.assign({}, suiteOptions, options);
|
315
|
+
const test3 = task(
|
316
|
+
formatName(name2),
|
317
|
+
{ ...this, ...options, handler: fn }
|
318
|
+
);
|
319
|
+
test3.type = "test";
|
320
|
+
});
|
323
321
|
const collector = {
|
324
322
|
type: "collector",
|
325
323
|
name,
|
@@ -328,7 +326,7 @@ function createSuiteCollector(name, factory = () => {
|
|
328
326
|
test: test2,
|
329
327
|
tasks,
|
330
328
|
collect,
|
331
|
-
|
329
|
+
task,
|
332
330
|
clear,
|
333
331
|
on: addHook
|
334
332
|
};
|
@@ -364,10 +362,10 @@ function createSuiteCollector(name, factory = () => {
|
|
364
362
|
allChildren.push(i.type === "collector" ? await i.collect(file) : i);
|
365
363
|
suite2.file = file;
|
366
364
|
suite2.tasks = allChildren;
|
367
|
-
allChildren.forEach((
|
368
|
-
|
365
|
+
allChildren.forEach((task2) => {
|
366
|
+
task2.suite = suite2;
|
369
367
|
if (file)
|
370
|
-
|
368
|
+
task2.file = file;
|
371
369
|
});
|
372
370
|
return suite2;
|
373
371
|
}
|
@@ -406,9 +404,9 @@ function createSuite() {
|
|
406
404
|
suiteFn
|
407
405
|
);
|
408
406
|
}
|
409
|
-
function
|
410
|
-
const
|
411
|
-
|
407
|
+
function createTaskCollector(fn, context) {
|
408
|
+
const taskFn = fn;
|
409
|
+
taskFn.each = function(cases, ...args) {
|
412
410
|
const test2 = this.withContext();
|
413
411
|
this.setContext("each", true);
|
414
412
|
if (Array.isArray(cases) && args.length)
|
@@ -423,9 +421,9 @@ function createTest(fn, context) {
|
|
423
421
|
this.setContext("each", void 0);
|
424
422
|
};
|
425
423
|
};
|
426
|
-
|
427
|
-
|
428
|
-
|
424
|
+
taskFn.skipIf = (condition) => condition ? test.skip : test;
|
425
|
+
taskFn.runIf = (condition) => condition ? test : test.skip;
|
426
|
+
taskFn.extend = function(fixtures) {
|
429
427
|
const _context = mergeContextFixtures(fixtures, context);
|
430
428
|
return createTest(function fn2(name, fn2, options) {
|
431
429
|
getCurrentSuite().test.fn.call(this, formatName(name), fn2, options);
|
@@ -433,12 +431,15 @@ function createTest(fn, context) {
|
|
433
431
|
};
|
434
432
|
const _test = createChainable(
|
435
433
|
["concurrent", "skip", "only", "todo", "fails"],
|
436
|
-
|
434
|
+
taskFn
|
437
435
|
);
|
438
436
|
if (context)
|
439
437
|
_test.mergeContext(context);
|
440
438
|
return _test;
|
441
439
|
}
|
440
|
+
function createTest(fn, context) {
|
441
|
+
return createTaskCollector(fn, context);
|
442
|
+
}
|
442
443
|
function formatName(name) {
|
443
444
|
return typeof name === "string" ? name : name instanceof Function ? name.name || "<anonymous>" : String(name);
|
444
445
|
}
|
@@ -630,7 +631,7 @@ async function callCleanupHooks(cleanups) {
|
|
630
631
|
}
|
631
632
|
async function runTest(test, runner) {
|
632
633
|
var _a, _b, _c, _d, _e, _f, _g;
|
633
|
-
await ((_a = runner.
|
634
|
+
await ((_a = runner.onBeforeRunTask) == null ? void 0 : _a.call(runner, test));
|
634
635
|
if (test.mode !== "run")
|
635
636
|
return;
|
636
637
|
if (((_b = test.result) == null ? void 0 : _b.state) === "fail") {
|
@@ -651,11 +652,11 @@ async function runTest(test, runner) {
|
|
651
652
|
for (let retryCount = 0; retryCount <= retry; retryCount++) {
|
652
653
|
let beforeEachCleanups = [];
|
653
654
|
try {
|
654
|
-
await ((_c = runner.
|
655
|
+
await ((_c = runner.onBeforeTryTask) == null ? void 0 : _c.call(runner, test, { retry: retryCount, repeats: repeatCount }));
|
655
656
|
test.result.repeatCount = repeatCount;
|
656
657
|
beforeEachCleanups = await callSuiteHook(test.suite, test, "beforeEach", runner, [test.context, test.suite]);
|
657
|
-
if (runner.
|
658
|
-
await runner.
|
658
|
+
if (runner.runTask) {
|
659
|
+
await runner.runTask(test);
|
659
660
|
} else {
|
660
661
|
const fn = getFn(test);
|
661
662
|
if (!fn)
|
@@ -668,7 +669,7 @@ async function runTest(test, runner) {
|
|
668
669
|
if (errors.length)
|
669
670
|
throw errors;
|
670
671
|
}
|
671
|
-
await ((_d = runner.
|
672
|
+
await ((_d = runner.onAfterTryTask) == null ? void 0 : _d.call(runner, test, { retry: retryCount, repeats: repeatCount }));
|
672
673
|
if (test.result.state !== "fail") {
|
673
674
|
if (!test.repeats)
|
674
675
|
test.result.state = "pass";
|
@@ -715,7 +716,7 @@ async function runTest(test, runner) {
|
|
715
716
|
}
|
716
717
|
setCurrentTest(void 0);
|
717
718
|
test.result.duration = now() - start;
|
718
|
-
await ((_g = runner.
|
719
|
+
await ((_g = runner.onAfterRunTask) == null ? void 0 : _g.call(runner, test));
|
719
720
|
updateTask(test, runner);
|
720
721
|
}
|
721
722
|
function failTask(result, err, diffOptions) {
|
@@ -813,7 +814,7 @@ async function runSuite(suite, runner) {
|
|
813
814
|
}
|
814
815
|
}
|
815
816
|
async function runSuiteChild(c, runner) {
|
816
|
-
if (c.type === "test")
|
817
|
+
if (c.type === "test" || c.type === "custom")
|
817
818
|
return runTest(c, runner);
|
818
819
|
else if (c.type === "suite")
|
819
820
|
return runSuite(c, runner);
|
@@ -839,9 +840,9 @@ async function startTests(paths, runner) {
|
|
839
840
|
await ((_a = runner.onBeforeCollect) == null ? void 0 : _a.call(runner, paths));
|
840
841
|
const files = await collectTests(paths, runner);
|
841
842
|
(_b = runner.onCollected) == null ? void 0 : _b.call(runner, files);
|
842
|
-
await ((_c = runner.
|
843
|
+
await ((_c = runner.onBeforeRunFiles) == null ? void 0 : _c.call(runner, files));
|
843
844
|
await runFiles(files, runner);
|
844
|
-
await ((_d = runner.
|
845
|
+
await ((_d = runner.onAfterRunFiles) == null ? void 0 : _d.call(runner, files));
|
845
846
|
await sendTasksUpdate(runner);
|
846
847
|
return files;
|
847
848
|
}
|
@@ -874,4 +875,4 @@ function createTestHook(name, handler) {
|
|
874
875
|
};
|
875
876
|
}
|
876
877
|
|
877
|
-
export { afterAll, afterEach, beforeAll, beforeEach, describe, getCurrentSuite, getCurrentTest, getFn, it, onTestFailed, setFn, startTests, suite, test, updateTask };
|
878
|
+
export { afterAll, afterEach, beforeAll, beforeEach, createTaskCollector, describe, getCurrentSuite, getCurrentTest, getFn, it, onTestFailed, setFn, startTests, suite, test, updateTask };
|
@@ -9,6 +9,20 @@ type ChainableFunction<T extends string, Args extends any[], R = any, E = {}> =
|
|
9
9
|
} & E;
|
10
10
|
declare function createChainable<T extends string, Args extends any[], R = any, E = {}>(keys: T[], fn: (this: Record<T, any>, ...args: Args) => R): ChainableFunction<T, Args, R, E>;
|
11
11
|
|
12
|
+
interface FixtureItem {
|
13
|
+
prop: string;
|
14
|
+
value: any;
|
15
|
+
index: number;
|
16
|
+
/**
|
17
|
+
* Indicates whether the fixture is a function
|
18
|
+
*/
|
19
|
+
isFn: boolean;
|
20
|
+
/**
|
21
|
+
* The dependencies(fixtures) of current fixture function.
|
22
|
+
*/
|
23
|
+
deps?: FixtureItem[];
|
24
|
+
}
|
25
|
+
|
12
26
|
type RunMode = 'run' | 'skip' | 'only' | 'todo';
|
13
27
|
type TaskState = RunMode | 'pass' | 'fail';
|
14
28
|
interface TaskBase {
|
@@ -25,10 +39,18 @@ interface TaskBase {
|
|
25
39
|
retry?: number;
|
26
40
|
repeats?: number;
|
27
41
|
}
|
28
|
-
interface
|
42
|
+
interface TaskPopulated extends TaskBase {
|
43
|
+
suite: Suite;
|
44
|
+
pending?: boolean;
|
45
|
+
result?: TaskResult;
|
46
|
+
fails?: boolean;
|
47
|
+
onFailed?: OnTestFailedHandler[];
|
48
|
+
/**
|
49
|
+
* Store promises (from async expects) to wait for them before finishing the test
|
50
|
+
*/
|
51
|
+
promises?: Promise<any>[];
|
29
52
|
}
|
30
|
-
interface
|
31
|
-
type: 'custom';
|
53
|
+
interface TaskMeta {
|
32
54
|
}
|
33
55
|
interface TaskResult {
|
34
56
|
state: TaskState;
|
@@ -57,22 +79,17 @@ interface File extends Suite {
|
|
57
79
|
collectDuration?: number;
|
58
80
|
setupDuration?: number;
|
59
81
|
}
|
60
|
-
interface Test<ExtraContext = {}> extends
|
82
|
+
interface Test<ExtraContext = {}> extends TaskPopulated {
|
61
83
|
type: 'test';
|
62
|
-
|
63
|
-
pending?: boolean;
|
64
|
-
result?: TaskResult;
|
65
|
-
fails?: boolean;
|
66
|
-
context: TestContext & ExtraContext;
|
67
|
-
onFailed?: OnTestFailedHandler[];
|
68
|
-
/**
|
69
|
-
* Store promises (from async expects) to wait for them before finishing the test
|
70
|
-
*/
|
71
|
-
promises?: Promise<any>[];
|
84
|
+
context: TaskContext<Test> & ExtraContext & TestContext;
|
72
85
|
}
|
73
|
-
|
86
|
+
interface Custom<ExtraContext = {}> extends TaskPopulated {
|
87
|
+
type: 'custom';
|
88
|
+
context: TaskContext<Custom> & ExtraContext & TestContext;
|
89
|
+
}
|
90
|
+
type Task = Test | Suite | Custom | File;
|
74
91
|
type DoneCallback = (error?: any) => void;
|
75
|
-
type TestFunction<ExtraContext = {}> = (context:
|
92
|
+
type TestFunction<ExtraContext = {}> = (context: ExtendedContext<Test> & ExtraContext) => Awaitable<any> | void;
|
76
93
|
type ExtractEachCallbackArgs<T extends ReadonlyArray<any>> = {
|
77
94
|
1: [T[0]];
|
78
95
|
2: [T[0], T[1]];
|
@@ -125,19 +142,31 @@ interface TestOptions {
|
|
125
142
|
*/
|
126
143
|
repeats?: number;
|
127
144
|
}
|
128
|
-
|
145
|
+
interface ExtendedAPI<ExtraContext> {
|
129
146
|
each: TestEachFunction;
|
130
147
|
skipIf(condition: any): ChainableTestAPI<ExtraContext>;
|
131
148
|
runIf(condition: any): ChainableTestAPI<ExtraContext>;
|
149
|
+
}
|
150
|
+
type CustomAPI<ExtraContext = {}> = ChainableTestAPI<ExtraContext> & ExtendedAPI<ExtraContext> & {
|
151
|
+
extend<T extends Record<string, any> = {}>(fixtures: Fixtures<T, ExtraContext>): CustomAPI<{
|
152
|
+
[K in keyof T | keyof ExtraContext]: K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never;
|
153
|
+
}>;
|
154
|
+
};
|
155
|
+
type TestAPI<ExtraContext = {}> = ChainableTestAPI<ExtraContext> & ExtendedAPI<ExtraContext> & {
|
132
156
|
extend<T extends Record<string, any> = {}>(fixtures: Fixtures<T, ExtraContext>): TestAPI<{
|
133
157
|
[K in keyof T | keyof ExtraContext]: K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never;
|
134
158
|
}>;
|
135
159
|
};
|
160
|
+
type FixtureType<T> = T extends (context: any, use: (fixture: infer F) => any) => any ? F : T;
|
161
|
+
type Fixture<T, K extends keyof T, OnlyFunction, ExtraContext = {}, V = FixtureType<T[K]>, FN = (context: {
|
162
|
+
[P in keyof T | keyof ExtraContext as P extends K ? P extends keyof ExtraContext ? P : never : P]: K extends P ? K extends keyof ExtraContext ? ExtraContext[K] : V : P extends keyof T ? T[P] : never;
|
163
|
+
} & TestContext, use: (fixture: V) => Promise<void>) => Promise<void>> = OnlyFunction extends true ? FN : (FN | V);
|
136
164
|
type Fixtures<T extends Record<string, any>, ExtraContext = {}> = {
|
137
|
-
[K in keyof T]: T
|
138
|
-
|
139
|
-
|
165
|
+
[K in keyof T]: Fixture<T, K, false, ExtraContext>;
|
166
|
+
} | {
|
167
|
+
[K in keyof T]: Fixture<T, K, true, ExtraContext>;
|
140
168
|
};
|
169
|
+
type InferFixturesTypes<T> = T extends TestAPI<infer C> ? C : T;
|
141
170
|
type ChainableSuiteAPI<ExtraContext = {}> = ChainableFunction<'concurrent' | 'sequential' | 'only' | 'skip' | 'todo' | 'shuffle', [
|
142
171
|
name: string | Function,
|
143
172
|
factory?: SuiteFactory<ExtraContext>,
|
@@ -156,8 +185,20 @@ type HookCleanupCallback = (() => Awaitable<unknown>) | void;
|
|
156
185
|
interface SuiteHooks<ExtraContext = {}> {
|
157
186
|
beforeAll: HookListener<[Readonly<Suite | File>], HookCleanupCallback>[];
|
158
187
|
afterAll: HookListener<[Readonly<Suite | File>]>[];
|
159
|
-
beforeEach: HookListener<[
|
160
|
-
afterEach: HookListener<[
|
188
|
+
beforeEach: HookListener<[ExtendedContext<Test | Custom> & ExtraContext, Readonly<Suite>], HookCleanupCallback>[];
|
189
|
+
afterEach: HookListener<[ExtendedContext<Test | Custom> & ExtraContext, Readonly<Suite>]>[];
|
190
|
+
}
|
191
|
+
interface TaskCustomOptions extends TestOptions {
|
192
|
+
concurrent?: boolean;
|
193
|
+
sequential?: boolean;
|
194
|
+
skip?: boolean;
|
195
|
+
only?: boolean;
|
196
|
+
todo?: boolean;
|
197
|
+
fails?: boolean;
|
198
|
+
each?: boolean;
|
199
|
+
meta?: Record<string, unknown>;
|
200
|
+
fixtures?: FixtureItem[];
|
201
|
+
handler?: (context: TaskContext<Custom>) => Awaitable<void>;
|
161
202
|
}
|
162
203
|
interface SuiteCollector<ExtraContext = {}> {
|
163
204
|
readonly name: string;
|
@@ -165,8 +206,8 @@ interface SuiteCollector<ExtraContext = {}> {
|
|
165
206
|
options?: TestOptions;
|
166
207
|
type: 'collector';
|
167
208
|
test: TestAPI<ExtraContext>;
|
168
|
-
tasks: (Suite |
|
169
|
-
|
209
|
+
tasks: (Suite | Custom<ExtraContext> | Test<ExtraContext> | SuiteCollector<ExtraContext>)[];
|
210
|
+
task: (name: string, options?: TaskCustomOptions) => Custom<ExtraContext>;
|
170
211
|
collect: (file?: File) => Promise<Suite>;
|
171
212
|
clear: () => void;
|
172
213
|
on: <T extends keyof SuiteHooks<ExtraContext>>(name: T, ...fn: SuiteHooks<ExtraContext>[T]) => void;
|
@@ -177,16 +218,12 @@ interface RuntimeContext {
|
|
177
218
|
currentSuite: SuiteCollector | null;
|
178
219
|
}
|
179
220
|
interface TestContext {
|
180
|
-
|
181
|
-
|
182
|
-
*
|
183
|
-
* @deprecated Use `task` instead
|
184
|
-
*/
|
185
|
-
meta: Readonly<Test>;
|
221
|
+
}
|
222
|
+
interface TaskContext<Task extends Custom | Test = Custom | Test> {
|
186
223
|
/**
|
187
224
|
* Metadata of the current test
|
188
225
|
*/
|
189
|
-
task: Readonly<
|
226
|
+
task: Readonly<Task>;
|
190
227
|
/**
|
191
228
|
* Extract hooks on test failed
|
192
229
|
*/
|
@@ -196,8 +233,9 @@ interface TestContext {
|
|
196
233
|
*/
|
197
234
|
skip: () => void;
|
198
235
|
}
|
236
|
+
type ExtendedContext<T extends Custom | Test> = TaskContext<T> & TestContext;
|
199
237
|
type OnTestFailedHandler = (result: TaskResult) => Awaitable<void>;
|
200
238
|
type SequenceHooks = 'stack' | 'list' | 'parallel';
|
201
239
|
type SequenceSetupFiles = 'list' | 'parallel';
|
202
240
|
|
203
|
-
export {
|
241
|
+
export { Custom as C, DoneCallback as D, ExtendedContext as E, File as F, HookListener as H, InferFixturesTypes as I, OnTestFailedHandler as O, RunMode as R, Suite as S, Task as T, Test as a, ChainableFunction as b, createChainable as c, SuiteAPI as d, TestAPI as e, SuiteCollector as f, CustomAPI as g, SuiteHooks as h, TaskState as i, TaskBase as j, TaskPopulated as k, TaskMeta as l, TaskResult as m, TaskResultPack as n, TestFunction as o, TestOptions as p, Fixture as q, Fixtures as r, HookCleanupCallback as s, TaskCustomOptions as t, SuiteFactory as u, RuntimeContext as v, TestContext as w, TaskContext as x, SequenceHooks as y, SequenceSetupFiles as z };
|
package/dist/types.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import {
|
2
|
-
export { D as DoneCallback,
|
1
|
+
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';
|
2
|
+
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';
|
3
3
|
import '@vitest/utils';
|
4
4
|
|
5
5
|
/**
|
@@ -84,28 +84,28 @@ interface VitestRunner {
|
|
84
84
|
/**
|
85
85
|
* Called when test runner should cancel next test runs.
|
86
86
|
* Runner should listen for this method and mark tests and suites as skipped in
|
87
|
-
* "onBeforeRunSuite" and "
|
87
|
+
* "onBeforeRunSuite" and "onBeforeRunTask" when called.
|
88
88
|
*/
|
89
89
|
onCancel?(reason: CancelReason): unknown;
|
90
90
|
/**
|
91
91
|
* Called before running a single test. Doesn't have "result" yet.
|
92
92
|
*/
|
93
|
-
|
93
|
+
onBeforeRunTask?(test: TaskPopulated): unknown;
|
94
94
|
/**
|
95
95
|
* Called before actually running the test function. Already has "result" with "state" and "startTime".
|
96
96
|
*/
|
97
|
-
|
97
|
+
onBeforeTryTask?(test: TaskPopulated, options: {
|
98
98
|
retry: number;
|
99
99
|
repeats: number;
|
100
100
|
}): unknown;
|
101
101
|
/**
|
102
102
|
* Called after result and state are set.
|
103
103
|
*/
|
104
|
-
|
104
|
+
onAfterRunTask?(test: TaskPopulated): unknown;
|
105
105
|
/**
|
106
106
|
* Called right after running the test function. Doesn't have new state yet. Will not be called, if the test function throws.
|
107
107
|
*/
|
108
|
-
|
108
|
+
onAfterTryTask?(test: TaskPopulated, options: {
|
109
109
|
retry: number;
|
110
110
|
repeats: number;
|
111
111
|
}): unknown;
|
@@ -126,7 +126,7 @@ interface VitestRunner {
|
|
126
126
|
* If defined, will be called instead of usual Vitest handling. Useful, if you have your custom test function.
|
127
127
|
* "before" and "after" hooks will not be ignored.
|
128
128
|
*/
|
129
|
-
|
129
|
+
runTask?(test: TaskPopulated): Promise<void>;
|
130
130
|
/**
|
131
131
|
* Called, when a task is updated. The same as "onTaskUpdate" in a reporter, but this is running in the same thread as tests.
|
132
132
|
*/
|
@@ -134,16 +134,20 @@ interface VitestRunner {
|
|
134
134
|
/**
|
135
135
|
* Called before running all tests in collected paths.
|
136
136
|
*/
|
137
|
-
|
137
|
+
onBeforeRunFiles?(files: File[]): unknown;
|
138
138
|
/**
|
139
139
|
* Called right after running all tests in collected paths.
|
140
140
|
*/
|
141
|
-
|
141
|
+
onAfterRunFiles?(files: File[]): unknown;
|
142
142
|
/**
|
143
143
|
* Called when new context for a test is defined. Useful, if you want to add custom properties to the context.
|
144
144
|
* If you only want to define custom context, consider using "beforeAll" in "setupFiles" instead.
|
145
|
+
*
|
146
|
+
* This method is called for both "test" and "custom" handlers.
|
147
|
+
*
|
148
|
+
* @see https://vitest.dev/advanced/runner.html#your-task-function
|
145
149
|
*/
|
146
|
-
|
150
|
+
extendTaskContext?<T extends Test | Custom>(context: TaskContext<T>): ExtendedContext<T>;
|
147
151
|
/**
|
148
152
|
* Called, when files are imported. Can be called in two situations: when collecting tests and when importing setup files.
|
149
153
|
*/
|
@@ -154,4 +158,4 @@ interface VitestRunner {
|
|
154
158
|
config: VitestRunnerConfig;
|
155
159
|
}
|
156
160
|
|
157
|
-
export { CancelReason, File, SequenceHooks, SequenceSetupFiles, Suite, TaskResultPack, Test,
|
161
|
+
export { CancelReason, Custom, ExtendedContext, File, SequenceHooks, SequenceSetupFiles, Suite, TaskContext, TaskPopulated, TaskResultPack, Test, VitestRunner, VitestRunnerConfig, VitestRunnerConstructor, VitestRunnerImportSource };
|
package/dist/utils.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { S as Suite, T as Task, a as Test,
|
2
|
-
export {
|
1
|
+
import { S as Suite, T as Task, a as Test, C as Custom } from './tasks-b31a73cb.js';
|
2
|
+
export { b as ChainableFunction, c as createChainable } from './tasks-b31a73cb.js';
|
3
3
|
import { Arrayable } from '@vitest/utils';
|
4
4
|
|
5
5
|
/**
|
@@ -15,7 +15,7 @@ declare function calculateSuiteHash(parent: Suite): void;
|
|
15
15
|
*/
|
16
16
|
declare function partitionSuiteChildren(suite: Suite): Task[][];
|
17
17
|
|
18
|
-
declare function getTests(suite: Arrayable<Task>): (Test |
|
18
|
+
declare function getTests(suite: Arrayable<Task>): (Test | Custom)[];
|
19
19
|
declare function getTasks(tasks?: Arrayable<Task>): Task[];
|
20
20
|
declare function getSuites(suite: Arrayable<Task>): Suite[];
|
21
21
|
declare function hasTests(suite: Arrayable<Suite>): boolean;
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/runner",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "1.0.0-beta.0",
|
5
5
|
"description": "Vitest test runner",
|
6
6
|
"license": "MIT",
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
@@ -40,7 +40,7 @@
|
|
40
40
|
"dependencies": {
|
41
41
|
"p-limit": "^4.0.0",
|
42
42
|
"pathe": "^1.1.1",
|
43
|
-
"@vitest/utils": "0.
|
43
|
+
"@vitest/utils": "1.0.0-beta.0"
|
44
44
|
},
|
45
45
|
"scripts": {
|
46
46
|
"build": "rimraf dist && rollup -c",
|