vitest 0.0.100 → 0.0.101

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,201 @@
1
+ import { n as nanoid } from './index-9e71c815.js';
2
+ import { n as noop } from './utils-c8e62373.js';
3
+
4
+ var __defProp = Object.defineProperty;
5
+ var __defProps = Object.defineProperties;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
+ function createChainable(keys, fn) {
24
+ function create(obj) {
25
+ const chain2 = function(...args) {
26
+ return fn.apply(obj, args);
27
+ };
28
+ for (const key of keys) {
29
+ Object.defineProperty(chain2, key, {
30
+ get() {
31
+ return create(__spreadProps(__spreadValues({}, obj), { [key]: true }));
32
+ }
33
+ });
34
+ }
35
+ return chain2;
36
+ }
37
+ const chain = create({});
38
+ chain.fn = fn;
39
+ return chain;
40
+ }
41
+
42
+ const context = {
43
+ tasks: [],
44
+ currentSuite: null
45
+ };
46
+ function collectTask(task) {
47
+ var _a;
48
+ (_a = context.currentSuite) == null ? void 0 : _a.tasks.push(task);
49
+ }
50
+ async function runWithSuite(suite, fn) {
51
+ const prev = context.currentSuite;
52
+ context.currentSuite = suite;
53
+ await fn();
54
+ context.currentSuite = prev;
55
+ }
56
+ function getDefaultTestTimeout() {
57
+ return process.__vitest_worker__.config.testTimeout;
58
+ }
59
+ function getDefaultHookTimeout() {
60
+ return process.__vitest_worker__.config.hookTimeout;
61
+ }
62
+ function withTimeout(fn, _timeout) {
63
+ const timeout = _timeout ?? getDefaultTestTimeout();
64
+ if (timeout <= 0 || timeout === Infinity)
65
+ return fn;
66
+ return (...args) => {
67
+ return Promise.race([fn(...args), new Promise((resolve, reject) => {
68
+ const timer = setTimeout(() => {
69
+ clearTimeout(timer);
70
+ reject(new Error(`Test timed out in ${timeout}ms.`));
71
+ }, timeout);
72
+ timer.unref();
73
+ })]);
74
+ };
75
+ }
76
+ function ensureAsyncTest(fn) {
77
+ if (!fn.length)
78
+ return fn;
79
+ return () => new Promise((resolve, reject) => {
80
+ const done = (...args) => args[0] ? reject(args[0]) : resolve();
81
+ fn(done);
82
+ });
83
+ }
84
+ function normalizeTest(fn, timeout) {
85
+ return withTimeout(ensureAsyncTest(fn), timeout);
86
+ }
87
+
88
+ const fnMap = /* @__PURE__ */ new WeakMap();
89
+ const hooksMap = /* @__PURE__ */ new WeakMap();
90
+ function setFn(key, fn) {
91
+ fnMap.set(key, fn);
92
+ }
93
+ function getFn(key) {
94
+ return fnMap.get(key);
95
+ }
96
+ function setHooks(key, hooks) {
97
+ hooksMap.set(key, hooks);
98
+ }
99
+ function getHooks(key) {
100
+ return hooksMap.get(key);
101
+ }
102
+
103
+ const suite = createSuite();
104
+ const test = createChainable(["concurrent", "skip", "only", "todo", "fails"], function(name, fn, timeout) {
105
+ getCurrentSuite().test.fn.call(this, name, fn, timeout);
106
+ });
107
+ const describe = suite;
108
+ const it = test;
109
+ const defaultSuite = suite("");
110
+ function clearContext() {
111
+ context.tasks.length = 0;
112
+ defaultSuite.clear();
113
+ context.currentSuite = defaultSuite;
114
+ }
115
+ function getCurrentSuite() {
116
+ return context.currentSuite || defaultSuite;
117
+ }
118
+ function createSuiteHooks() {
119
+ return {
120
+ beforeAll: [],
121
+ afterAll: [],
122
+ beforeEach: [],
123
+ afterEach: []
124
+ };
125
+ }
126
+ function createSuiteCollector(name, factory = () => {
127
+ }, mode, suiteComputeMode) {
128
+ const tasks = [];
129
+ const factoryQueue = [];
130
+ let suite2;
131
+ initSuite();
132
+ const test2 = createChainable(["concurrent", "skip", "only", "todo", "fails"], function(name2, fn, timeout) {
133
+ const mode2 = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
134
+ const computeMode = this.concurrent ? "concurrent" : void 0;
135
+ const test3 = {
136
+ id: nanoid(),
137
+ type: "test",
138
+ name: name2,
139
+ mode: mode2,
140
+ computeMode: computeMode ?? (suiteComputeMode ?? "serial"),
141
+ suite: void 0,
142
+ fails: this.fails
143
+ };
144
+ setFn(test3, normalizeTest(fn || noop, timeout));
145
+ tasks.push(test3);
146
+ });
147
+ const collector = {
148
+ type: "collector",
149
+ name,
150
+ mode,
151
+ test: test2,
152
+ tasks,
153
+ collect,
154
+ clear,
155
+ on: addHook
156
+ };
157
+ function addHook(name2, ...fn) {
158
+ getHooks(suite2)[name2].push(...fn);
159
+ }
160
+ function initSuite() {
161
+ suite2 = {
162
+ id: nanoid(),
163
+ type: "suite",
164
+ computeMode: "serial",
165
+ name,
166
+ mode,
167
+ tasks: []
168
+ };
169
+ setHooks(suite2, createSuiteHooks());
170
+ }
171
+ function clear() {
172
+ tasks.length = 0;
173
+ factoryQueue.length = 0;
174
+ initSuite();
175
+ }
176
+ async function collect(file) {
177
+ factoryQueue.length = 0;
178
+ if (factory)
179
+ await runWithSuite(collector, () => factory(test2));
180
+ const allChildren = await Promise.all([...factoryQueue, ...tasks].map((i) => i.type === "collector" ? i.collect(file) : i));
181
+ suite2.file = file;
182
+ suite2.tasks = allChildren;
183
+ allChildren.forEach((task) => {
184
+ task.suite = suite2;
185
+ if (file)
186
+ task.file = file;
187
+ });
188
+ return suite2;
189
+ }
190
+ collectTask(collector);
191
+ return collector;
192
+ }
193
+ function createSuite() {
194
+ return createChainable(["concurrent", "skip", "only", "todo"], function(name, factory) {
195
+ const mode = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
196
+ const computeMode = this.concurrent ? "concurrent" : void 0;
197
+ return createSuiteCollector(name, factory, mode, computeMode);
198
+ });
199
+ }
200
+
201
+ 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 };
@@ -323,7 +323,7 @@ function getNames(task) {
323
323
  }
