vitest 0.0.22 → 0.0.26
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/{index.d.ts → node.d.ts} +0 -0
- package/dist/node/{index.js → node.js} +0 -0
- package/dist/reporters/default.js +11 -10
- package/dist/run/index.d.ts +3 -3
- package/dist/run/index.js +22 -19
- package/dist/suite.js +2 -2
- package/dist/types.d.ts +33 -9
- 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/README.gh.md
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
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.**<br>
|
|
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
|
+
> ⚠️ **DISCLAIMER**: Vitest is still in development and not stable yet. It's not recommended to use it in production.
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- [Vite](https://vitejs.dev/)'s config, transformers, resolvers, and plugins.
|
|
15
|
+
- [Jest Snapshot](https://jestjs.io/docs/snapshot-testing)
|
|
16
|
+
- [Chai](https://www.chaijs.com/) for assertions
|
|
17
|
+
- [Sinon](https://sinonjs.org/) for mocking
|
|
18
|
+
- [JSDOM](https://github.com/jsdom/jsdom) for DOM mocking
|
|
19
|
+
- Async suite / test, top level await
|
|
20
|
+
- ESM friendly
|
|
21
|
+
- Out-of-box TypeScript support
|
|
22
|
+
- Suite and Test filtering (skip, only, todo)
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { it, describe, expect, assert } from 'vitest'
|
|
26
|
+
|
|
27
|
+
describe('suite name', () => {
|
|
28
|
+
it('foo', () => {
|
|
29
|
+
expect(1 + 1).toEqual(2)
|
|
30
|
+
expect(true).to.be.true
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('bar', () => {
|
|
34
|
+
assert.equal(Math.sqrt(4), 2)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('snapshot', () => {
|
|
38
|
+
expect({ foo: 'bar' }).toMatchSnapshot()
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
$ npx vitest
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Configuration
|
|
48
|
+
|
|
49
|
+
`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:
|
|
50
|
+
|
|
51
|
+
- Create `vitest.config.ts`, which will have the higher priority
|
|
52
|
+
- Pass `--config` option to CLI, e.g. `vitest --config ./path/to/vitest.config.ts`
|
|
53
|
+
- Use `process.env.VITEST` to conditionally apply differnet configuration in `vite.config.ts`
|
|
54
|
+
|
|
55
|
+
To configure `vitest` itself, add `test` property in your Vite config
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
// vite.config.ts
|
|
59
|
+
import { defineConfig } from 'vite'
|
|
60
|
+
|
|
61
|
+
export default defineConfig({
|
|
62
|
+
test: {
|
|
63
|
+
// ...
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Global APIs
|
|
69
|
+
|
|
70
|
+
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.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
// vite.config.ts
|
|
74
|
+
import { defineConfig } from 'vite'
|
|
75
|
+
|
|
76
|
+
export default defineConfig({
|
|
77
|
+
test: {
|
|
78
|
+
global: true
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
To get TypeScript working with the global APIs, add `vitest/global` to the `types` filed in your `tsconfig.json`
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
// tsconfig.json
|
|
87
|
+
{
|
|
88
|
+
"compilerOptions": {
|
|
89
|
+
"types": [
|
|
90
|
+
"vitest/global"
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
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
|
+
|
|
119
|
+
## Filtering
|
|
120
|
+
|
|
121
|
+
### Skipping suites and tasks
|
|
122
|
+
|
|
123
|
+
Use `.skip` to avoid running certain suites or tests
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
describe.skip('skipped suite', () => {
|
|
127
|
+
it('task', () => {
|
|
128
|
+
// Suite skipped, no error
|
|
129
|
+
assert.equal(Math.sqrt(4), 3)
|
|
130
|
+
})
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
describe('suite', () => {
|
|
134
|
+
it.skip('skipped task', () => {
|
|
135
|
+
// Task skipped, no error
|
|
136
|
+
assert.equal(Math.sqrt(4), 3)
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Selecting suites and tests to run
|
|
142
|
+
|
|
143
|
+
Use `.only` to only run certain suites or tests
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
// Only this suite (and others marked with only) are run
|
|
147
|
+
describe.only('suite', () => {
|
|
148
|
+
it('task', () => {
|
|
149
|
+
assert.equal(Math.sqrt(4), 3)
|
|
150
|
+
})
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
describe('another suite', () => {
|
|
154
|
+
it('skipped task', () => {
|
|
155
|
+
// Task skipped, as tests are running in Only mode
|
|
156
|
+
assert.equal(Math.sqrt(4), 3)
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
it.only('task', () => {
|
|
160
|
+
// Only this task (and others marked with only) are run
|
|
161
|
+
assert.equal(Math.sqrt(4), 2)
|
|
162
|
+
})
|
|
163
|
+
})
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Unimplemented suites and tests
|
|
167
|
+
|
|
168
|
+
Use `.todo` to stub suites and tests that should be implemented
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
// An entry will be shown in the report for this suite
|
|
172
|
+
describe.todo('unimplemented suite')
|
|
173
|
+
|
|
174
|
+
// An entry will be shown in the report for this task
|
|
175
|
+
describe('suite', () => {
|
|
176
|
+
it.todo('unimplemented task')
|
|
177
|
+
})
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## TODO
|
|
181
|
+
|
|
182
|
+
- [x] Reporter & Better output
|
|
183
|
+
- [x] Task filter
|
|
184
|
+
- [x] Mock
|
|
185
|
+
- [x] Global Mode & Types
|
|
186
|
+
- [ ] Parallel Executing
|
|
187
|
+
- [x] CLI Help
|
|
188
|
+
- [x] JSDom
|
|
189
|
+
- [x] Watch
|
|
190
|
+
- [ ] Source Map
|
|
191
|
+
- [ ] Coverage
|
|
192
|
+
|
|
193
|
+
## Sponsors
|
|
194
|
+
|
|
195
|
+
<p align="center">
|
|
196
|
+
<a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
|
|
197
|
+
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
|
|
198
|
+
</a>
|
|
199
|
+
</p>
|
|
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
|
+
|
|
210
|
+
## License
|
|
211
|
+
|
|
212
|
+
[MIT](./LICENSE) License © 2021 [Anthony Fu](https://github.com/antfu)
|
package/README.md
CHANGED
|
@@ -2,174 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/vitest)
|
|
4
4
|
|
|
5
|
-
A blazing fast test
|
|
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
|
-
- [ ] Parallel Executing
|
|
159
|
-
- [ ] CLI Help (Use yargs)
|
|
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.**<br>
|
|
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.**<br>
|
|
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
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function setupChai(config:
|
|
1
|
+
import { ResolvedConfig } from 'vitest';
|
|
2
|
+
export declare function setupChai(config: ResolvedConfig): Promise<void>;
|
|
@@ -5,8 +5,5 @@ import { SnapshotPlugin } from './snapshot';
|
|
|
5
5
|
export async function setupChai(config) {
|
|
6
6
|
chai.use(SinonChai);
|
|
7
7
|
chai.use(JestChaiExpect());
|
|
8
|
-
chai.use(await SnapshotPlugin(
|
|
9
|
-
rootDir: config.rootDir || process.cwd(),
|
|
10
|
-
update: config.updateSnapshot,
|
|
11
|
-
}));
|
|
8
|
+
chai.use(await SnapshotPlugin(config));
|
|
12
9
|
}
|
|
File without changes
|
package/dist/node/cli.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
import { resolve, dirname } from 'path';
|
|
4
|
+
import { findUp } from 'find-up';
|
|
5
|
+
import sade from 'sade';
|
|
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`));
|
|
10
|
+
// TODO: use bundler
|
|
11
|
+
const version = '0.0.0';
|
|
12
|
+
sade('vitest [filter]', true)
|
|
13
|
+
.version(version)
|
|
14
|
+
.describe('A blazing fast unit test framework powered by Vite.')
|
|
15
|
+
.option('-r, --root', 'root path', process.cwd())
|
|
16
|
+
.option('-c, --config', 'path to config file')
|
|
17
|
+
.option('-w, --watch', 'watch mode', false)
|
|
18
|
+
.option('-u, --update', 'update snapshot', false)
|
|
19
|
+
.option('--global', 'inject apis globally', false)
|
|
20
|
+
.option('--dev', 'dev mode', false)
|
|
21
|
+
.option('--jsdom', 'mock browser api using JSDOM', false)
|
|
22
|
+
.action(async (filters, options) => {
|
|
23
|
+
process.env.VITEST = 'true';
|
|
24
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
25
|
+
const root = resolve(options.root || process.cwd());
|
|
26
|
+
const configPath = options.config
|
|
27
|
+
? resolve(root, options.config)
|
|
28
|
+
: await findUp(['vitest.config.ts', 'vitest.config.js', 'vitest.config.mjs', 'vite.config.ts', 'vite.config.js', 'vite.config.mjs'], { cwd: root });
|
|
29
|
+
options.config = configPath;
|
|
30
|
+
options.root = root;
|
|
31
|
+
options.filters = filters
|
|
32
|
+
? Array.isArray(filters)
|
|
33
|
+
? filters
|
|
34
|
+
: [filters]
|
|
35
|
+
: undefined;
|
|
36
|
+
process.__vitest__ = {
|
|
37
|
+
options,
|
|
38
|
+
};
|
|
39
|
+
await startViteNode({
|
|
40
|
+
root,
|
|
41
|
+
files: [
|
|
42
|
+
resolve(__dirname, options.dev ? '../../src/node/entry.ts' : './entry.js'),
|
|
43
|
+
],
|
|
44
|
+
config: configPath,
|
|
45
|
+
defaultConfig: {
|
|
46
|
+
optimizeDeps: {
|
|
47
|
+
exclude: [
|
|
48
|
+
'vitest',
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
shouldExternalize(id) {
|
|
53
|
+
if (id.includes('/node_modules/vitest/'))
|
|
54
|
+
return false;
|
|
55
|
+
else
|
|
56
|
+
return id.includes('/node_modules/');
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
})
|
|
60
|
+
.parse(process.argv);
|
|
File without changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { run } from '../run';
|
|
2
|
+
if (!process.__vite_node__ || !process.__vitest__)
|
|
3
|
+
throw new Error('Vitest can only run in vite-node environment, please use the CLI to start the process');
|
|
4
|
+
const inlineOptions = process.__vite_node__.server.config.test || {};
|
|
5
|
+
const cliOptions = process.__vitest__.options || {};
|
|
6
|
+
await run(Object.assign(Object.assign({}, inlineOptions), cliOptions));
|
|
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');
|
|
@@ -85,7 +85,7 @@ export class DefaultReporter {
|
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
87
|
if (failedSuites.length) {
|
|
88
|
-
console.error(c.bold(`\nFailed to run ${failedSuites.length} suites:`));
|
|
88
|
+
console.error(c.bold(c.red(`\nFailed to run ${failedSuites.length} suites:`)));
|
|
89
89
|
failedSuites.forEach((i) => {
|
|
90
90
|
var _a;
|
|
91
91
|
console.error(c.red(`\n- ${(_a = i.file) === null || _a === void 0 ? void 0 : _a.filepath} > ${i.name}`));
|
|
@@ -94,7 +94,7 @@ export class DefaultReporter {
|
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
if (failed.length) {
|
|
97
|
-
console.error(c.bold(`\nFailed Tests (${failed.length})`));
|
|
97
|
+
console.error(c.bold(c.red(`\nFailed Tests (${failed.length})`)));
|
|
98
98
|
failed.forEach((task) => {
|
|
99
99
|
var _a;
|
|
100
100
|
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}`))}`);
|
|
@@ -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)
|
|
@@ -113,15 +113,16 @@ export class DefaultReporter {
|
|
|
113
113
|
}
|
|
114
114
|
async onWatcherStart(ctx) {
|
|
115
115
|
await this.listrPromise;
|
|
116
|
-
const failed = ctx.tasks.
|
|
117
|
-
if (failed)
|
|
118
|
-
console.log(c.red('
|
|
116
|
+
const failed = ctx.tasks.filter(i => i.state === 'fail');
|
|
117
|
+
if (failed.length)
|
|
118
|
+
console.log(`\n${c.bold(c.inverse(c.red(' FAIL ')))}${c.red(` ${failed.length} tests failed. Watching for file changes...`)}`);
|
|
119
119
|
else
|
|
120
|
-
console.log(c.green('
|
|
120
|
+
console.log(`\n${c.bold(c.inverse(c.green(' PASS ')))}${c.green(' Watching for file changes...')}`);
|
|
121
121
|
}
|
|
122
122
|
async onWatcherRerun(files, trigger) {
|
|
123
123
|
await this.listrPromise;
|
|
124
|
-
console.
|
|
124
|
+
console.clear();
|
|
125
|
+
console.log(c.blue('Re-running tests...') + c.dim(` [ ${relative(process.cwd(), trigger)} ]\n`));
|
|
125
126
|
}
|
|
126
127
|
// TODO:
|
|
127
128
|
onSnapshotUpdate() {
|
package/dist/run/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { File,
|
|
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
|
-
export declare function run(config:
|
|
7
|
+
export declare function run(config: ResolvedConfig): Promise<void>;
|
|
8
8
|
export declare function startWatcher(ctx: RunnerContext): 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));
|
|
@@ -97,9 +98,8 @@ export async function runSite(suite, ctx) {
|
|
|
97
98
|
else {
|
|
98
99
|
try {
|
|
99
100
|
await callHook(suite, 'beforeAll', [suite]);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
// await runTask(t, ctx)
|
|
101
|
+
for (const t of suite.tasks)
|
|
102
|
+
await runTask(t, ctx);
|
|
103
103
|
await callHook(suite, 'afterAll', [suite]);
|
|
104
104
|
}
|
|
105
105
|
catch (e) {
|
|
@@ -113,16 +113,16 @@ export async function runSite(suite, ctx) {
|
|
|
113
113
|
export async function runFile(file, ctx) {
|
|
114
114
|
var _a, _b;
|
|
115
115
|
const { reporter } = ctx;
|
|
116
|
-
const
|
|
117
|
-
if (
|
|
116
|
+
const runnableSuites = file.suites.filter(i => i.mode === 'run');
|
|
117
|
+
if (runnableSuites.length === 0)
|
|
118
118
|
return;
|
|
119
119
|
await ((_a = reporter.onFileBegin) === null || _a === void 0 ? void 0 : _a.call(reporter, file, ctx));
|
|
120
120
|
if (ctx.config.parallel) {
|
|
121
|
-
await Promise.all(file.suites.map(suite =>
|
|
121
|
+
await Promise.all(file.suites.map(suite => runSuite(suite, ctx)));
|
|
122
122
|
}
|
|
123
123
|
else {
|
|
124
124
|
for (const suite of file.suites)
|
|
125
|
-
await
|
|
125
|
+
await runSuite(suite, ctx);
|
|
126
126
|
}
|
|
127
127
|
await ((_b = reporter.onFileEnd) === null || _b === void 0 ? void 0 : _b.call(reporter, file, ctx));
|
|
128
128
|
}
|
|
@@ -135,6 +135,8 @@ export async function runFiles(filesMap, ctx) {
|
|
|
135
135
|
}
|
|
136
136
|
export async function run(config) {
|
|
137
137
|
var _a, _b, _c;
|
|
138
|
+
config.reporter = config.reporter || new DefaultReporter();
|
|
139
|
+
const { reporter } = config;
|
|
138
140
|
// if watch, tell `vite-node` not to end the process
|
|
139
141
|
if (config.watch)
|
|
140
142
|
process.__vite_node__.watch = true;
|
|
@@ -143,12 +145,12 @@ export async function run(config) {
|
|
|
143
145
|
// collect files
|
|
144
146
|
let testFilepaths = await fg(config.includes || defaultIncludes, {
|
|
145
147
|
absolute: true,
|
|
146
|
-
cwd: config.
|
|
148
|
+
cwd: config.root,
|
|
147
149
|
ignore: config.excludes || defaultExcludes,
|
|
148
150
|
});
|
|
149
151
|
// if name filters are provided by the CLI
|
|
150
|
-
if ((_a = config.
|
|
151
|
-
testFilepaths = testFilepaths.filter(i => config.
|
|
152
|
+
if ((_a = config.filters) === null || _a === void 0 ? void 0 : _a.length)
|
|
153
|
+
testFilepaths = testFilepaths.filter(i => config.filters.some(f => i.includes(f)));
|
|
152
154
|
if (!testFilepaths.length) {
|
|
153
155
|
console.error('No test files found');
|
|
154
156
|
process.exitCode = 1;
|
|
@@ -156,10 +158,9 @@ export async function run(config) {
|
|
|
156
158
|
}
|
|
157
159
|
// setup envs
|
|
158
160
|
if (config.global)
|
|
159
|
-
(await import('../global')).registerApiGlobally();
|
|
161
|
+
(await import('../integrations/global')).registerApiGlobally();
|
|
160
162
|
if (config.jsdom)
|
|
161
163
|
(await import('../integrations/jsdom')).setupJSDOM(globalThis);
|
|
162
|
-
const reporter = new DefaultReporter();
|
|
163
164
|
await ((_b = reporter.onStart) === null || _b === void 0 ? void 0 : _b.call(reporter, config));
|
|
164
165
|
const filesMap = await collectFiles(testFilepaths);
|
|
165
166
|
const ctx = {
|
|
@@ -176,7 +177,7 @@ export async function run(config) {
|
|
|
176
177
|
.reduce((tasks, suite) => tasks.concat(suite.tasks), []);
|
|
177
178
|
},
|
|
178
179
|
config,
|
|
179
|
-
reporter,
|
|
180
|
+
reporter: config.reporter,
|
|
180
181
|
};
|
|
181
182
|
await runFiles(filesMap, ctx);
|
|
182
183
|
const snapshot = getSnapshotManager();
|
|
@@ -202,12 +203,14 @@ export async function startWatcher(ctx) {
|
|
|
202
203
|
clearTimeout(timer);
|
|
203
204
|
timer = setTimeout(async () => {
|
|
204
205
|
var _a, _b, _c, _d;
|
|
206
|
+
if (changedTests.size === 0)
|
|
207
|
+
return;
|
|
205
208
|
const snapshot = getSnapshotManager();
|
|
206
|
-
const
|
|
209
|
+
const paths = Array.from(changedTests);
|
|
207
210
|
changedTests.clear();
|
|
208
|
-
await ((_b = (_a = ctx.reporter).onWatcherRerun) === null || _b === void 0 ? void 0 : _b.call(_a,
|
|
209
|
-
|
|
210
|
-
const files = await collectFiles(
|
|
211
|
+
await ((_b = (_a = ctx.reporter).onWatcherRerun) === null || _b === void 0 ? void 0 : _b.call(_a, paths, id, ctx));
|
|
212
|
+
paths.forEach(i => moduleCache.delete(i));
|
|
213
|
+
const files = await collectFiles(paths);
|
|
211
214
|
Object.assign(ctx.filesMap, files);
|
|
212
215
|
await runFiles(files, ctx);
|
|
213
216
|
// 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,7 +1,15 @@
|
|
|
1
|
-
import { ViteDevServer } from 'vite';
|
|
2
1
|
export declare type Awaitable<T> = Promise<T> | T;
|
|
3
2
|
export interface UserOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Include globs for test files
|
|
5
|
+
*
|
|
6
|
+
* @default ['**\/*.test.ts']
|
|
7
|
+
*/
|
|
4
8
|
includes?: string[];
|
|
9
|
+
/**
|
|
10
|
+
* Exclude globs for test files
|
|
11
|
+
* @default ['**\/node_modules\/**']
|
|
12
|
+
*/
|
|
5
13
|
excludes?: string[];
|
|
6
14
|
/**
|
|
7
15
|
* Register apis globally
|
|
@@ -21,13 +29,29 @@ export interface UserOptions {
|
|
|
21
29
|
* @default false
|
|
22
30
|
*/
|
|
23
31
|
parallel?: boolean;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Update snapshot files
|
|
34
|
+
*
|
|
35
|
+
* @default false
|
|
36
|
+
*/
|
|
37
|
+
update?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Watch mode
|
|
40
|
+
*
|
|
41
|
+
* @default false
|
|
42
|
+
*/
|
|
30
43
|
watch?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Project root
|
|
46
|
+
*/
|
|
47
|
+
root?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Custom reporter for output
|
|
50
|
+
*/
|
|
51
|
+
reporter?: Reporter;
|
|
52
|
+
}
|
|
53
|
+
export interface ResolvedConfig extends Required<UserOptions> {
|
|
54
|
+
filters?: string[];
|
|
31
55
|
}
|
|
32
56
|
export declare type RunMode = 'run' | 'skip' | 'only' | 'todo';
|
|
33
57
|
export declare type TaskState = RunMode | 'pass' | 'fail';
|
|
@@ -82,7 +106,7 @@ export interface RunnerContext {
|
|
|
82
106
|
files: File[];
|
|
83
107
|
suites: Suite[];
|
|
84
108
|
tasks: Task[];
|
|
85
|
-
config:
|
|
109
|
+
config: ResolvedConfig;
|
|
86
110
|
reporter: Reporter;
|
|
87
111
|
}
|
|
88
112
|
export interface GlobalContext {
|
|
@@ -90,7 +114,7 @@ export interface GlobalContext {
|
|
|
90
114
|
currentSuite: SuiteCollector | null;
|
|
91
115
|
}
|
|
92
116
|
export interface Reporter {
|
|
93
|
-
onStart?: (userOptions:
|
|
117
|
+
onStart?: (userOptions: ResolvedConfig) => Awaitable<void>;
|
|
94
118
|
onCollected?: (files: File[], ctx: RunnerContext) => Awaitable<void>;
|
|
95
119
|
onFinished?: (ctx: RunnerContext) => Awaitable<void>;
|
|
96
120
|
onSuiteBegin?: (suite: Suite, ctx: RunnerContext) => Awaitable<void>;
|
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.26",
|
|
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
|
-
import minimist from 'minimist';
|
|
2
|
-
import c from 'picocolors';
|
|
3
|
-
import { run } from './run';
|
|
4
|
-
const { log } = console;
|
|
5
|
-
const argv = minimist(process.argv.slice(2), {
|
|
6
|
-
alias: {
|
|
7
|
-
u: 'update',
|
|
8
|
-
w: 'watch',
|
|
9
|
-
},
|
|
10
|
-
string: ['root', 'config'],
|
|
11
|
-
boolean: ['update', 'dev', 'global', 'watch', 'jsdom'],
|
|
12
|
-
unknown(name) {
|
|
13
|
-
if (name[0] === '-') {
|
|
14
|
-
console.error(c.red(`Unknown argument: ${name}`));
|
|
15
|
-
help();
|
|
16
|
-
process.exit(1);
|
|
17
|
-
}
|
|
18
|
-
return true;
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
if (!process.__vite_node__)
|
|
22
|
-
throw new Error('Vite can only run in Vite environment, please use the CLI to start the process');
|
|
23
|
-
const server = process.__vite_node__.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/index.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
|
-
});
|