vitest 0.0.23 → 0.0.27

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 ADDED
@@ -0,0 +1,212 @@
1
+ # vitest
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/vitest?color=a1b858&label=)](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
@@ -4,172 +4,5 @@
4
4
 
5
5
  A blazing fast unit test framework powered by Vite.
6
6
 
7
- ## Features
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.**<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
+ [![NPM version](https://img.shields.io/npm/v/vitest?color=a1b858&label=)](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
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict'
3
3
 
4
- import '../dist/cli.js'
4
+ import '../dist/node/cli.js'
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,6 +1,4 @@
1
- /* eslint-disable @typescript-eslint/no-namespace */
2
1
  export * from './types';
3
2
  export * from './suite';
4
- export * from './config';
5
3
  export * from './integrations/chai';
6
4
  export * from './integrations/sinon';
File without changes
@@ -1,5 +1,5 @@
1
- import { globalApis } from './constants';
2
- import * as index from './index';
1
+ import { globalApis } from '../constants';
2
+ import * as index from '../index';
3
3
  export function registerApiGlobally() {
4
4
  globalApis.forEach((api) => {
5
5
  // @ts-expect-error
@@ -1,4 +1,4 @@
1
- import type { UserOptions } from './types';
1
+ import type { UserOptions } from '../types';
2
2
  declare global {
3
3
  namespace NodeJS {
4
4
  interface Process {
@@ -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 { run as startViteNode } from './node/index.js';
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 ? '../src/entry.ts' : './entry.js'),
42
+ resolve(__dirname, options.dev ? '../../src/node/entry.ts' : './entry.js'),
39
43
  ],
40
44
  config: configPath,
41
45
  defaultConfig: {
File without changes
@@ -1,6 +1,6 @@
1
- import { run } from './run';
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 || {};
5
5
  const cliOptions = process.__vitest__.options || {};
6
- await run(Object.assign(Object.assign({}, inlineOptions), cliOptions));
6
+ await run(Object.assign(Object.assign({}, cliOptions), inlineOptions));
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 runable = tasks.filter(i => i.state === 'pass' || i.state === 'fail');
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} / ${runable.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} / ${runable.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.some(i => i.state === 'fail');
117
- if (failed)
118
- console.log(c.red('\nTests failed. Watching for file changes...'));
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('\nWatching for file changes...'));
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.log(c.blue(`File ${relative(process.cwd(), trigger)} changed, re-running tests...`));
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() {
@@ -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 runSite(suite: Suite, ctx: RunnerContext): Promise<void>;
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.state = 'skip'));
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 runSite(suite, ctx) {
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
- await Promise.all(suite.tasks.map(i => runTask(i, ctx)));
101
- // for (const t of suite.tasks)
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 runableSuites = file.suites.filter(i => i.mode === 'run');
117
- if (runableSuites.length === 0)
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 => runSite(suite, ctx)));
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 runSite(suite, ctx);
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;
@@ -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 pathes = Array.from(changedTests);
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, pathes, id, ctx));
209
- pathes.forEach(i => moduleCache.delete(i));
210
- const files = await collectFiles(pathes);
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, mode);
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
@@ -32,7 +41,14 @@ export interface UserOptions {
32
41
  * @default false
33
42
  */
34
43
  watch?: boolean;
44
+ /**
45
+ * Project root
46
+ */
35
47
  root?: string;
48
+ /**
49
+ * Custom reporter for output
50
+ */
51
+ reporter?: Reporter;
36
52
  }
37
53
  export interface ResolvedConfig extends Required<UserOptions> {
38
54
  filters?: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest",
3
- "version": "0.0.23",
3
+ "version": "0.0.27",
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.11.1",
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.3.0",
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
@@ -1,3 +0,0 @@
1
- export function defineConfig(config) {
2
- return config;
3
- }