vitest 0.28.4 → 0.28.5
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/dist/browser.d.ts +1 -1
- package/dist/browser.js +2 -2
- package/dist/{chunk-api-setup.ec61b167.js → chunk-api-setup.d88afda6.js} +3 -3
- package/dist/{chunk-install-pkg.13d8e7be.js → chunk-install-pkg.e1e08354.js} +2 -2
- package/dist/{chunk-integrations-globals.aacbac4d.js → chunk-integrations-globals.59432f4f.js} +4 -4
- package/dist/{chunk-integrations-utils.dae69d89.js → chunk-integrations-utils.9717ad89.js} +1 -1
- package/dist/{chunk-node-pkg.94145502.js → chunk-node-pkg.9a107dfb.js} +25 -29
- package/dist/{chunk-runtime-mocker.eb0c265c.js → chunk-runtime-mocker.dafe0f77.js} +22 -36
- package/dist/{chunk-runtime-setup.7dfc1a6a.js → chunk-runtime-setup.30ab0a4b.js} +1 -1
- package/dist/{chunk-snapshot-env.6457638e.js → chunk-snapshot-env.a347d647.js} +2 -2
- package/dist/{chunk-utils-import.0402c9db.js → chunk-utils-import.847b4a2d.js} +15 -26
- package/dist/{chunk-utils-tasks.a9a8d8e1.js → chunk-utils-tasks.d07dcea9.js} +13 -9
- package/dist/cli.js +2 -2
- package/dist/config.d.ts +1 -1
- package/dist/entry.js +29 -19
- package/dist/environments.d.ts +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +5 -5
- package/dist/node.d.ts +6 -9
- package/dist/node.js +4 -3
- package/dist/runners.d.ts +3 -1
- package/dist/runners.js +219 -11
- package/dist/{types-aac763a5.d.ts → types-0373403c.d.ts} +2 -2
- package/dist/worker.js +9 -10
- package/package.json +6 -6
- package/dist/runners-chunk.js +0 -215
package/dist/browser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { startTests } from '@vitest/runner';
|
|
2
|
-
import { a as ResolvedConfig } from './types-
|
|
2
|
+
import { a as ResolvedConfig } from './types-0373403c.js';
|
|
3
3
|
export { s as setupSnapshotEnvironment } from './env-afee91f0.js';
|
|
4
4
|
import '@vitest/expect';
|
|
5
5
|
import 'vite';
|
package/dist/browser.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { startTests } from '@vitest/runner';
|
|
2
|
-
export { s as setupCommonEnv } from './chunk-runtime-setup.
|
|
3
|
-
export { s as setupSnapshotEnvironment } from './chunk-snapshot-env.
|
|
2
|
+
export { s as setupCommonEnv } from './chunk-runtime-setup.30ab0a4b.js';
|
|
3
|
+
export { s as setupSnapshotEnvironment } from './chunk-snapshot-env.a347d647.js';
|
|
4
4
|
import '@vitest/utils';
|
|
5
5
|
import './chunk-integrations-run-once.38756e30.js';
|
|
6
6
|
import './chunk-utils-global.442d1d33.js';
|
|
@@ -12,7 +12,7 @@ import require$$2$1 from 'http';
|
|
|
12
12
|
import require$$7 from 'url';
|
|
13
13
|
import { A as API_PATH } from './chunk-constants.797d3ebf.js';
|
|
14
14
|
import './chunk-utils-global.442d1d33.js';
|
|
15
|
-
import { a as
|
|
15
|
+
import { a as parseErrorStacktrace } from './chunk-utils-tasks.d07dcea9.js';
|
|
16
16
|
import 'node:url';
|
|
17
17
|
import 'pathe';
|
|
18
18
|
import './chunk-utils-env.860d90c2.js';
|
|
@@ -4601,9 +4601,9 @@ class WebSocketReporter {
|
|
|
4601
4601
|
packs.forEach(([, result]) => {
|
|
4602
4602
|
var _a;
|
|
4603
4603
|
if (result == null ? void 0 : result.error)
|
|
4604
|
-
result.error.stacks =
|
|
4604
|
+
result.error.stacks = parseErrorStacktrace(result.error);
|
|
4605
4605
|
(_a = result == null ? void 0 : result.errors) == null ? void 0 : _a.forEach((error) => {
|
|
4606
|
-
error.stacks =
|
|
4606
|
+
error.stacks = parseErrorStacktrace(error);
|
|
4607
4607
|
});
|
|
4608
4608
|
});
|
|
4609
4609
|
this.clients.forEach((client) => {
|
|
@@ -3,7 +3,7 @@ import k from 'path';
|
|
|
3
3
|
import require$$0$1 from 'util';
|
|
4
4
|
import require$$0$3 from 'child_process';
|
|
5
5
|
import { p as pathKey, s as signalExit, m as mergeStream$1, g as getStream$1, c as crossSpawn$1 } from './vendor-index.618ca5a1.js';
|
|
6
|
-
import { o as onetime$1 } from './chunk-node-pkg.
|
|
6
|
+
import { o as onetime$1 } from './chunk-node-pkg.9a107dfb.js';
|
|
7
7
|
import require$$0$2 from 'os';
|
|
8
8
|
import 'node:buffer';
|
|
9
9
|
import 'node:path';
|
|
@@ -42,7 +42,7 @@ import 'tinypool';
|
|
|
42
42
|
import './vendor-index.783e7f3e.js';
|
|
43
43
|
import 'perf_hooks';
|
|
44
44
|
import './chunk-utils-base.904102a8.js';
|
|
45
|
-
import './chunk-utils-tasks.
|
|
45
|
+
import './chunk-utils-tasks.d07dcea9.js';
|
|
46
46
|
import 'crypto';
|
|
47
47
|
import 'vite-node/utils';
|
|
48
48
|
import '@vitest/utils/diff';
|
package/dist/{chunk-integrations-globals.aacbac4d.js → chunk-integrations-globals.59432f4f.js}
RENAMED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { g as globalApis } from './chunk-constants.797d3ebf.js';
|
|
2
|
-
import { i as index } from './chunk-integrations-utils.
|
|
2
|
+
import { i as index } from './chunk-integrations-utils.9717ad89.js';
|
|
3
3
|
import 'node:url';
|
|
4
4
|
import 'pathe';
|
|
5
5
|
import './chunk-utils-env.860d90c2.js';
|
|
6
6
|
import 'std-env';
|
|
7
7
|
import '@vitest/runner';
|
|
8
|
-
import './chunk-utils-import.
|
|
8
|
+
import './chunk-utils-import.847b4a2d.js';
|
|
9
9
|
import '@vitest/runner/utils';
|
|
10
10
|
import '@vitest/utils';
|
|
11
11
|
import './chunk-utils-global.442d1d33.js';
|
|
@@ -13,9 +13,9 @@ import 'chai';
|
|
|
13
13
|
import './vendor-_commonjsHelpers.addc3445.js';
|
|
14
14
|
import '@vitest/expect';
|
|
15
15
|
import './chunk-runtime-rpc.9c0386cc.js';
|
|
16
|
-
import './chunk-snapshot-env.
|
|
16
|
+
import './chunk-snapshot-env.a347d647.js';
|
|
17
17
|
import './chunk-utils-base.904102a8.js';
|
|
18
|
-
import './chunk-utils-tasks.
|
|
18
|
+
import './chunk-utils-tasks.d07dcea9.js';
|
|
19
19
|
import 'util';
|
|
20
20
|
import '@vitest/spy';
|
|
21
21
|
import './chunk-integrations-run-once.38756e30.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { suite, test, describe, it, beforeAll, beforeEach, afterAll, afterEach, onTestFailed } from '@vitest/runner';
|
|
2
|
-
import { b as bench, c as createExpect, g as globalExpect, v as vitest, a as vi } from './chunk-utils-import.
|
|
2
|
+
import { b as bench, c as createExpect, g as globalExpect, v as vitest, a as vi } from './chunk-utils-import.847b4a2d.js';
|
|
3
3
|
import { r as runOnce, i as isFirstRun } from './chunk-integrations-run-once.38756e30.js';
|
|
4
4
|
import * as chai from 'chai';
|
|
5
5
|
import { assert, should } from 'chai';
|
|
@@ -6,7 +6,7 @@ import c from 'picocolors';
|
|
|
6
6
|
import { isPackageExists, resolveModule } from 'local-pkg';
|
|
7
7
|
import { i as isNode } from './chunk-utils-env.860d90c2.js';
|
|
8
8
|
import { isCI } from 'std-env';
|
|
9
|
-
import { loadConfigFromFile,
|
|
9
|
+
import { loadConfigFromFile, createServer, mergeConfig } from 'vite';
|
|
10
10
|
import path$8 from 'node:path';
|
|
11
11
|
import url, { fileURLToPath } from 'node:url';
|
|
12
12
|
import process$1 from 'node:process';
|
|
@@ -33,7 +33,7 @@ import { Tinypool } from 'tinypool';
|
|
|
33
33
|
import { c as createBirpc } from './vendor-index.783e7f3e.js';
|
|
34
34
|
import { performance } from 'perf_hooks';
|
|
35
35
|
import { s as slash$1, n as notNullish, t as toArray, a as noop$1, d as deepMerge, b as stdout } from './chunk-utils-base.904102a8.js';
|
|
36
|
-
import { g as getFullName, h as hasFailedSnapshot, a as
|
|
36
|
+
import { g as getFullName, h as hasFailedSnapshot, a as parseErrorStacktrace, p as positionToOffset, l as lineSplitRE } from './chunk-utils-tasks.d07dcea9.js';
|
|
37
37
|
import { getSafeTimers, shuffle, stringify } from '@vitest/utils';
|
|
38
38
|
import { createHash } from 'crypto';
|
|
39
39
|
import { slash as slash$2, cleanUrl } from 'vite-node/utils';
|
|
@@ -58,7 +58,7 @@ function _mergeNamespaces(n, m) {
|
|
|
58
58
|
return Object.freeze(n);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
var version$1 = "0.28.
|
|
61
|
+
var version$1 = "0.28.5";
|
|
62
62
|
|
|
63
63
|
async function ensurePackageInstalled(dependency, root) {
|
|
64
64
|
if (isPackageExists(dependency, { paths: [root] }))
|
|
@@ -76,7 +76,7 @@ async function ensurePackageInstalled(dependency, root) {
|
|
|
76
76
|
message: c.reset(`Do you want to install ${c.green(dependency)}?`)
|
|
77
77
|
});
|
|
78
78
|
if (install) {
|
|
79
|
-
await (await import('./chunk-install-pkg.
|
|
79
|
+
await (await import('./chunk-install-pkg.e1e08354.js')).installPackage(dependency, { dev: true });
|
|
80
80
|
process.stderr.write(c.yellow(`
|
|
81
81
|
Package ${dependency} installed, re-run the command to start.
|
|
82
82
|
`));
|
|
@@ -4133,15 +4133,15 @@ ${log.content}
|
|
|
4133
4133
|
}
|
|
4134
4134
|
async reportBenchmarkSummary(files) {
|
|
4135
4135
|
const logger = this.ctx.logger;
|
|
4136
|
-
const
|
|
4137
|
-
const
|
|
4136
|
+
const benches = getTests(files);
|
|
4137
|
+
const topBenches = benches.filter((i) => {
|
|
4138
4138
|
var _a2, _b;
|
|
4139
4139
|
return ((_b = (_a2 = i.result) == null ? void 0 : _a2.benchmark) == null ? void 0 : _b.rank) === 1;
|
|
4140
4140
|
});
|
|
4141
4141
|
logger.log(`
|
|
4142
4142
|
${c.cyan(c.inverse(c.bold(" BENCH ")))} ${c.cyan("Summary")}
|
|
4143
4143
|
`);
|
|
4144
|
-
for (const bench of
|
|
4144
|
+
for (const bench of topBenches) {
|
|
4145
4145
|
const group = bench.suite;
|
|
4146
4146
|
if (!group)
|
|
4147
4147
|
continue;
|
|
@@ -5082,11 +5082,11 @@ function renderBenchmark$1(task, tasks) {
|
|
|
5082
5082
|
const result = (_a = task.result) == null ? void 0 : _a.benchmark;
|
|
5083
5083
|
if (!result)
|
|
5084
5084
|
return task.name;
|
|
5085
|
-
const
|
|
5085
|
+
const benches = tasks.map((i) => {
|
|
5086
5086
|
var _a2, _b;
|
|
5087
5087
|
return ((_a2 = i.meta) == null ? void 0 : _a2.benchmark) ? (_b = i.result) == null ? void 0 : _b.benchmark : void 0;
|
|
5088
5088
|
}).filter(notNullish);
|
|
5089
|
-
const allItems =
|
|
5089
|
+
const allItems = benches.map(renderBenchmarkItems$1);
|
|
5090
5090
|
const items = renderBenchmarkItems$1(result);
|
|
5091
5091
|
const padded = items.map((i, idx) => {
|
|
5092
5092
|
const width = Math.max(...allItems.map((i2) => i2[idx].length));
|
|
@@ -5099,7 +5099,7 @@ function renderBenchmark$1(task, tasks) {
|
|
|
5099
5099
|
c.dim(" ops/sec "),
|
|
5100
5100
|
c.cyan(padded[3]),
|
|
5101
5101
|
c.dim(` (${padded[4]} samples)`),
|
|
5102
|
-
result.rank === 1 ? c.bold(c.green(" fastest")) : result.rank ===
|
|
5102
|
+
result.rank === 1 ? c.bold(c.green(" fastest")) : result.rank === benches.length && benches.length > 2 ? c.bold(c.gray(" slowest")) : ""
|
|
5103
5103
|
].join("");
|
|
5104
5104
|
}
|
|
5105
5105
|
function renderTree$1(tasks, options, level = 0) {
|
|
@@ -5468,7 +5468,7 @@ class JsonReporter$1 {
|
|
|
5468
5468
|
const error = (_b = (_a = test.result) == null ? void 0 : _a.errors) == null ? void 0 : _b[0];
|
|
5469
5469
|
if (!error)
|
|
5470
5470
|
return;
|
|
5471
|
-
const stack =
|
|
5471
|
+
const stack = parseErrorStacktrace(error);
|
|
5472
5472
|
const frame = stack[stack.length - 1];
|
|
5473
5473
|
if (!frame)
|
|
5474
5474
|
return;
|
|
@@ -5565,7 +5565,7 @@ class TapReporter {
|
|
|
5565
5565
|
if (((_b = task.result) == null ? void 0 : _b.state) === "fail" && task.result.errors) {
|
|
5566
5566
|
this.logger.indent();
|
|
5567
5567
|
task.result.errors.forEach((error) => {
|
|
5568
|
-
const stacks =
|
|
5568
|
+
const stacks = parseErrorStacktrace(error);
|
|
5569
5569
|
const stack = stacks[0];
|
|
5570
5570
|
this.logger.log("---");
|
|
5571
5571
|
this.logger.log("error:");
|
|
@@ -5667,7 +5667,7 @@ class JUnitReporter {
|
|
|
5667
5667
|
const errorName = error.name ?? error.nameStr ?? "Unknown Error";
|
|
5668
5668
|
const errorDetails = `${errorName}: ${error.message}`;
|
|
5669
5669
|
await this.baseLog(escapeXML(errorDetails));
|
|
5670
|
-
const stack =
|
|
5670
|
+
const stack = parseErrorStacktrace(error);
|
|
5671
5671
|
for (const frame of stack) {
|
|
5672
5672
|
const path = relative(this.ctx.config.root, frame.file);
|
|
5673
5673
|
await this.baseLog(` ${F_POINTER} ${[frame.method, `${path}:${frame.line}:${frame.column}`].filter(Boolean).join(" ")}`);
|
|
@@ -5879,11 +5879,11 @@ function formatNumber(number) {
|
|
|
5879
5879
|
}
|
|
5880
5880
|
const tableHead = ["name", "hz", "min", "max", "mean", "p75", "p99", "p995", "p999", "rme", "samples"];
|
|
5881
5881
|
function renderTableHead(tasks) {
|
|
5882
|
-
const
|
|
5882
|
+
const benches = tasks.map((i) => {
|
|
5883
5883
|
var _a, _b;
|
|
5884
5884
|
return ((_a = i.meta) == null ? void 0 : _a.benchmark) ? (_b = i.result) == null ? void 0 : _b.benchmark : void 0;
|
|
5885
5885
|
}).filter(notNullish);
|
|
5886
|
-
const allItems =
|
|
5886
|
+
const allItems = benches.map(renderBenchmarkItems).concat([tableHead]);
|
|
5887
5887
|
return `${" ".repeat(3)}${tableHead.map((i, idx) => {
|
|
5888
5888
|
const width = Math.max(...allItems.map((i2) => i2[idx].length));
|
|
5889
5889
|
return idx ? i.padStart(width, " ") : i.padEnd(width, " ");
|
|
@@ -5909,11 +5909,11 @@ function renderBenchmark(task, tasks) {
|
|
|
5909
5909
|
const result = (_a = task.result) == null ? void 0 : _a.benchmark;
|
|
5910
5910
|
if (!result)
|
|
5911
5911
|
return task.name;
|
|
5912
|
-
const
|
|
5912
|
+
const benches = tasks.map((i) => {
|
|
5913
5913
|
var _a2, _b;
|
|
5914
5914
|
return ((_a2 = i.meta) == null ? void 0 : _a2.benchmark) ? (_b = i.result) == null ? void 0 : _b.benchmark : void 0;
|
|
5915
5915
|
}).filter(notNullish);
|
|
5916
|
-
const allItems =
|
|
5916
|
+
const allItems = benches.map(renderBenchmarkItems).concat([tableHead]);
|
|
5917
5917
|
const items = renderBenchmarkItems(result);
|
|
5918
5918
|
const padded = items.map((i, idx) => {
|
|
5919
5919
|
const width = Math.max(...allItems.map((i2) => i2[idx].length));
|
|
@@ -5931,7 +5931,7 @@ function renderBenchmark(task, tasks) {
|
|
|
5931
5931
|
c.cyan(padded[8]),
|
|
5932
5932
|
c.dim(padded[9]),
|
|
5933
5933
|
c.dim(padded[10]),
|
|
5934
|
-
result.rank === 1 ? c.bold(c.green(" fastest")) : result.rank ===
|
|
5934
|
+
result.rank === 1 ? c.bold(c.green(" fastest")) : result.rank === benches.length && benches.length > 2 ? c.bold(c.gray(" slowest")) : ""
|
|
5935
5935
|
].join(" ");
|
|
5936
5936
|
}
|
|
5937
5937
|
function renderTree(tasks, options, level = 0) {
|
|
@@ -6467,9 +6467,6 @@ const extraInlineDeps = [
|
|
|
6467
6467
|
/^(?!.*(?:node_modules)).*\.mjs$/,
|
|
6468
6468
|
/^(?!.*(?:node_modules)).*\.cjs\.js$/,
|
|
6469
6469
|
/vite\w*\/dist\/client\/env.mjs/,
|
|
6470
|
-
/\/vitest\/dist\/(runners-chunk|entry)\.js/,
|
|
6471
|
-
/vitest-virtual-\w+\/dist\/(runners-chunk|entry)\.js/,
|
|
6472
|
-
/@vitest\/dist\/(runners-chunk|entry)\.js/,
|
|
6473
6470
|
"@nuxt/test-utils"
|
|
6474
6471
|
];
|
|
6475
6472
|
function resolveApiConfig(options) {
|
|
@@ -7169,7 +7166,7 @@ createLogUpdate(process$1.stdout);
|
|
|
7169
7166
|
|
|
7170
7167
|
createLogUpdate(process$1.stderr);
|
|
7171
7168
|
|
|
7172
|
-
var version = "0.28.
|
|
7169
|
+
var version = "0.28.5";
|
|
7173
7170
|
|
|
7174
7171
|
async function printError(error, ctx, options = {}) {
|
|
7175
7172
|
const { showCodeFrame = true, fullStack = false, type } = options;
|
|
@@ -7187,7 +7184,7 @@ async function printError(error, ctx, options = {}) {
|
|
|
7187
7184
|
stack: error2.stack
|
|
7188
7185
|
};
|
|
7189
7186
|
}
|
|
7190
|
-
const stacks =
|
|
7187
|
+
const stacks = parseErrorStacktrace(e, fullStack);
|
|
7191
7188
|
const nearest = error instanceof TypeCheckError ? error.stacks[0] : stacks.find(
|
|
7192
7189
|
(stack) => ctx.server.moduleGraph.getModuleById(stack.file) && existsSync$1(stack.file)
|
|
7193
7190
|
);
|
|
@@ -7303,8 +7300,6 @@ function printErrorMessage(error, logger) {
|
|
|
7303
7300
|
logger.error(c.red(`${c.bold(errorName)}: ${error.message}`));
|
|
7304
7301
|
}
|
|
7305
7302
|
function printStack(ctx, stack, highlight, errorProperties, onStack) {
|
|
7306
|
-
if (!stack.length)
|
|
7307
|
-
return;
|
|
7308
7303
|
const logger = ctx.logger;
|
|
7309
7304
|
for (const frame of stack) {
|
|
7310
7305
|
const color = frame === highlight ? c.yellow : c.gray;
|
|
@@ -7312,7 +7307,8 @@ function printStack(ctx, stack, highlight, errorProperties, onStack) {
|
|
|
7312
7307
|
logger.error(color(` ${c.dim(F_POINTER)} ${[frame.method, c.dim(`${path}:${frame.line}:${frame.column}`)].filter(Boolean).join(" ")}`));
|
|
7313
7308
|
onStack == null ? void 0 : onStack(frame);
|
|
7314
7309
|
}
|
|
7315
|
-
|
|
7310
|
+
if (stack.length)
|
|
7311
|
+
logger.error();
|
|
7316
7312
|
const hasProperties = Object.keys(errorProperties).length > 0;
|
|
7317
7313
|
if (hasProperties) {
|
|
7318
7314
|
logger.error(c.red(c.dim(divider())));
|
|
@@ -7527,7 +7523,7 @@ class Vitest {
|
|
|
7527
7523
|
return await serverRestart(...args);
|
|
7528
7524
|
};
|
|
7529
7525
|
server.watcher.on("change", async (file) => {
|
|
7530
|
-
file =
|
|
7526
|
+
file = normalize(file);
|
|
7531
7527
|
const isConfig = file === server.config.configFile;
|
|
7532
7528
|
if (isConfig) {
|
|
7533
7529
|
await Promise.all(this._onRestartListeners.map((fn) => fn("config")));
|
|
@@ -8134,7 +8130,7 @@ const MocksPlugin = () => {
|
|
|
8134
8130
|
found = true;
|
|
8135
8131
|
}
|
|
8136
8132
|
if (!found) {
|
|
8137
|
-
m.prepend(`
|
|
8133
|
+
m.prepend(`if (typeof globalThis.vi === "undefined" && typeof globalThis.vitest === "undefined") { throw new Error(${JSON.stringify(API_NOT_FOUND_ERROR)}) }
|
|
8138
8134
|
`);
|
|
8139
8135
|
}
|
|
8140
8136
|
return {
|
|
@@ -8403,7 +8399,7 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
|
|
|
8403
8399
|
try {
|
|
8404
8400
|
await ctx.setServer(options, server);
|
|
8405
8401
|
if (options.api && options.watch)
|
|
8406
|
-
(await import('./chunk-api-setup.
|
|
8402
|
+
(await import('./chunk-api-setup.d88afda6.js')).setup(ctx);
|
|
8407
8403
|
} catch (err) {
|
|
8408
8404
|
ctx.logger.printError(err, true);
|
|
8409
8405
|
process.exit(1);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ViteNodeRunner } from 'vite-node/client';
|
|
2
2
|
import { isInternalRequest } from 'vite-node/utils';
|
|
3
|
-
import {
|
|
3
|
+
import { isAbsolute, dirname, join, basename, extname, resolve, normalize } from 'pathe';
|
|
4
4
|
import { i as isNodeBuiltin } from './vendor-index.bdee400f.js';
|
|
5
5
|
import { g as getWorkerState, b as getCurrentEnvironment } from './chunk-utils-global.442d1d33.js';
|
|
6
6
|
import { existsSync, readdirSync } from 'node:fs';
|
|
7
7
|
import { getColors, getType } from '@vitest/utils';
|
|
8
8
|
import { g as getAllMockableProperties } from './chunk-utils-base.904102a8.js';
|
|
9
|
-
import {
|
|
9
|
+
import { spyOn } from '@vitest/spy';
|
|
10
10
|
|
|
11
11
|
class RefTracker {
|
|
12
12
|
constructor() {
|
|
@@ -30,21 +30,21 @@ function isSpecialProp(prop, parentType) {
|
|
|
30
30
|
return parentType.includes("Function") && typeof prop === "string" && ["arguments", "callee", "caller", "length", "name"].includes(prop);
|
|
31
31
|
}
|
|
32
32
|
const _VitestMocker = class {
|
|
33
|
-
constructor(
|
|
34
|
-
this.
|
|
33
|
+
constructor(executor) {
|
|
34
|
+
this.executor = executor;
|
|
35
35
|
this.resolveCache = /* @__PURE__ */ new Map();
|
|
36
36
|
}
|
|
37
37
|
get root() {
|
|
38
|
-
return this.
|
|
38
|
+
return this.executor.options.root;
|
|
39
39
|
}
|
|
40
40
|
get base() {
|
|
41
|
-
return this.
|
|
41
|
+
return this.executor.options.base;
|
|
42
42
|
}
|
|
43
43
|
get mockMap() {
|
|
44
|
-
return this.
|
|
44
|
+
return this.executor.options.mockMap;
|
|
45
45
|
}
|
|
46
46
|
get moduleCache() {
|
|
47
|
-
return this.
|
|
47
|
+
return this.executor.moduleCache;
|
|
48
48
|
}
|
|
49
49
|
getSuiteFilepath() {
|
|
50
50
|
return getWorkerState().filepath || "global";
|
|
@@ -59,7 +59,7 @@ const _VitestMocker = class {
|
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
async resolvePath(rawId, importer) {
|
|
62
|
-
const [id, fsPath] = await this.
|
|
62
|
+
const [id, fsPath] = await this.executor.resolveUrl(rawId, importer);
|
|
63
63
|
const external = !isAbsolute(fsPath) || fsPath.includes("/node_modules/") ? rawId : null;
|
|
64
64
|
return {
|
|
65
65
|
id,
|
|
@@ -87,7 +87,7 @@ const _VitestMocker = class {
|
|
|
87
87
|
exports = await mock();
|
|
88
88
|
} catch (err) {
|
|
89
89
|
const vitestError = new Error(
|
|
90
|
-
'[vitest] There was an error
|
|
90
|
+
'[vitest] There was an error when mocking a module. If you are using "vi.mock" factory, make sure there are no top level variables inside, since this call is hoisted to top of the file. Read more: https://vitest.dev/api/#vi-mock'
|
|
91
91
|
);
|
|
92
92
|
vitestError.cause = err;
|
|
93
93
|
throw vitestError;
|
|
@@ -103,6 +103,8 @@ const _VitestMocker = class {
|
|
|
103
103
|
if (target instanceof Promise)
|
|
104
104
|
return target.then.bind(target);
|
|
105
105
|
} else if (!(prop in target)) {
|
|
106
|
+
if (prop === "__esModule")
|
|
107
|
+
return void 0;
|
|
106
108
|
const c = getColors();
|
|
107
109
|
throw new Error(
|
|
108
110
|
`[vitest] No "${String(prop)}" export is defined on the "${mockpath}" mock. Did you forget to return it from "vi.mock"?
|
|
@@ -155,12 +157,6 @@ ${c.green(`vi.mock("${mockpath}", async () => {
|
|
|
155
157
|
return existsSync(fullPath) ? fullPath : null;
|
|
156
158
|
}
|
|
157
159
|
mockObject(object, mockExports = {}) {
|
|
158
|
-
if (!_VitestMocker.spyModule) {
|
|
159
|
-
throw new Error(
|
|
160
|
-
"Error: Spy module is not defined. This is likely an internal bug in Vitest. Please report it to https://github.com/vitest-dev/vitest/issues"
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
const spyModule = _VitestMocker.spyModule;
|
|
164
160
|
const finalizers = new Array();
|
|
165
161
|
const refs = new RefTracker();
|
|
166
162
|
const define = (container, key, value) => {
|
|
@@ -203,7 +199,7 @@ ${c.green(`vi.mock("${mockpath}", async () => {
|
|
|
203
199
|
if (!define(newContainer, property, isFunction ? value : {}))
|
|
204
200
|
continue;
|
|
205
201
|
if (isFunction) {
|
|
206
|
-
|
|
202
|
+
spyOn(newContainer, property).mockImplementation(() => void 0);
|
|
207
203
|
Object.defineProperty(newContainer[property], "length", { value: 0 });
|
|
208
204
|
}
|
|
209
205
|
refs.track(value, newContainer[property]);
|
|
@@ -238,7 +234,7 @@ ${c.green(`vi.mock("${mockpath}", async () => {
|
|
|
238
234
|
}
|
|
239
235
|
async importActual(rawId, importee) {
|
|
240
236
|
const { id, fsPath } = await this.resolvePath(rawId, importee);
|
|
241
|
-
const result = await this.
|
|
237
|
+
const result = await this.executor.cachedRequest(id, fsPath, [importee]);
|
|
242
238
|
return result;
|
|
243
239
|
}
|
|
244
240
|
async importMock(rawId, importee) {
|
|
@@ -248,17 +244,12 @@ ${c.green(`vi.mock("${mockpath}", async () => {
|
|
|
248
244
|
if (mock === void 0)
|
|
249
245
|
mock = this.resolveMockPath(fsPath, external);
|
|
250
246
|
if (mock === null) {
|
|
251
|
-
const mod = await this.
|
|
247
|
+
const mod = await this.executor.cachedRequest(id, fsPath, [importee]);
|
|
252
248
|
return this.mockObject(mod);
|
|
253
249
|
}
|
|
254
250
|
if (typeof mock === "function")
|
|
255
251
|
return this.callFunctionMock(fsPath, mock);
|
|
256
|
-
return this.
|
|
257
|
-
}
|
|
258
|
-
async initializeSpyModule() {
|
|
259
|
-
if (_VitestMocker.spyModule)
|
|
260
|
-
return;
|
|
261
|
-
_VitestMocker.spyModule = await this.runner.executeId(_VitestMocker.spyModulePath);
|
|
252
|
+
return this.executor.dependencyRequest(mock, mock, [importee]);
|
|
262
253
|
}
|
|
263
254
|
async requestWithMock(url, callstack) {
|
|
264
255
|
if (_VitestMocker.pendingIds.length)
|
|
@@ -272,7 +263,7 @@ ${c.green(`vi.mock("${mockpath}", async () => {
|
|
|
272
263
|
return cache.exports;
|
|
273
264
|
const exports = {};
|
|
274
265
|
this.moduleCache.set(mockPath, { exports });
|
|
275
|
-
const mod = await this.
|
|
266
|
+
const mod = await this.executor.directRequest(url, url, callstack);
|
|
276
267
|
this.mockObject(mod, exports);
|
|
277
268
|
return exports;
|
|
278
269
|
}
|
|
@@ -295,18 +286,13 @@ ${c.green(`vi.mock("${mockpath}", async () => {
|
|
|
295
286
|
};
|
|
296
287
|
let VitestMocker = _VitestMocker;
|
|
297
288
|
VitestMocker.pendingIds = [];
|
|
298
|
-
VitestMocker.spyModulePath = resolve(distDir, "spy.js");
|
|
299
289
|
|
|
300
|
-
async function
|
|
301
|
-
const runner = new
|
|
290
|
+
async function createVitestExecutor(options) {
|
|
291
|
+
const runner = new VitestExecutor(options);
|
|
302
292
|
await runner.executeId("/@vite/env");
|
|
303
|
-
|
|
304
|
-
const result = [];
|
|
305
|
-
for (const file of options.files)
|
|
306
|
-
result.push(await runner.executeFile(file));
|
|
307
|
-
return result;
|
|
293
|
+
return runner;
|
|
308
294
|
}
|
|
309
|
-
class
|
|
295
|
+
class VitestExecutor extends ViteNodeRunner {
|
|
310
296
|
constructor(options) {
|
|
311
297
|
super(options);
|
|
312
298
|
this.options = options;
|
|
@@ -345,4 +331,4 @@ class VitestRunner extends ViteNodeRunner {
|
|
|
345
331
|
}
|
|
346
332
|
}
|
|
347
333
|
|
|
348
|
-
export {
|
|
334
|
+
export { VitestExecutor as V, createVitestExecutor as c };
|
|
@@ -10,7 +10,7 @@ async function setupCommonEnv(config) {
|
|
|
10
10
|
globalSetup = true;
|
|
11
11
|
setSafeTimers();
|
|
12
12
|
if (config.globals)
|
|
13
|
-
(await import('./chunk-integrations-globals.
|
|
13
|
+
(await import('./chunk-integrations-globals.59432f4f.js')).registerApiGlobally();
|
|
14
14
|
}
|
|
15
15
|
function setupDefines(defines) {
|
|
16
16
|
for (const key in defines)
|
|
@@ -2,10 +2,10 @@ let _snapshotEnvironment;
|
|
|
2
2
|
function setupSnapshotEnvironment(environment) {
|
|
3
3
|
_snapshotEnvironment = environment;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
5
|
+
function getSnapshotEnvironment() {
|
|
6
6
|
if (!_snapshotEnvironment)
|
|
7
7
|
throw new Error("Snapshot environment is not setup");
|
|
8
8
|
return _snapshotEnvironment;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export {
|
|
11
|
+
export { getSnapshotEnvironment as g, setupSnapshotEnvironment as s };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getCurrentSuite } from '@vitest/runner';
|
|
2
2
|
import { createChainable, getNames } from '@vitest/runner/utils';
|
|
3
|
-
import { getSafeTimers, noop } from '@vitest/utils';
|
|
3
|
+
import { getSafeTimers, noop, createSimpleStackTrace } from '@vitest/utils';
|
|
4
4
|
import { g as getWorkerState, i as isRunningInBenchmark, a as getCallLastIndex, b as getCurrentEnvironment, r as resetModules } from './chunk-utils-global.442d1d33.js';
|
|
5
5
|
import * as chai$1 from 'chai';
|
|
6
6
|
import { expect } from 'chai';
|
|
@@ -8,9 +8,9 @@ import { c as commonjsGlobal } from './vendor-_commonjsHelpers.addc3445.js';
|
|
|
8
8
|
import { equals, iterableEquality, subsetEquality, JestExtend, JestChaiExpect, JestAsymmetricMatchers, GLOBAL_EXPECT, getState, setState } from '@vitest/expect';
|
|
9
9
|
import { r as rpc } from './chunk-runtime-rpc.9c0386cc.js';
|
|
10
10
|
import { join, dirname } from 'pathe';
|
|
11
|
-
import { g as
|
|
12
|
-
import { i as isObject
|
|
13
|
-
import { p as positionToOffset, o as offsetToLineNumber, l as lineSplitRE, a as
|
|
11
|
+
import { g as getSnapshotEnvironment } from './chunk-snapshot-env.a347d647.js';
|
|
12
|
+
import { i as isObject } from './chunk-utils-base.904102a8.js';
|
|
13
|
+
import { p as positionToOffset, o as offsetToLineNumber, l as lineSplitRE, a as parseErrorStacktrace, g as getFullName, b as parseSingleStack } from './chunk-utils-tasks.d07dcea9.js';
|
|
14
14
|
import require$$0 from 'util';
|
|
15
15
|
import { spyOn, fn, isMockFunction, spies } from '@vitest/spy';
|
|
16
16
|
|
|
@@ -2618,7 +2618,7 @@ function printBacktickString(str) {
|
|
|
2618
2618
|
}
|
|
2619
2619
|
async function ensureDirectoryExists(filePath) {
|
|
2620
2620
|
try {
|
|
2621
|
-
const environment =
|
|
2621
|
+
const environment = getSnapshotEnvironment();
|
|
2622
2622
|
await environment.prepareDirectory(join(dirname(filePath)));
|
|
2623
2623
|
} catch {
|
|
2624
2624
|
}
|
|
@@ -2627,7 +2627,7 @@ function normalizeNewlines(string) {
|
|
|
2627
2627
|
return string.replace(/\r\n|\r/g, "\n");
|
|
2628
2628
|
}
|
|
2629
2629
|
async function saveSnapshotFile(snapshotData, snapshotPath) {
|
|
2630
|
-
const environment =
|
|
2630
|
+
const environment = getSnapshotEnvironment();
|
|
2631
2631
|
const snapshots = Object.keys(snapshotData).sort(naturalCompare$1.exports).map(
|
|
2632
2632
|
(key) => `exports[${printBacktickString(key)}] = ${printBacktickString(normalizeNewlines(snapshotData[key]))};`
|
|
2633
2633
|
);
|
|
@@ -2699,7 +2699,7 @@ function deepMergeSnapshot(target, source) {
|
|
|
2699
2699
|
}
|
|
2700
2700
|
|
|
2701
2701
|
async function saveInlineSnapshots(snapshots) {
|
|
2702
|
-
const environment =
|
|
2702
|
+
const environment = getSnapshotEnvironment();
|
|
2703
2703
|
const MagicString = (await import('./chunk-magic-string.3a794426.js')).default;
|
|
2704
2704
|
const files = new Set(snapshots.map((i) => i.file));
|
|
2705
2705
|
await Promise.all(Array.from(files).map(async (file) => {
|
|
@@ -2815,10 +2815,10 @@ class SnapshotState {
|
|
|
2815
2815
|
printBasicPrototype: false,
|
|
2816
2816
|
...options.snapshotFormat
|
|
2817
2817
|
};
|
|
2818
|
-
this._environment =
|
|
2818
|
+
this._environment = getSnapshotEnvironment();
|
|
2819
2819
|
}
|
|
2820
2820
|
static async create(testFilePath, options) {
|
|
2821
|
-
const environment =
|
|
2821
|
+
const environment = getSnapshotEnvironment();
|
|
2822
2822
|
const snapshotPath = await environment.resolvePath(testFilePath);
|
|
2823
2823
|
const content = await environment.readSnapshotFile(snapshotPath);
|
|
2824
2824
|
return new SnapshotState(testFilePath, snapshotPath, content, options);
|
|
@@ -2839,9 +2839,7 @@ class SnapshotState {
|
|
|
2839
2839
|
_addSnapshot(key, receivedSerialized, options) {
|
|
2840
2840
|
this._dirty = true;
|
|
2841
2841
|
if (options.isInline) {
|
|
2842
|
-
const
|
|
2843
|
-
const stacks = parseStacktrace(error, true);
|
|
2844
|
-
stacks.forEach((i) => i.file = slash(i.file));
|
|
2842
|
+
const stacks = parseErrorStacktrace(options.error || new Error("snapshot"), true);
|
|
2845
2843
|
const stack = this._inferInlineSnapshotStack(stacks);
|
|
2846
2844
|
if (!stack) {
|
|
2847
2845
|
throw new Error(
|
|
@@ -3271,19 +3269,6 @@ Object.defineProperty(globalThis, GLOBAL_EXPECT, {
|
|
|
3271
3269
|
configurable: true
|
|
3272
3270
|
});
|
|
3273
3271
|
|
|
3274
|
-
function createSimpleStackTrace(options) {
|
|
3275
|
-
const { message = "error", stackTraceLimit = 1 } = options || {};
|
|
3276
|
-
const limit = Error.stackTraceLimit;
|
|
3277
|
-
const prepareStackTrace = Error.prepareStackTrace;
|
|
3278
|
-
Error.stackTraceLimit = stackTraceLimit;
|
|
3279
|
-
Error.prepareStackTrace = (e) => e.stack;
|
|
3280
|
-
const err = new Error(message);
|
|
3281
|
-
const stackTrace = err.stack || "";
|
|
3282
|
-
Error.prepareStackTrace = prepareStackTrace;
|
|
3283
|
-
Error.stackTraceLimit = limit;
|
|
3284
|
-
return stackTrace;
|
|
3285
|
-
}
|
|
3286
|
-
|
|
3287
3272
|
/**
|
|
3288
3273
|
* A reference to the global object
|
|
3289
3274
|
*
|
|
@@ -6014,7 +5999,11 @@ class VitestUtils {
|
|
|
6014
5999
|
this._mocker = typeof __vitest_mocker__ !== "undefined" ? __vitest_mocker__ : null;
|
|
6015
6000
|
this._mockedDate = null;
|
|
6016
6001
|
if (!this._mocker) {
|
|
6017
|
-
const errorMsg =
|
|
6002
|
+
const errorMsg = `Vitest was initialized with native Node instead of Vite Node.
|
|
6003
|
+
|
|
6004
|
+
It's possible that you are importing "vitest" directly inside "globalSetup". In that case, use "setupFiles" because "globalSetup" runs in a different context.
|
|
6005
|
+
Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues
|
|
6006
|
+
`;
|
|
6018
6007
|
throw new Error(errorMsg);
|
|
6019
6008
|
}
|
|
6020
6009
|
const workerState = getWorkerState();
|
|
@@ -5,7 +5,7 @@ import { n as notNullish } from './chunk-utils-base.904102a8.js';
|
|
|
5
5
|
function hasFailedSnapshot(suite) {
|
|
6
6
|
return getTests(suite).some((s) => {
|
|
7
7
|
var _a, _b;
|
|
8
|
-
return (_b = (_a = s.result) == null ? void 0 : _a.errors) == null ? void 0 : _b.some((e) => e.message.match(/Snapshot .* mismatched/));
|
|
8
|
+
return (_b = (_a = s.result) == null ? void 0 : _a.errors) == null ? void 0 : _b.some((e) => e && e.message && e.message.match(/Snapshot .* mismatched/));
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
function getFullName(task, separator = " > ") {
|
|
@@ -58,18 +58,22 @@ function parseSingleStack(raw) {
|
|
|
58
58
|
column: parseInt(columnNumber)
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
function parseStacktrace(
|
|
61
|
+
function parseStacktrace(stack, full = false) {
|
|
62
|
+
const stackFrames = stack.split("\n").map((raw) => {
|
|
63
|
+
const stack2 = parseSingleStack(raw);
|
|
64
|
+
if (!stack2 || !full && stackIgnorePatterns.some((p) => stack2.file.match(p)))
|
|
65
|
+
return null;
|
|
66
|
+
return stack2;
|
|
67
|
+
}).filter(notNullish);
|
|
68
|
+
return stackFrames;
|
|
69
|
+
}
|
|
70
|
+
function parseErrorStacktrace(e, full = false) {
|
|
62
71
|
if (!e)
|
|
63
72
|
return [];
|
|
64
73
|
if (e.stacks)
|
|
65
74
|
return e.stacks;
|
|
66
75
|
const stackStr = e.stack || e.stackStr || "";
|
|
67
|
-
const stackFrames = stackStr
|
|
68
|
-
const stack = parseSingleStack(raw);
|
|
69
|
-
if (!stack || !full && stackIgnorePatterns.some((p) => stack.file.match(p)))
|
|
70
|
-
return null;
|
|
71
|
-
return stack;
|
|
72
|
-
}).filter(notNullish);
|
|
76
|
+
const stackFrames = parseStacktrace(stackStr, full);
|
|
73
77
|
e.stacks = stackFrames;
|
|
74
78
|
return stackFrames;
|
|
75
79
|
}
|
|
@@ -100,4 +104,4 @@ function offsetToLineNumber(source, offset) {
|
|
|
100
104
|
return line + 1;
|
|
101
105
|
}
|
|
102
106
|
|
|
103
|
-
export {
|
|
107
|
+
export { parseErrorStacktrace as a, parseSingleStack as b, getFullName as g, hasFailedSnapshot as h, lineSplitRE as l, offsetToLineNumber as o, positionToOffset as p };
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { normalize } from 'pathe';
|
|
2
2
|
import cac from 'cac';
|
|
3
3
|
import c from 'picocolors';
|
|
4
|
-
import { v as version, s as startVitest, d as divider } from './chunk-node-pkg.
|
|
4
|
+
import { v as version, s as startVitest, d as divider } from './chunk-node-pkg.9a107dfb.js';
|
|
5
5
|
import './chunk-constants.797d3ebf.js';
|
|
6
6
|
import 'node:url';
|
|
7
7
|
import './chunk-utils-env.860d90c2.js';
|
|
@@ -43,7 +43,7 @@ import 'tinypool';
|
|
|
43
43
|
import './vendor-index.783e7f3e.js';
|
|
44
44
|
import 'perf_hooks';
|
|
45
45
|
import './chunk-utils-base.904102a8.js';
|
|
46
|
-
import './chunk-utils-tasks.
|
|
46
|
+
import './chunk-utils-tasks.d07dcea9.js';
|
|
47
47
|
import 'crypto';
|
|
48
48
|
import 'vite-node/utils';
|
|
49
49
|
import '@vitest/utils/diff';
|