324
324
  return names;
325
325
  }
326
- async function ensurePackageInstalled(dependency, promptInstall = !process.env.CI) {
326
+ async function ensurePackageInstalled(dependency, promptInstall = !process.env.CI && process.stdout.isTTY) {
327
327
  if (isPackageExists(dependency))
328
328
  return true;
329
329
  console.log(c.red(`${c.inverse(c.red(" MISSING DEP "))} Can not find dependency '${dependency}'
package/dist/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- export { e as ensurePackageInstalled, g as getNames, f as getSuites, q as getTasks, a as getTests, j as hasFailed, o as hasTests, m as interpretOnlyMode, n as noop, k as notNullish, p as partitionSuiteChildren, h as resolvePath, s as slash, t as toArray } from './utils-b780070b.js';
1
+ export { e as ensurePackageInstalled, g as getNames, f as getSuites, q as getTasks, a as getTests, j as hasFailed, o as hasTests, m as interpretOnlyMode, n as noop, k as notNullish, p as partitionSuiteChildren, h as resolvePath, s as slash, t as toArray } from './utils-c8e62373.js';
2
2
  import 'local-pkg';
3
3
  import 'tty';
4
4
  import 'path';
package/dist/worker.js CHANGED
@@ -1,6 +1,6 @@
1
- import { s as slash, h as resolve, d as dirname$2 } from './utils-b780070b.js';
1
+ import { s as slash, h as resolve, d as dirname$2 } from './utils-c8e62373.js';
2
2
  import { n as nanoid } from './index-9e71c815.js';
3
- import { c as distDir } from './constants-3cbd9066.js';
3
+ import { c as distDir } from './constants-a1417084.js';
4
4
  import { builtinModules, createRequire } from 'module';
5
5
  import { pathToFileURL, fileURLToPath as fileURLToPath$2, URL as URL$1 } from 'url';
6
6
  import vm from 'vm';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest",
3
- "version": "0.0.100",
3
+ "version": "0.0.101",
4
4
  "description": "A blazing fast unit test framework powered by Vite",
5
5
  "keywords": [
6
6
  "vite",
@@ -49,6 +49,7 @@
49
49
  "dependencies": {
50
50
  "@types/chai": "^4.3.0",
51
51
  "@types/chai-subset": "^1.3.3",
52
+ "chai": "^4.3.4",
52
53
  "local-pkg": "^0.4.0",
53
54
  "tinypool": "^0.0.3",
54
55
  "tinyspy": "^0.1.2"
@@ -63,7 +64,6 @@
63
64
  "@types/prompts": "^2.4.0",
64
65
  "c8": "^7.10.0",
65
66
  "cac": "^6.7.12",
66
- "chai": "^4.3.4",
67
67
  "chai-subset": "^1.6.0",
68
68
  "cli-truncate": "^3.1.0",
69
69
  "diff": "^5.0.0",
@@ -111,5 +111,6 @@
111
111
  "build": "rimraf dist && rollup -c",
112
112
  "dev": "rollup -c --watch src",
113
113
  "typecheck": "tsc --noEmit"
114
- }
114
+ },
115
+ "readme": "# vitest\n\n[![NPM version](https://img.shields.io/npm/v/vitest?color=a1b858&label=)](https://www.npmjs.com/package/vitest)\n\nA blazing fast unit test framework powered by Vite.\n\n> **This project is currently in closed beta exclusively for Sponsors.**<br>\n> 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.\n> Learn more at [vitest.dev](https://vitest.dev)\n"
115
116
  }