vitest 0.0.98 → 0.0.102

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, defaultSuite as b, clearContext as c, describe as d, setHooks as e, getHooks as f, getCurrentSuite as g, context as h, it as i, getFn as j, suite as s, test as t, withTimeout as w };
@@ -1,5 +1,6 @@
1
1
  import require$$0 from 'tty';
2
2
  import { isPackageExists } from 'local-pkg';
3
+ import path from 'path';
3
4
 
4
5
  var picocolors = {exports: {}};
5
6
 
@@ -64,6 +65,189 @@ picocolors.exports.createColors = createColors;
64
65
 
65
66
  var c = picocolors.exports;
66
67
 
68
+ function normalizeWindowsPath(input = "") {
69
+ if (!input.includes("\\")) {
70
+ return input;
71
+ }
72
+ return input.replace(/\\/g, "/");
73
+ }
74
+
75
+ const _UNC_REGEX = /^[/][/]/;
76
+ const _UNC_DRIVE_REGEX = /^[/][/]([.]{1,2}[/])?([a-zA-Z]):[/]/;
77
+ const _IS_ABSOLUTE_RE = /^\/|^\\|^[a-zA-Z]:[/\\]/;
78
+ const sep = "/";
79
+ const delimiter = ":";
80
+ const normalize = function(path2) {
81
+ if (path2.length === 0) {
82
+ return ".";
83
+ }
84
+ path2 = normalizeWindowsPath(path2);
85
+ const isUNCPath = path2.match(_UNC_REGEX);
86
+ const hasUNCDrive = isUNCPath && path2.match(_UNC_DRIVE_REGEX);
87
+ const isPathAbsolute = isAbsolute(path2);
88
+ const trailingSeparator = path2[path2.length - 1] === "/";
89
+ path2 = normalizeString(path2, !isPathAbsolute);
90
+ if (path2.length === 0) {
91
+ if (isPathAbsolute) {
92
+ return "/";
93
+ }
94
+ return trailingSeparator ? "./" : ".";
95
+ }
96
+ if (trailingSeparator) {
97
+ path2 += "/";
98
+ }
99
+ if (isUNCPath) {
100
+ if (hasUNCDrive) {
101
+ return `//./${path2}`;
102
+ }
103
+ return `//${path2}`;
104
+ }
105
+ return isPathAbsolute && !isAbsolute(path2) ? `/${path2}` : path2;
106
+ };
107
+ const join = function(...args) {
108
+ if (args.length === 0) {
109
+ return ".";
110
+ }
111
+ let joined;
112
+ for (let i = 0; i < args.length; ++i) {
113
+ const arg = args[i];
114
+ if (arg.length > 0) {
115
+ if (joined === void 0) {
116
+ joined = arg;
117
+ } else {
118
+ joined += `/${arg}`;
119
+ }
120
+ }
121
+ }
122
+ if (joined === void 0) {
123
+ return ".";
124
+ }
125
+ return normalize(joined);
126
+ };
127
+ const resolve = function(...args) {
128
+ args = args.map((arg) => normalizeWindowsPath(arg));
129
+ let resolvedPath = "";
130
+ let resolvedAbsolute = false;
131
+ for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
132
+ const path2 = i >= 0 ? args[i] : process.cwd();
133
+ if (path2.length === 0) {
134
+ continue;
135
+ }
136
+ resolvedPath = `${path2}/${resolvedPath}`;
137
+ resolvedAbsolute = isAbsolute(path2);
138
+ }
139
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
140
+ if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
141
+ return `/${resolvedPath}`;
142
+ }
143
+ return resolvedPath.length > 0 ? resolvedPath : ".";
144
+ };
145
+ function normalizeString(path2, allowAboveRoot) {
146
+ let res = "";
147
+ let lastSegmentLength = 0;
148
+ let lastSlash = -1;
149
+ let dots = 0;
150
+ let char = null;
151
+ for (let i = 0; i <= path2.length; ++i) {
152
+ if (i < path2.length) {
153
+ char = path2[i];
154
+ } else if (char === "/") {
155
+ break;
156
+ } else {
157
+ char = "/";
158
+ }
159
+ if (char === "/") {
160
+ if (lastSlash === i - 1 || dots === 1) ; else if (dots === 2) {
161
+ if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
162
+ if (res.length > 2) {
163
+ const lastSlashIndex = res.lastIndexOf("/");
164
+ if (lastSlashIndex === -1) {
165
+ res = "";
166
+ lastSegmentLength = 0;
167
+ } else {
168
+ res = res.slice(0, lastSlashIndex);
169
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
170
+ }
171
+ lastSlash = i;
172
+ dots = 0;
173
+ continue;
174
+ } else if (res.length !== 0) {
175
+ res = "";
176
+ lastSegmentLength = 0;
177
+ lastSlash = i;
178
+ dots = 0;
179
+ continue;
180
+ }
181
+ }
182
+ if (allowAboveRoot) {
183
+ res += res.length > 0 ? "/.." : "..";
184
+ lastSegmentLength = 2;
185
+ }
186
+ } else {
187
+ if (res.length > 0) {
188
+ res += `/${path2.slice(lastSlash + 1, i)}`;
189
+ } else {
190
+ res = path2.slice(lastSlash + 1, i);
191
+ }
192
+ lastSegmentLength = i - lastSlash - 1;
193
+ }
194
+ lastSlash = i;
195
+ dots = 0;
196
+ } else if (char === "." && dots !== -1) {
197
+ ++dots;
198
+ } else {
199
+ dots = -1;
200
+ }
201
+ }
202
+ return res;
203
+ }
204
+ const isAbsolute = function(p) {
205
+ return _IS_ABSOLUTE_RE.test(p);
206
+ };
207
+ const toNamespacedPath = function(p) {
208
+ return normalizeWindowsPath(p);
209
+ };
210
+ const extname = function(p) {
211
+ return path.posix.extname(normalizeWindowsPath(p));
212
+ };
213
+ const relative = function(from, to) {
214
+ return path.posix.relative(normalizeWindowsPath(from), normalizeWindowsPath(to));
215
+ };
216
+ const dirname = function(p) {
217
+ return path.posix.dirname(normalizeWindowsPath(p));
218
+ };
219
+ const format = function(p) {
220
+ return normalizeWindowsPath(path.posix.format(p));
221
+ };
222
+ const basename = function(p, ext) {
223
+ return path.posix.basename(normalizeWindowsPath(p), ext);
224
+ };
225
+ const parse = function(p) {
226
+ return path.posix.parse(normalizeWindowsPath(p));
227
+ };
228
+
229
+ const _path = /*#__PURE__*/Object.freeze({
230
+ __proto__: null,
231
+ sep: sep,
232
+ delimiter: delimiter,
233
+ normalize: normalize,
234
+ join: join,
235
+ resolve: resolve,
236
+ normalizeString: normalizeString,
237
+ isAbsolute: isAbsolute,
238
+ toNamespacedPath: toNamespacedPath,
239
+ extname: extname,
240
+ relative: relative,
241
+ dirname: dirname,
242
+ format: format,
243
+ basename: basename,
244
+ parse: parse
245
+ });
246
+
247
+ const index = {
248
+ ..._path
249
+ };
250
+
67
251
  function toArray(array) {
68
252
  array = array || [];
69
253
  if (Array.isArray(array))
@@ -139,7 +323,7 @@ function getNames(task) {
139
323
  }
140
324
  return names;
141
325
  }
