vitest 0.0.7 → 0.0.8
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/README.md +62 -0
- package/dist/reporters/default.d.ts +18 -0
- package/dist/reporters/default.js +86 -0
- package/dist/run.d.ts +3 -3
- package/dist/run.js +53 -69
- package/dist/suite.d.ts +19 -9
- package/dist/suite.js +47 -27
- package/dist/types.d.ts +44 -13
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ A blazing fast test runner powered by Vite.
|
|
|
11
11
|
- Chai for assertions.
|
|
12
12
|
- Async suite / test.
|
|
13
13
|
- ESM friendly, top level await.
|
|
14
|
+
- Suite and Test filtering (skip, only, todo).
|
|
14
15
|
|
|
15
16
|
```ts
|
|
16
17
|
import { it, describe, expect, assert } from 'vitest'
|
|
@@ -34,6 +35,67 @@ describe('suite name', () => {
|
|
|
34
35
|
$ npx vitest
|
|
35
36
|
```
|
|
36
37
|
|
|
38
|
+
## Filtering
|
|
39
|
+
|
|
40
|
+
### Skipping suites and tasks
|
|
41
|
+
|
|
42
|
+
Use `.skip` to avoid running certain suites or tests
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
describe.skip('skipped suite', () => {
|
|
46
|
+
it('task', () => {
|
|
47
|
+
// Suite skipped, no error
|
|
48
|
+
assert.equal(Math.sqrt(4), 3)
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
describe('suite', () => {
|
|
53
|
+
it.skip('skipped task', () => {
|
|
54
|
+
// Task skipped, no error
|
|
55
|
+
assert.equal(Math.sqrt(4), 3)
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Selecting suites and tests to run
|
|
61
|
+
|
|
62
|
+
Use `.only` to only run certain suites or tests
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
// Only this suite (and others marked with only) are run
|
|
66
|
+
describe.only('suite', () => {
|
|
67
|
+
it('task', () => {
|
|
68
|
+
assert.equal(Math.sqrt(4), 3)
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
describe('another suite', () => {
|
|
73
|
+
it('skipped task', () => {
|
|
74
|
+
// Task skipped, as tests are running in Only mode
|
|
75
|
+
assert.equal(Math.sqrt(4), 3)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it.only('task', () => {
|
|
79
|
+
// Only this task (and others marked with only) are run
|
|
80
|
+
assert.equal(Math.sqrt(4), 2)
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Unimplemented suites and tests
|
|
86
|
+
|
|
87
|
+
Use `.todo` to stub suites and tests that should be implemented
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
// An entry will be shown in the report for this suite
|
|
91
|
+
describe.todo('unimplemented suite')
|
|
92
|
+
|
|
93
|
+
// An entry will be shown in the report for this task
|
|
94
|
+
describe.suite('suite', () => {
|
|
95
|
+
it.todo('unimplemented task')
|
|
96
|
+
})
|
|
97
|
+
```
|
|
98
|
+
|
|
37
99
|
## TODO
|
|
38
100
|
|
|
39
101
|
- [ ] Reporter & Better output
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { File, Reporter, RunnerContext, Suite, Task } from '../types';
|
|
2
|
+
export declare class DefaultReporter implements Reporter {
|
|
3
|
+
indent: number;
|
|
4
|
+
start: number;
|
|
5
|
+
end: number;
|
|
6
|
+
onStart(): void;
|
|
7
|
+
onCollected(): void;
|
|
8
|
+
onFinished({ files }: RunnerContext): void;
|
|
9
|
+
onSuiteBegin(suite: Suite): void;
|
|
10
|
+
onSuiteEnd(suite: Suite): void;
|
|
11
|
+
onFileBegin(file: File): void;
|
|
12
|
+
onFileEnd(): void;
|
|
13
|
+
onTaskBegin(): void;
|
|
14
|
+
onTaskEnd(t: Task): void;
|
|
15
|
+
log(msg?: string, indentDelta?: number): void;
|
|
16
|
+
error(msg?: string, indentDelta?: number): void;
|
|
17
|
+
onSnapshotUpdate(): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { relative } from 'path';
|
|
2
|
+
import { performance } from 'perf_hooks';
|
|
3
|
+
import c from 'picocolors';
|
|
4
|
+
const DOT = '· ';
|
|
5
|
+
export class DefaultReporter {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.indent = 0;
|
|
8
|
+
this.start = 0;
|
|
9
|
+
this.end = 0;
|
|
10
|
+
}
|
|
11
|
+
onStart() {
|
|
12
|
+
this.indent = 0;
|
|
13
|
+
}
|
|
14
|
+
onCollected() {
|
|
15
|
+
this.start = performance.now();
|
|
16
|
+
}
|
|
17
|
+
onFinished({ files }) {
|
|
18
|
+
this.end = performance.now();
|
|
19
|
+
const tasks = files.reduce((acc, file) => acc.concat(file.suites.flatMap(i => i.tasks)), []);
|
|
20
|
+
const passed = tasks.filter(i => i.status === 'pass');
|
|
21
|
+
const failed = tasks.filter(i => i.status === 'fail');
|
|
22
|
+
const skipped = tasks.filter(i => i.status === 'skip');
|
|
23
|
+
const todo = tasks.filter(i => i.status === 'todo');
|
|
24
|
+
this.indent = 0;
|
|
25
|
+
this.log(c.green(`Passed ${passed.length} / ${tasks.length}`));
|
|
26
|
+
if (skipped.length)
|
|
27
|
+
this.log(c.yellow(`Skipped ${skipped.length}`));
|
|
28
|
+
if (todo.length)
|
|
29
|
+
this.log(c.dim(`Todo ${todo.length}`));
|
|
30
|
+
if (failed.length)
|
|
31
|
+
this.log(c.red(`Failed ${failed.length} / ${tasks.length}`));
|
|
32
|
+
this.log(`Time ${(this.end - this.start).toFixed(2)}ms`);
|
|
33
|
+
}
|
|
34
|
+
onSuiteBegin(suite) {
|
|
35
|
+
if (suite.name) {
|
|
36
|
+
this.indent += 1;
|
|
37
|
+
const name = DOT + suite.name;
|
|
38
|
+
if (suite.mode === 'skip')
|
|
39
|
+
this.log(c.dim(c.yellow(`${name} (skipped)`)));
|
|
40
|
+
else if (suite.mode === 'todo')
|
|
41
|
+
this.log(c.dim(`${name} (todo)`));
|
|
42
|
+
else
|
|
43
|
+
this.log(name);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
onSuiteEnd(suite) {
|
|
47
|
+
if (suite.name)
|
|
48
|
+
this.indent -= 1;
|
|
49
|
+
}
|
|
50
|
+
onFileBegin(file) {
|
|
51
|
+
this.log(`- ${relative(process.cwd(), file.filepath)} ${c.dim(`(${file.suites.flatMap(i => i.tasks).length} tests)`)}`);
|
|
52
|
+
}
|
|
53
|
+
onFileEnd() {
|
|
54
|
+
this.log();
|
|
55
|
+
}
|
|
56
|
+
onTaskBegin() {
|
|
57
|
+
this.indent += 1;
|
|
58
|
+
}
|
|
59
|
+
onTaskEnd(t) {
|
|
60
|
+
if (t.status === 'pass') {
|
|
61
|
+
this.log(`${c.green(`✔ ${t.name}`)}`);
|
|
62
|
+
}
|
|
63
|
+
else if (t.status === 'skip') {
|
|
64
|
+
this.log(c.dim(c.yellow(`${DOT + t.name} (skipped)`)));
|
|
65
|
+
}
|
|
66
|
+
else if (t.status === 'todo') {
|
|
67
|
+
this.log(c.dim(`${DOT + t.name} (todo)`));
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
this.error(`${c.red(`⤫ ${c.inverse(c.red(' FAIL '))} ${t.name}`)}`);
|
|
71
|
+
this.error(String(t.error), 1);
|
|
72
|
+
process.exitCode = 1;
|
|
73
|
+
}
|
|
74
|
+
this.indent -= 1;
|
|
75
|
+
}
|
|
76
|
+
log(msg = '', indentDelta = 0) {
|
|
77
|
+
// eslint-disable-next-line no-console
|
|
78
|
+
console.log(`${' '.repeat((this.indent + indentDelta) * 2)}${msg}`);
|
|
79
|
+
}
|
|
80
|
+
error(msg = '', indentDelta = 0) {
|
|
81
|
+
// eslint-disable-next-line no-console
|
|
82
|
+
console.error(c.red(`${' '.repeat((this.indent + indentDelta) * 2)}${msg}`));
|
|
83
|
+
}
|
|
84
|
+
onSnapshotUpdate() {
|
|
85
|
+
}
|
|
86
|
+
}
|
package/dist/run.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { File, Options, Task,
|
|
2
|
-
export declare function
|
|
1
|
+
import { File, Options, Task, RunnerContext } from './types';
|
|
2
|
+
export declare function runTask(task: Task, ctx: RunnerContext): Promise<void>;
|
|
3
3
|
export declare function collectFiles(files: string[]): Promise<File[]>;
|
|
4
|
-
export declare function runFile(file: File): Promise<void>;
|
|
4
|
+
export declare function runFile(file: File, ctx: RunnerContext): Promise<void>;
|
|
5
5
|
export declare function run(options?: Options): Promise<void>;
|
package/dist/run.js
CHANGED
|
@@ -1,88 +1,72 @@
|
|
|
1
|
-
import { relative } from 'path';
|
|
2
|
-
import { performance } from 'perf_hooks';
|
|
3
|
-
import c from 'picocolors';
|
|
4
1
|
import chai from 'chai';
|
|
5
2
|
import fg from 'fast-glob';
|
|
6
3
|
import { clearContext, defaultSuite } from './suite';
|
|
7
4
|
import { context } from './context';
|
|
8
5
|
import { afterEachHook, afterFileHook, afterAllHook, afterSuiteHook, beforeEachHook, beforeFileHook, beforeAllHook, beforeSuiteHook } from './hooks';
|
|
9
|
-
import { SnapshotPlugin } from './snapshot
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
import { SnapshotPlugin } from './snapshot';
|
|
7
|
+
import { DefaultReporter } from './reporters/default';
|
|
8
|
+
export async function runTask(task, ctx) {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
const { reporter } = ctx;
|
|
11
|
+
await ((_a = reporter.onTaskBegin) === null || _a === void 0 ? void 0 : _a.call(reporter, task, ctx));
|
|
12
|
+
await beforeEachHook.fire(task);
|
|
13
|
+
if (task.suite.mode === 'skip' || task.mode === 'skip') {
|
|
14
|
+
task.status = 'skip';
|
|
15
|
+
}
|
|
16
|
+
else if (task.suite.mode === 'todo' || task.mode === 'todo') {
|
|
17
|
+
task.status = 'todo';
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
15
20
|
try {
|
|
16
21
|
await task.fn();
|
|
22
|
+
task.status = 'pass';
|
|
17
23
|
}
|
|
18
24
|
catch (e) {
|
|
19
|
-
task.
|
|
25
|
+
task.status = 'fail';
|
|
26
|
+
task.error = e;
|
|
20
27
|
}
|
|
21
|
-
await afterEachHook.fire(task);
|
|
22
28
|
}
|
|
23
|
-
|
|
29
|
+
await afterEachHook.fire(task);
|
|
30
|
+
await ((_b = reporter.onTaskEnd) === null || _b === void 0 ? void 0 : _b.call(reporter, task, ctx));
|
|
24
31
|
}
|
|
25
|
-
// TODO: REPORTER
|
|
26
|
-
const { log } = console;
|
|
27
32
|
export async function collectFiles(files) {
|
|
28
33
|
const result = [];
|
|
29
34
|
for (const filepath of files) {
|
|
30
35
|
clearContext();
|
|
31
36
|
await import(filepath);
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
for (const suite of suites) {
|
|
35
|
-
context.currentSuite = suite;
|
|
36
|
-
const tasks = await suite.collect();
|
|
37
|
-
collected.push([suite, tasks]);
|
|
38
|
-
}
|
|
37
|
+
const collectors = [defaultSuite, ...context.suites];
|
|
38
|
+
const suites = [];
|
|
39
39
|
const file = {
|
|
40
40
|
filepath,
|
|
41
|
-
suites,
|
|
42
|
-
collected,
|
|
41
|
+
suites: [],
|
|
43
42
|
};
|
|
44
|
-
|
|
43
|
+
for (const c of collectors) {
|
|
44
|
+
context.currentSuite = c;
|
|
45
|
+
suites.push(await c.collect(file));
|
|
46
|
+
}
|
|
47
|
+
file.suites = suites;
|
|
45
48
|
result.push(file);
|
|
46
49
|
}
|
|
47
50
|
return result;
|
|
48
51
|
}
|
|
49
|
-
export async function runFile(file) {
|
|
52
|
+
export async function runFile(file, ctx) {
|
|
53
|
+
var _a, _b, _c, _d;
|
|
54
|
+
const { reporter } = ctx;
|
|
55
|
+
await ((_a = reporter.onFileBegin) === null || _a === void 0 ? void 0 : _a.call(reporter, file, ctx));
|
|
50
56
|
await beforeFileHook.fire(file);
|
|
51
|
-
for (const
|
|
57
|
+
for (const suite of file.suites) {
|
|
58
|
+
await ((_b = reporter.onSuiteBegin) === null || _b === void 0 ? void 0 : _b.call(reporter, suite, ctx));
|
|
52
59
|
await beforeSuiteHook.fire(suite);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
log(' '.repeat(indent * 2) + suite.name);
|
|
56
|
-
indent += 1;
|
|
57
|
-
}
|
|
58
|
-
if (suite.mode === 'run' || suite.mode === 'only') {
|
|
59
|
-
// TODO: If there is a task with 'only', skip all others
|
|
60
|
-
await runTasks(tasks);
|
|
61
|
-
for (const t of tasks) {
|
|
62
|
-
if (t.result && t.result.error === undefined) {
|
|
63
|
-
log(`${' '.repeat(indent * 2)}${c.inverse(c.green(' PASS '))} ${c.green(t.name)}`);
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
console.error(`${' '.repeat(indent * 2)}${c.inverse(c.red(' FAIL '))} ${c.red(t.name)}`);
|
|
67
|
-
console.error(' '.repeat((indent + 2) * 2) + c.red(String(t.result.error)));
|
|
68
|
-
process.exitCode = 1;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
else if (suite.mode === 'skip') {
|
|
73
|
-
log(`${' '.repeat(indent * 2)}${c.inverse(c.gray(' SKIP '))}`);
|
|
74
|
-
}
|
|
75
|
-
else if (suite.mode === 'todo') {
|
|
76
|
-
// TODO: In Jest, these suites are collected and printed together at the end of the report
|
|
77
|
-
log(`${' '.repeat(indent * 2)}${c.inverse(c.gray(' TODO '))}`);
|
|
78
|
-
}
|
|
79
|
-
if (suite.name)
|
|
80
|
-
indent -= 1;
|
|
60
|
+
for (const t of suite.tasks)
|
|
61
|
+
await runTask(t, ctx);
|
|
81
62
|
await afterSuiteHook.fire(suite);
|
|
63
|
+
await ((_c = reporter.onSuiteEnd) === null || _c === void 0 ? void 0 : _c.call(reporter, suite, ctx));
|
|
82
64
|
}
|
|
83
65
|
await afterFileHook.fire(file);
|
|
66
|
+
await ((_d = reporter.onFileEnd) === null || _d === void 0 ? void 0 : _d.call(reporter, file, ctx));
|
|
84
67
|
}
|
|
85
68
|
export async function run(options = {}) {
|
|
69
|
+
var _a, _b, _c;
|
|
86
70
|
const { rootDir = process.cwd() } = options;
|
|
87
71
|
chai.use(await SnapshotPlugin({
|
|
88
72
|
rootDir,
|
|
@@ -98,22 +82,22 @@ export async function run(options = {}) {
|
|
|
98
82
|
process.exitCode = 1;
|
|
99
83
|
return;
|
|
100
84
|
}
|
|
85
|
+
const reporter = new DefaultReporter();
|
|
86
|
+
await ((_a = reporter.onStart) === null || _a === void 0 ? void 0 : _a.call(reporter, options));
|
|
101
87
|
const files = await collectFiles(paths);
|
|
88
|
+
const ctx = {
|
|
89
|
+
files,
|
|
90
|
+
mode: isOnlyMode(files) ? 'only' : 'all',
|
|
91
|
+
userOptions: options,
|
|
92
|
+
reporter,
|
|
93
|
+
};
|
|
94
|
+
await ((_b = reporter.onCollected) === null || _b === void 0 ? void 0 : _b.call(reporter, ctx));
|
|
102
95
|
await beforeAllHook.fire();
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
log(`${relative(process.cwd(), file.filepath)}`);
|
|
106
|
-
await runFile(file);
|
|
107
|
-
log();
|
|
108
|
-
}
|
|
109
|
-
const end = performance.now();
|
|
96
|
+
for (const file of files)
|
|
97
|
+
await runFile(file, ctx);
|
|
110
98
|
await afterAllHook.fire();
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (failed.length)
|
|
116
|
-
log(`Failed ${failed.length} / ${tasks.length}`);
|
|
117
|
-
log(`Time ${(end - start).toFixed(2)}ms`);
|
|
118
|
-
log();
|
|
99
|
+
await ((_c = reporter.onFinished) === null || _c === void 0 ? void 0 : _c.call(reporter, ctx));
|
|
100
|
+
}
|
|
101
|
+
function isOnlyMode(files) {
|
|
102
|
+
return !!files.find(file => file.suites.find(suite => suite.mode === 'only' || suite.tasks.find(t => t.mode === 'only')));
|
|
119
103
|
}
|
package/dist/suite.d.ts
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const defaultSuite:
|
|
3
|
-
export declare const test:
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { SuiteCollector, TestFactory, TestFunction } from './types';
|
|
2
|
+
export declare const defaultSuite: SuiteCollector;
|
|
3
|
+
export declare const test: {
|
|
4
|
+
(name: string, fn: TestFunction): void;
|
|
5
|
+
skip(name: string, fn: TestFunction): void;
|
|
6
|
+
only(name: string, fn: TestFunction): void;
|
|
7
|
+
todo(name: string): void;
|
|
8
|
+
};
|
|
9
|
+
export declare function suite(suiteName: string, factory?: TestFactory): SuiteCollector;
|
|
6
10
|
export declare namespace suite {
|
|
7
|
-
var skip: (suiteName: string, factory?: TestFactory | undefined) =>
|
|
8
|
-
var only: (suiteName: string, factory?: TestFactory | undefined) =>
|
|
9
|
-
var todo: (suiteName: string) =>
|
|
11
|
+
var skip: (suiteName: string, factory?: TestFactory | undefined) => SuiteCollector;
|
|
12
|
+
var only: (suiteName: string, factory?: TestFactory | undefined) => SuiteCollector;
|
|
13
|
+
var todo: (suiteName: string) => SuiteCollector;
|
|
10
14
|
}
|
|
11
15
|
export declare const describe: typeof suite;
|
|
12
|
-
export declare const it:
|
|
16
|
+
export declare const it: {
|
|
17
|
+
(name: string, fn: TestFunction): void;
|
|
18
|
+
skip(name: string, fn: TestFunction): void;
|
|
19
|
+
only(name: string, fn: TestFunction): void;
|
|
20
|
+
todo(name: string): void;
|
|
21
|
+
};
|
|
22
|
+
export declare function clearContext(): void;
|
package/dist/suite.js
CHANGED
|
@@ -1,55 +1,75 @@
|
|
|
1
1
|
import { context } from './context';
|
|
2
2
|
export const defaultSuite = suite('');
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
context.suites.length = 0;
|
|
6
|
-
defaultSuite.clear();
|
|
7
|
-
context.currentSuite = defaultSuite;
|
|
3
|
+
function getCurrentSuite() {
|
|
4
|
+
return context.currentSuite || defaultSuite;
|
|
8
5
|
}
|
|
9
|
-
|
|
6
|
+
export const test = (name, fn) => getCurrentSuite().test(name, fn);
|
|
7
|
+
test.skip = (name, fn) => getCurrentSuite().test.skip(name, fn);
|
|
8
|
+
test.only = (name, fn) => getCurrentSuite().test.only(name, fn);
|
|
9
|
+
test.todo = (name) => getCurrentSuite().test.todo(name);
|
|
10
|
+
function createSuiteCollector(mode, suiteName, factory) {
|
|
10
11
|
const queue = [];
|
|
11
12
|
const factoryQueue = [];
|
|
12
|
-
const
|
|
13
|
+
const collector = {
|
|
13
14
|
name: suiteName,
|
|
14
15
|
mode,
|
|
15
16
|
test,
|
|
16
17
|
collect,
|
|
17
18
|
clear,
|
|
18
19
|
};
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
suite,
|
|
20
|
+
function collectTask(name, fn, mode) {
|
|
21
|
+
queue.push({
|
|
22
22
|
name,
|
|
23
|
+
mode,
|
|
24
|
+
suite: {},
|
|
25
|
+
status: 'init',
|
|
23
26
|
fn,
|
|
24
|
-
};
|
|
25
|
-
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function test(name, fn) {
|
|
30
|
+
collectTask(name, fn, mode);
|
|
26
31
|
}
|
|
32
|
+
test.skip = (name, fn) => collectTask(name, fn, 'skip');
|
|
33
|
+
test.only = (name, fn) => collectTask(name, fn, 'only');
|
|
34
|
+
test.todo = (name) => collectTask(name, () => { }, 'todo');
|
|
27
35
|
function clear() {
|
|
28
36
|
queue.length = 0;
|
|
29
37
|
factoryQueue.length = 0;
|
|
30
38
|
}
|
|
31
|
-
async function collect() {
|
|
39
|
+
async function collect(file) {
|
|
32
40
|
factoryQueue.length = 0;
|
|
33
41
|
if (factory)
|
|
34
42
|
await factory(test);
|
|
35
|
-
|
|
43
|
+
const tasks = [...factoryQueue, ...queue];
|
|
44
|
+
const suite = {
|
|
45
|
+
name: collector.name,
|
|
46
|
+
mode: collector.mode,
|
|
47
|
+
tasks,
|
|
48
|
+
file,
|
|
49
|
+
};
|
|
50
|
+
tasks.forEach((task) => {
|
|
51
|
+
task.suite = suite;
|
|
52
|
+
if (file)
|
|
53
|
+
task.file = file;
|
|
54
|
+
});
|
|
55
|
+
return suite;
|
|
36
56
|
}
|
|
37
|
-
context.currentSuite =
|
|
38
|
-
context.suites.push(
|
|
39
|
-
return
|
|
57
|
+
context.currentSuite = collector;
|
|
58
|
+
context.suites.push(collector);
|
|
59
|
+
return collector;
|
|
40
60
|
}
|
|
41
61
|
export function suite(suiteName, factory) {
|
|
42
|
-
return
|
|
62
|
+
return createSuiteCollector('run', suiteName, factory);
|
|
43
63
|
}
|
|
44
|
-
suite.skip =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
suite.only = function skip(suiteName, factory) {
|
|
48
|
-
return processSuite('only', suiteName, factory);
|
|
49
|
-
};
|
|
50
|
-
suite.todo = function skip(suiteName) {
|
|
51
|
-
return processSuite('todo', suiteName);
|
|
52
|
-
};
|
|
64
|
+
suite.skip = (suiteName, factory) => createSuiteCollector('skip', suiteName, factory);
|
|
65
|
+
suite.only = (suiteName, factory) => createSuiteCollector('only', suiteName, factory);
|
|
66
|
+
suite.todo = (suiteName) => createSuiteCollector('todo', suiteName);
|
|
53
67
|
// alias
|
|
54
68
|
export const describe = suite;
|
|
55
69
|
export const it = test;
|
|
70
|
+
// utils
|
|
71
|
+
export function clearContext() {
|
|
72
|
+
context.suites.length = 0;
|
|
73
|
+
defaultSuite.clear();
|
|
74
|
+
context.currentSuite = defaultSuite;
|
|
75
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare type Awaitable<T> = Promise<T> | T;
|
|
1
2
|
export interface UserOptions {
|
|
2
3
|
includes?: string[];
|
|
3
4
|
excludes?: string[];
|
|
@@ -6,31 +7,61 @@ export interface Options extends UserOptions {
|
|
|
6
7
|
rootDir?: string;
|
|
7
8
|
updateSnapshot?: boolean;
|
|
8
9
|
}
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
}
|
|
10
|
+
export declare type RunMode = 'run' | 'skip' | 'only' | 'todo';
|
|
11
|
+
export declare type TaskStatus = 'init' | 'pass' | 'fail' | 'skip' | 'todo';
|
|
12
12
|
export interface Task {
|
|
13
13
|
name: string;
|
|
14
|
+
mode: RunMode;
|
|
14
15
|
suite: Suite;
|
|
15
|
-
fn: () =>
|
|
16
|
+
fn: () => Awaitable<void>;
|
|
16
17
|
file?: File;
|
|
17
|
-
|
|
18
|
+
status: TaskStatus;
|
|
19
|
+
error?: unknown;
|
|
20
|
+
}
|
|
21
|
+
export declare type TestFunction = () => Awaitable<void>;
|
|
22
|
+
export interface TestCollector {
|
|
23
|
+
(name: string, fn: TestFunction): void;
|
|
24
|
+
only: (name: string, fn: TestFunction) => void;
|
|
25
|
+
skip: (name: string, fn: TestFunction) => void;
|
|
26
|
+
todo: (name: string) => void;
|
|
18
27
|
}
|
|
19
|
-
export declare type SuiteMode = 'run' | 'skip' | 'only' | 'todo';
|
|
20
28
|
export interface Suite {
|
|
21
29
|
name: string;
|
|
22
|
-
mode:
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
mode: RunMode;
|
|
31
|
+
tasks: Task[];
|
|
32
|
+
file?: File;
|
|
33
|
+
}
|
|
34
|
+
export interface SuiteCollector {
|
|
35
|
+
name: string;
|
|
36
|
+
mode: RunMode;
|
|
37
|
+
test: TestCollector;
|
|
38
|
+
collect: (file?: File) => Promise<Suite>;
|
|
25
39
|
clear: () => void;
|
|
26
40
|
}
|
|
27
|
-
export declare type TestFactory = (test:
|
|
41
|
+
export declare type TestFactory = (test: (name: string, fn: TestFunction) => void) => Awaitable<void>;
|
|
28
42
|
export interface File {
|
|
29
43
|
filepath: string;
|
|
30
44
|
suites: Suite[];
|
|
31
|
-
|
|
45
|
+
}
|
|
46
|
+
export interface RunnerContext {
|
|
47
|
+
files: File[];
|
|
48
|
+
mode: 'all' | 'only';
|
|
49
|
+
userOptions: Options;
|
|
50
|
+
reporter: Reporter;
|
|
32
51
|
}
|
|
33
52
|
export interface GlobalContext {
|
|
34
|
-
suites:
|
|
35
|
-
currentSuite:
|
|
53
|
+
suites: SuiteCollector[];
|
|
54
|
+
currentSuite: SuiteCollector | null;
|
|
55
|
+
}
|
|
56
|
+
export interface Reporter {
|
|
57
|
+
onStart: (userOptions: Options) => Awaitable<void>;
|
|
58
|
+
onCollected: (ctx: RunnerContext) => Awaitable<void>;
|
|
59
|
+
onFinished: (ctx: RunnerContext) => Awaitable<void>;
|
|
60
|
+
onSuiteBegin: (suite: Suite, ctx: RunnerContext) => Awaitable<void>;
|
|
61
|
+
onSuiteEnd: (suite: Suite, ctx: RunnerContext) => Awaitable<void>;
|
|
62
|
+
onFileBegin: (file: File, ctx: RunnerContext) => Awaitable<void>;
|
|
63
|
+
onFileEnd: (file: File, ctx: RunnerContext) => Awaitable<void>;
|
|
64
|
+
onTaskBegin: (task: Task, ctx: RunnerContext) => Awaitable<void>;
|
|
65
|
+
onTaskEnd: (task: Task, ctx: RunnerContext) => Awaitable<void>;
|
|
66
|
+
onSnapshotUpdate: () => Awaitable<void>;
|
|
36
67
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"jest-util": "^27.4.2",
|
|
54
54
|
"minimist": "^1.2.5",
|
|
55
55
|
"picocolors": "^1.0.0",
|
|
56
|
-
"vite-node": "^0.1.
|
|
56
|
+
"vite-node": "^0.1.10"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "tsc",
|