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/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
|
-
- [ ] 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));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { InlineConfig, ViteDevServer } from 'vite';
|
|
2
|
+
declare global {
|
|
3
|
+
namespace NodeJS {
|
|
4
|
+
interface Process {
|
|
5
|
+
__vite_node__: {
|
|
6
|
+
server: ViteDevServer;
|
|
7
|
+
watch?: boolean;
|
|
8
|
+
moduleCache: Map<string, Promise<any>>;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export interface ViteNodeOptions {
|
|
14
|
+
silent?: boolean;
|
|
15
|
+
root: string;
|
|
16
|
+
files: string[];
|
|
17
|
+
_?: string[];
|
|
18
|
+
shouldExternalize?: (file: string) => boolean;
|
|
19
|
+
config?: string;
|
|
20
|
+
defaultConfig?: InlineConfig;
|
|
21
|
+
}
|
|
22
|
+
export declare function run(argv: ViteNodeOptions): Promise<void>;
|