vitest 0.0.24 → 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 CHANGED
@@ -4,9 +4,11 @@
4
4
 
5
5
  A blazing fast unit test framework powered by Vite.
6
6
 
7
- > **This project is currently in closed beta exclusively for Sponsors.**
7
+ > **This project is currently in closed beta exclusively for Sponsors.**<br>
8
8
  > Become a Sponsor of [@patak-js](https://github.com/sponsors/patak-js) or [@antfu](https://github.com/sponsors/antfu) to access the source code and issues tracker.
9
9
 
10
+ > ⚠️ **DISCLAIMER**: Vitest is still in development and not stable yet. It's not recommended to use it in production.
11
+
10
12
  ## Features
11
13
 
12
14
  - [Vite](https://vitejs.dev/)'s config, transformers, resolvers, and plugins.
@@ -91,6 +93,29 @@ To get TypeScript working with the global APIs, add `vitest/global` to the `type
91
93
  }
92
94
  ```
93
95
 
96
+ ## Browser Mocking
97
+
98
+ Pass `--jsdom` option in CLI to enable browser mocking. Or the `jsdom` flag in the config.
99
+
100
+ ```ts
101
+ // vite.config.ts
102
+ import { defineConfig } from 'vite'
103
+
104
+ export default defineConfig({
105
+ test: {
106
+ jsdom: true
107
+ }
108
+ })
109
+ ```
110
+
111
+ ## Watch Mode
112
+
113
+ ```bash
114
+ $ vitest -w
115
+ ```
116
+
117
+ Vitest will smartly search for the module graph to only rerun the related tests.
118
+
94
119
  ## Filtering
95
120
 
96
121
  ### Skipping suites and tasks
@@ -173,6 +198,15 @@ describe('suite', () => {
173
198
  </a>
174
199
  </p>
175
200
 
201
+ ## Credits
202
+
203
+ Thanks to:
204
+
205
+ - [@patak-js](https://github.com/patak-js) for the awesome package name!
206
+ - [The Vite team](https://github.com/vitejs/vite) for brainstorming the initial idea.
207
+ - [@pi0](https://github.com/pi0) for the idea and implementation of using Vite to transform and bundle the server code.
208
+ - [@lukeed](https://github.com/lukeed) for the work on [uvu](https://github.com/lukeed/uvu) where we are inspired a lot from.
209
+
176
210
  ## License
177
211
 
178
212
  [MIT](./LICENSE) License © 2021 [Anthony Fu](https://github.com/antfu)
package/README.md CHANGED
@@ -4,5 +4,5 @@
4
4
 
5
5
  A blazing fast unit test framework powered by Vite.
6
6
 
7
- > **This project is currently in closed beta exclusively for Sponsors.**
7
+ > **This project is currently in closed beta exclusively for Sponsors.**<br>
8
8
  > Become a Sponsor of [@patak-js](https://github.com/sponsors/patak-js) or [@antfu](https://github.com/sponsors/antfu) to access the source code and issues tracker.
package/README.npm.md CHANGED
@@ -4,5 +4,5 @@
4
4
 
5
5
  A blazing fast unit test framework powered by Vite.
6
6
 
7
- > **This project is currently in closed beta exclusively for Sponsors.**
7
+ > **This project is currently in closed beta exclusively for Sponsors.**<br>
8
8
  > Become a Sponsor of [@patak-js](https://github.com/sponsors/patak-js) or [@antfu](https://github.com/sponsors/antfu) to access the source code and issues tracker.
@@ -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}`))}`);
@@ -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() {
package/dist/run/index.js CHANGED
@@ -136,6 +136,8 @@ export async function runFiles(filesMap, ctx) {
136
136
  }
137
137
  export async function run(config) {
138
138
  var _a, _b, _c;
139
+ config.reporter = config.reporter || new DefaultReporter();
140
+ const { reporter } = config;
139
141
  // if watch, tell `vite-node` not to end the process
140
142
  if (config.watch)
141
143
  process.__vite_node__.watch = true;
@@ -160,7 +162,6 @@ export async function run(config) {
160
162
  (await import('../integrations/global')).registerApiGlobally();
161
163
  if (config.jsdom)
162
164
  (await import('../integrations/jsdom')).setupJSDOM(globalThis);
163
- const reporter = new DefaultReporter();
164
165
  await ((_b = reporter.onStart) === null || _b === void 0 ? void 0 : _b.call(reporter, config));
165
166
  const filesMap = await collectFiles(testFilepaths);
166
167
  const ctx = {
@@ -177,7 +178,7 @@ export async function run(config) {
177
178
  .reduce((tasks, suite) => tasks.concat(suite.tasks), []);
178
179
  },
179
180
  config,
180
- reporter,
181
+ reporter: config.reporter,
181
182
  };
182
183
  await runFiles(filesMap, ctx);
183
184
  const snapshot = getSnapshotManager();
@@ -203,6 +204,8 @@ export async function startWatcher(ctx) {
203
204
  clearTimeout(timer);
204
205
  timer = setTimeout(async () => {
205
206
  var _a, _b, _c, _d;
207
+ if (changedTests.size === 0)
208
+ return;
206
209
  const snapshot = getSnapshotManager();
207
210
  const paths = Array.from(changedTests);
208
211
  changedTests.clear();
package/dist/types.d.ts CHANGED
@@ -41,7 +41,14 @@ export interface UserOptions {
41
41
  * @default false
42
42
  */
43
43
  watch?: boolean;
44
+ /**
45
+ * Project root
46
+ */
44
47
  root?: string;
48
+ /**
49
+ * Custom reporter for output
50
+ */
51
+ reporter?: Reporter;
45
52
  }
46
53
  export interface ResolvedConfig extends Required<UserOptions> {
47
54
  filters?: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest",
3
- "version": "0.0.24",
3
+ "version": "0.0.25",
4
4
  "description": "A blazing fast unit test framework powered by Vite",
5
5
  "keywords": [
6
6
  "vite",