vitest 0.0.75 → 0.0.79

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.
@@ -0,0 +1,10 @@
1
+ const rpc = async (method, ...args) => {
2
+ var _a;
3
+ return (_a = process.__vitest_worker__) == null ? void 0 : _a.rpc(method, ...args);
4
+ };
5
+ const send = async (method, ...args) => {
6
+ var _a;
7
+ return (_a = process.__vitest_worker__) == null ? void 0 : _a.send(method, ...args);
8
+ };
9
+
10
+ export { rpc as r, send as s };
@@ -1,9 +1,41 @@
1
- import { n as nanoid } from './index-6427e0f2.js';
1
+ import { n as nanoid } from './index-9e71c815.js';
2
2
 
3
3
  const context = {
4
4
  tasks: [],
5
5
  currentSuite: null
6
6
  };
7
+ function collectTask(task) {
8
+ var _a;
9
+ (_a = context.currentSuite) == null ? void 0 : _a.tasks.push(task);
10
+ }
11
+ async function runWithSuite(suite, fn) {
12
+ const prev = context.currentSuite;
13
+ context.currentSuite = suite;
14
+ await fn();
15
+ context.currentSuite = prev;
16
+ }
17
+ function getDefaultTestTimeout() {
18
+ var _a, _b;
19
+ return ((_b = (_a = process.__vitest_worker__) == null ? void 0 : _a.config) == null ? void 0 : _b.testTimeout) ?? 5e3;
20
+ }
21
+ function getDefaultHookTimeout() {
22
+ var _a, _b;
23
+ return ((_b = (_a = process.__vitest_worker__) == null ? void 0 : _a.config) == null ? void 0 : _b.hookTimeout) ?? 5e3;
24
+ }
25
+ function withTimeout(fn, _timeout) {
26
+ const timeout = _timeout ?? getDefaultTestTimeout();
27
+ if (timeout <= 0 || timeout === Infinity)
28
+ return fn;
29
+ return (...args) => {
30
+ return Promise.race([fn(...args), new Promise((resolve, reject) => {
31
+ const timer = setTimeout(() => {
32
+ clearTimeout(timer);
33
+ reject(new Error(`Test timed out in ${timeout}ms.`));
34
+ }, timeout);
35
+ timer.unref();
36
+ })]);
37
+ };
38
+ }
7
39
 
8
40
  const fnMap = new WeakMap();
9
41
  const hooksMap = new WeakMap();