142
- async function ensurePackageInstalled(dependency, promptInstall = !process.env.CI) {
326
+ async function ensurePackageInstalled(dependency, promptInstall = !process.env.CI && process.stdout.isTTY) {
143
327
  if (isPackageExists(dependency))
144
328
  return true;
145
329
  console.log(c.red(`${c.inverse(c.red(" MISSING DEP "))} Can not find dependency '${dependency}'
@@ -153,10 +337,10 @@ async function ensurePackageInstalled(dependency, promptInstall = !process.env.C
153
337
  message: c.reset(`Do you want to install ${c.green(dependency)}?`)
154
338
  });
155
339
  if (install) {
156
- await (await import('./index-e7a421bb.js')).installPackage(dependency, { dev: true });
340
+ await (await import('./index-0c3a317d.js')).installPackage(dependency, { dev: true });
157
341
  return true;
158
342
  }
159
343
  return false;
160
344
  }
161
345
 
162
- export { getTests as a, getSuites as b, c, notNullish as d, ensurePackageInstalled as e, hasTests as f, getNames as g, hasFailed as h, interpretOnlyMode as i, getTasks as j, noop as n, partitionSuiteChildren as p, slash as s, toArray as t };
346
+ export { getTests as a, basename as b, c, dirname as d, ensurePackageInstalled as e, getSuites as f, getNames as g, resolve as h, isAbsolute as i, hasFailed as j, notNullish as k, index as l, interpretOnlyMode as m, noop as n, hasTests as o, partitionSuiteChildren as p, getTasks as q, relative as r, slash as s, toArray as t };
package/dist/utils.js CHANGED
@@ -1,3 +1,4 @@
1
- export { e as ensurePackageInstalled, g as getNames, b as getSuites, j as getTasks, a as getTests, h as hasFailed, f as hasTests, i as interpretOnlyMode, n as noop, d as notNullish, p as partitionSuiteChildren, s as slash, t as toArray } from './utils-70b78878.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
+ import 'path';
package/dist/worker.js CHANGED
@@ -1,6 +1,6 @@
1
- import { a as resolve, d as dirname$2 } from './index-1488b423.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-e78c749a.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';
@@ -8,7 +8,6 @@ import path from 'path';
8
8
  import fs, { promises, realpathSync, statSync, Stats } from 'fs';
9
9
  import assert from 'assert';
10
10
  import { format as format$2, inspect } from 'util';
11
- import { s as slash } from './utils-70b78878.js';
12
11
  import { s as send } from './rpc-7de86f29.js';
13
12
  import 'tty';
14
13
  import 'local-pkg';
package/node.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/node'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest",
3
- "version": "0.0.98",
3
+ "version": "0.0.102",
4
4
  "description": "A blazing fast unit test framework powered by Vite",
5
5
  "keywords": [
6
6
  "vite",
@@ -25,34 +25,32 @@
25
25
  "import": "./dist/index.js",
26
26
  "types": "./dist/index.d.ts"
27
27
  },
28
- "./node": {
29
- "import": "./dist/node.js",
30
- "types": "./dist/node.d.ts"
31
- },
28
+ "./*": "./*",
32
29
  "./global": {
33
30
  "types": "./global.d.ts"
34
31
  },
35
- "./*": "./*"
32
+ "./node": {
33
+ "import": "./dist/node.js",
34
+ "types": "./dist/node.d.ts"
35
+ }
36
36
  },
37
37
  "main": "./dist/index.js",
38
38
  "module": "./dist/index.js",
39
39
  "types": "./dist/index.d.ts",
40
40
  "bin": {
41
- "vitest": "./bin/vitest.mjs"
41
+ "vitest": "./vitest.mjs"
42
42
  },
43
43
  "files": [
44
44
  "dist",
45
45
  "bin",
46
- "*.d.ts"
46
+ "*.d.ts",
47
+ "*.mjs"
47
48
  ],
48
49
  "dependencies": {
49
50
  "@types/chai": "^4.3.0",
50
51
  "@types/chai-subset": "^1.3.3",
51
52
  "chai": "^4.3.4",
52
- "chai-subset": "^1.6.0",
53
- "fast-glob": "^3.2.7",
54
53
  "local-pkg": "^0.4.0",
55
- "source-map": "^0.7.3",
56
54
  "tinypool": "^0.0.3",
57
55
  "tinyspy": "^0.1.2"
58
56
  },
@@ -66,8 +64,10 @@
66
64
  "@types/prompts": "^2.4.0",
67
65
  "c8": "^7.10.0",
68
66
  "cac": "^6.7.12",
67
+ "chai-subset": "^1.6.0",
69
68
  "cli-truncate": "^3.1.0",
70
69
  "diff": "^5.0.0",
70
+ "fast-glob": "^3.2.7",
71
71
  "find-up": "^6.2.0",
72
72
  "flatted": "^3.2.4",
73
73
  "happy-dom": "^2.25.0",
@@ -83,6 +83,7 @@
83
83
  "pretty-format": "^27.4.2",
84
84
  "prompts": "^2.4.2",
85
85
  "rollup": "^2.61.1",
86
+ "source-map-js": "^1.0.1",
86
87
  "strip-ansi": "^7.0.1",
87
88
  "typescript": "^4.5.4"
88
89
  },
@@ -104,7 +105,7 @@
104
105
  }
105
106
  },
106
107
  "engines": {
107
- "node": ">=16.0.0"
108
+ "node": ">=14.14.0"
108
109
  },
109
110
  "scripts": {
110
111
  "build": "rimraf dist && rollup -c",
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { fileURLToPath } from 'url'
4
- import { resolve } from 'pathe'
5
- import { ensurePackageInstalled } from '../dist/utils.js'
4
+ import { ensurePackageInstalled, resolvePath } from './dist/utils.js'
6
5
 
7
6
  const argv = process.argv.slice(2)
8
7
 
@@ -13,10 +12,10 @@ if (argv.includes('--coverage')) {
13
12
  if (!await ensurePackageInstalled('c8'))
14
13
  process.exit(1)
15
14
  const filename = fileURLToPath(import.meta.url)
16
- const entry = resolve(filename, '../../dist/cli.js')
15
+ const entry = resolvePath(filename, '../../dist/cli.js')
17
16
  process.argv.splice(2, 0, process.argv[0], entry)
18
17
  await import('c8/bin/c8.js')
19
18
  }
20
19
  else {
21
- await import('../dist/cli.js')
20
+ await import('./dist/cli.js')
22
21
  }
package/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2021-Present Anthony Fu <https://github.com/antfu>
4
- Copyright (c) 2021-Present Matias Capeletto <https://github.com/patak-dev>
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in all
14
- copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- SOFTWARE.