vitest 1.0.0-beta.2 → 1.0.0-beta.4
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/LICENSE.md +17 -29
- package/dist/browser.d.ts +1 -2
- package/dist/browser.js +3 -3
- package/dist/child.js +13 -7
- package/dist/{chunk-api-setup.5d9a93c7.js → chunk-api-setup.6d19ab38.js} +6 -4
- package/dist/{chunk-install-pkg.43d58972.js → chunk-install-pkg.e1d6323e.js} +12 -14
- package/dist/{chunk-integrations-globals.9df12d91.js → chunk-integrations-globals.2b099e04.js} +6 -6
- package/dist/{chunk-node-git.2f1df48f.js → chunk-node-git.6c12e560.js} +1 -1
- package/dist/cli-wrapper.js +1 -1
- package/dist/cli.js +16 -20
- package/dist/config.cjs +1 -0
- package/dist/config.d.ts +2 -3
- package/dist/config.js +1 -0
- package/dist/coverage.d.ts +1 -2
- package/dist/coverage.js +2 -2
- package/dist/entry-vm.js +8 -8
- package/dist/entry.js +8 -8
- package/dist/environments.d.ts +1 -2
- package/dist/environments.js +1 -13
- package/dist/execute.d.ts +2 -3
- package/dist/execute.js +1 -2
- package/dist/index.d.ts +232 -59
- package/dist/index.js +7 -7
- package/dist/node.d.ts +10 -4
- package/dist/node.js +16 -18
- package/dist/{reporters-d10f25e1.d.ts → reporters-50c2bd49.d.ts} +100 -35
- package/dist/reporters.d.ts +1 -2
- package/dist/reporters.js +3 -3
- package/dist/runners.d.ts +3 -3
- package/dist/runners.js +37 -41
- package/dist/{suite-919dd548.d.ts → suite-ad69b7cd.d.ts} +1 -1
- package/dist/suite.d.ts +2 -3
- package/dist/suite.js +3 -3
- package/dist/{vendor-benchmark.44931cfa.js → vendor-benchmark.b6befc50.js} +1 -1
- package/dist/{vendor-environments.094f240c.js → vendor-environments.dcc4a34e.js} +4 -37
- package/dist/{vendor-execute.07d1a420.js → vendor-execute.157302d6.js} +3 -3
- package/dist/vendor-global.c3664e75.js +14 -0
- package/dist/{vendor-index.29282562.js → vendor-index.2b92937b.js} +1 -1
- package/dist/{vendor-index.d36f5516.js → vendor-index.57925a34.js} +8 -3
- package/dist/{vendor-index.68ecee35.js → vendor-index.72df742e.js} +11 -4
- package/dist/{vendor-index.e006069f.js → vendor-index.8efe7746.js} +371 -371
- package/dist/{vendor-index.0b5b3600.js → vendor-loader.9c966f23.js} +36 -9
- package/dist/{vendor-node.e5a35bfe.js → vendor-node.65461b16.js} +2660 -2021
- package/dist/{vendor-reporters.2953082e.js → vendor-reporters.d24d80a4.js} +42 -25
- package/dist/{vendor-rpc.cbd8e972.js → vendor-rpc.171f65fb.js} +1 -1
- package/dist/{vendor-run-once.3e5ef7d7.js → vendor-run-once.fb836747.js} +1 -1
- package/dist/{vendor-vi.d30b47ae.js → vendor-vi.3baa7c4a.js} +32 -35
- package/dist/vm.js +14 -8
- package/dist/worker.js +14 -8
- package/package.json +12 -28
- package/dist/loader.js +0 -100
- package/dist/vendor-global.97e4527c.js +0 -9
- package/dist/vendor-index.98139333.js +0 -129
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { performance } from 'node:perf_hooks';
|
|
2
2
|
import c from 'picocolors';
|
|
3
|
-
import { b as isNode, c as relativePath } from './vendor-index.
|
|
3
|
+
import { b as isNode, c as relativePath } from './vendor-index.2b92937b.js';
|
|
4
4
|
import { UNKNOWN_TEST_ID } from './chunk-runtime-console.f3263f87.js';
|
|
5
5
|
import { isAbsolute, relative, dirname, basename, resolve } from 'pathe';
|
|
6
6
|
import { s as slash } from './vendor-base.9c08bbd0.js';
|
|
@@ -229,6 +229,7 @@ class BaseReporter {
|
|
|
229
229
|
_lastRunTimer;
|
|
230
230
|
_lastRunCount = 0;
|
|
231
231
|
_timeStart = /* @__PURE__ */ new Date();
|
|
232
|
+
_offUnhandledRejection;
|
|
232
233
|
constructor() {
|
|
233
234
|
this.registerUnhandledRejection();
|
|
234
235
|
}
|
|
@@ -237,6 +238,10 @@ class BaseReporter {
|
|
|
237
238
|
}
|
|
238
239
|
onInit(ctx) {
|
|
239
240
|
this.ctx = ctx;
|
|
241
|
+
ctx.onClose(() => {
|
|
242
|
+
var _a2;
|
|
243
|
+
(_a2 = this._offUnhandledRejection) == null ? void 0 : _a2.call(this);
|
|
244
|
+
});
|
|
240
245
|
ctx.logger.printBanner();
|
|
241
246
|
this.start = performance.now();
|
|
242
247
|
}
|
|
@@ -303,8 +308,7 @@ class BaseReporter {
|
|
|
303
308
|
else
|
|
304
309
|
this.ctx.logger.log(WAIT_FOR_CHANGE_PASS);
|
|
305
310
|
const hints = [];
|
|
306
|
-
|
|
307
|
-
hints.push(HELP_HINT);
|
|
311
|
+
hints.push(HELP_HINT);
|
|
308
312
|
if (failedSnap)
|
|
309
313
|
hints.unshift(HELP_UPDATE_SNAP);
|
|
310
314
|
else
|
|
@@ -426,7 +430,7 @@ ${log.content}
|
|
|
426
430
|
}
|
|
427
431
|
logger.log(padTitle("Test Files"), getStateString(files));
|
|
428
432
|
logger.log(padTitle("Tests"), getStateString(tests));
|
|
429
|
-
if (this.
|
|
433
|
+
if (this.ctx.projects.some((c2) => c2.config.typecheck.enabled)) {
|
|
430
434
|
const failed = tests.filter((t) => {
|
|
431
435
|
var _a2, _b, _c;
|
|
432
436
|
return ((_a2 = t.meta) == null ? void 0 : _a2.typecheck) && ((_c = (_b = t.result) == null ? void 0 : _b.errors) == null ? void 0 : _c.length);
|
|
@@ -436,12 +440,18 @@ ${log.content}
|
|
|
436
440
|
if (errors.length)
|
|
437
441
|
logger.log(padTitle("Errors"), c.bold(c.red(`${errors.length} error${errors.length > 1 ? "s" : ""}`)));
|
|
438
442
|
logger.log(padTitle("Start at"), formatTimeString(this._timeStart));
|
|
439
|
-
if (this.watchFilters)
|
|
443
|
+
if (this.watchFilters) {
|
|
440
444
|
logger.log(padTitle("Duration"), time(threadTime));
|
|
441
|
-
else
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
+
} else {
|
|
446
|
+
let timers = `transform ${time(transformTime)}, setup ${time(setupTime)}, collect ${time(collectTime)}, tests ${time(testsTime)}, environment ${time(environmentTime)}, prepare ${time(prepareTime)}`;
|
|
447
|
+
const typecheck = this.ctx.projects.reduce((acc, c2) => {
|
|
448
|
+
var _a2;
|
|
449
|
+
return acc + (((_a2 = c2.typechecker) == null ? void 0 : _a2.getResult().time) || 0);
|
|
450
|
+
}, 0);
|
|
451
|
+
if (typecheck)
|
|
452
|
+
timers += `, typecheck ${time(typecheck)}`;
|
|
453
|
+
logger.log(padTitle("Duration"), time(executionTime) + c.dim(` (${timers})`));
|
|
454
|
+
}
|
|
445
455
|
logger.log();
|
|
446
456
|
}
|
|
447
457
|
async printErrorsSummary(files, errors) {
|
|
@@ -539,12 +549,16 @@ ${c.cyan(c.inverse(c.bold(" BENCH ")))} ${c.cyan("Summary")}
|
|
|
539
549
|
}
|
|
540
550
|
}
|
|
541
551
|
registerUnhandledRejection() {
|
|
542
|
-
|
|
552
|
+
const onUnhandledRejection = async (err) => {
|
|
543
553
|
process.exitCode = 1;
|
|
544
554
|
await this.ctx.logger.printError(err, { fullStack: true, type: "Unhandled Rejection" });
|
|
545
555
|
this.ctx.logger.error("\n\n");
|
|
546
556
|
process.exit(1);
|
|
547
|
-
}
|
|
557
|
+
};
|
|
558
|
+
process.on("unhandledRejection", onUnhandledRejection);
|
|
559
|
+
this._offUnhandledRejection = () => {
|
|
560
|
+
process.off("unhandledRejection", onUnhandledRejection);
|
|
561
|
+
};
|
|
548
562
|
}
|
|
549
563
|
}
|
|
550
564
|
|
|
@@ -1455,7 +1469,7 @@ function renderBenchmark$1(task, tasks) {
|
|
|
1455
1469
|
].join("");
|
|
1456
1470
|
}
|
|
1457
1471
|
function renderTree$1(tasks, options, level = 0, maxRows) {
|
|
1458
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
1472
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1459
1473
|
const output = [];
|
|
1460
1474
|
let currentRowCount = 0;
|
|
1461
1475
|
for (const task of [...tasks].reverse()) {
|
|
@@ -1466,27 +1480,27 @@ function renderTree$1(tasks, options, level = 0, maxRows) {
|
|
|
1466
1480
|
prefix += formatProjectName(task.projectName);
|
|
1467
1481
|
if (task.type === "test" && ((_a = task.result) == null ? void 0 : _a.retryCount) && task.result.retryCount > 0)
|
|
1468
1482
|
suffix += c.yellow(` (retry x${task.result.retryCount})`);
|
|
1469
|
-
if (task.type === "suite"
|
|
1483
|
+
if (task.type === "suite") {
|
|
1470
1484
|
const tests = getTests(task);
|
|
1471
1485
|
suffix += c.dim(` (${tests.length})`);
|
|
1472
1486
|
}
|
|
1473
1487
|
if (task.mode === "skip" || task.mode === "todo")
|
|
1474
1488
|
suffix += ` ${c.dim(c.gray("[skipped]"))}`;
|
|
1475
|
-
if (task.type === "test" && ((
|
|
1489
|
+
if (task.type === "test" && ((_b = task.result) == null ? void 0 : _b.repeatCount) && task.result.repeatCount > 0)
|
|
1476
1490
|
suffix += c.yellow(` (repeat x${task.result.repeatCount})`);
|
|
1477
|
-
if (((
|
|
1491
|
+
if (((_c = task.result) == null ? void 0 : _c.duration) != null) {
|
|
1478
1492
|
if (task.result.duration > DURATION_LONG$1)
|
|
1479
1493
|
suffix += c.yellow(` ${Math.round(task.result.duration)}${c.dim("ms")}`);
|
|
1480
1494
|
}
|
|
1481
|
-
if (options.showHeap && ((
|
|
1495
|
+
if (options.showHeap && ((_d = task.result) == null ? void 0 : _d.heap) != null)
|
|
1482
1496
|
suffix += c.magenta(` ${Math.floor(task.result.heap / 1024 / 1024)} MB heap used`);
|
|
1483
1497
|
let name = task.name;
|
|
1484
1498
|
if (level === 0)
|
|
1485
1499
|
name = formatFilepath$1(name);
|
|
1486
1500
|
const padding = " ".repeat(level);
|
|
1487
|
-
const body = ((
|
|
1501
|
+
const body = ((_e = task.meta) == null ? void 0 : _e.benchmark) ? renderBenchmark$1(task, tasks) : name;
|
|
1488
1502
|
taskOutput.push(padding + prefix + body + suffix);
|
|
1489
|
-
if (((
|
|
1503
|
+
if (((_f = task.result) == null ? void 0 : _f.state) !== "pass" && outputMap$1.get(task) != null) {
|
|
1490
1504
|
let data = outputMap$1.get(task);
|
|
1491
1505
|
if (typeof data === "string") {
|
|
1492
1506
|
data = stripAnsi(data.trim().split("\n").filter(Boolean).pop());
|
|
@@ -1501,7 +1515,7 @@ function renderTree$1(tasks, options, level = 0, maxRows) {
|
|
|
1501
1515
|
taskOutput.push(renderHookState(task, "beforeAll", level + 1));
|
|
1502
1516
|
taskOutput.push(renderHookState(task, "beforeEach", level + 1));
|
|
1503
1517
|
if (task.type === "suite" && task.tasks.length > 0) {
|
|
1504
|
-
if (((
|
|
1518
|
+
if (((_g = task.result) == null ? void 0 : _g.state) === "fail" || ((_h = task.result) == null ? void 0 : _h.state) === "run" || options.renderSucceed) {
|
|
1505
1519
|
if (options.logger.ctx.config.hideSkippedTests) {
|
|
1506
1520
|
const filteredTasks = task.tasks.filter((t) => t.mode !== "skip" && t.mode !== "todo");
|
|
1507
1521
|
taskOutput.push(renderTree$1(filteredTasks, options, level + 1, maxRows));
|
|
@@ -1910,7 +1924,8 @@ let JsonReporter$1 = class JsonReporter {
|
|
|
1910
1924
|
return;
|
|
1911
1925
|
const project = this.ctx.getProjectByTaskId(test.id);
|
|
1912
1926
|
const stack = parseErrorStacktrace(error, {
|
|
1913
|
-
getSourceMap: (file) => project.getBrowserSourceMapModuleById(file)
|
|
1927
|
+
getSourceMap: (file) => project.getBrowserSourceMapModuleById(file),
|
|
1928
|
+
frameFilter: this.ctx.config.onStackTrace
|
|
1914
1929
|
});
|
|
1915
1930
|
const frame = stack[0];
|
|
1916
1931
|
if (!frame)
|
|
@@ -2015,7 +2030,8 @@ class TapReporter {
|
|
|
2015
2030
|
this.logger.indent();
|
|
2016
2031
|
task.result.errors.forEach((error) => {
|
|
2017
2032
|
const stacks = parseErrorStacktrace(error, {
|
|
2018
|
-
getSourceMap: (file) => project.getBrowserSourceMapModuleById(file)
|
|
2033
|
+
getSourceMap: (file) => project.getBrowserSourceMapModuleById(file),
|
|
2034
|
+
frameFilter: this.ctx.config.onStackTrace
|
|
2019
2035
|
});
|
|
2020
2036
|
const stack = stacks[0];
|
|
2021
2037
|
this.logger.log("---");
|
|
@@ -2128,7 +2144,8 @@ class JUnitReporter {
|
|
|
2128
2144
|
await this.baseLog(escapeXML(errorDetails));
|
|
2129
2145
|
const project = this.ctx.getProjectByTaskId(task.id);
|
|
2130
2146
|
const stack = parseErrorStacktrace(error, {
|
|
2131
|
-
getSourceMap: (file) => project.getBrowserSourceMapModuleById(file)
|
|
2147
|
+
getSourceMap: (file) => project.getBrowserSourceMapModuleById(file),
|
|
2148
|
+
frameFilter: this.ctx.config.onStackTrace
|
|
2132
2149
|
});
|
|
2133
2150
|
for (const frame of stack) {
|
|
2134
2151
|
const path = relative(this.ctx.config.root, frame.file);
|
|
@@ -2156,13 +2173,13 @@ class JUnitReporter {
|
|
|
2156
2173
|
name: task.name,
|
|
2157
2174
|
time: getDuration(task)
|
|
2158
2175
|
}, async () => {
|
|
2159
|
-
var _a
|
|
2176
|
+
var _a;
|
|
2160
2177
|
await this.writeLogs(task, "out");
|
|
2161
2178
|
await this.writeLogs(task, "err");
|
|
2162
2179
|
if (task.mode === "skip" || task.mode === "todo")
|
|
2163
2180
|
await this.logger.log("<skipped/>");
|
|
2164
2181
|
if (((_a = task.result) == null ? void 0 : _a.state) === "fail") {
|
|
2165
|
-
const errors =
|
|
2182
|
+
const errors = task.result.errors || [];
|
|
2166
2183
|
for (const error of errors) {
|
|
2167
2184
|
await this.writeElement("failure", {
|
|
2168
2185
|
message: error == null ? void 0 : error.message,
|
|
@@ -2582,4 +2599,4 @@ const ReportersMap = {
|
|
|
2582
2599
|
"hanging-process": HangingProcessReporter
|
|
2583
2600
|
};
|
|
2584
2601
|
|
|
2585
|
-
export { BenchmarkReportsMap as B, DefaultReporter as D, F_POINTER as F, HangingProcessReporter as H, JsonReporter$1 as J, ReportersMap as R, TapReporter as T, VerboseReporter as V, ansiStyles as a,
|
|
2602
|
+
export { BenchmarkReportsMap as B, DefaultReporter as D, F_POINTER as F, HangingProcessReporter as H, JsonReporter$1 as J, ReportersMap as R, TapReporter as T, VerboseReporter as V, ansiStyles as a, BasicReporter as b, cliTruncate as c, divider as d, DotReporter as e, JUnitReporter as f, TapFlatReporter as g, stripAnsi as s };
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import * as chai$1 from 'chai';
|
|
2
2
|
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './vendor-_commonjsHelpers.7d1333e8.js';
|
|
3
|
-
import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT as GLOBAL_EXPECT$1, getState, setState } from '@vitest/expect';
|
|
3
|
+
import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT as GLOBAL_EXPECT$1, ASYMMETRIC_MATCHERS_OBJECT as ASYMMETRIC_MATCHERS_OBJECT$1, getState, setState } from '@vitest/expect';
|
|
4
4
|
import { stripSnapshotIndentation, addSerializer, SnapshotClient } from '@vitest/snapshot';
|
|
5
5
|
import { getNames } from '@vitest/runner/utils';
|
|
6
6
|
import '@vitest/utils/error';
|
|
7
7
|
import { getCurrentTest } from '@vitest/runner';
|
|
8
8
|
import { g as getFullName } from './vendor-tasks.f9d75aed.js';
|
|
9
|
-
import { g as getWorkerState, a as getCurrentEnvironment } from './vendor-global.
|
|
9
|
+
import { g as getWorkerState, a as getCurrentEnvironment } from './vendor-global.c3664e75.js';
|
|
10
10
|
import { getSafeTimers, assertTypes, createSimpleStackTrace } from '@vitest/utils';
|
|
11
11
|
import { parseSingleStack } from '@vitest/utils/source-map';
|
|
12
12
|
import { R as RealDate, r as resetDate, m as mockDate } from './vendor-date.6e993429.js';
|
|
13
|
-
import { spyOn, fn, isMockFunction,
|
|
13
|
+
import { spyOn, fn, isMockFunction, mocks } from '@vitest/spy';
|
|
14
14
|
|
|
15
15
|
function resetModules(modules, resetMocks = false) {
|
|
16
16
|
const skipPaths = [
|
|
@@ -144,10 +144,12 @@ var Subset = /*@__PURE__*/getDefaultExportFromCjs(chaiSubsetExports);
|
|
|
144
144
|
const MATCHERS_OBJECT = Symbol.for("matchers-object");
|
|
145
145
|
const JEST_MATCHERS_OBJECT = Symbol.for("$$jest-matchers-object");
|
|
146
146
|
const GLOBAL_EXPECT = Symbol.for("expect-global");
|
|
147
|
+
const ASYMMETRIC_MATCHERS_OBJECT = Symbol.for("asymmetric-matchers-object");
|
|
147
148
|
|
|
148
149
|
if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
|
|
149
150
|
const globalState = /* @__PURE__ */ new WeakMap();
|
|
150
151
|
const matchers = /* @__PURE__ */ Object.create(null);
|
|
152
|
+
const assymetricMatchers = /* @__PURE__ */ Object.create(null);
|
|
151
153
|
Object.defineProperty(globalThis, MATCHERS_OBJECT, {
|
|
152
154
|
get: () => globalState
|
|
153
155
|
});
|
|
@@ -158,6 +160,9 @@ if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
|
|
|
158
160
|
matchers
|
|
159
161
|
})
|
|
160
162
|
});
|
|
163
|
+
Object.defineProperty(globalThis, ASYMMETRIC_MATCHERS_OBJECT, {
|
|
164
|
+
get: () => assymetricMatchers
|
|
165
|
+
});
|
|
161
166
|
}
|
|
162
167
|
|
|
163
168
|
function recordAsyncExpect(test, promise) {
|
|
@@ -185,21 +190,16 @@ function getSnapshotClient() {
|
|
|
185
190
|
}
|
|
186
191
|
return _client;
|
|
187
192
|
}
|
|
188
|
-
function
|
|
189
|
-
if (err instanceof Error)
|
|
190
|
-
return err.message;
|
|
191
|
-
return err;
|
|
192
|
-
}
|
|
193
|
-
function getErrorString(expected, promise) {
|
|
193
|
+
function getError(expected, promise) {
|
|
194
194
|
if (typeof expected !== "function") {
|
|
195
195
|
if (!promise)
|
|
196
196
|
throw new Error(`expected must be a function, received ${typeof expected}`);
|
|
197
|
-
return
|
|
197
|
+
return expected;
|
|
198
198
|
}
|
|
199
199
|
try {
|
|
200
200
|
expected();
|
|
201
201
|
} catch (e) {
|
|
202
|
-
return
|
|
202
|
+
return e;
|
|
203
203
|
}
|
|
204
204
|
throw new Error("snapshot function didn't throw");
|
|
205
205
|
}
|
|
@@ -296,7 +296,7 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
296
296
|
const promise = utils.flag(this, "promise");
|
|
297
297
|
const errorMessage = utils.flag(this, "message");
|
|
298
298
|
getSnapshotClient().assert({
|
|
299
|
-
received:
|
|
299
|
+
received: getError(expected, promise),
|
|
300
300
|
message,
|
|
301
301
|
errorMessage,
|
|
302
302
|
...getTestNames(test)
|
|
@@ -317,7 +317,7 @@ const SnapshotPlugin = (chai, utils) => {
|
|
|
317
317
|
const promise = utils.flag(this, "promise");
|
|
318
318
|
const errorMessage = utils.flag(this, "message");
|
|
319
319
|
getSnapshotClient().assert({
|
|
320
|
-
received:
|
|
320
|
+
received: getError(expected, promise),
|
|
321
321
|
message,
|
|
322
322
|
inlineSnapshot,
|
|
323
323
|
isInline: true,
|
|
@@ -353,6 +353,7 @@ function createExpect(test) {
|
|
|
353
353
|
return assert2;
|
|
354
354
|
};
|
|
355
355
|
Object.assign(expect, chai$1.expect);
|
|
356
|
+
Object.assign(expect, globalThis[ASYMMETRIC_MATCHERS_OBJECT$1]);
|
|
356
357
|
expect.getState = () => getState(expect);
|
|
357
358
|
expect.setState = (state) => setState(state, expect);
|
|
358
359
|
const globalState = getState(globalThis[GLOBAL_EXPECT$1]) || {};
|
|
@@ -3297,10 +3298,6 @@ function createVitest() {
|
|
|
3297
3298
|
let _mockedDate = null;
|
|
3298
3299
|
let _config = null;
|
|
3299
3300
|
const workerState = getWorkerState();
|
|
3300
|
-
if (!workerState) {
|
|
3301
|
-
const errorMsg = 'Vitest failed to access its internal state.\n\nOne of the following is possible:\n- "vitest" is imported directly without running "vitest" command\n- "vitest" is imported inside "globalSetup" (to fix this, use "setupFiles" instead, because "globalSetup" runs in a different context)\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n';
|
|
3302
|
-
throw new Error(errorMsg);
|
|
3303
|
-
}
|
|
3304
3301
|
const _timers = new FakeTimers({
|
|
3305
3302
|
global: globalThis,
|
|
3306
3303
|
config: workerState.config.fakeTimers
|
|
@@ -3316,18 +3313,17 @@ function createVitest() {
|
|
|
3316
3313
|
const utils = {
|
|
3317
3314
|
useFakeTimers(config) {
|
|
3318
3315
|
var _a, _b, _c, _d;
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
if (((_a = config == null ? void 0 : config.toFake) == null ? void 0 : _a.includes("nextTick")) || ((_d = (_c = (_b = workerState2.config) == null ? void 0 : _b.fakeTimers) == null ? void 0 : _c.toFake) == null ? void 0 : _d.includes("nextTick"))) {
|
|
3316
|
+
if (workerState.isChildProcess) {
|
|
3317
|
+
if (((_a = config == null ? void 0 : config.toFake) == null ? void 0 : _a.includes("nextTick")) || ((_d = (_c = (_b = workerState.config) == null ? void 0 : _b.fakeTimers) == null ? void 0 : _c.toFake) == null ? void 0 : _d.includes("nextTick"))) {
|
|
3322
3318
|
throw new Error(
|
|
3323
3319
|
'vi.useFakeTimers({ toFake: ["nextTick"] }) is not supported in node:child_process. Use --pool=threads if mocking nextTick is required.'
|
|
3324
3320
|
);
|
|
3325
3321
|
}
|
|
3326
3322
|
}
|
|
3327
3323
|
if (config)
|
|
3328
|
-
_timers.configure({ ...
|
|
3324
|
+
_timers.configure({ ...workerState.config.fakeTimers, ...config });
|
|
3329
3325
|
else
|
|
3330
|
-
_timers.configure(
|
|
3326
|
+
_timers.configure(workerState.config.fakeTimers);
|
|
3331
3327
|
_timers.useFakeTimers();
|
|
3332
3328
|
return utils;
|
|
3333
3329
|
},
|
|
@@ -3415,7 +3411,12 @@ function createVitest() {
|
|
|
3415
3411
|
_mocker.queueUnmock(path, getImporter());
|
|
3416
3412
|
},
|
|
3417
3413
|
doMock(path, factory) {
|
|
3418
|
-
|
|
3414
|
+
const importer = getImporter();
|
|
3415
|
+
_mocker.queueMock(
|
|
3416
|
+
path,
|
|
3417
|
+
importer,
|
|
3418
|
+
factory ? () => factory(() => _mocker.importActual(path, importer)) : void 0
|
|
3419
|
+
);
|
|
3419
3420
|
},
|
|
3420
3421
|
doUnmock(path) {
|
|
3421
3422
|
_mocker.queueUnmock(path, getImporter());
|
|
@@ -3433,15 +3434,15 @@ function createVitest() {
|
|
|
3433
3434
|
return isMockFunction(fn2);
|
|
3434
3435
|
},
|
|
3435
3436
|
clearAllMocks() {
|
|
3436
|
-
|
|
3437
|
+
mocks.forEach((spy) => spy.mockClear());
|
|
3437
3438
|
return utils;
|
|
3438
3439
|
},
|
|
3439
3440
|
resetAllMocks() {
|
|
3440
|
-
|
|
3441
|
+
mocks.forEach((spy) => spy.mockReset());
|
|
3441
3442
|
return utils;
|
|
3442
3443
|
},
|
|
3443
3444
|
restoreAllMocks() {
|
|
3444
|
-
|
|
3445
|
+
mocks.forEach((spy) => spy.mockRestore());
|
|
3445
3446
|
return utils;
|
|
3446
3447
|
},
|
|
3447
3448
|
stubGlobal(name, value) {
|
|
@@ -3482,24 +3483,20 @@ function createVitest() {
|
|
|
3482
3483
|
return utils;
|
|
3483
3484
|
},
|
|
3484
3485
|
resetModules() {
|
|
3485
|
-
|
|
3486
|
-
resetModules(state.moduleCache);
|
|
3486
|
+
resetModules(workerState.moduleCache);
|
|
3487
3487
|
return utils;
|
|
3488
3488
|
},
|
|
3489
3489
|
async dynamicImportSettled() {
|
|
3490
3490
|
return waitForImportsToResolve();
|
|
3491
3491
|
},
|
|
3492
3492
|
setConfig(config) {
|
|
3493
|
-
const state = getWorkerState();
|
|
3494
3493
|
if (!_config)
|
|
3495
|
-
_config = { ...
|
|
3496
|
-
Object.assign(
|
|
3494
|
+
_config = { ...workerState.config };
|
|
3495
|
+
Object.assign(workerState.config, config);
|
|
3497
3496
|
},
|
|
3498
3497
|
resetConfig() {
|
|
3499
|
-
if (_config)
|
|
3500
|
-
|
|
3501
|
-
Object.assign(state.config, _config);
|
|
3502
|
-
}
|
|
3498
|
+
if (_config)
|
|
3499
|
+
Object.assign(workerState.config, _config);
|
|
3503
3500
|
}
|
|
3504
3501
|
};
|
|
3505
3502
|
return utils;
|
package/dist/vm.js
CHANGED
|
@@ -7,11 +7,10 @@ import { c as createBirpc } from './vendor-index.1ca68bd5.js';
|
|
|
7
7
|
import { resolve } from 'pathe';
|
|
8
8
|
import { installSourcemapsSupport } from 'vite-node/source-map';
|
|
9
9
|
import { d as distDir } from './vendor-paths.84fc7a99.js';
|
|
10
|
-
import { l as loadEnvironment } from './vendor-
|
|
11
|
-
import { b as startVitestExecutor } from './vendor-execute.
|
|
10
|
+
import { l as loadEnvironment } from './vendor-loader.9c966f23.js';
|
|
11
|
+
import { b as startVitestExecutor } from './vendor-execute.157302d6.js';
|
|
12
12
|
import { createCustomConsole } from './chunk-runtime-console.f3263f87.js';
|
|
13
|
-
import { c as createSafeRpc } from './vendor-rpc.
|
|
14
|
-
import './vendor-index.0b5b3600.js';
|
|
13
|
+
import { c as createSafeRpc } from './vendor-rpc.171f65fb.js';
|
|
15
14
|
import 'acorn';
|
|
16
15
|
import 'node:module';
|
|
17
16
|
import 'node:fs';
|
|
@@ -20,23 +19,24 @@ import 'node:process';
|
|
|
20
19
|
import 'node:path';
|
|
21
20
|
import 'node:v8';
|
|
22
21
|
import 'node:util';
|
|
22
|
+
import './vendor-environments.dcc4a34e.js';
|
|
23
23
|
import 'node:console';
|
|
24
24
|
import 'local-pkg';
|
|
25
25
|
import 'vite-node/utils';
|
|
26
26
|
import '@vitest/utils/error';
|
|
27
|
-
import './vendor-global.97e4527c.js';
|
|
28
27
|
import '@vitest/utils';
|
|
29
28
|
import './vendor-base.9c08bbd0.js';
|
|
30
29
|
import 'vite-node/constants';
|
|
31
30
|
import 'node:stream';
|
|
32
31
|
import './vendor-date.6e993429.js';
|
|
32
|
+
import './vendor-global.c3664e75.js';
|
|
33
33
|
|
|
34
34
|
const entryFile = pathToFileURL(resolve(distDir, "entry-vm.js")).href;
|
|
35
35
|
async function run(ctx) {
|
|
36
36
|
var _a;
|
|
37
37
|
const moduleCache = new ModuleCacheMap();
|
|
38
38
|
const mockMap = /* @__PURE__ */ new Map();
|
|
39
|
-
const { config, port } = ctx;
|
|
39
|
+
const { config, port, providedContext } = ctx;
|
|
40
40
|
let setCancel = (_reason) => {
|
|
41
41
|
};
|
|
42
42
|
const onCancel = new Promise((resolve2) => {
|
|
@@ -79,7 +79,8 @@ async function run(ctx) {
|
|
|
79
79
|
environment: performance.now(),
|
|
80
80
|
prepare: performance.now()
|
|
81
81
|
},
|
|
82
|
-
rpc
|
|
82
|
+
rpc,
|
|
83
|
+
providedContext
|
|
83
84
|
};
|
|
84
85
|
installSourcemapsSupport({
|
|
85
86
|
getSourceMap: (source) => moduleCache.getSourceMap(source)
|
|
@@ -94,7 +95,12 @@ async function run(ctx) {
|
|
|
94
95
|
const context = vm.getVmContext();
|
|
95
96
|
if (!isContext(context))
|
|
96
97
|
throw new TypeError(`Environment ${ctx.environment.name} doesn't provide a valid context. It should be created by "vm.createContext" method.`);
|
|
97
|
-
context
|
|
98
|
+
Object.defineProperty(context, "__vitest_worker__", {
|
|
99
|
+
value: state,
|
|
100
|
+
configurable: true,
|
|
101
|
+
writable: true,
|
|
102
|
+
enumerable: false
|
|
103
|
+
});
|
|
98
104
|
context.process = process;
|
|
99
105
|
context.global = context;
|
|
100
106
|
context.console = createCustomConsole(state);
|
package/dist/worker.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { performance } from 'node:perf_hooks';
|
|
2
2
|
import { c as createBirpc } from './vendor-index.1ca68bd5.js';
|
|
3
3
|
import { workerId } from 'tinypool';
|
|
4
|
-
import { g as getWorkerState } from './vendor-global.
|
|
5
|
-
import { l as loadEnvironment } from './vendor-
|
|
6
|
-
import { s as startViteNode, m as moduleCache, a as mockMap } from './vendor-execute.
|
|
4
|
+
import { g as getWorkerState } from './vendor-global.c3664e75.js';
|
|
5
|
+
import { l as loadEnvironment } from './vendor-loader.9c966f23.js';
|
|
6
|
+
import { s as startViteNode, m as moduleCache, a as mockMap } from './vendor-execute.157302d6.js';
|
|
7
7
|
import { s as setupInspect } from './vendor-inspector.209edf5a.js';
|
|
8
|
-
import { r as rpcDone, c as createSafeRpc } from './vendor-rpc.
|
|
8
|
+
import { r as rpcDone, c as createSafeRpc } from './vendor-rpc.171f65fb.js';
|
|
9
9
|
import 'pathe';
|
|
10
|
-
import './vendor-index.0b5b3600.js';
|
|
11
10
|
import 'acorn';
|
|
12
11
|
import 'node:module';
|
|
13
12
|
import 'node:fs';
|
|
@@ -18,6 +17,7 @@ import 'node:path';
|
|
|
18
17
|
import 'node:v8';
|
|
19
18
|
import 'node:util';
|
|
20
19
|
import 'vite-node/client';
|
|
20
|
+
import './vendor-environments.dcc4a34e.js';
|
|
21
21
|
import 'node:console';
|
|
22
22
|
import 'local-pkg';
|
|
23
23
|
import 'node:vm';
|
|
@@ -34,7 +34,7 @@ async function init(ctx) {
|
|
|
34
34
|
const isIsolatedThreads = ctx.config.pool === "threads" && (((_b = (_a = ctx.config.poolOptions) == null ? void 0 : _a.threads) == null ? void 0 : _b.isolate) ?? true);
|
|
35
35
|
if (isInitialized && isIsolatedThreads)
|
|
36
36
|
throw new Error(`worker for ${ctx.files.join(",")} already initialized by ${getWorkerState().ctx.files.join(",")}. This is probably an internal bug of Vitest.`);
|
|
37
|
-
const { config, port, workerId: workerId$1 } = ctx;
|
|
37
|
+
const { config, port, workerId: workerId$1, providedContext } = ctx;
|
|
38
38
|
process.env.VITEST_WORKER_ID = String(workerId$1);
|
|
39
39
|
process.env.VITEST_POOL_ID = String(workerId);
|
|
40
40
|
let setCancel = (_reason) => {
|
|
@@ -74,9 +74,15 @@ async function init(ctx) {
|
|
|
74
74
|
environment: 0,
|
|
75
75
|
prepare: performance.now()
|
|
76
76
|
},
|
|
77
|
-
rpc
|
|
77
|
+
rpc,
|
|
78
|
+
providedContext
|
|
78
79
|
};
|
|
79
|
-
globalThis
|
|
80
|
+
Object.defineProperty(globalThis, "__vitest_worker__", {
|
|
81
|
+
value: state,
|
|
82
|
+
configurable: true,
|
|
83
|
+
writable: true,
|
|
84
|
+
enumerable: false
|
|
85
|
+
});
|
|
80
86
|
if (ctx.invalidates) {
|
|
81
87
|
ctx.invalidates.forEach((fsPath) => {
|
|
82
88
|
moduleCache.delete(fsPath);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.4",
|
|
5
5
|
"description": "Next generation testing framework powered by Vite",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -98,18 +98,15 @@
|
|
|
98
98
|
"*.cjs"
|
|
99
99
|
],
|
|
100
100
|
"engines": {
|
|
101
|
-
"node": ">=
|
|
101
|
+
"node": "^18.0.0 || >=20.0.0"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
104
|
"@edge-runtime/vm": "*",
|
|
105
|
-
"@types/node": ">=
|
|
105
|
+
"@types/node": "^18.0.0 || >=20.0.0",
|
|
106
106
|
"@vitest/browser": "*",
|
|
107
107
|
"@vitest/ui": "*",
|
|
108
108
|
"happy-dom": "*",
|
|
109
|
-
"jsdom": "*"
|
|
110
|
-
"playwright": "*",
|
|
111
|
-
"safaridriver": "*",
|
|
112
|
-
"webdriverio": "*"
|
|
109
|
+
"jsdom": "*"
|
|
113
110
|
},
|
|
114
111
|
"peerDependenciesMeta": {
|
|
115
112
|
"@types/node": {
|
|
@@ -127,15 +124,6 @@
|
|
|
127
124
|
"jsdom": {
|
|
128
125
|
"optional": true
|
|
129
126
|
},
|
|
130
|
-
"webdriverio": {
|
|
131
|
-
"optional": true
|
|
132
|
-
},
|
|
133
|
-
"safaridriver": {
|
|
134
|
-
"optional": true
|
|
135
|
-
},
|
|
136
|
-
"playwright": {
|
|
137
|
-
"optional": true
|
|
138
|
-
},
|
|
139
127
|
"@edge-runtime/vm": {
|
|
140
128
|
"optional": true
|
|
141
129
|
}
|
|
@@ -147,7 +135,7 @@
|
|
|
147
135
|
"chai": "^4.3.10",
|
|
148
136
|
"debug": "^4.3.4",
|
|
149
137
|
"local-pkg": "^0.4.3",
|
|
150
|
-
"magic-string": "^0.30.
|
|
138
|
+
"magic-string": "^0.30.5",
|
|
151
139
|
"pathe": "^1.1.1",
|
|
152
140
|
"picocolors": "^1.0.0",
|
|
153
141
|
"std-env": "^3.3.3",
|
|
@@ -156,12 +144,12 @@
|
|
|
156
144
|
"tinypool": "^0.8.1",
|
|
157
145
|
"vite": "^3.1.0 || ^4.0.0 || ^5.0.0-0",
|
|
158
146
|
"why-is-node-running": "^2.2.2",
|
|
159
|
-
"@vitest/
|
|
160
|
-
"@vitest/
|
|
161
|
-
"
|
|
162
|
-
"@vitest/
|
|
163
|
-
"@vitest/
|
|
164
|
-
"
|
|
147
|
+
"@vitest/spy": "1.0.0-beta.4",
|
|
148
|
+
"@vitest/expect": "1.0.0-beta.4",
|
|
149
|
+
"@vitest/runner": "1.0.0-beta.4",
|
|
150
|
+
"@vitest/snapshot": "1.0.0-beta.4",
|
|
151
|
+
"@vitest/utils": "1.0.0-beta.4",
|
|
152
|
+
"vite-node": "1.0.0-beta.4"
|
|
165
153
|
},
|
|
166
154
|
"devDependencies": {
|
|
167
155
|
"@ampproject/remapping": "^2.2.1",
|
|
@@ -179,7 +167,6 @@
|
|
|
179
167
|
"birpc": "0.2.14",
|
|
180
168
|
"chai-subset": "^1.6.0",
|
|
181
169
|
"cli-truncate": "^3.1.0",
|
|
182
|
-
"event-target-polyfill": "^0.0.3",
|
|
183
170
|
"execa": "^7.1.1",
|
|
184
171
|
"expect-type": "^0.16.0",
|
|
185
172
|
"fast-glob": "^3.3.0",
|
|
@@ -188,17 +175,14 @@
|
|
|
188
175
|
"get-tsconfig": "^4.6.2",
|
|
189
176
|
"happy-dom": "^9.20.3",
|
|
190
177
|
"jsdom": "^22.1.0",
|
|
191
|
-
"log-update": "^
|
|
178
|
+
"log-update": "^6.0.0",
|
|
192
179
|
"micromatch": "^4.0.5",
|
|
193
180
|
"mlly": "^1.4.0",
|
|
194
181
|
"p-limit": "^4.0.0",
|
|
195
182
|
"pkg-types": "^1.0.3",
|
|
196
|
-
"playwright": "^1.35.1",
|
|
197
183
|
"pretty-format": "^29.5.0",
|
|
198
184
|
"prompts": "^2.4.2",
|
|
199
|
-
"safaridriver": "^0.0.5",
|
|
200
185
|
"strip-ansi": "^7.1.0",
|
|
201
|
-
"webdriverio": "^8.11.2",
|
|
202
186
|
"ws": "^8.13.0"
|
|
203
187
|
},
|
|
204
188
|
"scripts": {
|