vitest 0.0.21 → 0.0.25
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.gh.md +212 -0
- package/README.md +3 -170
- package/README.npm.md +8 -0
- package/bin/vitest.mjs +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +0 -2
- package/dist/integrations/chai/setup.d.ts +2 -2
- package/dist/integrations/chai/setup.js +1 -4
- package/dist/integrations/chai/snapshot/index.d.ts +1 -1
- package/dist/integrations/chai/snapshot/index.js +1 -1
- package/dist/{global.d.ts → integrations/global.d.ts} +0 -0
- package/dist/{global.js → integrations/global.js} +2 -2
- package/dist/node/cli.d.ts +10 -0
- package/dist/node/cli.js +60 -0
- package/dist/{entry.d.ts → node/entry.d.ts} +0 -0
- package/dist/node/entry.js +6 -0
- package/dist/node/node.d.ts +22 -0
- package/dist/{node.js → node/node.js} +24 -21
- package/dist/reporters/default.d.ts +5 -8
- package/dist/reporters/default.js +34 -36
- package/dist/run/index.d.ts +8 -0
- package/dist/run/index.js +240 -0
- package/dist/suite.js +2 -2
- package/dist/types.d.ts +39 -10
- package/package.json +23 -17
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -29
- package/dist/config.d.ts +0 -17
- package/dist/config.js +0 -3
- package/dist/entry.js +0 -38
- package/dist/node.d.ts +0 -11
- package/dist/run.d.ts +0 -6
- package/dist/run.js +0 -164
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"keywords": [
|
|
3
|
+
"version": "0.0.25",
|
|
4
|
+
"description": "A blazing fast unit test framework powered by Vite",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"vite",
|
|
7
|
+
"vite-node",
|
|
8
|
+
"test",
|
|
9
|
+
"jest"
|
|
10
|
+
],
|
|
6
11
|
"homepage": "https://github.com/antfu/vitest#readme",
|
|
7
12
|
"bugs": {
|
|
8
13
|
"url": "https://github.com/antfu/vitest/issues"
|
|
@@ -33,6 +38,16 @@
|
|
|
33
38
|
"bin",
|
|
34
39
|
"*.d.ts"
|
|
35
40
|
],
|
|
41
|
+
"scripts": {
|
|
42
|
+
"prepare": "esmo scripts/generate-types.ts",
|
|
43
|
+
"build": "rimraf dist && tsc -p src/tsconfig.json",
|
|
44
|
+
"lint": "eslint \"{src,test}/**/*.ts\"",
|
|
45
|
+
"prepublishOnly": "nr build",
|
|
46
|
+
"release": "bumpp --commit --push --tag && esmo scripts/publish.ts",
|
|
47
|
+
"test": "node bin/vitest.mjs --dev",
|
|
48
|
+
"test:update": "nr test -u",
|
|
49
|
+
"watch": "tsc -p src/tsconfig.json --watch"
|
|
50
|
+
},
|
|
36
51
|
"dependencies": {
|
|
37
52
|
"@jest/test-result": "^27.4.2",
|
|
38
53
|
"@types/chai": "^4.2.22",
|
|
@@ -44,33 +59,24 @@
|
|
|
44
59
|
"jest-util": "^27.4.2",
|
|
45
60
|
"jsdom": "^19.0.0",
|
|
46
61
|
"listr": "^0.14.3",
|
|
47
|
-
"minimist": "^1.2.5",
|
|
48
|
-
"ora": "^6.0.1",
|
|
49
62
|
"picocolors": "^1.0.0",
|
|
63
|
+
"sade": "^1.7.4",
|
|
50
64
|
"sinon": "^12.0.1",
|
|
51
65
|
"sinon-chai": "^3.7.0"
|
|
52
66
|
},
|
|
53
67
|
"devDependencies": {
|
|
54
|
-
"@antfu/eslint-config": "^0.
|
|
68
|
+
"@antfu/eslint-config": "^0.12.1",
|
|
55
69
|
"@antfu/ni": "^0.11.0",
|
|
56
70
|
"@types/jsdom": "^16.2.13",
|
|
57
71
|
"@types/listr": "^0.14.4",
|
|
58
|
-
"@types/minimist": "^1.2.2",
|
|
59
72
|
"@types/node": "^16.11.11",
|
|
73
|
+
"@types/sade": "^1.7.3",
|
|
60
74
|
"@types/sinon": "^10.0.6",
|
|
61
75
|
"bumpp": "^7.1.1",
|
|
62
|
-
"eslint": "^8.
|
|
76
|
+
"eslint": "^8.4.0",
|
|
63
77
|
"esno": "^0.12.1",
|
|
64
78
|
"rimraf": "^3.0.2",
|
|
65
79
|
"typescript": "^4.5.2",
|
|
66
80
|
"vite": "^2.6.14"
|
|
67
|
-
},
|
|
68
|
-
"scripts": {
|
|
69
|
-
"build": "rimraf dist && tsc -p src/tsconfig.json",
|
|
70
|
-
"lint": "eslint \"{src,test}/**/*.ts\"",
|
|
71
|
-
"release": "bumpp --commit --push --tag && pnpm publish",
|
|
72
|
-
"test": "node bin/vitest.mjs --dev",
|
|
73
|
-
"test:update": "nr test -u",
|
|
74
|
-
"watch": "tsc -p src/tsconfig.json --watch"
|
|
75
81
|
}
|
|
76
|
-
}
|
|
82
|
+
}
|
package/dist/cli.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/cli.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
var _a;
|
|
2
|
-
import minimist from 'minimist';
|
|
3
|
-
import c from 'picocolors';
|
|
4
|
-
import { run } from './run';
|
|
5
|
-
const { log } = console;
|
|
6
|
-
const argv = minimist(process.argv.slice(2), {
|
|
7
|
-
alias: {
|
|
8
|
-
u: 'update',
|
|
9
|
-
w: 'watch',
|
|
10
|
-
},
|
|
11
|
-
string: ['root', 'config'],
|
|
12
|
-
boolean: ['update', 'dev', 'global', 'watch', 'jsdom'],
|
|
13
|
-
unknown(name) {
|
|
14
|
-
if (name[0] === '-') {
|
|
15
|
-
console.error(c.red(`Unknown argument: ${name}`));
|
|
16
|
-
help();
|
|
17
|
-
process.exit(1);
|
|
18
|
-
}
|
|
19
|
-
return true;
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
// @ts-expect-error
|
|
23
|
-
const server = (_a = process === null || process === void 0 ? void 0 : process.__vite_node__) === null || _a === void 0 ? void 0 : _a.server;
|
|
24
|
-
const viteConfig = (server === null || server === void 0 ? void 0 : server.config) || {};
|
|
25
|
-
const testOptions = viteConfig.test || {};
|
|
26
|
-
await run(Object.assign(Object.assign(Object.assign({}, argv), testOptions), { server, updateSnapshot: argv.update, rootDir: argv.root || process.cwd(), nameFilters: argv._ }));
|
|
27
|
-
function help() {
|
|
28
|
-
log('Help: finish help');
|
|
29
|
-
}
|
package/dist/config.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { UserConfig } from 'vite';
|
|
2
|
-
import { UserOptions } from './types';
|
|
3
|
-
export interface VitestConfig extends UserConfig {
|
|
4
|
-
/**
|
|
5
|
-
* Options for Vitest
|
|
6
|
-
*/
|
|
7
|
-
test?: UserOptions;
|
|
8
|
-
}
|
|
9
|
-
export declare function defineConfig(config: VitestConfig): VitestConfig;
|
|
10
|
-
declare module 'vite' {
|
|
11
|
-
interface UserConfig {
|
|
12
|
-
/**
|
|
13
|
-
* Options for Vitest
|
|
14
|
-
*/
|
|
15
|
-
test?: UserOptions;
|
|
16
|
-
}
|
|
17
|
-
}
|
package/dist/config.js
DELETED
package/dist/entry.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { fileURLToPath } from 'url';
|
|
2
|
-
import { resolve, dirname } from 'path';
|
|
3
|
-
import minimist from 'minimist';
|
|
4
|
-
import { findUp } from 'find-up';
|
|
5
|
-
import { run } from './node.js';
|
|
6
|
-
process.env.VITEST = 'true';
|
|
7
|
-
const argv = minimist(process.argv.slice(2), {
|
|
8
|
-
alias: {
|
|
9
|
-
c: 'config',
|
|
10
|
-
},
|
|
11
|
-
string: ['root', 'config'],
|
|
12
|
-
boolean: ['dev'],
|
|
13
|
-
});
|
|
14
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
15
|
-
const root = resolve(argv.root || process.cwd());
|
|
16
|
-
const configPath = argv.config
|
|
17
|
-
? resolve(root, argv.config)
|
|
18
|
-
: await findUp(['vitest.config.ts', 'vitest.config.js', 'vitest.config.mjs', 'vite.config.ts', 'vite.config.js', 'vite.config.mjs'], { cwd: root });
|
|
19
|
-
await run({
|
|
20
|
-
root,
|
|
21
|
-
files: [
|
|
22
|
-
resolve(__dirname, argv.dev ? '../src/cli.ts' : './cli.js'),
|
|
23
|
-
],
|
|
24
|
-
config: configPath,
|
|
25
|
-
defaultConfig: {
|
|
26
|
-
optimizeDeps: {
|
|
27
|
-
exclude: [
|
|
28
|
-
'vitest',
|
|
29
|
-
],
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
shouldExternalize(id) {
|
|
33
|
-
if (id.includes('/node_modules/vitest/'))
|
|
34
|
-
return false;
|
|
35
|
-
else
|
|
36
|
-
return id.includes('/node_modules/');
|
|
37
|
-
},
|
|
38
|
-
});
|
package/dist/node.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { InlineConfig } from 'vite';
|
|
2
|
-
export interface ViteNodeOptions {
|
|
3
|
-
silent?: boolean;
|
|
4
|
-
root: string;
|
|
5
|
-
files: string[];
|
|
6
|
-
_?: string[];
|
|
7
|
-
shouldExternalize?: (file: string) => boolean;
|
|
8
|
-
config?: string;
|
|
9
|
-
defaultConfig?: InlineConfig;
|
|
10
|
-
}
|
|
11
|
-
export declare function run(argv: ViteNodeOptions): Promise<void>;
|
package/dist/run.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { File, Config, Task, RunnerContext, Suite } from './types';
|
|
2
|
-
export declare function runTask(task: Task, ctx: RunnerContext): Promise<void>;
|
|
3
|
-
export declare function collectFiles(paths: string[]): Promise<File[]>;
|
|
4
|
-
export declare function runSite(suite: Suite, ctx: RunnerContext): Promise<void>;
|
|
5
|
-
export declare function runFile(file: File, ctx: RunnerContext): Promise<void>;
|
|
6
|
-
export declare function run(config: Config): Promise<void>;
|
package/dist/run.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import fg from 'fast-glob';
|
|
2
|
-
import { setupChai } from './integrations/chai/setup';
|
|
3
|
-
import { clearContext, defaultSuite } from './suite';
|
|
4
|
-
import { context } from './context';
|
|
5
|
-
import { DefaultReporter } from './reporters/default';
|
|
6
|
-
import { defaultIncludes, defaultExcludes } from './constants';
|
|
7
|
-
import { getSnapshotManager } from './integrations/chai/snapshot';
|
|
8
|
-
async function callHook(suite, name, args) {
|
|
9
|
-
await Promise.all(suite.hooks[name].map(fn => fn(...args)));
|
|
10
|
-
}
|
|
11
|
-
export async function runTask(task, ctx) {
|
|
12
|
-
var _a, _b, _c;
|
|
13
|
-
const { reporter } = ctx;
|
|
14
|
-
(_a = getSnapshotManager()) === null || _a === void 0 ? void 0 : _a.setTask(task);
|
|
15
|
-
await ((_b = reporter.onTaskBegin) === null || _b === void 0 ? void 0 : _b.call(reporter, task, ctx));
|
|
16
|
-
if (task.mode === 'run') {
|
|
17
|
-
try {
|
|
18
|
-
await callHook(task.suite, 'beforeEach', [task, task.suite]);
|
|
19
|
-
await task.fn();
|
|
20
|
-
task.state = 'pass';
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
task.state = 'fail';
|
|
24
|
-
task.error = e;
|
|
25
|
-
process.exitCode = 1;
|
|
26
|
-
}
|
|
27
|
-
try {
|
|
28
|
-
await callHook(task.suite, 'afterEach', [task, task.suite]);
|
|
29
|
-
}
|
|
30
|
-
catch (e) {
|
|
31
|
-
task.state = 'fail';
|
|
32
|
-
task.error = e;
|
|
33
|
-
process.exitCode = 1;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
await ((_c = reporter.onTaskEnd) === null || _c === void 0 ? void 0 : _c.call(reporter, task, ctx));
|
|
37
|
-
}
|
|
38
|
-
export async function collectFiles(paths) {
|
|
39
|
-
const files = [];
|
|
40
|
-
for (const filepath of paths) {
|
|
41
|
-
const file = {
|
|
42
|
-
filepath,
|
|
43
|
-
suites: [],
|
|
44
|
-
collected: false,
|
|
45
|
-
};
|
|
46
|
-
clearContext();
|
|
47
|
-
try {
|
|
48
|
-
await import(filepath);
|
|
49
|
-
const collectors = [defaultSuite, ...context.suites];
|
|
50
|
-
for (const c of collectors) {
|
|
51
|
-
context.currentSuite = c;
|
|
52
|
-
file.suites.push(await c.collect(file));
|
|
53
|
-
}
|
|
54
|
-
file.collected = true;
|
|
55
|
-
}
|
|
56
|
-
catch (e) {
|
|
57
|
-
file.error = e;
|
|
58
|
-
file.collected = false;
|
|
59
|
-
process.exitCode = 1;
|
|
60
|
-
}
|
|
61
|
-
files.push(file);
|
|
62
|
-
}
|
|
63
|
-
const allSuites = files.reduce((suites, file) => suites.concat(file.suites), []);
|
|
64
|
-
interpretOnlyMode(allSuites);
|
|
65
|
-
allSuites.forEach((i) => {
|
|
66
|
-
if (i.mode === 'skip')
|
|
67
|
-
i.tasks.forEach(t => t.mode === 'run' && (t.state = 'skip'));
|
|
68
|
-
else
|
|
69
|
-
interpretOnlyMode(i.tasks);
|
|
70
|
-
});
|
|
71
|
-
return files;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* If any items been marked as `only`, mark all other items as `skip`.
|
|
75
|
-
*/
|
|
76
|
-
function interpretOnlyMode(items) {
|
|
77
|
-
if (items.some(i => i.mode === 'only')) {
|
|
78
|
-
items.forEach((i) => {
|
|
79
|
-
if (i.mode === 'run')
|
|
80
|
-
i.mode = 'skip';
|
|
81
|
-
else if (i.mode === 'only')
|
|
82
|
-
i.mode = 'run';
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
export async function runSite(suite, ctx) {
|
|
87
|
-
var _a, _b;
|
|
88
|
-
const { reporter } = ctx;
|
|
89
|
-
await ((_a = reporter.onSuiteBegin) === null || _a === void 0 ? void 0 : _a.call(reporter, suite, ctx));
|
|
90
|
-
if (suite.mode === 'skip') {
|
|
91
|
-
suite.status = 'skip';
|
|
92
|
-
}
|
|
93
|
-
else if (suite.mode === 'todo') {
|
|
94
|
-
suite.status = 'todo';
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
try {
|
|
98
|
-
await callHook(suite, 'beforeAll', [suite]);
|
|
99
|
-
await Promise.all(suite.tasks.map(i => runTask(i, ctx)));
|
|
100
|
-
// for (const t of suite.tasks)
|
|
101
|
-
// await runTask(t, ctx)
|
|
102
|
-
await callHook(suite, 'afterAll', [suite]);
|
|
103
|
-
}
|
|
104
|
-
catch (e) {
|
|
105
|
-
suite.error = e;
|
|
106
|
-
suite.status = 'fail';
|
|
107
|
-
process.exitCode = 1;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
await ((_b = reporter.onSuiteEnd) === null || _b === void 0 ? void 0 : _b.call(reporter, suite, ctx));
|
|
111
|
-
}
|
|
112
|
-
export async function runFile(file, ctx) {
|
|
113
|
-
var _a, _b;
|
|
114
|
-
const { reporter } = ctx;
|
|
115
|
-
const runableSuites = file.suites.filter(i => i.mode === 'run');
|
|
116
|
-
if (runableSuites.length === 0)
|
|
117
|
-
return;
|
|
118
|
-
await ((_a = reporter.onFileBegin) === null || _a === void 0 ? void 0 : _a.call(reporter, file, ctx));
|
|
119
|
-
if (ctx.config.parallel) {
|
|
120
|
-
await Promise.all(file.suites.map(suite => runSite(suite, ctx)));
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
for (const suite of file.suites)
|
|
124
|
-
await runSite(suite, ctx);
|
|
125
|
-
}
|
|
126
|
-
await ((_b = reporter.onFileEnd) === null || _b === void 0 ? void 0 : _b.call(reporter, file, ctx));
|
|
127
|
-
}
|
|
128
|
-
export async function run(config) {
|
|
129
|
-
var _a, _b, _c, _d;
|
|
130
|
-
// setup chai
|
|
131
|
-
await setupChai(config);
|
|
132
|
-
// collect files
|
|
133
|
-
let paths = await fg(config.includes || defaultIncludes, {
|
|
134
|
-
absolute: true,
|
|
135
|
-
cwd: config.rootDir,
|
|
136
|
-
ignore: config.excludes || defaultExcludes,
|
|
137
|
-
});
|
|
138
|
-
if ((_a = config.nameFilters) === null || _a === void 0 ? void 0 : _a.length)
|
|
139
|
-
paths = paths.filter(i => config.nameFilters.some(f => i.includes(f)));
|
|
140
|
-
if (!paths.length) {
|
|
141
|
-
console.error('No test files found');
|
|
142
|
-
process.exitCode = 1;
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
const reporter = new DefaultReporter();
|
|
146
|
-
await ((_b = reporter.onStart) === null || _b === void 0 ? void 0 : _b.call(reporter, config));
|
|
147
|
-
if (config.global)
|
|
148
|
-
(await import('./global')).registerApiGlobally();
|
|
149
|
-
if (config.jsdom)
|
|
150
|
-
(await import('./integrations/jsdom')).setupJSDOM(globalThis);
|
|
151
|
-
const files = await collectFiles(paths);
|
|
152
|
-
const ctx = {
|
|
153
|
-
files,
|
|
154
|
-
config,
|
|
155
|
-
reporter,
|
|
156
|
-
};
|
|
157
|
-
await ((_c = reporter.onCollected) === null || _c === void 0 ? void 0 : _c.call(reporter, ctx));
|
|
158
|
-
for (const file of files)
|
|
159
|
-
await runFile(file, ctx);
|
|
160
|
-
const snapshot = getSnapshotManager();
|
|
161
|
-
snapshot === null || snapshot === void 0 ? void 0 : snapshot.saveSnap();
|
|
162
|
-
snapshot === null || snapshot === void 0 ? void 0 : snapshot.report();
|
|
163
|
-
await ((_d = reporter.onFinished) === null || _d === void 0 ? void 0 : _d.call(reporter, ctx));
|
|
164
|
-
}
|