@@ -22,17 +54,14 @@ function getHooks(key) {
22
54
 
23
55
  const suite = createSuite();
24
56
  const defaultSuite = suite("");
57
+ function clearContext() {
58
+ context.tasks.length = 0;
59
+ defaultSuite.clear();
60
+ context.currentSuite = defaultSuite;
61
+ }
25
62
  function getCurrentSuite() {
26
63
  return context.currentSuite || defaultSuite;
27
64
  }
28
- const getDefaultTestTimeout = () => {
29
- var _a, _b;
30
- return ((_b = (_a = process.__vitest_worker__) == null ? void 0 : _a.config) == null ? void 0 : _b.testTimeout) ?? 5e3;
31
- };
32
- const getDefaultHookTimeout = () => {
33
- var _a, _b;
34
- return ((_b = (_a = process.__vitest_worker__) == null ? void 0 : _a.config) == null ? void 0 : _b.hookTimeout) ?? 5e3;
35
- };
36
65
  function createSuiteHooks() {
37
66
  return {
38
67
  beforeAll: [],
@@ -43,7 +72,6 @@ function createSuiteHooks() {
43
72
  }
44
73
  function createSuiteCollector(name, factory = () => {
45
74
  }, mode, suiteComputeMode) {
46
- var _a;
47
75
  const tasks = [];
48
76
  const factoryQueue = [];
49
77
  let suite2;
@@ -91,12 +119,8 @@ function createSuiteCollector(name, factory = () => {
91
119
  }
92
120
  async function collect(file) {
93
121
  factoryQueue.length = 0;
94
- if (factory) {
95
- const prev = context.currentSuite;
96
- context.currentSuite = collector;
97
- await factory(test2);
98
- context.currentSuite = prev;
99
- }
122
+ if (factory)
123
+ await runWithSuite(collector, () => factory(test2));
100
124
  const allChildren = await Promise.all([...factoryQueue, ...tasks].map((i) => i.type === "collector" ? i.collect(file) : i));
101
125
  suite2.file = file;
102
126
  suite2.tasks = allChildren;
@@ -107,7 +131,7 @@ function createSuiteCollector(name, factory = () => {
107
131
  });
108
132
  return suite2;
109
133
  }
110
- (_a = context.currentSuite) == null ? void 0 : _a.tasks.push(collector);
134
+ collectTask(collector);
111
135
  return collector;
112
136
  }
113
137
  function createTestCollector(collectTest) {
@@ -197,28 +221,5 @@ function createSuite() {
197
221
  }
198
222
  const describe = suite;
199
223
  const it = test;
200
- const beforeAll = (fn, timeout) => getCurrentSuite().on("beforeAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
201
- const afterAll = (fn, timeout) => getCurrentSuite().on("afterAll", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
202
- const beforeEach = (fn, timeout) => getCurrentSuite().on("beforeEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
203
- const afterEach = (fn, timeout) => getCurrentSuite().on("afterEach", withTimeout(fn, timeout ?? getDefaultHookTimeout()));
204
- function clearContext() {
205
- context.tasks.length = 0;
206
- defaultSuite.clear();
207
- context.currentSuite = defaultSuite;
208
- }
209
- function withTimeout(fn, _timeout) {
210
- const timeout = _timeout ?? getDefaultTestTimeout();
211
- if (timeout <= 0 || timeout === Infinity)
212
- return fn;
213
- return (...args) => {
214
- return Promise.race([fn(...args), new Promise((resolve, reject) => {
215
- const timer = setTimeout(() => {
216
- clearTimeout(timer);
217
- reject(new Error(`Test timed out in ${timeout}ms.`));
218
- }, timeout);
219
- timer.unref();
220
- })]);
221
- };
222
- }
223
224
 
224
- export { describe as a, beforeAll as b, createSuiteHooks as c, defaultSuite as d, afterAll as e, beforeEach as f, afterEach as g, clearContext as h, it as i, setHooks as j, context as k, getHooks as l, getFn as m, suite as s, test as t };
225
+ export { getDefaultHookTimeout as a, setHooks as b, createSuiteHooks as c, describe as d, clearContext as e, defaultSuite as f, getCurrentSuite as g, context as h, it as i, getHooks as j, getFn as k, suite as s, test as t, withTimeout as w };
package/dist/worker.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import { resolve, dirname } from 'path';
2
- import { n as nanoid } from './index-6427e0f2.js';
3
- import { b as distDir } from './constants-d4c70610.js';
2
+ import { n as nanoid } from './index-9e71c815.js';
3
+ import { e as distDir } from './constants-2435fa16.js';
4
4
  import { builtinModules, createRequire } from 'module';
5
5
  import { pathToFileURL, fileURLToPath } from 'url';
6
6
  import vm from 'vm';
7
7
  import { s as slash } from './utils-9dcc4050.js';
8
+ import { s as send } from './rpc-7de86f29.js';
8
9
 
9
10
  const defaultInline = [
10
11
  "vitest/dist",
@@ -208,6 +209,14 @@ const moduleCache = new Map();
208
209
  async function init(ctx) {
209
210
  if (_run)
210
211
  return _run;
212
+ const processExit = process.exit;
213
+ process.on("beforeExit", (code) => {
214
+ send("processExit", code);
215
+ });
216
+ process.exit = (code = process.exitCode || 0) => {
217
+ send("processExit", code);
218
+ return processExit(code);
219
+ };
211
220
  const { config } = ctx;
212
221
  _run = (await executeInViteNode({
213
222
  root: config.root,
@@ -229,6 +238,7 @@ async function run(ctx) {
229
238
  const { config, port } = ctx;
230
239
  const rpcPromiseMap = new Map();
231
240
  process.__vitest_worker__ = {
241
+ moduleCache,
232
242
  config,
233
243
  rpc: (method, ...args) => {
234
244
  return new Promise((resolve2, reject) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest",
3
- "version": "0.0.75",
3
+ "version": "0.0.79",
4
4
  "description": "A blazing fast unit test framework powered by Vite",
5
5
  "keywords": [
6
6
  "vite",
@@ -38,22 +38,6 @@
38
38
  "bin",
39
39
  "*.d.ts"
40
40
  ],
41
- "scripts": {
42
- "build": "rimraf dist && rollup -c",
43
- "coverage": "node bin/vitest.mjs -r test/core --coverage",
44
- "dev": "rollup -c -w src",
45
- "docs": "npm -C docs run dev",
46
- "docs:build": "npm -C docs run build",
47
- "docs:serve": "npm -C docs run serve",
48
- "lint": "eslint \"{src,test}/**/*.ts\"",
49
- "prepublishOnly": "nr build",
50
- "release": "bumpp --commit --push --tag && esmo scripts/publish.ts",
51
- "test": "node bin/vitest.mjs -r test/core",
52
- "test:all": "cross-env CI=true pnpm -r --stream --filter !vitest run test --",
53
- "test:ci": "cross-env CI=true pnpm -r --stream --filter !vitest --filter !@vitest/test-fails run test --",
54
- "typecheck": "tsc --noEmit && nr lint",
55
- "ci": "ni && nr typecheck && nr lint && nr build && nr test:all"
56
- },
57
41
  "dependencies": {
58
42
  "@types/chai": "^4.3.0",
59
43
  "@types/chai-subset": "^1.3.3",
@@ -62,6 +46,7 @@
62
46
  "chai": "^4.3.4",
63
47
  "chai-subset": "^1.6.0",
64
48
  "fast-glob": "^3.2.7",
49
+ "flatted": "^3.2.4",
65
50
  "local-pkg": "^0.4.0",
66
51
  "micromatch": "^4.0.4",
67
52
  "piscina": "^3.2.0",
@@ -70,42 +55,24 @@
70
55
  "source-map": "^0.7.3"
71
56
  },
72
57
  "devDependencies": {
73
- "@antfu/eslint-config": "^0.13.1",
74
- "@antfu/ni": "^0.12.0",
75
- "@rollup/plugin-alias": "^3.1.8",
76
- "@rollup/plugin-commonjs": "^21.0.1",
77
- "@rollup/plugin-json": "^4.1.0",
78
- "@rollup/plugin-node-resolve": "^13.0.6",
79
58
  "@types/diff": "^5.0.1",
80
59
  "@types/jsdom": "^16.2.13",
81
60
  "@types/micromatch": "^4.0.2",
82
61
  "@types/natural-compare": "^1.4.1",
83
62
  "@types/node": "^16.11.12",
84
- "@types/sade": "^1.7.3",
85
- "bumpp": "^7.1.1",
86
63
  "c8": "^7.10.0",
87
64
  "cac": "^6.7.12",
88
65
  "cli-truncate": "^3.1.0",
89
- "cross-env": "^7.0.3",
90
66
  "diff": "^5.0.0",
91
- "eslint": "^8.4.1",
92
- "esno": "^0.12.1",
93
67
  "find-up": "^6.2.0",
94
68
  "happy-dom": "^2.24.5",
95
69
  "jsdom": "^19.0.0",
96
70
  "log-update": "^5.0.0",
97
71
  "nanoid": "^3.1.30",
98
72
  "natural-compare": "^1.4.0",
99
- "npm-run-all": "^4.1.5",
100
73
  "picocolors": "^1.0.0",
101
74
  "pretty-format": "^27.4.2",
102
- "rimraf": "^3.0.2",
103
- "rollup-plugin-dts": "^4.0.1",
104
- "rollup-plugin-esbuild": "^4.7.2",
105
- "strip-ansi": "^7.0.1",
106
- "tsup": "^5.11.1",
107
- "typescript": "^4.5.3",
108
- "vite": "^2.7.1"
75
+ "strip-ansi": "^7.0.1"
109
76
  },
110
77
  "peerDependencies": {
111
78
  "c8": "*",
@@ -126,5 +93,10 @@
126
93
  },
127
94
  "engines": {
128
95
  "node": ">=16.0.0"
96
+ },
97
+ "scripts": {
98
+ "build": "rimraf dist && rollup -c",
99
+ "dev": "rollup -c --watch src",
100
+ "typecheck": "tsc --noEmit"
129
101
  }
130
- }
102
+ }
package/README.gh.md DELETED
@@ -1,105 +0,0 @@
1
- <p align="center">
2
- <img src="https://user-images.githubusercontent.com/11247099/145112184-a9ff6727-661c-439d-9ada-963124a281f7.png" height="200">
3
- </p>
4
-
5
- <h1 align="center">
6
- Vitest
7
- </h1>
8
- <p align="center">
9
- A blazing fast unit test framework powered by Vite.
10
- <p>
11
- <p align="center">
12
- <a href="https://www.npmjs.com/package/vitest"><img src="https://img.shields.io/npm/v/vitest?color=a1b858&label="></a>
13
- <p>
14
- <h2 align="center">
15
- <a href="https://preview.vitest.dev">Open the Docs</a>
16
- </h2>
17
- <h3 align="center">
18
- <a href=https://discord.com/invite/2zYZNngd7y"><i>Get involved!</i></a>
19
- </h3>
20
- <br>
21
- <br>
22
-
23
- > 💖 **This project is currently in closed beta exclusively for Sponsors.**<br>
24
- > Become a Sponsor of [@patak-dev](https://github.com/sponsors/patak-dev) or [@antfu](https://github.com/sponsors/antfu) to access the source code and issues tracker.
25
-
26
- > ⚠️ **DISCLAIMER**: Vitest is still in development and not stable yet. It's not recommended to use it in production.
27
-
28
- > Vitest requires Vite v2.7 and Node v16
29
-
30
-
31
- Switch to Vitest by following the [Getting Started Guide](https://preview.vitest.dev/guide) or learn [why we are building a new test runner](https://preview.vitest.dev/guide).
32
-
33
- ## Features
34
-
35
- - [Vite](https://vitejs.dev/)'s config, transformers, resolvers, and plugins. Use the same setup from your app!
36
- - [Jest Snapshot](https://jestjs.io/docs/snapshot-testing)
37
- - [Chai](https://www.chaijs.com/) built-in for assertions, with [Jest expect](https://jestjs.io/docs/expect) compatible APIs.
38
- - [Smart & instant watch mode](#watch-mode), like HMR for tests!
39
- - [Native code coverage](#coverage) via [c8](https://github.com/bcoe/c8)
40
- - [Sinon](https://sinonjs.org/) built-in for mocking, stubbing, and spies.
41
- - [JSDOM](https://github.com/jsdom/jsdom) and [happy-dom](https://github.com/capricorn86/happy-dom) for DOM and browser API mocking
42
- - Components testing ([Vue](./test/vue), [React](./test/react), [Lit](./test/lit), [Vitesse](./test/vitesse))
43
- - Workers multi-threading via [Piscina](https://github.com/piscinajs/piscina)
44
- - ESM first, top level await
45
- - Out-of-box TypeScript / JSX support
46
- - Filtering, timeouts, concurrent for suite and tests
47
-
48
- ```ts
49
- import { it, describe, expect, assert } from 'vitest'
50
-
51
- describe('suite name', () => {
52
- it('foo', () => {
53
- expect(1 + 1).toEqual(2)
54
- expect(true).to.be.true
55
- })
56
-
57
- it('bar', () => {
58
- assert.equal(Math.sqrt(4), 2)
59
- })
60
-
61
- it('snapshot', () => {
62
- expect({ foo: 'bar' }).toMatchSnapshot()
63
- })
64
- })
65
- ```
66
-
67
- ```bash
68
- $ npx vitest
69
- ```
70
-
71
- ## Examples
72
-
73
- - [Unit Testing](./test/core)
74
- - [Vue Component Testing](./test/vue)
75
- - [React Component Testing](./test/react)
76
- - [Lit Component Testing](./test/lit)
77
- - [Vitesse Component Testing](./test/vitesse)
78
-
79
- ## Projects using Vitest
80
-
81
- - [unocss](https://github.com/antfu/unocss)
82
- - [unplugin-auto-import](https://github.com/antfu/unplugin-auto-import)
83
- - [unplugin-vue-components](https://github.com/antfu/unplugin-vue-components)
84
- - [vitesse-lite](https://github.com/antfu/vitesse-lite)
85
-
86
- ## Sponsors
87
-
88
- <p align="center">
89
- <a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
90
- <img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
91
- </a>
92
- </p>
93
-
94
- ## Credits
95
-
96
- Thanks to:
97
-
98
- - [@patak-dev](https://github.com/patak-dev) for the awesome package name!
99
- - [The Vite team](https://github.com/vitejs/vite) for brainstorming the initial idea.
100
- - [@pi0](https://github.com/pi0) for the idea and implementation of using Vite to transform and bundle the server code.
101
- - [@lukeed](https://github.com/lukeed) for the work on [uvu](https://github.com/lukeed/uvu) where we are inspired a lot from.
102
-
103
- ## License
104
-
105
- [MIT](./LICENSE) License © 2021 [Anthony Fu](https://github.com/antfu)
package/README.npm.md DELETED
@@ -1,9 +0,0 @@
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-dev](https://github.com/sponsors/patak-dev) or [@antfu](https://github.com/sponsors/antfu) to access the source code and issues tracker.
9
- > Learn more at [vitest.dev](https://vitest.dev)
@@ -1,31 +0,0 @@
1
- import { s as suite, d as defaultSuite, c as createSuiteHooks, t as test, a as describe, i as it, b as beforeAll, e as afterAll, f as beforeEach, g as afterEach, h as clearContext } from './suite-819c135e.js';
2
- import chai, { assert, should, expect } from 'chai';
3
- import sinon from 'sinon';
4
-
5
- const { mock, spy, stub } = sinon;
6
- sinon.fn = sinon.spy;
7
-
8
- var index = /*#__PURE__*/Object.freeze({
9
- __proto__: null,
10
- suite: suite,
11
- defaultSuite: defaultSuite,
12
- createSuiteHooks: createSuiteHooks,
13
- test: test,
14
- describe: describe,
15
- it: it,
16
- beforeAll: beforeAll,
17
- afterAll: afterAll,
18
- beforeEach: beforeEach,
19
- afterEach: afterEach,
20
- clearContext: clearContext,
21
- assert: assert,
22
- should: should,
23
- expect: expect,
24
- chai: chai,
25
- sinon: sinon,
26
- mock: mock,
27
- spy: spy,
28
- stub: stub
29
- });
30
-
31
- export { stub as a, index as i, mock as m, spy as s };