vitest 0.0.23 → 0.0.24
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 +178 -0
- package/README.md +2 -169
- 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/{global.d.ts → integrations/global.d.ts} +0 -0
- package/dist/{global.js → integrations/global.js} +2 -2
- package/dist/{cli.d.ts → node/cli.d.ts} +1 -1
- package/dist/{cli.js → node/cli.js} +6 -2
- package/dist/{entry.d.ts → node/entry.d.ts} +0 -0
- package/dist/{entry.js → node/entry.js} +1 -1
- package/dist/node/{index.d.ts → node.d.ts} +0 -0
- package/dist/node/{index.js → node.js} +0 -0
- package/dist/reporters/default.js +3 -3
- package/dist/run/index.d.ts +1 -1
- package/dist/run/index.js +12 -11
- package/dist/suite.js +2 -2
- package/dist/types.d.ts +9 -0
- package/package.json +14 -12
- package/dist/config.d.ts +0 -17
- package/dist/config.js +0 -3
package/README.gh.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# vitest
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/vitest)
|
|
4
|
+
|
|
5
|
+
A blazing fast unit test framework powered by Vite.
|
|
6
|
+
|
|
7
|
+
> **This project is currently in closed beta exclusively for Sponsors.**
|
|
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
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- [Vite](https://vitejs.dev/)'s config, transformers, resolvers, and plugins.
|
|
13
|
+
- [Jest Snapshot](https://jestjs.io/docs/snapshot-testing)
|
|
14
|
+
- [Chai](https://www.chaijs.com/) for assertions
|
|
15
|
+
- [Sinon](https://sinonjs.org/) for mocking
|
|
16
|
+
- [JSDOM](https://github.com/jsdom/jsdom) for DOM mocking
|
|
17
|
+
- Async suite / test, top level await
|
|
18
|
+
- ESM friendly
|
|
19
|
+
- Out-of-box TypeScript support
|
|
20
|
+
- Suite and Test filtering (skip, only, todo)
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { it, describe, expect, assert } from 'vitest'
|
|
24
|
+
|
|
25
|
+
describe('suite name', () => {
|
|
26
|
+
it('foo', () => {
|
|
27
|
+
expect(1 + 1).toEqual(2)
|
|
28
|
+
expect(true).to.be.true
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('bar', () => {
|
|
32
|
+
assert.equal(Math.sqrt(4), 2)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('snapshot', () => {
|
|
36
|
+
expect({ foo: 'bar' }).toMatchSnapshot()
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
$ npx vitest
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Configuration
|
|
46
|
+
|
|
47
|
+
`vitest` will read your root `vite.config.ts` when it present to match with the plugins and setup as your Vite app. If you want to it to have a different configuration for testing, you could either:
|
|
48
|
+
|
|
49
|
+
- Create `vitest.config.ts`, which will have the higher priority
|
|
50
|
+
- Pass `--config` option to CLI, e.g. `vitest --config ./path/to/vitest.config.ts`
|
|
51
|
+
- Use `process.env.VITEST` to conditionally apply differnet configuration in `vite.config.ts`
|
|
52
|
+
|
|
53
|
+
To configure `vitest` itself, add `test` property in your Vite config
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
// vite.config.ts
|
|
57
|
+
import { defineConfig } from 'vite'
|
|
58
|
+
|
|
59
|
+
export default defineConfig({
|
|
60
|
+
test: {
|
|
61
|
+
// ...
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Global APIs
|
|
67
|
+
|
|
68
|
+
By default, `vitest` does not provide global APIs for explicitness. If you prefer to use the APIs globally like Jest, you can pass the `--global` option to CLI or add `global: true` in the config.
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
// vite.config.ts
|
|
72
|
+
import { defineConfig } from 'vite'
|
|
73
|
+
|
|
74
|
+
export default defineConfig({
|
|
75
|
+
test: {
|
|
76
|
+
global: true
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
To get TypeScript working with the global APIs, add `vitest/global` to the `types` filed in your `tsconfig.json`
|
|
82
|
+
|
|
83
|
+
```json
|
|
84
|
+
// tsconfig.json
|
|
85
|
+
{
|
|
86
|
+
"compilerOptions": {
|
|
87
|
+
"types": [
|
|
88
|
+
"vitest/global"
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Filtering
|
|
95
|
+
|
|
96
|
+
### Skipping suites and tasks
|
|
97
|
+
|
|
98
|
+
Use `.skip` to avoid running certain suites or tests
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
describe.skip('skipped suite', () => {
|
|
102
|
+
it('task', () => {
|
|
103
|
+
// Suite skipped, no error
|
|
104
|
+
assert.equal(Math.sqrt(4), 3)
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
describe('suite', () => {
|
|
109
|
+
it.skip('skipped task', () => {
|
|
110
|
+
// Task skipped, no error
|
|
111
|
+
assert.equal(Math.sqrt(4), 3)
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Selecting suites and tests to run
|
|
117
|
+
|
|
118
|
+
Use `.only` to only run certain suites or tests
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
// Only this suite (and others marked with only) are run
|
|
122
|
+
describe.only('suite', () => {
|
|
123
|
+
it('task', () => {
|
|
124
|
+
assert.equal(Math.sqrt(4), 3)
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
describe('another suite', () => {
|
|
129
|
+
it('skipped task', () => {
|
|
130
|
+
// Task skipped, as tests are running in Only mode
|
|
131
|
+
assert.equal(Math.sqrt(4), 3)
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
it.only('task', () => {
|
|
135
|
+
// Only this task (and others marked with only) are run
|
|
136
|
+
assert.equal(Math.sqrt(4), 2)
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Unimplemented suites and tests
|
|
142
|
+
|
|
143
|
+
Use `.todo` to stub suites and tests that should be implemented
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
// An entry will be shown in the report for this suite
|
|
147
|
+
describe.todo('unimplemented suite')
|
|
148
|
+
|
|
149
|
+
// An entry will be shown in the report for this task
|
|
150
|
+
describe('suite', () => {
|
|
151
|
+
it.todo('unimplemented task')
|
|
152
|
+
})
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## TODO
|
|
156
|
+
|
|
157
|
+
- [x] Reporter & Better output
|
|
158
|
+
- [x] Task filter
|
|
159
|
+
- [x] Mock
|
|
160
|
+
- [x] Global Mode & Types
|
|
161
|
+
- [ ] Parallel Executing
|
|
162
|
+
- [x] CLI Help
|
|
163
|
+
- [x] JSDom
|
|
164
|
+
- [x] Watch
|
|
165
|
+
- [ ] Source Map
|
|
166
|
+
- [ ] Coverage
|
|
167
|
+
|
|
168
|
+
## Sponsors
|
|
169
|
+
|
|
170
|
+
<p align="center">
|
|
171
|
+
<a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
|
|
172
|
+
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
|
|
173
|
+
</a>
|
|
174
|
+
</p>
|
|
175
|
+
|
|
176
|
+
## License
|
|
177
|
+
|
|
178
|
+
[MIT](./LICENSE) License © 2021 [Anthony Fu](https://github.com/antfu)
|
package/README.md
CHANGED
|
@@ -4,172 +4,5 @@
|
|
|
4
4
|
|
|
5
5
|
A blazing fast unit test framework powered by Vite.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
- [Vite](https://vitejs.dev/)'s config, transformers, resolvers, and plugins.
|
|
10
|
-
- [Jest Snapshot](https://jestjs.io/docs/snapshot-testing)
|
|
11
|
-
- [Chai](https://www.chaijs.com/) for assertions
|
|
12
|
-
- [Sinon](https://sinonjs.org/) for mocking
|
|
13
|
-
- [JSDOM](https://github.com/jsdom/jsdom) for DOM mocking
|
|
14
|
-
- Async suite / test, top level await
|
|
15
|
-
- ESM friendly
|
|
16
|
-
- Out-of-box TypeScript support
|
|
17
|
-
- Suite and Test filtering (skip, only, todo)
|
|
18
|
-
|
|
19
|
-
```ts
|
|
20
|
-
import { it, describe, expect, assert } from 'vitest'
|
|
21
|
-
|
|
22
|
-
describe('suite name', () => {
|
|
23
|
-
it('foo', () => {
|
|
24
|
-
expect(1 + 1).toEqual(2)
|
|
25
|
-
expect(true).to.be.true
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
it('bar', () => {
|
|
29
|
-
assert.equal(Math.sqrt(4), 2)
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it('snapshot', () => {
|
|
33
|
-
expect({ foo: 'bar' }).toMatchSnapshot()
|
|
34
|
-
})
|
|
35
|
-
})
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
$ npx vitest
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Configuration
|
|
43
|
-
|
|
44
|
-
`vitest` will read your root `vite.config.ts` when it present to match with the plugins and setup as your Vite app. If you want to it to have a different configuration for testing, you could either:
|
|
45
|
-
|
|
46
|
-
- Create `vitest.config.ts`, which will have the higher priority
|
|
47
|
-
- Pass `--config` option to CLI, e.g. `vitest --config ./path/to/vitest.config.ts`
|
|
48
|
-
- Use `process.env.VITEST` to conditionally apply differnet configuration in `vite.config.ts`
|
|
49
|
-
|
|
50
|
-
To configure `vitest` itself, add `test` property in your Vite config
|
|
51
|
-
|
|
52
|
-
```ts
|
|
53
|
-
// vite.config.ts
|
|
54
|
-
import { defineConfig } from 'vite'
|
|
55
|
-
|
|
56
|
-
export default defineConfig({
|
|
57
|
-
test: {
|
|
58
|
-
// ...
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## Global APIs
|
|
64
|
-
|
|
65
|
-
By default, `vitest` does not provide global APIs for explicitness. If you prefer to use the APIs globally like Jest, you can pass the `--global` option to CLI or add `global: true` in the config.
|
|
66
|
-
|
|
67
|
-
```ts
|
|
68
|
-
// vite.config.ts
|
|
69
|
-
import { defineConfig } from 'vite'
|
|
70
|
-
|
|
71
|
-
export default defineConfig({
|
|
72
|
-
test: {
|
|
73
|
-
global: true
|
|
74
|
-
}
|
|
75
|
-
})
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
To get TypeScript working with the global APIs, add `vitest/global` to the `types` filed in your `tsconfig.json`
|
|
79
|
-
|
|
80
|
-
```json
|
|
81
|
-
// tsconfig.json
|
|
82
|
-
{
|
|
83
|
-
"compilerOptions": {
|
|
84
|
-
"types": [
|
|
85
|
-
"vitest/global"
|
|
86
|
-
]
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
## Filtering
|
|
92
|
-
|
|
93
|
-
### Skipping suites and tasks
|
|
94
|
-
|
|
95
|
-
Use `.skip` to avoid running certain suites or tests
|
|
96
|
-
|
|
97
|
-
```ts
|
|
98
|
-
describe.skip('skipped suite', () => {
|
|
99
|
-
it('task', () => {
|
|
100
|
-
// Suite skipped, no error
|
|
101
|
-
assert.equal(Math.sqrt(4), 3)
|
|
102
|
-
})
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
describe('suite', () => {
|
|
106
|
-
it.skip('skipped task', () => {
|
|
107
|
-
// Task skipped, no error
|
|
108
|
-
assert.equal(Math.sqrt(4), 3)
|
|
109
|
-
})
|
|
110
|
-
})
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
### Selecting suites and tests to run
|
|
114
|
-
|
|
115
|
-
Use `.only` to only run certain suites or tests
|
|
116
|
-
|
|
117
|
-
```ts
|
|
118
|
-
// Only this suite (and others marked with only) are run
|
|
119
|
-
describe.only('suite', () => {
|
|
120
|
-
it('task', () => {
|
|
121
|
-
assert.equal(Math.sqrt(4), 3)
|
|
122
|
-
})
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
describe('another suite', () => {
|
|
126
|
-
it('skipped task', () => {
|
|
127
|
-
// Task skipped, as tests are running in Only mode
|
|
128
|
-
assert.equal(Math.sqrt(4), 3)
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
it.only('task', () => {
|
|
132
|
-
// Only this task (and others marked with only) are run
|
|
133
|
-
assert.equal(Math.sqrt(4), 2)
|
|
134
|
-
})
|
|
135
|
-
})
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
### Unimplemented suites and tests
|
|
139
|
-
|
|
140
|
-
Use `.todo` to stub suites and tests that should be implemented
|
|
141
|
-
|
|
142
|
-
```ts
|
|
143
|
-
// An entry will be shown in the report for this suite
|
|
144
|
-
describe.todo('unimplemented suite')
|
|
145
|
-
|
|
146
|
-
// An entry will be shown in the report for this task
|
|
147
|
-
describe('suite', () => {
|
|
148
|
-
it.todo('unimplemented task')
|
|
149
|
-
})
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
## TODO
|
|
153
|
-
|
|
154
|
-
- [x] Reporter & Better output
|
|
155
|
-
- [x] Task filter
|
|
156
|
-
- [x] Mock
|
|
157
|
-
- [x] Global Mode & Types
|
|
158
|
-
- [ ] Concurrent Executing
|
|
159
|
-
- [x] CLI Help
|
|
160
|
-
- [x] JSDom
|
|
161
|
-
- [x] Watch
|
|
162
|
-
- [ ] Source Map
|
|
163
|
-
- [ ] Coverage
|
|
164
|
-
|
|
165
|
-
## Sponsors
|
|
166
|
-
|
|
167
|
-
<p align="center">
|
|
168
|
-
<a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
|
|
169
|
-
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
|
|
170
|
-
</a>
|
|
171
|
-
</p>
|
|
172
|
-
|
|
173
|
-
## License
|
|
174
|
-
|
|
175
|
-
[MIT](./LICENSE) License © 2021 [Anthony Fu](https://github.com/antfu)
|
|
7
|
+
> **This project is currently in closed beta exclusively for Sponsors.**
|
|
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
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# vitest
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/vitest)
|
|
4
|
+
|
|
5
|
+
A blazing fast unit test framework powered by Vite.
|
|
6
|
+
|
|
7
|
+
> **This project is currently in closed beta exclusively for Sponsors.**
|
|
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/bin/vitest.mjs
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
import { UserOptions } from './types';
|
|
1
2
|
export * from './types';
|
|
2
3
|
export * from './suite';
|
|
3
|
-
export * from './config';
|
|
4
4
|
export * from './integrations/chai';
|
|
5
5
|
export * from './integrations/sinon';
|
|
6
|
+
declare module 'vite' {
|
|
7
|
+
interface UserConfig {
|
|
8
|
+
/**
|
|
9
|
+
* Options for Vitest
|
|
10
|
+
*/
|
|
11
|
+
test?: UserOptions;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
6
14
|
declare global {
|
|
7
15
|
namespace Chai {
|
|
8
16
|
interface Assertion {
|
package/dist/index.js
CHANGED
|
File without changes
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
1
2
|
import { fileURLToPath } from 'url';
|
|
2
3
|
import { resolve, dirname } from 'path';
|
|
3
4
|
import { findUp } from 'find-up';
|
|
4
5
|
import sade from 'sade';
|
|
5
|
-
import
|
|
6
|
+
import c from 'picocolors';
|
|
7
|
+
import { run as startViteNode } from './node.js';
|
|
8
|
+
console.log(c.yellow(c.bold('\nVitest is currently in closed beta exclusively for Sponsors')));
|
|
9
|
+
console.log(c.magenta(`Become a Sponsor of ${c.underline('https://github.com/sponsors/patak-js')} or ${c.underline('https://github.com/sponsors/antfu')} \nto access the source code and issues tracker 💖\n`));
|
|
6
10
|
// TODO: use bundler
|
|
7
11
|
const version = '0.0.0';
|
|
8
12
|
sade('vitest [filter]', true)
|
|
@@ -35,7 +39,7 @@ sade('vitest [filter]', true)
|
|
|
35
39
|
await startViteNode({
|
|
36
40
|
root,
|
|
37
41
|
files: [
|
|
38
|
-
resolve(__dirname, options.dev ? '
|
|
42
|
+
resolve(__dirname, options.dev ? '../../src/node/entry.ts' : './entry.js'),
|
|
39
43
|
],
|
|
40
44
|
config: configPath,
|
|
41
45
|
defaultConfig: {
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { run } from '
|
|
1
|
+
import { run } from '../run';
|
|
2
2
|
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 || {};
|
|
File without changes
|
|
File without changes
|
|
@@ -71,7 +71,7 @@ export class DefaultReporter {
|
|
|
71
71
|
const { tasks, suites, files } = ctx;
|
|
72
72
|
const failedFiles = files.filter(i => i.error);
|
|
73
73
|
const failedSuites = suites.filter(i => i.error);
|
|
74
|
-
const
|
|
74
|
+
const runnable = tasks.filter(i => i.state === 'pass' || i.state === 'fail');
|
|
75
75
|
const passed = tasks.filter(i => i.state === 'pass');
|
|
76
76
|
const failed = tasks.filter(i => i.state === 'fail');
|
|
77
77
|
const skipped = tasks.filter(i => i.state === 'skip');
|
|
@@ -102,9 +102,9 @@ export class DefaultReporter {
|
|
|
102
102
|
console.log();
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
|
-
console.log(c.bold(c.green(`Passed ${passed.length} / ${
|
|
105
|
+
console.log(c.bold(c.green(`Passed ${passed.length} / ${runnable.length}`)));
|
|
106
106
|
if (failed.length)
|
|
107
|
-
console.log(c.bold(c.red(`Failed ${failed.length} / ${
|
|
107
|
+
console.log(c.bold(c.red(`Failed ${failed.length} / ${runnable.length}`)));
|
|
108
108
|
if (skipped.length)
|
|
109
109
|
console.log(c.yellow(`Skipped ${skipped.length}`));
|
|
110
110
|
if (todo.length)
|
package/dist/run/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { File, ResolvedConfig, Task, RunnerContext, Suite } from '../types';
|
|
2
2
|
export declare function runTask(task: Task, ctx: RunnerContext): Promise<void>;
|
|
3
3
|
export declare function collectFiles(paths: string[]): Promise<Record<string, File>>;
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function runSuite(suite: Suite, ctx: RunnerContext): Promise<void>;
|
|
5
5
|
export declare function runFile(file: File, ctx: RunnerContext): Promise<void>;
|
|
6
6
|
export declare function runFiles(filesMap: Record<string, File>, ctx: RunnerContext): Promise<void>;
|
|
7
7
|
export declare function run(config: ResolvedConfig): Promise<void>;
|
package/dist/run/index.js
CHANGED
|
@@ -65,9 +65,10 @@ export async function collectFiles(paths) {
|
|
|
65
65
|
interpretOnlyMode(allSuites);
|
|
66
66
|
allSuites.forEach((i) => {
|
|
67
67
|
if (i.mode === 'skip')
|
|
68
|
-
i.tasks.forEach(t => t.mode === 'run' && (t.
|
|
68
|
+
i.tasks.forEach(t => t.mode === 'run' && (t.mode = 'skip'));
|
|
69
69
|
else
|
|
70
70
|
interpretOnlyMode(i.tasks);
|
|
71
|
+
i.tasks.forEach(t => t.mode === 'skip' && (t.state = 'skip'));
|
|
71
72
|
});
|
|
72
73
|
return files;
|
|
73
74
|
}
|
|
@@ -84,7 +85,7 @@ function interpretOnlyMode(items) {
|
|
|
84
85
|
});
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
|
-
export async function
|
|
88
|
+
export async function runSuite(suite, ctx) {
|
|
88
89
|
var _a, _b;
|
|
89
90
|
const { reporter } = ctx;
|
|
90
91
|
await ((_a = reporter.onSuiteBegin) === null || _a === void 0 ? void 0 : _a.call(reporter, suite, ctx));
|
|
@@ -113,16 +114,16 @@ export async function runSite(suite, ctx) {
|
|
|
113
114
|
export async function runFile(file, ctx) {
|
|
114
115
|
var _a, _b;
|
|
115
116
|
const { reporter } = ctx;
|
|
116
|
-
const
|
|
117
|
-
if (
|
|
117
|
+
const runnableSuites = file.suites.filter(i => i.mode === 'run');
|
|
118
|
+
if (runnableSuites.length === 0)
|
|
118
119
|
return;
|
|
119
120
|
await ((_a = reporter.onFileBegin) === null || _a === void 0 ? void 0 : _a.call(reporter, file, ctx));
|
|
120
121
|
if (ctx.config.parallel) {
|
|
121
|
-
await Promise.all(file.suites.map(suite =>
|
|
122
|
+
await Promise.all(file.suites.map(suite => runSuite(suite, ctx)));
|
|
122
123
|
}
|
|
123
124
|
else {
|
|
124
125
|
for (const suite of file.suites)
|
|
125
|
-
await
|
|
126
|
+
await runSuite(suite, ctx);
|
|
126
127
|
}
|
|
127
128
|
await ((_b = reporter.onFileEnd) === null || _b === void 0 ? void 0 : _b.call(reporter, file, ctx));
|
|
128
129
|
}
|
|
@@ -156,7 +157,7 @@ export async function run(config) {
|
|
|
156
157
|
}
|
|
157
158
|
// setup envs
|
|
158
159
|
if (config.global)
|
|
159
|
-
(await import('../global')).registerApiGlobally();
|
|
160
|
+
(await import('../integrations/global')).registerApiGlobally();
|
|
160
161
|
if (config.jsdom)
|
|
161
162
|
(await import('../integrations/jsdom')).setupJSDOM(globalThis);
|
|
162
163
|
const reporter = new DefaultReporter();
|
|
@@ -203,11 +204,11 @@ export async function startWatcher(ctx) {
|
|
|
203
204
|
timer = setTimeout(async () => {
|
|
204
205
|
var _a, _b, _c, _d;
|
|
205
206
|
const snapshot = getSnapshotManager();
|
|
206
|
-
const
|
|
207
|
+
const paths = Array.from(changedTests);
|
|
207
208
|
changedTests.clear();
|
|
208
|
-
await ((_b = (_a = ctx.reporter).onWatcherRerun) === null || _b === void 0 ? void 0 : _b.call(_a,
|
|
209
|
-
|
|
210
|
-
const files = await collectFiles(
|
|
209
|
+
await ((_b = (_a = ctx.reporter).onWatcherRerun) === null || _b === void 0 ? void 0 : _b.call(_a, paths, id, ctx));
|
|
210
|
+
paths.forEach(i => moduleCache.delete(i));
|
|
211
|
+
const files = await collectFiles(paths);
|
|
211
212
|
Object.assign(ctx.filesMap, files);
|
|
212
213
|
await runFiles(files, ctx);
|
|
213
214
|
// TODO: clear snapshot state
|
package/dist/suite.js
CHANGED
|
@@ -32,12 +32,12 @@ function createSuiteCollector(name, factory = () => { }, mode) {
|
|
|
32
32
|
name,
|
|
33
33
|
mode,
|
|
34
34
|
suite: {},
|
|
35
|
-
state: mode !== 'run' ? mode : undefined,
|
|
35
|
+
state: (mode !== 'run' && mode !== 'only') ? mode : undefined,
|
|
36
36
|
fn,
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
function test(name, fn) {
|
|
40
|
-
collectTask(name, fn,
|
|
40
|
+
collectTask(name, fn, 'run');
|
|
41
41
|
}
|
|
42
42
|
test.skip = (name, fn) => collectTask(name, fn, 'skip');
|
|
43
43
|
test.only = (name, fn) => collectTask(name, fn, 'only');
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
export declare type Awaitable<T> = Promise<T> | T;
|
|
2
2
|
export interface UserOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Include globs for test files
|
|
5
|
+
*
|
|
6
|
+
* @default ['**\/*.test.ts']
|
|
7
|
+
*/
|
|
3
8
|
includes?: string[];
|
|
9
|
+
/**
|
|
10
|
+
* Exclude globs for test files
|
|
11
|
+
* @default ['**\/node_modules\/**']
|
|
12
|
+
*/
|
|
4
13
|
excludes?: string[];
|
|
5
14
|
/**
|
|
6
15
|
* Register apis globally
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"description": "A blazing fast unit test framework powered by Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -38,6 +38,16 @@
|
|
|
38
38
|
"bin",
|
|
39
39
|
"*.d.ts"
|
|
40
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
|
+
},
|
|
41
51
|
"dependencies": {
|
|
42
52
|
"@jest/test-result": "^27.4.2",
|
|
43
53
|
"@types/chai": "^4.2.22",
|
|
@@ -55,7 +65,7 @@
|
|
|
55
65
|
"sinon-chai": "^3.7.0"
|
|
56
66
|
},
|
|
57
67
|
"devDependencies": {
|
|
58
|
-
"@antfu/eslint-config": "^0.
|
|
68
|
+
"@antfu/eslint-config": "^0.12.1",
|
|
59
69
|
"@antfu/ni": "^0.11.0",
|
|
60
70
|
"@types/jsdom": "^16.2.13",
|
|
61
71
|
"@types/listr": "^0.14.4",
|
|
@@ -63,18 +73,10 @@
|
|
|
63
73
|
"@types/sade": "^1.7.3",
|
|
64
74
|
"@types/sinon": "^10.0.6",
|
|
65
75
|
"bumpp": "^7.1.1",
|
|
66
|
-
"eslint": "^8.
|
|
76
|
+
"eslint": "^8.4.0",
|
|
67
77
|
"esno": "^0.12.1",
|
|
68
78
|
"rimraf": "^3.0.2",
|
|
69
79
|
"typescript": "^4.5.2",
|
|
70
80
|
"vite": "^2.6.14"
|
|
71
|
-
},
|
|
72
|
-
"scripts": {
|
|
73
|
-
"build": "rimraf dist && tsc -p src/tsconfig.json",
|
|
74
|
-
"lint": "eslint \"{src,test}/**/*.ts\"",
|
|
75
|
-
"release": "bumpp --commit --push --tag && pnpm publish",
|
|
76
|
-
"test": "node bin/vitest.mjs --dev",
|
|
77
|
-
"test:update": "nr test -u",
|
|
78
|
-
"watch": "tsc -p src/tsconfig.json --watch"
|
|
79
81
|
}
|
|
80
|
-
}
|
|
82
|
+
}
|
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