vitest 0.0.6 → 0.0.7
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/hooks.d.ts +14 -15
- package/dist/hooks.js +4 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/run.d.ts +2 -2
- package/dist/run.js +66 -41
- package/dist/snapshot/index.d.ts +1 -1
- package/dist/snapshot/index.js +7 -9
- package/dist/suite.d.ts +7 -2
- package/dist/suite.js +15 -1
- package/dist/types.d.ts +8 -5
- package/package.json +10 -11
package/dist/hooks.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { Suite, Task } from './types';
|
|
2
|
-
|
|
3
|
-
export declare const beforeHook: {
|
|
1
|
+
import { File, Suite, Task } from './types';
|
|
2
|
+
export declare const beforeAllHook: {
|
|
4
3
|
on(fn: (...args: any[]) => void | Promise<void>): void;
|
|
5
4
|
fire(...args: any[]): Promise<void>;
|
|
6
5
|
clear(): void;
|
|
7
6
|
};
|
|
8
|
-
export declare const
|
|
7
|
+
export declare const afterAllHook: {
|
|
9
8
|
on(fn: (...args: any[]) => void | Promise<void>): void;
|
|
10
9
|
fire(...args: any[]): Promise<void>;
|
|
11
10
|
clear(): void;
|
|
@@ -16,18 +15,18 @@ export declare const beforeEachHook: {
|
|
|
16
15
|
clear(): void;
|
|
17
16
|
};
|
|
18
17
|
export declare const afterEachHook: {
|
|
19
|
-
on(fn: (args_0: Task
|
|
20
|
-
fire(args_0: Task
|
|
18
|
+
on(fn: (args_0: Task) => void | Promise<void>): void;
|
|
19
|
+
fire(args_0: Task): Promise<void>;
|
|
21
20
|
clear(): void;
|
|
22
21
|
};
|
|
23
22
|
export declare const beforeFileHook: {
|
|
24
|
-
on(fn: (args_0:
|
|
25
|
-
fire(args_0:
|
|
23
|
+
on(fn: (args_0: File) => void | Promise<void>): void;
|
|
24
|
+
fire(args_0: File): Promise<void>;
|
|
26
25
|
clear(): void;
|
|
27
26
|
};
|
|
28
27
|
export declare const afterFileHook: {
|
|
29
|
-
on(fn: (args_0:
|
|
30
|
-
fire(args_0:
|
|
28
|
+
on(fn: (args_0: File) => void | Promise<void>): void;
|
|
29
|
+
fire(args_0: File): Promise<void>;
|
|
31
30
|
clear(): void;
|
|
32
31
|
};
|
|
33
32
|
export declare const beforeSuiteHook: {
|
|
@@ -40,11 +39,11 @@ export declare const afterSuiteHook: {
|
|
|
40
39
|
fire(args_0: Suite): Promise<void>;
|
|
41
40
|
clear(): void;
|
|
42
41
|
};
|
|
43
|
-
export declare const
|
|
44
|
-
export declare const
|
|
42
|
+
export declare const beforeAll: (fn: (...args: any[]) => void | Promise<void>) => void;
|
|
43
|
+
export declare const afterAll: (fn: (...args: any[]) => void | Promise<void>) => void;
|
|
45
44
|
export declare const beforeEach: (fn: (args_0: Task) => void | Promise<void>) => void;
|
|
46
|
-
export declare const afterEach: (fn: (args_0: Task
|
|
47
|
-
export declare const beforeFile: (fn: (args_0:
|
|
48
|
-
export declare const afterFile: (fn: (args_0:
|
|
45
|
+
export declare const afterEach: (fn: (args_0: Task) => void | Promise<void>) => void;
|
|
46
|
+
export declare const beforeFile: (fn: (args_0: File) => void | Promise<void>) => void;
|
|
47
|
+
export declare const afterFile: (fn: (args_0: File) => void | Promise<void>) => void;
|
|
49
48
|
export declare const beforeSuite: (fn: (args_0: Suite) => void | Promise<void>) => void;
|
|
50
49
|
export declare const afterSuite: (fn: (args_0: Suite) => void | Promise<void>) => void;
|
package/dist/hooks.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { createHook } from './utils/hook';
|
|
2
|
-
export const
|
|
3
|
-
export const
|
|
2
|
+
export const beforeAllHook = createHook();
|
|
3
|
+
export const afterAllHook = createHook();
|
|
4
4
|
export const beforeEachHook = createHook();
|
|
5
5
|
export const afterEachHook = createHook();
|
|
6
6
|
export const beforeFileHook = createHook();
|
|
7
7
|
export const afterFileHook = createHook();
|
|
8
8
|
export const beforeSuiteHook = createHook();
|
|
9
9
|
export const afterSuiteHook = createHook();
|
|
10
|
-
export const
|
|
11
|
-
export const
|
|
10
|
+
export const beforeAll = beforeAllHook.on;
|
|
11
|
+
export const afterAll = afterAllHook.on;
|
|
12
12
|
export const beforeEach = beforeEachHook.on;
|
|
13
13
|
export const afterEach = afterEachHook.on;
|
|
14
14
|
export const beforeFile = beforeFileHook.on;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/run.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { File, Options, Task, TaskResult } from './types';
|
|
2
2
|
export declare function runTasks(tasks: Task[]): Promise<TaskResult[]>;
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function runFile(
|
|
3
|
+
export declare function collectFiles(files: string[]): Promise<File[]>;
|
|
4
|
+
export declare function runFile(file: File): Promise<void>;
|
|
5
5
|
export declare function run(options?: Options): Promise<void>;
|
package/dist/run.js
CHANGED
|
@@ -1,94 +1,119 @@
|
|
|
1
1
|
import { relative } from 'path';
|
|
2
|
+
import { performance } from 'perf_hooks';
|
|
2
3
|
import c from 'picocolors';
|
|
3
4
|
import chai from 'chai';
|
|
4
5
|
import fg from 'fast-glob';
|
|
5
6
|
import { clearContext, defaultSuite } from './suite';
|
|
6
7
|
import { context } from './context';
|
|
7
|
-
import { afterEachHook, afterFileHook,
|
|
8
|
+
import { afterEachHook, afterFileHook, afterAllHook, afterSuiteHook, beforeEachHook, beforeFileHook, beforeAllHook, beforeSuiteHook } from './hooks';
|
|
8
9
|
import { SnapshotPlugin } from './snapshot/index';
|
|
9
10
|
export async function runTasks(tasks) {
|
|
10
11
|
const results = [];
|
|
11
12
|
for (const task of tasks) {
|
|
12
|
-
const result = { task };
|
|
13
13
|
await beforeEachHook.fire(task);
|
|
14
|
+
task.result = {};
|
|
14
15
|
try {
|
|
15
16
|
await task.fn();
|
|
16
17
|
}
|
|
17
18
|
catch (e) {
|
|
18
|
-
result.error = e;
|
|
19
|
+
task.result.error = e;
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
await afterEachHook.fire(task, result);
|
|
21
|
+
await afterEachHook.fire(task);
|
|
22
22
|
}
|
|
23
23
|
return results;
|
|
24
24
|
}
|
|
25
25
|
// TODO: REPORTER
|
|
26
26
|
const { log } = console;
|
|
27
|
-
export async function
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
27
|
+
export async function collectFiles(files) {
|
|
28
|
+
const result = [];
|
|
29
|
+
for (const filepath of files) {
|
|
30
|
+
clearContext();
|
|
31
|
+
await import(filepath);
|
|
32
|
+
const suites = [defaultSuite, ...context.suites];
|
|
33
|
+
const collected = [];
|
|
34
|
+
for (const suite of suites) {
|
|
35
|
+
context.currentSuite = suite;
|
|
36
|
+
const tasks = await suite.collect();
|
|
37
|
+
collected.push([suite, tasks]);
|
|
38
|
+
}
|
|
39
|
+
const file = {
|
|
40
|
+
filepath,
|
|
41
|
+
suites,
|
|
42
|
+
collected,
|
|
43
|
+
};
|
|
44
|
+
file.collected.forEach(([, tasks]) => tasks.forEach(task => task.file = file));
|
|
45
|
+
result.push(file);
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
43
48
|
}
|
|
44
|
-
export async function runFile(
|
|
45
|
-
await beforeFileHook.fire(
|
|
46
|
-
const
|
|
47
|
-
|
|
49
|
+
export async function runFile(file) {
|
|
50
|
+
await beforeFileHook.fire(file);
|
|
51
|
+
for (const [suite, tasks] of file.collected) {
|
|
52
|
+
await beforeSuiteHook.fire(suite);
|
|
48
53
|
let indent = 1;
|
|
49
54
|
if (suite.name) {
|
|
50
55
|
log(' '.repeat(indent * 2) + suite.name);
|
|
51
56
|
indent += 1;
|
|
52
57
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
}
|
|
62
70
|
}
|
|
63
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
|
+
}
|
|
64
79
|
if (suite.name)
|
|
65
80
|
indent -= 1;
|
|
66
81
|
await afterSuiteHook.fire(suite);
|
|
67
82
|
}
|
|
68
|
-
await afterFileHook.fire(
|
|
83
|
+
await afterFileHook.fire(file);
|
|
69
84
|
}
|
|
70
85
|
export async function run(options = {}) {
|
|
71
86
|
const { rootDir = process.cwd() } = options;
|
|
72
|
-
chai.use(SnapshotPlugin({
|
|
87
|
+
chai.use(await SnapshotPlugin({
|
|
73
88
|
rootDir,
|
|
74
89
|
update: options.updateSnapshot,
|
|
75
90
|
}));
|
|
76
|
-
const
|
|
91
|
+
const paths = await fg(options.includes || ['**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], {
|
|
77
92
|
absolute: true,
|
|
78
93
|
cwd: options.rootDir,
|
|
79
94
|
ignore: options.excludes || ['**/node_modules/**', '**/dist/**'],
|
|
80
95
|
});
|
|
81
|
-
if (!
|
|
96
|
+
if (!paths.length) {
|
|
82
97
|
console.error('No test files found');
|
|
83
98
|
process.exitCode = 1;
|
|
84
99
|
return;
|
|
85
100
|
}
|
|
86
|
-
await
|
|
101
|
+
const files = await collectFiles(paths);
|
|
102
|
+
await beforeAllHook.fire();
|
|
103
|
+
const start = performance.now();
|
|
87
104
|
for (const file of files) {
|
|
88
|
-
log(`${relative(process.cwd(), file)}`);
|
|
105
|
+
log(`${relative(process.cwd(), file.filepath)}`);
|
|
89
106
|
await runFile(file);
|
|
90
107
|
log();
|
|
91
108
|
}
|
|
92
|
-
|
|
109
|
+
const end = performance.now();
|
|
110
|
+
await afterAllHook.fire();
|
|
111
|
+
const tasks = files.reduce((acc, file) => acc.concat(file.collected.flatMap(([, tasks]) => tasks)), []);
|
|
112
|
+
const passed = tasks.filter(i => { var _a; return !((_a = i.result) === null || _a === void 0 ? void 0 : _a.error); });
|
|
113
|
+
const failed = tasks.filter(i => { var _a; return (_a = i.result) === null || _a === void 0 ? void 0 : _a.error; });
|
|
114
|
+
log(`Passed ${passed.length} / ${tasks.length}`);
|
|
115
|
+
if (failed.length)
|
|
116
|
+
log(`Failed ${failed.length} / ${tasks.length}`);
|
|
117
|
+
log(`Time ${(end - start).toFixed(2)}ms`);
|
|
93
118
|
log();
|
|
94
119
|
}
|
package/dist/snapshot/index.d.ts
CHANGED
package/dist/snapshot/index.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import Snap from 'jest-snapshot';
|
|
2
|
-
import {
|
|
2
|
+
import { afterAll, beforeEach } from '../hooks';
|
|
3
3
|
import { SnapshotManager } from './manager';
|
|
4
4
|
const { addSerializer } = Snap;
|
|
5
5
|
let _manager;
|
|
6
|
-
export function SnapshotPlugin(options) {
|
|
6
|
+
export async function SnapshotPlugin(options) {
|
|
7
7
|
const { rootDir } = options;
|
|
8
8
|
_manager = new SnapshotManager({
|
|
9
9
|
rootDir,
|
|
10
10
|
update: options.update,
|
|
11
11
|
});
|
|
12
|
+
_manager.snapshotResolver = await Snap.buildSnapshotResolver({
|
|
13
|
+
transform: [],
|
|
14
|
+
rootDir,
|
|
15
|
+
});
|
|
12
16
|
return function (chai, utils) {
|
|
13
|
-
before(async () => {
|
|
14
|
-
_manager.snapshotResolver = await Snap.buildSnapshotResolver({
|
|
15
|
-
transform: [],
|
|
16
|
-
rootDir,
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
17
|
beforeEach((task) => {
|
|
20
18
|
var _a;
|
|
21
19
|
_manager.setContext({
|
|
@@ -24,7 +22,7 @@ export function SnapshotPlugin(options) {
|
|
|
24
22
|
fullTitle: [task.suite.name, task.name].filter(Boolean).join(' > '),
|
|
25
23
|
});
|
|
26
24
|
});
|
|
27
|
-
|
|
25
|
+
afterAll(() => {
|
|
28
26
|
_manager.saveSnap();
|
|
29
27
|
_manager.report();
|
|
30
28
|
});
|
package/dist/suite.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import { Suite } from './types';
|
|
1
|
+
import { Suite, TestFactory } from './types';
|
|
2
2
|
export declare const defaultSuite: Suite;
|
|
3
3
|
export declare const test: (name: string, fn: () => Promise<void> | void) => void;
|
|
4
4
|
export declare function clearContext(): void;
|
|
5
|
-
export declare function suite(suiteName: string, factory?:
|
|
5
|
+
export declare function suite(suiteName: string, factory?: TestFactory): Suite;
|
|
6
|
+
export declare namespace suite {
|
|
7
|
+
var skip: (suiteName: string, factory?: TestFactory | undefined) => Suite;
|
|
8
|
+
var only: (suiteName: string, factory?: TestFactory | undefined) => Suite;
|
|
9
|
+
var todo: (suiteName: string) => Suite;
|
|
10
|
+
}
|
|
6
11
|
export declare const describe: typeof suite;
|
|
7
12
|
export declare const it: (name: string, fn: () => Promise<void> | void) => void;
|
package/dist/suite.js
CHANGED
|
@@ -4,12 +4,14 @@ export const test = (name, fn) => (context.currentSuite || defaultSuite).test(na
|
|
|
4
4
|
export function clearContext() {
|
|
5
5
|
context.suites.length = 0;
|
|
6
6
|
defaultSuite.clear();
|
|
7
|
+
context.currentSuite = defaultSuite;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
function processSuite(mode, suiteName, factory) {
|
|
9
10
|
const queue = [];
|
|
10
11
|
const factoryQueue = [];
|
|
11
12
|
const suite = {
|
|
12
13
|
name: suiteName,
|
|
14
|
+
mode,
|
|
13
15
|
test,
|
|
14
16
|
collect,
|
|
15
17
|
clear,
|
|
@@ -36,6 +38,18 @@ export function suite(suiteName, factory) {
|
|
|
36
38
|
context.suites.push(suite);
|
|
37
39
|
return suite;
|
|
38
40
|
}
|
|
41
|
+
export function suite(suiteName, factory) {
|
|
42
|
+
return processSuite('run', suiteName, factory);
|
|
43
|
+
}
|
|
44
|
+
suite.skip = function skip(suiteName, factory) {
|
|
45
|
+
return processSuite('skip', suiteName, factory);
|
|
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
|
+
};
|
|
39
53
|
// alias
|
|
40
54
|
export const describe = suite;
|
|
41
55
|
export const it = test;
|
package/dist/types.d.ts
CHANGED
|
@@ -6,26 +6,29 @@ export interface Options extends UserOptions {
|
|
|
6
6
|
rootDir?: string;
|
|
7
7
|
updateSnapshot?: boolean;
|
|
8
8
|
}
|
|
9
|
+
export interface TaskResult {
|
|
10
|
+
error?: unknown;
|
|
11
|
+
}
|
|
9
12
|
export interface Task {
|
|
10
13
|
name: string;
|
|
11
14
|
suite: Suite;
|
|
12
15
|
fn: () => Promise<void> | void;
|
|
13
16
|
file?: File;
|
|
17
|
+
result?: TaskResult;
|
|
14
18
|
}
|
|
15
|
-
export
|
|
16
|
-
task: Task;
|
|
17
|
-
error?: unknown;
|
|
18
|
-
}
|
|
19
|
+
export declare type SuiteMode = 'run' | 'skip' | 'only' | 'todo';
|
|
19
20
|
export interface Suite {
|
|
20
21
|
name: string;
|
|
22
|
+
mode: SuiteMode;
|
|
21
23
|
test: (name: string, fn: () => Promise<void> | void) => void;
|
|
22
24
|
collect: () => Promise<Task[]>;
|
|
23
25
|
clear: () => void;
|
|
24
26
|
}
|
|
27
|
+
export declare type TestFactory = (test: Suite['test']) => Promise<void> | void;
|
|
25
28
|
export interface File {
|
|
26
29
|
filepath: string;
|
|
27
30
|
suites: Suite[];
|
|
28
|
-
|
|
31
|
+
collected: [Suite, Task[]][];
|
|
29
32
|
}
|
|
30
33
|
export interface GlobalContext {
|
|
31
34
|
suites: Suite[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -32,15 +32,6 @@
|
|
|
32
32
|
"bin": {
|
|
33
33
|
"vitest": "./bin/vitest.mjs"
|
|
34
34
|
},
|
|
35
|
-
"scripts": {
|
|
36
|
-
"build": "tsc",
|
|
37
|
-
"watch": "tsc --watch",
|
|
38
|
-
"lint": "eslint \"{src,test}/**/*.ts\"",
|
|
39
|
-
"prepublishOnly": "nr build",
|
|
40
|
-
"release": "bumpp --commit --push --tag && pnpm publish",
|
|
41
|
-
"test": "node bin/vitest.mjs --dev",
|
|
42
|
-
"test:update": "nr test -u"
|
|
43
|
-
},
|
|
44
35
|
"devDependencies": {
|
|
45
36
|
"@antfu/eslint-config": "^0.11.1",
|
|
46
37
|
"@antfu/ni": "^0.11.0",
|
|
@@ -63,5 +54,13 @@
|
|
|
63
54
|
"minimist": "^1.2.5",
|
|
64
55
|
"picocolors": "^1.0.0",
|
|
65
56
|
"vite-node": "^0.1.9"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "tsc",
|
|
60
|
+
"watch": "tsc --watch",
|
|
61
|
+
"lint": "eslint \"{src,test}/**/*.ts\"",
|
|
62
|
+
"release": "bumpp --commit --push --tag && pnpm publish",
|
|
63
|
+
"test": "node bin/vitest.mjs --dev",
|
|
64
|
+
"test:update": "nr test -u"
|
|
66
65
|
}
|
|
67
|
-
}
|
|
66
|
+
}
|