vitest 0.0.24 → 0.0.28
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 +35 -1
- package/README.md +1 -1
- package/README.npm.md +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/integrations/chai/jest-expect.js +15 -3
- package/dist/integrations/chai/setup.js +2 -0
- package/dist/node/entry.js +2 -1
- package/dist/reporters/default.js +14 -8
- package/dist/run/index.js +7 -5
- package/dist/types.d.ts +7 -0
- package/package.json +4 -2
package/README.gh.md
CHANGED
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
A blazing fast unit test framework powered by Vite.
|
|
6
6
|
|
|
7
|
-
> **This project is currently in closed beta exclusively for Sponsors
|
|
7
|
+
> **This project is currently in closed beta exclusively for Sponsors.**<br>
|
|
8
8
|
> Become a Sponsor of [@patak-js](https://github.com/sponsors/patak-js) or [@antfu](https://github.com/sponsors/antfu) to access the source code and issues tracker.
|
|
9
9
|
|
|
10
|
+
> ⚠️ **DISCLAIMER**: Vitest is still in development and not stable yet. It's not recommended to use it in production.
|
|
11
|
+
|
|
10
12
|
## Features
|
|
11
13
|
|
|
12
14
|
- [Vite](https://vitejs.dev/)'s config, transformers, resolvers, and plugins.
|
|
@@ -91,6 +93,29 @@ To get TypeScript working with the global APIs, add `vitest/global` to the `type
|
|
|
91
93
|
}
|
|
92
94
|
```
|
|
93
95
|
|
|
96
|
+
## Browser Mocking
|
|
97
|
+
|
|
98
|
+
Pass `--jsdom` option in CLI to enable browser mocking. Or the `jsdom` flag in the config.
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
// vite.config.ts
|
|
102
|
+
import { defineConfig } from 'vite'
|
|
103
|
+
|
|
104
|
+
export default defineConfig({
|
|
105
|
+
test: {
|
|
106
|
+
jsdom: true
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Watch Mode
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
$ vitest -w
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Vitest will smartly search for the module graph to only rerun the related tests.
|
|
118
|
+
|
|
94
119
|
## Filtering
|
|
95
120
|
|
|
96
121
|
### Skipping suites and tasks
|
|
@@ -173,6 +198,15 @@ describe('suite', () => {
|
|
|
173
198
|
</a>
|
|
174
199
|
</p>
|
|
175
200
|
|
|
201
|
+
## Credits
|
|
202
|
+
|
|
203
|
+
Thanks to:
|
|
204
|
+
|
|
205
|
+
- [@patak-js](https://github.com/patak-js) for the awesome package name!
|
|
206
|
+
- [The Vite team](https://github.com/vitejs/vite) for brainstorming the initial idea.
|
|
207
|
+
- [@pi0](https://github.com/pi0) for the idea and implementation of using Vite to transform and bundle the server code.
|
|
208
|
+
- [@lukeed](https://github.com/lukeed) for the work on [uvu](https://github.com/lukeed/uvu) where we are inspired a lot from.
|
|
209
|
+
|
|
176
210
|
## License
|
|
177
211
|
|
|
178
212
|
[MIT](./LICENSE) License © 2021 [Anthony Fu](https://github.com/antfu)
|
package/README.md
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
|
|
5
5
|
A blazing fast unit test framework powered by Vite.
|
|
6
6
|
|
|
7
|
-
> **This project is currently in closed beta exclusively for Sponsors
|
|
7
|
+
> **This project is currently in closed beta exclusively for Sponsors.**<br>
|
|
8
8
|
> Become a Sponsor of [@patak-js](https://github.com/sponsors/patak-js) or [@antfu](https://github.com/sponsors/antfu) to access the source code and issues tracker.
|
package/README.npm.md
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
|
|
5
5
|
A blazing fast unit test framework powered by Vite.
|
|
6
6
|
|
|
7
|
-
> **This project is currently in closed beta exclusively for Sponsors
|
|
7
|
+
> **This project is currently in closed beta exclusively for Sponsors.**<br>
|
|
8
8
|
> Become a Sponsor of [@patak-js](https://github.com/sponsors/patak-js) or [@antfu](https://github.com/sponsors/antfu) to access the source code and issues tracker.
|
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ declare global {
|
|
|
19
19
|
toEqual(expected: any): void;
|
|
20
20
|
toStrictEqual(expected: any): void;
|
|
21
21
|
toBe(expected: any): void;
|
|
22
|
+
toMatch(expected: string | RegExp): void;
|
|
23
|
+
toMatchObject(expected: any): void;
|
|
22
24
|
toContain(item: any): void;
|
|
23
25
|
toBeTruthy(): void;
|
|
24
26
|
toBeFalsy(): void;
|
|
@@ -27,10 +29,10 @@ declare global {
|
|
|
27
29
|
toBeNull(): void;
|
|
28
30
|
toBeDefined(): void;
|
|
29
31
|
toBeInstanceOf(c: any): void;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
toBeCalled(): void;
|
|
32
|
+
toHaveBeenCalledTimes(n: number): void;
|
|
33
|
+
toHaveBeenCalledOnce(): void;
|
|
33
34
|
toHaveBeenCalled(): void;
|
|
35
|
+
toHaveBeenCalledWith(...args: any[]): void;
|
|
34
36
|
}
|
|
35
37
|
interface ExpectStatic {
|
|
36
38
|
addSnapshotSerializer: import('pretty-format').Plugin;
|
|
@@ -12,6 +12,15 @@ export function JestChaiExpect() {
|
|
|
12
12
|
utils.addMethod(proto, 'toBe', function (expected) {
|
|
13
13
|
return this.equal(expected);
|
|
14
14
|
});
|
|
15
|
+
utils.addMethod(proto, 'toMatchObject', function (expected) {
|
|
16
|
+
return this.containSubset(expected);
|
|
17
|
+
});
|
|
18
|
+
utils.addMethod(proto, 'toMatch', function (expected) {
|
|
19
|
+
if (typeof expected === 'string')
|
|
20
|
+
return this.include(expected);
|
|
21
|
+
else
|
|
22
|
+
return this.match(expected);
|
|
23
|
+
});
|
|
15
24
|
utils.addMethod(proto, 'toContain', function (item) {
|
|
16
25
|
return this.contain(item);
|
|
17
26
|
});
|
|
@@ -39,17 +48,20 @@ export function JestChaiExpect() {
|
|
|
39
48
|
return this.instanceOf(obj);
|
|
40
49
|
});
|
|
41
50
|
// mock
|
|
42
|
-
utils.addMethod(proto, '
|
|
51
|
+
utils.addMethod(proto, 'toHaveBeenCalledTimes', function (number) {
|
|
43
52
|
return this.callCount(number);
|
|
44
53
|
});
|
|
45
|
-
utils.addMethod(proto, '
|
|
54
|
+
utils.addMethod(proto, 'toHaveBeenCalledOnce', function () {
|
|
46
55
|
return this.callCount(1);
|
|
47
56
|
});
|
|
48
|
-
utils.addMethod(proto, '
|
|
57
|
+
utils.addMethod(proto, 'toHaveBeenCalled', function () {
|
|
49
58
|
return this.called;
|
|
50
59
|
});
|
|
51
60
|
utils.addMethod(proto, 'toHaveBeenCalled', function () {
|
|
52
61
|
return this.called;
|
|
53
62
|
});
|
|
63
|
+
utils.addMethod(proto, 'toHaveBeenCalledWith', function (...args) {
|
|
64
|
+
return this.calledWith(...args);
|
|
65
|
+
});
|
|
54
66
|
};
|
|
55
67
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import chai from 'chai';
|
|
2
2
|
import SinonChai from 'sinon-chai';
|
|
3
|
+
import Subset from 'chai-subset';
|
|
3
4
|
import { JestChaiExpect } from './jest-expect';
|
|
4
5
|
import { SnapshotPlugin } from './snapshot';
|
|
5
6
|
export async function setupChai(config) {
|
|
6
7
|
chai.use(SinonChai);
|
|
7
8
|
chai.use(JestChaiExpect());
|
|
9
|
+
chai.use(Subset);
|
|
8
10
|
chai.use(await SnapshotPlugin(config));
|
|
9
11
|
}
|
package/dist/node/entry.js
CHANGED
|
@@ -3,4 +3,5 @@ if (!process.__vite_node__ || !process.__vitest__)
|
|
|
3
3
|
throw new Error('Vitest can only run in vite-node environment, please use the CLI to start the process');
|
|
4
4
|
const inlineOptions = process.__vite_node__.server.config.test || {};
|
|
5
5
|
const cliOptions = process.__vitest__.options || {};
|
|
6
|
-
|
|
6
|
+
const options = Object.assign(Object.assign({}, cliOptions), inlineOptions);
|
|
7
|
+
await run(options);
|
|
@@ -43,7 +43,12 @@ export class DefaultReporter {
|
|
|
43
43
|
return {
|
|
44
44
|
title: relative(process.cwd(), file.filepath),
|
|
45
45
|
task: () => {
|
|
46
|
-
|
|
46
|
+
if (file.error)
|
|
47
|
+
throw file.error;
|
|
48
|
+
const suites = file.suites.filter(i => i.tasks.length);
|
|
49
|
+
if (!suites.length)
|
|
50
|
+
throw new Error('No tasks found');
|
|
51
|
+
return new Listr(suites.flatMap((suite) => {
|
|
47
52
|
if (!suite.name)
|
|
48
53
|
return createTasksListr(suite.tasks);
|
|
49
54
|
return [{
|
|
@@ -85,7 +90,7 @@ export class DefaultReporter {
|
|
|
85
90
|
});
|
|
86
91
|
}
|
|
87
92
|
if (failedSuites.length) {
|
|
88
|
-
console.error(c.bold(`\nFailed to run ${failedSuites.length} suites:`));
|
|
93
|
+
console.error(c.bold(c.red(`\nFailed to run ${failedSuites.length} suites:`)));
|
|
89
94
|
failedSuites.forEach((i) => {
|
|
90
95
|
var _a;
|
|
91
96
|
console.error(c.red(`\n- ${(_a = i.file) === null || _a === void 0 ? void 0 : _a.filepath} > ${i.name}`));
|
|
@@ -94,7 +99,7 @@ export class DefaultReporter {
|
|
|
94
99
|
});
|
|
95
100
|
}
|
|
96
101
|
if (failed.length) {
|
|
97
|
-
console.error(c.bold(`\nFailed Tests (${failed.length})`));
|
|
102
|
+
console.error(c.bold(c.red(`\nFailed Tests (${failed.length})`)));
|
|
98
103
|
failed.forEach((task) => {
|
|
99
104
|
var _a;
|
|
100
105
|
console.error(`\n${CROSS + c.inverse(c.red(' FAIL '))} ${[task.suite.name, task.name].filter(Boolean).join(' > ')} ${c.gray(c.dim(`${(_a = task.file) === null || _a === void 0 ? void 0 : _a.filepath}`))}`);
|
|
@@ -113,15 +118,16 @@ export class DefaultReporter {
|
|
|
113
118
|
}
|
|
114
119
|
async onWatcherStart(ctx) {
|
|
115
120
|
await this.listrPromise;
|
|
116
|
-
const failed = ctx.tasks.
|
|
117
|
-
if (failed)
|
|
118
|
-
console.log(c.red('
|
|
121
|
+
const failed = ctx.tasks.filter(i => i.state === 'fail');
|
|
122
|
+
if (failed.length)
|
|
123
|
+
console.log(`\n${c.bold(c.inverse(c.red(' FAIL ')))}${c.red(` ${failed.length} tests failed. Watching for file changes...`)}`);
|
|
119
124
|
else
|
|
120
|
-
console.log(c.green('
|
|
125
|
+
console.log(`\n${c.bold(c.inverse(c.green(' PASS ')))}${c.green(' Watching for file changes...')}`);
|
|
121
126
|
}
|
|
122
127
|
async onWatcherRerun(files, trigger) {
|
|
123
128
|
await this.listrPromise;
|
|
124
|
-
console.
|
|
129
|
+
console.clear();
|
|
130
|
+
console.log(c.blue('Re-running tests...') + c.dim(` [ ${relative(process.cwd(), trigger)} ]\n`));
|
|
125
131
|
}
|
|
126
132
|
// TODO:
|
|
127
133
|
onSnapshotUpdate() {
|
package/dist/run/index.js
CHANGED
|
@@ -98,9 +98,8 @@ export async function runSuite(suite, ctx) {
|
|
|
98
98
|
else {
|
|
99
99
|
try {
|
|
100
100
|
await callHook(suite, 'beforeAll', [suite]);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// await runTask(t, ctx)
|
|
101
|
+
for (const t of suite.tasks)
|
|
102
|
+
await runTask(t, ctx);
|
|
104
103
|
await callHook(suite, 'afterAll', [suite]);
|
|
105
104
|
}
|
|
106
105
|
catch (e) {
|
|
@@ -136,6 +135,8 @@ export async function runFiles(filesMap, ctx) {
|
|
|
136
135
|
}
|
|
137
136
|
export async function run(config) {
|
|
138
137
|
var _a, _b, _c;
|
|
138
|
+
config.reporter = config.reporter || new DefaultReporter();
|
|
139
|
+
const { reporter } = config;
|
|
139
140
|
// if watch, tell `vite-node` not to end the process
|
|
140
141
|
if (config.watch)
|
|
141
142
|
process.__vite_node__.watch = true;
|
|
@@ -160,7 +161,6 @@ export async function run(config) {
|
|
|
160
161
|
(await import('../integrations/global')).registerApiGlobally();
|
|
161
162
|
if (config.jsdom)
|
|
162
163
|
(await import('../integrations/jsdom')).setupJSDOM(globalThis);
|
|
163
|
-
const reporter = new DefaultReporter();
|
|
164
164
|
await ((_b = reporter.onStart) === null || _b === void 0 ? void 0 : _b.call(reporter, config));
|
|
165
165
|
const filesMap = await collectFiles(testFilepaths);
|
|
166
166
|
const ctx = {
|
|
@@ -177,7 +177,7 @@ export async function run(config) {
|
|
|
177
177
|
.reduce((tasks, suite) => tasks.concat(suite.tasks), []);
|
|
178
178
|
},
|
|
179
179
|
config,
|
|
180
|
-
reporter,
|
|
180
|
+
reporter: config.reporter,
|
|
181
181
|
};
|
|
182
182
|
await runFiles(filesMap, ctx);
|
|
183
183
|
const snapshot = getSnapshotManager();
|
|
@@ -203,6 +203,8 @@ export async function startWatcher(ctx) {
|
|
|
203
203
|
clearTimeout(timer);
|
|
204
204
|
timer = setTimeout(async () => {
|
|
205
205
|
var _a, _b, _c, _d;
|
|
206
|
+
if (changedTests.size === 0)
|
|
207
|
+
return;
|
|
206
208
|
const snapshot = getSnapshotManager();
|
|
207
209
|
const paths = Array.from(changedTests);
|
|
208
210
|
changedTests.clear();
|
package/dist/types.d.ts
CHANGED
|
@@ -41,7 +41,14 @@ export interface UserOptions {
|
|
|
41
41
|
* @default false
|
|
42
42
|
*/
|
|
43
43
|
watch?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Project root
|
|
46
|
+
*/
|
|
44
47
|
root?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Custom reporter for output
|
|
50
|
+
*/
|
|
51
|
+
reporter?: Reporter;
|
|
45
52
|
}
|
|
46
53
|
export interface ResolvedConfig extends Required<UserOptions> {
|
|
47
54
|
filters?: string[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28",
|
|
4
4
|
"description": "A blazing fast unit test framework powered by Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"lint": "eslint \"{src,test}/**/*.ts\"",
|
|
45
45
|
"prepublishOnly": "nr build",
|
|
46
46
|
"release": "bumpp --commit --push --tag && esmo scripts/publish.ts",
|
|
47
|
-
"test": "node bin/vitest.mjs --dev",
|
|
47
|
+
"test": "node bin/vitest.mjs --dev -r test/core",
|
|
48
48
|
"test:update": "nr test -u",
|
|
49
49
|
"watch": "tsc -p src/tsconfig.json --watch"
|
|
50
50
|
},
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"@types/chai": "^4.2.22",
|
|
54
54
|
"@types/sinon-chai": "^3.2.6",
|
|
55
55
|
"chai": "^4.3.4",
|
|
56
|
+
"chai-subset": "^1.6.0",
|
|
56
57
|
"fast-glob": "^3.2.7",
|
|
57
58
|
"find-up": "^6.2.0",
|
|
58
59
|
"jest-snapshot": "^27.4.2",
|
|
@@ -67,6 +68,7 @@
|
|
|
67
68
|
"devDependencies": {
|
|
68
69
|
"@antfu/eslint-config": "^0.12.1",
|
|
69
70
|
"@antfu/ni": "^0.11.0",
|
|
71
|
+
"@types/chai-subset": "^1.3.3",
|
|
70
72
|
"@types/jsdom": "^16.2.13",
|
|
71
73
|
"@types/listr": "^0.14.4",
|
|
72
74
|
"@types/node": "^16.11.11",
|