vitest 0.22.1 → 0.23.2
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 +29 -29
- package/dist/browser.d.ts +5 -4
- package/dist/browser.mjs +10 -8
- package/dist/{chunk-api-setup.377c28aa.mjs → chunk-api-setup.11cfd513.mjs} +89 -86
- package/dist/{chunk-integrations-coverage.d205bd87.mjs → chunk-env-node.ceb43f1c.mjs} +31 -179
- package/dist/chunk-integrations-coverage.99c020eb.mjs +166 -0
- package/dist/{chunk-integrations-globals.60af7da3.mjs → chunk-integrations-globals.ad5b1b51.mjs} +5 -6
- package/dist/{chunk-magic-string.efe26975.mjs → chunk-magic-string.56b2b543.mjs} +30 -10
- package/dist/{chunk-mock-date.304e29b1.mjs → chunk-mock-date.2917be60.mjs} +25 -4
- package/dist/{chunk-node-git.9a7e3153.mjs → chunk-node-git.a44b4872.mjs} +14 -8
- package/dist/{chunk-runtime-chain.be610650.mjs → chunk-runtime-chain.7a7f3c3b.mjs} +494 -172
- package/dist/{chunk-runtime-error.1104e45a.mjs → chunk-runtime-error.2723946b.mjs} +219 -75
- package/dist/{chunk-runtime-hooks.5d7073db.mjs → chunk-runtime-hooks.1a0bc3fd.mjs} +18 -12
- package/dist/{chunk-runtime-mocker.49d21aa6.mjs → chunk-runtime-mocker.8d4a2494.mjs} +18 -11
- package/dist/{chunk-runtime-rpc.57586b73.mjs → chunk-runtime-rpc.00a890d2.mjs} +1 -2
- package/dist/{chunk-utils-source-map.bbf3ad19.mjs → chunk-utils-source-map.2be5aa48.mjs} +10 -4
- package/dist/{chunk-vite-node-client.cddda63d.mjs → chunk-vite-node-client.da0a17ff.mjs} +49 -12
- package/dist/{chunk-vite-node-externalize.c843f497.mjs → chunk-vite-node-externalize.f55c4577.mjs} +547 -218
- package/dist/{chunk-vite-node-utils.b432150c.mjs → chunk-vite-node-utils.473cd0b2.mjs} +39 -41
- package/dist/cli-wrapper.mjs +17 -13
- package/dist/cli.mjs +26 -14
- package/dist/config.cjs +2 -2
- package/dist/config.d.ts +4 -3
- package/dist/config.mjs +2 -2
- package/dist/entry.mjs +18 -13
- package/dist/environments.d.ts +23 -0
- package/dist/environments.mjs +3 -0
- package/dist/{global-fe52f84b.d.ts → global-d05ffb3f.d.ts} +140 -19
- package/dist/{index-ea17aa0c.d.ts → index-60e2a8e1.d.ts} +3 -2
- package/dist/index.d.ts +6 -5
- package/dist/index.mjs +5 -6
- package/dist/loader.mjs +5 -6
- package/dist/node.d.ts +5 -4
- package/dist/node.mjs +11 -9
- package/dist/suite.mjs +4 -5
- package/dist/vendor-index.0557b03a.mjs +147 -0
- package/dist/worker.mjs +16 -14
- package/package.json +20 -13
- package/dist/chunk-utils-global.fa20c2f6.mjs +0 -5
package/dist/{chunk-vite-node-externalize.c843f497.mjs → chunk-vite-node-externalize.f55c4577.mjs}
RENAMED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { a as resolve, j as join, b as basename, d as dirname, c as distDir, e as rootDir, p as picocolors, i as isAbsolute, r as relative, f as configFiles, g as defaultPort, n as normalize, t as toNamespacedPath, E as EXIT_CODE_RESTART } from './chunk-constants.71e8a211.mjs';
|
|
2
|
-
import { p as pLimit, g as getCoverageProvider,
|
|
3
|
-
import {
|
|
2
|
+
import { p as pLimit, g as getCoverageProvider, C as CoverageProviderMap } from './chunk-integrations-coverage.99c020eb.mjs';
|
|
3
|
+
import { g as getEnvPackageName } from './chunk-env-node.ceb43f1c.mjs';
|
|
4
|
+
import { A as AggregateErrorPonyfill, s as slash$2, o as isNode, p as relativePath, z as getTests, e as getFullName, x as hasFailed, B as hasFailedSnapshot, C as getSuites, j as notNullish, v as shuffle, t as toArray$1, n as noop$1, D as deepMerge, b as getCallLastIndex, E as ensurePackageInstalled, F as stdout } from './chunk-mock-date.2917be60.mjs';
|
|
4
5
|
import { loadConfigFromFile, normalizePath, createServer, mergeConfig } from 'vite';
|
|
5
6
|
import path$a from 'path';
|
|
6
7
|
import url, { fileURLToPath } from 'url';
|
|
@@ -11,23 +12,24 @@ import util$2 from 'util';
|
|
|
11
12
|
import require$$0$1 from 'stream';
|
|
12
13
|
import require$$2 from 'events';
|
|
13
14
|
import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
|
|
14
|
-
import { c as createBirpc, V as ViteNodeRunner } from './chunk-vite-node-client.
|
|
15
|
+
import { c as createBirpc, V as ViteNodeRunner } from './chunk-vite-node-client.da0a17ff.mjs';
|
|
15
16
|
import { performance } from 'perf_hooks';
|
|
16
17
|
import createDebug from 'debug';
|
|
17
|
-
import { i as isNodeBuiltin, a as isValidNodeImport, s as slash$1, t as toArray, b as toFilePath, w as withInlineSourcemap } from './chunk-vite-node-utils.
|
|
18
|
+
import { i as isNodeBuiltin, a as isValidNodeImport, s as slash$1, t as toArray, b as toFilePath, w as withInlineSourcemap } from './chunk-vite-node-utils.473cd0b2.mjs';
|
|
18
19
|
import { MessageChannel } from 'worker_threads';
|
|
19
20
|
import { Tinypool } from 'tinypool';
|
|
20
|
-
import { c as stripAnsi, d as cliTruncate, p as parseStacktrace,
|
|
21
|
+
import { c as stripAnsi, d as cliTruncate, p as parseStacktrace, i as interpretSourcePos, e as stringWidth, h as ansiStyles, j as sliceAnsi, s as stringify$5, u as unifiedDiff, b as posToNumber, l as lineSplitRE } from './chunk-utils-source-map.2be5aa48.mjs';
|
|
21
22
|
import { b as safeSetInterval, c as safeClearInterval, s as safeSetTimeout, a as safeClearTimeout } from './chunk-utils-timers.b48455ed.mjs';
|
|
22
23
|
import { resolveModule } from 'local-pkg';
|
|
23
24
|
import { createHash } from 'crypto';
|
|
24
25
|
import { o as onetime } from './vendor-index.9d9196cc.mjs';
|
|
25
26
|
import { s as signalExit } from './vendor-index.29636037.mjs';
|
|
26
|
-
import MagicString from './chunk-magic-string.
|
|
27
|
+
import MagicString from './chunk-magic-string.56b2b543.mjs';
|
|
28
|
+
import { stripLiteral } from 'strip-literal';
|
|
27
29
|
import require$$0$2 from 'readline';
|
|
28
30
|
import { p as prompts } from './vendor-index.ae96af6e.mjs';
|
|
29
31
|
|
|
30
|
-
var version$1 = "0.
|
|
32
|
+
var version$1 = "0.23.2";
|
|
31
33
|
|
|
32
34
|
class EndError extends Error {
|
|
33
35
|
constructor(value) {
|
|
@@ -82,14 +84,14 @@ const typeMappings = {
|
|
|
82
84
|
};
|
|
83
85
|
|
|
84
86
|
function checkType(type) {
|
|
85
|
-
if (type
|
|
87
|
+
if (Object.hasOwnProperty.call(typeMappings, type)) {
|
|
86
88
|
return;
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
throw new Error(`Invalid type specified: ${type}`);
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
const matchType = (type, stat) =>
|
|
94
|
+
const matchType = (type, stat) => stat[typeMappings[type]]();
|
|
93
95
|
|
|
94
96
|
const toPath$1 = urlOrPath => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
|
|
95
97
|
|
|
@@ -6864,19 +6866,25 @@ class ViteNodeServer {
|
|
|
6864
6866
|
}
|
|
6865
6867
|
async fetchModule(id) {
|
|
6866
6868
|
if (!this.fetchPromiseMap.has(id)) {
|
|
6867
|
-
this.fetchPromiseMap.set(
|
|
6868
|
-
|
|
6869
|
-
|
|
6870
|
-
|
|
6871
|
-
|
|
6869
|
+
this.fetchPromiseMap.set(
|
|
6870
|
+
id,
|
|
6871
|
+
this._fetchModule(id).then((r) => {
|
|
6872
|
+
return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
|
|
6873
|
+
}).finally(() => {
|
|
6874
|
+
this.fetchPromiseMap.delete(id);
|
|
6875
|
+
})
|
|
6876
|
+
);
|
|
6872
6877
|
}
|
|
6873
6878
|
return this.fetchPromiseMap.get(id);
|
|
6874
6879
|
}
|
|
6875
6880
|
async transformRequest(id) {
|
|
6876
6881
|
if (!this.transformPromiseMap.has(id)) {
|
|
6877
|
-
this.transformPromiseMap.set(
|
|
6878
|
-
|
|
6879
|
-
|
|
6882
|
+
this.transformPromiseMap.set(
|
|
6883
|
+
id,
|
|
6884
|
+
this._transformRequest(id).finally(() => {
|
|
6885
|
+
this.transformPromiseMap.delete(id);
|
|
6886
|
+
})
|
|
6887
|
+
);
|
|
6880
6888
|
}
|
|
6881
6889
|
return this.transformPromiseMap.get(id);
|
|
6882
6890
|
}
|
|
@@ -6958,7 +6966,13 @@ class SnapshotManager {
|
|
|
6958
6966
|
}
|
|
6959
6967
|
resolvePath(testPath) {
|
|
6960
6968
|
const resolver = this.options.resolveSnapshotPath || (() => {
|
|
6961
|
-
return join(
|
|
6969
|
+
return join(
|
|
6970
|
+
join(
|
|
6971
|
+
dirname(testPath),
|
|
6972
|
+
"__snapshots__"
|
|
6973
|
+
),
|
|
6974
|
+
`${basename(testPath)}${this.extension}`
|
|
6975
|
+
);
|
|
6962
6976
|
});
|
|
6963
6977
|
return resolver(testPath, this.extension);
|
|
6964
6978
|
}
|
|
@@ -7013,7 +7027,7 @@ function createPool(ctx) {
|
|
|
7013
7027
|
const threadsCount = ctx.config.watch ? Math.max(Math.floor(cpus().length / 2), 1) : Math.max(cpus().length - 1, 1);
|
|
7014
7028
|
const maxThreads = ctx.config.maxThreads ?? threadsCount;
|
|
7015
7029
|
const minThreads = ctx.config.minThreads ?? threadsCount;
|
|
7016
|
-
const conditions = (_a = ctx.server.config.resolve.conditions) == null ? void 0 : _a.flatMap((c) => ["-C", c]);
|
|
7030
|
+
const conditions = ((_a = ctx.server.config.resolve.conditions) == null ? void 0 : _a.flatMap((c) => ["-C", c])) || [];
|
|
7017
7031
|
const options = {
|
|
7018
7032
|
filename: workerPath,
|
|
7019
7033
|
useAtomics: false,
|
|
@@ -7024,8 +7038,8 @@ function createPool(ctx) {
|
|
|
7024
7038
|
suppressLoaderWarningsPath,
|
|
7025
7039
|
"--experimental-loader",
|
|
7026
7040
|
loaderPath,
|
|
7027
|
-
...conditions
|
|
7028
|
-
] :
|
|
7041
|
+
...conditions
|
|
7042
|
+
] : conditions
|
|
7029
7043
|
};
|
|
7030
7044
|
if (ctx.config.isolate) {
|
|
7031
7045
|
options.isolateWorkers = true;
|
|
@@ -7093,65 +7107,68 @@ function createChannel(ctx) {
|
|
|
7093
7107
|
const channel = new MessageChannel();
|
|
7094
7108
|
const port = channel.port2;
|
|
7095
7109
|
const workerPort = channel.port1;
|
|
7096
|
-
createBirpc(
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
|
|
7100
|
-
|
|
7101
|
-
|
|
7102
|
-
|
|
7103
|
-
|
|
7104
|
-
|
|
7105
|
-
|
|
7106
|
-
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7110
|
-
|
|
7111
|
-
|
|
7112
|
-
|
|
7113
|
-
|
|
7114
|
-
|
|
7115
|
-
|
|
7116
|
-
|
|
7117
|
-
|
|
7118
|
-
|
|
7119
|
-
|
|
7120
|
-
|
|
7121
|
-
|
|
7122
|
-
|
|
7123
|
-
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
|
|
7127
|
-
|
|
7128
|
-
|
|
7129
|
-
|
|
7130
|
-
|
|
7131
|
-
|
|
7132
|
-
|
|
7133
|
-
|
|
7134
|
-
|
|
7135
|
-
|
|
7136
|
-
|
|
7137
|
-
|
|
7138
|
-
|
|
7139
|
-
|
|
7140
|
-
|
|
7141
|
-
|
|
7142
|
-
|
|
7143
|
-
|
|
7144
|
-
|
|
7145
|
-
|
|
7146
|
-
|
|
7147
|
-
|
|
7148
|
-
post(v) {
|
|
7149
|
-
port.postMessage(v);
|
|
7110
|
+
createBirpc(
|
|
7111
|
+
{
|
|
7112
|
+
onWorkerExit(code) {
|
|
7113
|
+
process.exit(code || 1);
|
|
7114
|
+
},
|
|
7115
|
+
snapshotSaved(snapshot) {
|
|
7116
|
+
ctx.snapshot.add(snapshot);
|
|
7117
|
+
},
|
|
7118
|
+
resolveSnapshotPath(testPath) {
|
|
7119
|
+
return ctx.snapshot.resolvePath(testPath);
|
|
7120
|
+
},
|
|
7121
|
+
async getSourceMap(id, force) {
|
|
7122
|
+
if (force) {
|
|
7123
|
+
const mod = ctx.server.moduleGraph.getModuleById(id);
|
|
7124
|
+
if (mod)
|
|
7125
|
+
ctx.server.moduleGraph.invalidateModule(mod);
|
|
7126
|
+
}
|
|
7127
|
+
const r = await ctx.vitenode.transformRequest(id);
|
|
7128
|
+
return r == null ? void 0 : r.map;
|
|
7129
|
+
},
|
|
7130
|
+
fetch(id) {
|
|
7131
|
+
return ctx.vitenode.fetchModule(id);
|
|
7132
|
+
},
|
|
7133
|
+
resolveId(id, importer) {
|
|
7134
|
+
return ctx.vitenode.resolveId(id, importer);
|
|
7135
|
+
},
|
|
7136
|
+
onPathsCollected(paths) {
|
|
7137
|
+
ctx.state.collectPaths(paths);
|
|
7138
|
+
ctx.report("onPathsCollected", paths);
|
|
7139
|
+
},
|
|
7140
|
+
onCollected(files) {
|
|
7141
|
+
ctx.state.collectFiles(files);
|
|
7142
|
+
ctx.report("onCollected", files);
|
|
7143
|
+
},
|
|
7144
|
+
onAfterSuiteRun(meta) {
|
|
7145
|
+
var _a;
|
|
7146
|
+
(_a = ctx.coverageProvider) == null ? void 0 : _a.onAfterSuiteRun(meta);
|
|
7147
|
+
},
|
|
7148
|
+
onTaskUpdate(packs) {
|
|
7149
|
+
ctx.state.updateTasks(packs);
|
|
7150
|
+
ctx.report("onTaskUpdate", packs);
|
|
7151
|
+
},
|
|
7152
|
+
onUserConsoleLog(log) {
|
|
7153
|
+
ctx.state.updateUserLog(log);
|
|
7154
|
+
ctx.report("onUserConsoleLog", log);
|
|
7155
|
+
},
|
|
7156
|
+
onUnhandledRejection(err) {
|
|
7157
|
+
ctx.state.catchError(err, "Unhandled Rejection");
|
|
7158
|
+
},
|
|
7159
|
+
onFinished(files) {
|
|
7160
|
+
ctx.report("onFinished", files, ctx.state.getUnhandledErrors());
|
|
7161
|
+
}
|
|
7150
7162
|
},
|
|
7151
|
-
|
|
7152
|
-
|
|
7163
|
+
{
|
|
7164
|
+
post(v) {
|
|
7165
|
+
port.postMessage(v);
|
|
7166
|
+
},
|
|
7167
|
+
on(fn) {
|
|
7168
|
+
port.on("message", fn);
|
|
7169
|
+
}
|
|
7153
7170
|
}
|
|
7154
|
-
|
|
7171
|
+
);
|
|
7155
7172
|
return { workerPort, port };
|
|
7156
7173
|
}
|
|
7157
7174
|
|
|
@@ -7268,8 +7285,9 @@ function getStateSymbol(task) {
|
|
|
7268
7285
|
}
|
|
7269
7286
|
return picocolors.exports.yellow(spinner());
|
|
7270
7287
|
}
|
|
7271
|
-
if (task.result.state === "pass")
|
|
7272
|
-
return picocolors.exports.green(F_CHECK);
|
|
7288
|
+
if (task.result.state === "pass") {
|
|
7289
|
+
return task.type === "benchmark" ? picocolors.exports.green(F_DOT) : picocolors.exports.green(F_CHECK);
|
|
7290
|
+
}
|
|
7273
7291
|
if (task.result.state === "fail") {
|
|
7274
7292
|
return task.type === "suite" ? pointer : picocolors.exports.red(F_CROSS);
|
|
7275
7293
|
}
|
|
@@ -7327,6 +7345,9 @@ class BaseReporter {
|
|
|
7327
7345
|
this._timeStart = new Date();
|
|
7328
7346
|
this.registerUnhandledRejection();
|
|
7329
7347
|
}
|
|
7348
|
+
get mode() {
|
|
7349
|
+
return this.ctx.config.mode;
|
|
7350
|
+
}
|
|
7330
7351
|
onInit(ctx) {
|
|
7331
7352
|
this.ctx = ctx;
|
|
7332
7353
|
ctx.logger.printBanner();
|
|
@@ -7403,13 +7424,16 @@ class BaseReporter {
|
|
|
7403
7424
|
];
|
|
7404
7425
|
this.ctx.logger.logUpdate(BADGE_PADDING + LAST_RUN_TEXTS[0]);
|
|
7405
7426
|
this._lastRunTimeout = 0;
|
|
7406
|
-
this._lastRunTimer = safeSetInterval(
|
|
7407
|
-
|
|
7408
|
-
|
|
7409
|
-
this.
|
|
7410
|
-
|
|
7411
|
-
|
|
7412
|
-
|
|
7427
|
+
this._lastRunTimer = safeSetInterval(
|
|
7428
|
+
() => {
|
|
7429
|
+
this._lastRunTimeout += 1;
|
|
7430
|
+
if (this._lastRunTimeout >= LAST_RUN_TEXTS.length)
|
|
7431
|
+
this.resetLastRunLog();
|
|
7432
|
+
else
|
|
7433
|
+
this.ctx.logger.logUpdate(BADGE_PADDING + LAST_RUN_TEXTS[this._lastRunTimeout]);
|
|
7434
|
+
},
|
|
7435
|
+
LAST_RUN_LOG_TIMEOUT / LAST_RUN_TEXTS.length
|
|
7436
|
+
);
|
|
7413
7437
|
}
|
|
7414
7438
|
}
|
|
7415
7439
|
resetLastRunLog() {
|
|
@@ -7459,34 +7483,20 @@ ${BADGE}${TRIGGER} ${picocolors.exports.blue(`x${rerun}`)}
|
|
|
7459
7483
|
return true;
|
|
7460
7484
|
}
|
|
7461
7485
|
onServerRestart(reason) {
|
|
7462
|
-
this.ctx.logger.log(picocolors.exports.bold(picocolors.exports.magenta(
|
|
7486
|
+
this.ctx.logger.log(picocolors.exports.bold(picocolors.exports.magenta(
|
|
7487
|
+
reason === "config" ? "\nRestarting due to config changes..." : "\nRestarting Vitest..."
|
|
7488
|
+
)));
|
|
7463
7489
|
}
|
|
7464
7490
|
async reportSummary(files) {
|
|
7465
|
-
|
|
7466
|
-
|
|
7491
|
+
await this.printErrorsSummary(files);
|
|
7492
|
+
if (this.mode === "benchmark")
|
|
7493
|
+
await this.reportBenchmarkSummary(files);
|
|
7494
|
+
else
|
|
7495
|
+
await this.reportTestSummary(files);
|
|
7496
|
+
}
|
|
7497
|
+
async reportTestSummary(files) {
|
|
7467
7498
|
const tests = getTests(files);
|
|
7468
|
-
const
|
|
7469
|
-
var _a2;
|
|
7470
|
-
return (_a2 = i.result) == null ? void 0 : _a2.error;
|
|
7471
|
-
});
|
|
7472
|
-
const failedTests = tests.filter((i) => {
|
|
7473
|
-
var _a2;
|
|
7474
|
-
return ((_a2 = i.result) == null ? void 0 : _a2.state) === "fail";
|
|
7475
|
-
});
|
|
7476
|
-
const failedTotal = failedSuites.length + failedTests.length;
|
|
7477
|
-
let current = 1;
|
|
7478
|
-
const errorDivider = () => logger.error(`${picocolors.exports.red(picocolors.exports.dim(divider(`[${current++}/${failedTotal}]`, void 0, 1)))}
|
|
7479
|
-
`);
|
|
7480
|
-
if (failedSuites.length) {
|
|
7481
|
-
logger.error(picocolors.exports.red(divider(picocolors.exports.bold(picocolors.exports.inverse(` Failed Suites ${failedSuites.length} `)))));
|
|
7482
|
-
logger.error();
|
|
7483
|
-
await this.printTaskErrors(failedSuites, errorDivider);
|
|
7484
|
-
}
|
|
7485
|
-
if (failedTests.length) {
|
|
7486
|
-
logger.error(picocolors.exports.red(divider(picocolors.exports.bold(picocolors.exports.inverse(` Failed Tests ${failedTests.length} `)))));
|
|
7487
|
-
logger.error();
|
|
7488
|
-
await this.printTaskErrors(failedTests, errorDivider);
|
|
7489
|
-
}
|
|
7499
|
+
const logger = this.ctx.logger;
|
|
7490
7500
|
const executionTime = this.end - this.start;
|
|
7491
7501
|
const collectTime = files.reduce((acc, test) => acc + Math.max(0, test.collectDuration || 0), 0);
|
|
7492
7502
|
const setupTime = files.reduce((acc, test) => acc + Math.max(0, test.setupDuration || 0), 0);
|
|
@@ -7504,7 +7514,9 @@ ${BADGE}${TRIGGER} ${picocolors.exports.blue(`x${rerun}`)}
|
|
|
7504
7514
|
};
|
|
7505
7515
|
const snapshotOutput = renderSnapshotSummary(this.ctx.config.root, this.ctx.snapshot.summary);
|
|
7506
7516
|
if (snapshotOutput.length) {
|
|
7507
|
-
logger.log(snapshotOutput.map(
|
|
7517
|
+
logger.log(snapshotOutput.map(
|
|
7518
|
+
(t, i) => i === 0 ? `${padTitle("Snapshots")} ${t}` : `${padTitle("")} ${t}`
|
|
7519
|
+
).join("\n"));
|
|
7508
7520
|
if (snapshotOutput.length > 1)
|
|
7509
7521
|
logger.log();
|
|
7510
7522
|
}
|
|
@@ -7517,6 +7529,59 @@ ${BADGE}${TRIGGER} ${picocolors.exports.blue(`x${rerun}`)}
|
|
|
7517
7529
|
logger.log(padTitle("Duration"), time(executionTime) + picocolors.exports.dim(` (transform ${time(transformTime)}, setup ${time(setupTime)}, collect ${time(collectTime)}, tests ${time(testsTime)})`));
|
|
7518
7530
|
logger.log();
|
|
7519
7531
|
}
|
|
7532
|
+
async printErrorsSummary(files) {
|
|
7533
|
+
const logger = this.ctx.logger;
|
|
7534
|
+
const suites = getSuites(files);
|
|
7535
|
+
const tests = getTests(files);
|
|
7536
|
+
const failedSuites = suites.filter((i) => {
|
|
7537
|
+
var _a2;
|
|
7538
|
+
return (_a2 = i.result) == null ? void 0 : _a2.error;
|
|
7539
|
+
});
|
|
7540
|
+
const failedTests = tests.filter((i) => {
|
|
7541
|
+
var _a2;
|
|
7542
|
+
return ((_a2 = i.result) == null ? void 0 : _a2.state) === "fail";
|
|
7543
|
+
});
|
|
7544
|
+
const failedTotal = failedSuites.length + failedTests.length;
|
|
7545
|
+
let current = 1;
|
|
7546
|
+
const errorDivider = () => logger.error(`${picocolors.exports.red(picocolors.exports.dim(divider(`[${current++}/${failedTotal}]`, void 0, 1)))}
|
|
7547
|
+
`);
|
|
7548
|
+
if (failedSuites.length) {
|
|
7549
|
+
logger.error(picocolors.exports.red(divider(picocolors.exports.bold(picocolors.exports.inverse(` Failed Suites ${failedSuites.length} `)))));
|
|
7550
|
+
logger.error();
|
|
7551
|
+
await this.printTaskErrors(failedSuites, errorDivider);
|
|
7552
|
+
}
|
|
7553
|
+
if (failedTests.length) {
|
|
7554
|
+
logger.error(picocolors.exports.red(divider(picocolors.exports.bold(picocolors.exports.inverse(` Failed Tests ${failedTests.length} `)))));
|
|
7555
|
+
logger.error();
|
|
7556
|
+
await this.printTaskErrors(failedTests, errorDivider);
|
|
7557
|
+
}
|
|
7558
|
+
return tests;
|
|
7559
|
+
}
|
|
7560
|
+
async reportBenchmarkSummary(files) {
|
|
7561
|
+
const logger = this.ctx.logger;
|
|
7562
|
+
const benchs = getTests(files);
|
|
7563
|
+
const topBenchs = benchs.filter((i) => {
|
|
7564
|
+
var _a2, _b;
|
|
7565
|
+
return ((_b = (_a2 = i.result) == null ? void 0 : _a2.benchmark) == null ? void 0 : _b.rank) === 1;
|
|
7566
|
+
});
|
|
7567
|
+
logger.log(`
|
|
7568
|
+
${picocolors.exports.cyan(picocolors.exports.inverse(picocolors.exports.bold(" BENCH ")))} ${picocolors.exports.cyan("Summary")}
|
|
7569
|
+
`);
|
|
7570
|
+
for (const bench of topBenchs) {
|
|
7571
|
+
const group = bench.suite;
|
|
7572
|
+
const groupName = getFullName(group);
|
|
7573
|
+
logger.log(` ${bench.name}${picocolors.exports.dim(` - ${groupName}`)}`);
|
|
7574
|
+
const siblings = group.tasks.filter((i) => {
|
|
7575
|
+
var _a2;
|
|
7576
|
+
return ((_a2 = i.result) == null ? void 0 : _a2.benchmark) && i !== bench;
|
|
7577
|
+
}).sort((a, b) => a.result.benchmark.rank - b.result.benchmark.rank);
|
|
7578
|
+
for (const sibling of siblings) {
|
|
7579
|
+
const number = `${(sibling.result.benchmark.mean / bench.result.benchmark.mean).toFixed(2)}x`;
|
|
7580
|
+
logger.log(` ${picocolors.exports.green(number)} ${picocolors.exports.gray("faster than")} ${sibling.name}`);
|
|
7581
|
+
}
|
|
7582
|
+
logger.log("");
|
|
7583
|
+
}
|
|
7584
|
+
}
|
|
7520
7585
|
async printTaskErrors(tasks, errorDivider) {
|
|
7521
7586
|
var _a2;
|
|
7522
7587
|
const errorsQueue = [];
|
|
@@ -7565,6 +7630,10 @@ function formatFilepath(path) {
|
|
|
7565
7630
|
firstDot += lastSlash;
|
|
7566
7631
|
return picocolors.exports.dim(path.slice(0, lastSlash)) + path.slice(lastSlash, firstDot) + picocolors.exports.dim(path.slice(firstDot));
|
|
7567
7632
|
}
|
|
7633
|
+
function formatNumber(number) {
|
|
7634
|
+
const res = String(number.toFixed(number < 100 ? 4 : 2)).split(".");
|
|
7635
|
+
return res[0].replace(/(?=(?:\d{3})+$)(?!\b)/g, ",") + (res[1] ? `.${res[1]}` : "");
|
|
7636
|
+
}
|
|
7568
7637
|
function renderHookState(task, hookName, level = 0) {
|
|
7569
7638
|
var _a, _b;
|
|
7570
7639
|
const state = (_b = (_a = task.result) == null ? void 0 : _a.hooks) == null ? void 0 : _b[hookName];
|
|
@@ -7572,27 +7641,65 @@ function renderHookState(task, hookName, level = 0) {
|
|
|
7572
7641
|
return `${" ".repeat(level)} ${getHookStateSymbol(task, hookName)} ${picocolors.exports.dim(`[ ${hookName} ]`)}`;
|
|
7573
7642
|
return "";
|
|
7574
7643
|
}
|
|
7644
|
+
function renderBenchmarkItems(result) {
|
|
7645
|
+
return [
|
|
7646
|
+
result.name,
|
|
7647
|
+
formatNumber(result.hz || 0),
|
|
7648
|
+
formatNumber(result.p99 || 0),
|
|
7649
|
+
`\xB1${result.rme.toFixed(2)}%`,
|
|
7650
|
+
result.samples.length.toString()
|
|
7651
|
+
];
|
|
7652
|
+
}
|
|
7653
|
+
function renderBenchmark(task, tasks) {
|
|
7654
|
+
var _a;
|
|
7655
|
+
const result = (_a = task.result) == null ? void 0 : _a.benchmark;
|
|
7656
|
+
if (!result)
|
|
7657
|
+
return task.name;
|
|
7658
|
+
const benchs = tasks.map((i) => {
|
|
7659
|
+
var _a2;
|
|
7660
|
+
return i.type === "benchmark" ? (_a2 = i.result) == null ? void 0 : _a2.benchmark : void 0;
|
|
7661
|
+
}).filter(notNullish);
|
|
7662
|
+
const allItems = benchs.map(renderBenchmarkItems);
|
|
7663
|
+
const items = renderBenchmarkItems(result);
|
|
7664
|
+
const padded = items.map((i, idx) => {
|
|
7665
|
+
const width = Math.max(...allItems.map((i2) => i2[idx].length));
|
|
7666
|
+
return idx ? i.padStart(width, " ") : i.padEnd(width, " ");
|
|
7667
|
+
});
|
|
7668
|
+
return [
|
|
7669
|
+
padded[0],
|
|
7670
|
+
picocolors.exports.dim(" "),
|
|
7671
|
+
picocolors.exports.blue(padded[1]),
|
|
7672
|
+
picocolors.exports.dim(" ops/sec "),
|
|
7673
|
+
picocolors.exports.cyan(padded[3]),
|
|
7674
|
+
picocolors.exports.dim(` (${padded[4]} samples)`),
|
|
7675
|
+
result.rank === 1 ? picocolors.exports.bold(picocolors.exports.green(" fastest")) : result.rank === benchs.length && benchs.length > 2 ? picocolors.exports.bold(picocolors.exports.gray(" slowest")) : ""
|
|
7676
|
+
].join("");
|
|
7677
|
+
}
|
|
7575
7678
|
function renderTree(tasks, options, level = 0) {
|
|
7576
|
-
var _a, _b, _c, _d, _e;
|
|
7679
|
+
var _a, _b, _c, _d, _e, _f;
|
|
7577
7680
|
let output = [];
|
|
7578
7681
|
for (const task of tasks) {
|
|
7579
7682
|
let suffix = "";
|
|
7580
7683
|
const prefix = ` ${getStateSymbol(task)} `;
|
|
7684
|
+
if (task.type === "test" && ((_a = task.result) == null ? void 0 : _a.retryCount) && task.result.retryCount > 1)
|
|
7685
|
+
suffix += picocolors.exports.yellow(` (retry x${task.result.retryCount})`);
|
|
7581
7686
|
if (task.type === "suite")
|
|
7582
7687
|
suffix += picocolors.exports.dim(` (${getTests(task).length})`);
|
|
7583
7688
|
if (task.mode === "skip" || task.mode === "todo")
|
|
7584
7689
|
suffix += ` ${picocolors.exports.dim(picocolors.exports.gray("[skipped]"))}`;
|
|
7585
|
-
if (((
|
|
7690
|
+
if (((_b = task.result) == null ? void 0 : _b.duration) != null) {
|
|
7586
7691
|
if (task.result.duration > DURATION_LONG)
|
|
7587
7692
|
suffix += picocolors.exports.yellow(` ${Math.round(task.result.duration)}${picocolors.exports.dim("ms")}`);
|
|
7588
7693
|
}
|
|
7589
|
-
if (options.showHeap && ((
|
|
7694
|
+
if (options.showHeap && ((_c = task.result) == null ? void 0 : _c.heap) != null)
|
|
7590
7695
|
suffix += picocolors.exports.magenta(` ${Math.floor(task.result.heap / 1024 / 1024)} MB heap used`);
|
|
7591
7696
|
let name = task.name;
|
|
7592
7697
|
if (level === 0)
|
|
7593
7698
|
name = formatFilepath(name);
|
|
7594
|
-
|
|
7595
|
-
|
|
7699
|
+
const padding = " ".repeat(level);
|
|
7700
|
+
const body = task.type === "benchmark" ? renderBenchmark(task, tasks) : name;
|
|
7701
|
+
output.push(padding + prefix + body + suffix);
|
|
7702
|
+
if (((_d = task.result) == null ? void 0 : _d.state) !== "pass" && outputMap.get(task) != null) {
|
|
7596
7703
|
let data = outputMap.get(task);
|
|
7597
7704
|
if (typeof data === "string") {
|
|
7598
7705
|
data = stripAnsi(data.trim().split("\n").filter(Boolean).pop());
|
|
@@ -7607,7 +7714,7 @@ function renderTree(tasks, options, level = 0) {
|
|
|
7607
7714
|
output = output.concat(renderHookState(task, "beforeAll", level + 1));
|
|
7608
7715
|
output = output.concat(renderHookState(task, "beforeEach", level + 1));
|
|
7609
7716
|
if (task.type === "suite" && task.tasks.length > 0) {
|
|
7610
|
-
if (((
|
|
7717
|
+
if (((_e = task.result) == null ? void 0 : _e.state) === "fail" || ((_f = task.result) == null ? void 0 : _f.state) === "run" || options.renderSucceed)
|
|
7611
7718
|
output = output.concat(renderTree(task.tasks, options, level + 1));
|
|
7612
7719
|
}
|
|
7613
7720
|
output = output.concat(renderHookState(task, "afterAll", level + 1));
|
|
@@ -7808,7 +7915,7 @@ const StatusMap = {
|
|
|
7808
7915
|
skip: "skipped",
|
|
7809
7916
|
todo: "todo"
|
|
7810
7917
|
};
|
|
7811
|
-
class JsonReporter {
|
|
7918
|
+
class JsonReporter$1 {
|
|
7812
7919
|
constructor() {
|
|
7813
7920
|
this.start = 0;
|
|
7814
7921
|
}
|
|
@@ -7855,7 +7962,7 @@ class JsonReporter {
|
|
|
7855
7962
|
var _a2, _b2;
|
|
7856
7963
|
return Math.max(prev, (((_a2 = next.result) == null ? void 0 : _a2.startTime) ?? 0) + (((_b2 = next.result) == null ? void 0 : _b2.duration) ?? 0));
|
|
7857
7964
|
}, startTime);
|
|
7858
|
-
const assertionResults = tests2.map((t) => {
|
|
7965
|
+
const assertionResults = await Promise.all(tests2.map(async (t) => {
|
|
7859
7966
|
var _a2, _b2, _c, _d;
|
|
7860
7967
|
const ancestorTitles = [];
|
|
7861
7968
|
let iter = t.suite;
|
|
@@ -7871,9 +7978,9 @@ class JsonReporter {
|
|
|
7871
7978
|
title: t.name,
|
|
7872
7979
|
duration: (_b2 = t.result) == null ? void 0 : _b2.duration,
|
|
7873
7980
|
failureMessages: ((_d = (_c = t.result) == null ? void 0 : _c.error) == null ? void 0 : _d.message) == null ? [] : [t.result.error.message],
|
|
7874
|
-
location: this.getFailureLocation(t)
|
|
7981
|
+
location: await this.getFailureLocation(t)
|
|
7875
7982
|
};
|
|
7876
|
-
});
|
|
7983
|
+
}));
|
|
7877
7984
|
if (tests2.some((t) => {
|
|
7878
7985
|
var _a2;
|
|
7879
7986
|
return ((_a2 = t.result) == null ? void 0 : _a2.state) === "run";
|
|
@@ -7924,12 +8031,13 @@ class JsonReporter {
|
|
|
7924
8031
|
this.ctx.logger.log(report);
|
|
7925
8032
|
}
|
|
7926
8033
|
}
|
|
7927
|
-
getFailureLocation(test) {
|
|
8034
|
+
async getFailureLocation(test) {
|
|
7928
8035
|
var _a;
|
|
7929
8036
|
const error = (_a = test.result) == null ? void 0 : _a.error;
|
|
7930
8037
|
if (!error)
|
|
7931
8038
|
return;
|
|
7932
8039
|
const stack = parseStacktrace(error);
|
|
8040
|
+
await interpretSourcePos(stack, this.ctx);
|
|
7933
8041
|
const frame = stack[stack.length - 1];
|
|
7934
8042
|
if (!frame)
|
|
7935
8043
|
return;
|
|
@@ -8064,13 +8172,19 @@ function removeInvalidXMLCharacters(value, removeDiscouragedChars) {
|
|
|
8064
8172
|
let regex = /((?:[\0-\x08\x0B\f\x0E-\x1F\uFFFD\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))/g;
|
|
8065
8173
|
value = String(value || "").replace(regex, "");
|
|
8066
8174
|
if (removeDiscouragedChars) {
|
|
8067
|
-
regex = new RegExp(
|
|
8175
|
+
regex = new RegExp(
|
|
8176
|
+
"([\\x7F-\\x84]|[\\x86-\\x9F]|[\\uFDD0-\\uFDEF]|(?:\\uD83F[\\uDFFE\\uDFFF])|(?:\\uD87F[\\uDFFE\\uDFFF])|(?:\\uD8BF[\\uDFFE\\uDFFF])|(?:\\uD8FF[\\uDFFE\\uDFFF])|(?:\\uD93F[\\uDFFE\\uDFFF])|(?:\\uD97F[\\uDFFE\\uDFFF])|(?:\\uD9BF[\\uDFFE\\uDFFF])|(?:\\uD9FF[\\uDFFE\\uDFFF])|(?:\\uDA3F[\\uDFFE\\uDFFF])|(?:\\uDA7F[\\uDFFE\\uDFFF])|(?:\\uDABF[\\uDFFE\\uDFFF])|(?:\\uDAFF[\\uDFFE\\uDFFF])|(?:\\uDB3F[\\uDFFE\\uDFFF])|(?:\\uDB7F[\\uDFFE\\uDFFF])|(?:\\uDBBF[\\uDFFE\\uDFFF])|(?:\\uDBFF[\\uDFFE\\uDFFF])(?:[\\0-\\t\\x0B\\f\\x0E-\\u2027\\u202A-\\uD7FF\\uE000-\\uFFFF]|[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF]))",
|
|
8177
|
+
"g"
|
|
8178
|
+
);
|
|
8068
8179
|
value = value.replace(regex, "");
|
|
8069
8180
|
}
|
|
8070
8181
|
return value;
|
|
8071
8182
|
}
|
|
8072
8183
|
function escapeXML(value) {
|
|
8073
|
-
return removeInvalidXMLCharacters(
|
|
8184
|
+
return removeInvalidXMLCharacters(
|
|
8185
|
+
String(value).replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">"),
|
|
8186
|
+
true
|
|
8187
|
+
);
|
|
8074
8188
|
}
|
|
8075
8189
|
function getDuration(task) {
|
|
8076
8190
|
var _a;
|
|
@@ -8110,7 +8224,8 @@ class JUnitReporter {
|
|
|
8110
8224
|
}
|
|
8111
8225
|
async writeErrorDetails(error) {
|
|
8112
8226
|
const errorName = error.name ?? error.nameStr ?? "Unknown Error";
|
|
8113
|
-
|
|
8227
|
+
const errorDetails = `${errorName}: ${error.message}`;
|
|
8228
|
+
await this.baseLog(escapeXML(errorDetails));
|
|
8114
8229
|
const stack = parseStacktrace(error);
|
|
8115
8230
|
for (const frame of stack) {
|
|
8116
8231
|
const pos = frame.sourcePos ?? frame;
|
|
@@ -8162,18 +8277,21 @@ class JUnitReporter {
|
|
|
8162
8277
|
await this.logger.log('<?xml version="1.0" encoding="UTF-8" ?>');
|
|
8163
8278
|
const transformed = files.map((file) => {
|
|
8164
8279
|
const tasks = file.tasks.flatMap((task) => flattenTasks$1(task));
|
|
8165
|
-
const stats = tasks.reduce(
|
|
8166
|
-
|
|
8167
|
-
|
|
8168
|
-
|
|
8169
|
-
|
|
8170
|
-
|
|
8171
|
-
|
|
8172
|
-
|
|
8173
|
-
|
|
8174
|
-
|
|
8175
|
-
|
|
8176
|
-
|
|
8280
|
+
const stats = tasks.reduce(
|
|
8281
|
+
(stats2, task) => {
|
|
8282
|
+
var _a, _b;
|
|
8283
|
+
return {
|
|
8284
|
+
passed: stats2.passed + Number(((_a = task.result) == null ? void 0 : _a.state) === "pass"),
|
|
8285
|
+
failures: stats2.failures + Number(((_b = task.result) == null ? void 0 : _b.state) === "fail"),
|
|
8286
|
+
skipped: stats2.skipped + Number(task.mode === "skip" || task.mode === "todo")
|
|
8287
|
+
};
|
|
8288
|
+
},
|
|
8289
|
+
{
|
|
8290
|
+
passed: 0,
|
|
8291
|
+
failures: 0,
|
|
8292
|
+
skipped: 0
|
|
8293
|
+
}
|
|
8294
|
+
);
|
|
8177
8295
|
return {
|
|
8178
8296
|
...file,
|
|
8179
8297
|
tasks,
|
|
@@ -8223,11 +8341,73 @@ class TapFlatReporter extends TapReporter {
|
|
|
8223
8341
|
}
|
|
8224
8342
|
}
|
|
8225
8343
|
|
|
8344
|
+
class JsonReporter {
|
|
8345
|
+
constructor() {
|
|
8346
|
+
this.start = 0;
|
|
8347
|
+
}
|
|
8348
|
+
onInit(ctx) {
|
|
8349
|
+
this.ctx = ctx;
|
|
8350
|
+
}
|
|
8351
|
+
async logTasks(files) {
|
|
8352
|
+
var _a;
|
|
8353
|
+
const suites = getSuites(files);
|
|
8354
|
+
const numTotalTestSuites = suites.length;
|
|
8355
|
+
const tests = getTests(files);
|
|
8356
|
+
const numTotalTests = tests.length;
|
|
8357
|
+
const testResults = {};
|
|
8358
|
+
const outputFile = getOutputFile(this.ctx, "json");
|
|
8359
|
+
for (const file of files) {
|
|
8360
|
+
const tests2 = getTests([file]);
|
|
8361
|
+
for (const test of tests2) {
|
|
8362
|
+
const res = (_a = test.result) == null ? void 0 : _a.benchmark;
|
|
8363
|
+
if (!res || test.mode === "skip")
|
|
8364
|
+
continue;
|
|
8365
|
+
if (!outputFile)
|
|
8366
|
+
res.samples = "ignore on terminal";
|
|
8367
|
+
testResults[test.suite.name] = (testResults[test.suite.name] || []).concat(res);
|
|
8368
|
+
}
|
|
8369
|
+
if (tests2.some((t) => {
|
|
8370
|
+
var _a2;
|
|
8371
|
+
return ((_a2 = t.result) == null ? void 0 : _a2.state) === "run";
|
|
8372
|
+
})) {
|
|
8373
|
+
this.ctx.logger.warn("WARNING: Some tests are still running when generating the json report.This is likely an internal bug in Vitest.Please report it to https://github.com/vitest-dev/vitest/issues");
|
|
8374
|
+
}
|
|
8375
|
+
}
|
|
8376
|
+
const result = {
|
|
8377
|
+
numTotalTestSuites,
|
|
8378
|
+
numTotalTests,
|
|
8379
|
+
testResults
|
|
8380
|
+
};
|
|
8381
|
+
await this.writeReport(JSON.stringify(result, null, 2));
|
|
8382
|
+
}
|
|
8383
|
+
async onFinished(files = this.ctx.state.getFiles()) {
|
|
8384
|
+
await this.logTasks(files);
|
|
8385
|
+
}
|
|
8386
|
+
async writeReport(report) {
|
|
8387
|
+
const outputFile = getOutputFile(this.ctx, "json");
|
|
8388
|
+
if (outputFile) {
|
|
8389
|
+
const reportFile = resolve(this.ctx.config.root, outputFile);
|
|
8390
|
+
const outputDirectory = dirname(reportFile);
|
|
8391
|
+
if (!existsSync(outputDirectory))
|
|
8392
|
+
await promises.mkdir(outputDirectory, { recursive: true });
|
|
8393
|
+
await promises.writeFile(reportFile, report, "utf-8");
|
|
8394
|
+
this.ctx.logger.log(`json report written to ${reportFile}`);
|
|
8395
|
+
} else {
|
|
8396
|
+
this.ctx.logger.log(report);
|
|
8397
|
+
}
|
|
8398
|
+
}
|
|
8399
|
+
}
|
|
8400
|
+
|
|
8401
|
+
const BenchmarkReportsMap = {
|
|
8402
|
+
default: VerboseReporter,
|
|
8403
|
+
json: JsonReporter
|
|
8404
|
+
};
|
|
8405
|
+
|
|
8226
8406
|
const ReportersMap = {
|
|
8227
8407
|
"default": DefaultReporter,
|
|
8228
8408
|
"verbose": VerboseReporter,
|
|
8229
8409
|
"dot": DotReporter,
|
|
8230
|
-
"json": JsonReporter,
|
|
8410
|
+
"json": JsonReporter$1,
|
|
8231
8411
|
"tap": TapReporter,
|
|
8232
8412
|
"tap-flat": TapFlatReporter,
|
|
8233
8413
|
"junit": JUnitReporter
|
|
@@ -8259,6 +8439,21 @@ function createReporters(reporterReferences, runner) {
|
|
|
8259
8439
|
});
|
|
8260
8440
|
return Promise.all(promisedReporters);
|
|
8261
8441
|
}
|
|
8442
|
+
function createBenchmarkReporters(reporterReferences, runner) {
|
|
8443
|
+
const promisedReporters = reporterReferences.map(async (referenceOrInstance) => {
|
|
8444
|
+
if (typeof referenceOrInstance === "string") {
|
|
8445
|
+
if (referenceOrInstance in BenchmarkReportsMap) {
|
|
8446
|
+
const BuiltinReporter = BenchmarkReportsMap[referenceOrInstance];
|
|
8447
|
+
return new BuiltinReporter();
|
|
8448
|
+
} else {
|
|
8449
|
+
const CustomReporter = await loadCustomReporterModule(referenceOrInstance, runner);
|
|
8450
|
+
return new CustomReporter();
|
|
8451
|
+
}
|
|
8452
|
+
}
|
|
8453
|
+
return referenceOrInstance;
|
|
8454
|
+
});
|
|
8455
|
+
return Promise.all(promisedReporters);
|
|
8456
|
+
}
|
|
8262
8457
|
|
|
8263
8458
|
const isAggregateError = (err) => {
|
|
8264
8459
|
if (typeof AggregateError !== "undefined" && err instanceof AggregateError)
|
|
@@ -8361,6 +8556,12 @@ class StateManager {
|
|
|
8361
8556
|
|
|
8362
8557
|
const defaultInclude = ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"];
|
|
8363
8558
|
const defaultExclude = ["**/node_modules/**", "**/dist/**", "**/cypress/**", "**/.{idea,git,cache,output,temp}/**"];
|
|
8559
|
+
const benchmarkConfigDefaults = {
|
|
8560
|
+
include: ["**/*.{bench,benchmark}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
|
|
8561
|
+
exclude: defaultExclude,
|
|
8562
|
+
includeSource: [],
|
|
8563
|
+
reporters: ["default"]
|
|
8564
|
+
};
|
|
8364
8565
|
const defaultCoverageExcludes = [
|
|
8365
8566
|
"coverage/**",
|
|
8366
8567
|
"dist/**",
|
|
@@ -8383,7 +8584,7 @@ const coverageConfigDefaults = {
|
|
|
8383
8584
|
reportsDirectory: "./coverage",
|
|
8384
8585
|
excludeNodeModules: true,
|
|
8385
8586
|
exclude: defaultCoverageExcludes,
|
|
8386
|
-
reporter: ["text", "html", "clover"],
|
|
8587
|
+
reporter: ["text", "html", "clover", "json"],
|
|
8387
8588
|
allowExternal: false,
|
|
8388
8589
|
extension: [".js", ".cjs", ".mjs", ".ts", ".tsx", ".jsx", ".vue", ".svelte"]
|
|
8389
8590
|
};
|
|
@@ -8429,7 +8630,7 @@ const config = {
|
|
|
8429
8630
|
uiBase: "/__vitest__/",
|
|
8430
8631
|
open: true,
|
|
8431
8632
|
css: {
|
|
8432
|
-
include: [
|
|
8633
|
+
include: []
|
|
8433
8634
|
},
|
|
8434
8635
|
coverage: coverageConfigDefaults,
|
|
8435
8636
|
fakeTimers: fakeTimersDefaults,
|
|
@@ -8631,18 +8832,23 @@ function resolveApiConfig(options) {
|
|
|
8631
8832
|
}
|
|
8632
8833
|
return api;
|
|
8633
8834
|
}
|
|
8634
|
-
function resolveConfig(options, viteConfig) {
|
|
8635
|
-
var _a, _b, _c, _d, _e;
|
|
8835
|
+
function resolveConfig(mode, options, viteConfig) {
|
|
8836
|
+
var _a, _b, _c, _d, _e, _f;
|
|
8636
8837
|
if (options.dom) {
|
|
8637
8838
|
if (((_a = viteConfig.test) == null ? void 0 : _a.environment) != null && viteConfig.test.environment !== "happy-dom") {
|
|
8638
|
-
console.warn(
|
|
8839
|
+
console.warn(
|
|
8840
|
+
picocolors.exports.yellow(
|
|
8841
|
+
`${picocolors.exports.inverse(picocolors.exports.yellow(" Vitest "))} Your config.test.environment ("${viteConfig.test.environment}") conflicts with --dom flag ("happy-dom"), ignoring "${viteConfig.test.environment}"`
|
|
8842
|
+
)
|
|
8843
|
+
);
|
|
8639
8844
|
}
|
|
8640
8845
|
options.environment = "happy-dom";
|
|
8641
8846
|
}
|
|
8642
8847
|
const resolved = {
|
|
8643
8848
|
...configDefaults,
|
|
8644
8849
|
...options,
|
|
8645
|
-
root: viteConfig.root
|
|
8850
|
+
root: viteConfig.root,
|
|
8851
|
+
mode
|
|
8646
8852
|
};
|
|
8647
8853
|
if (viteConfig.base !== "/")
|
|
8648
8854
|
resolved.base = viteConfig.base;
|
|
@@ -8683,7 +8889,21 @@ function resolveConfig(options, viteConfig) {
|
|
|
8683
8889
|
resolved.maxThreads = parseInt(process.env.VITEST_MAX_THREADS);
|
|
8684
8890
|
if (process.env.VITEST_MIN_THREADS)
|
|
8685
8891
|
resolved.minThreads = parseInt(process.env.VITEST_MIN_THREADS);
|
|
8686
|
-
|
|
8892
|
+
if (mode === "benchmark") {
|
|
8893
|
+
resolved.benchmark = {
|
|
8894
|
+
...benchmarkConfigDefaults,
|
|
8895
|
+
...resolved.benchmark
|
|
8896
|
+
};
|
|
8897
|
+
resolved.coverage.enabled = false;
|
|
8898
|
+
resolved.include = resolved.benchmark.include;
|
|
8899
|
+
resolved.exclude = resolved.benchmark.exclude;
|
|
8900
|
+
resolved.includeSource = resolved.benchmark.includeSource;
|
|
8901
|
+
}
|
|
8902
|
+
resolved.setupFiles = toArray$1(resolved.setupFiles || []).map(
|
|
8903
|
+
(file) => normalize(
|
|
8904
|
+
resolveModule(file, { paths: [resolved.root] }) ?? resolve(resolved.root, file)
|
|
8905
|
+
)
|
|
8906
|
+
);
|
|
8687
8907
|
resolved.api = resolveApiConfig(options);
|
|
8688
8908
|
if (options.related)
|
|
8689
8909
|
resolved.related = toArray$1(options.related).map((file) => resolve(resolved.root, file));
|
|
@@ -8696,12 +8916,14 @@ function resolveConfig(options, viteConfig) {
|
|
|
8696
8916
|
if (resolved.changed)
|
|
8697
8917
|
resolved.passWithNoTests ?? (resolved.passWithNoTests = true);
|
|
8698
8918
|
resolved.css ?? (resolved.css = {});
|
|
8699
|
-
if (typeof resolved.css === "object")
|
|
8700
|
-
(_d = resolved.css).
|
|
8919
|
+
if (typeof resolved.css === "object") {
|
|
8920
|
+
(_d = resolved.css).modules ?? (_d.modules = {});
|
|
8921
|
+
(_e = resolved.css.modules).classNameStrategy ?? (_e.classNameStrategy = "stable");
|
|
8922
|
+
}
|
|
8701
8923
|
resolved.cache ?? (resolved.cache = { dir: "" });
|
|
8702
8924
|
if (resolved.cache)
|
|
8703
8925
|
resolved.cache.dir = VitestCache.resolveCacheDir(resolved.root, resolved.cache.dir);
|
|
8704
|
-
if (!((
|
|
8926
|
+
if (!((_f = resolved.sequence) == null ? void 0 : _f.sequencer)) {
|
|
8705
8927
|
resolved.sequence ?? (resolved.sequence = {});
|
|
8706
8928
|
resolved.sequence.sequencer = resolved.sequence.shuffle ? RandomSequencer : BaseSequencer;
|
|
8707
8929
|
}
|
|
@@ -9194,7 +9416,7 @@ createLogUpdate(process$1.stdout);
|
|
|
9194
9416
|
|
|
9195
9417
|
createLogUpdate(process$1.stderr);
|
|
9196
9418
|
|
|
9197
|
-
var version = "0.
|
|
9419
|
+
var version = "0.23.2";
|
|
9198
9420
|
|
|
9199
9421
|
function fileFromParsedStack(stack) {
|
|
9200
9422
|
var _a, _b;
|
|
@@ -9213,7 +9435,9 @@ async function printError(error, ctx, options = {}) {
|
|
|
9213
9435
|
}
|
|
9214
9436
|
const stacks = parseStacktrace(e, fullStack);
|
|
9215
9437
|
await interpretSourcePos(stacks, ctx);
|
|
9216
|
-
const nearest = stacks.find(
|
|
9438
|
+
const nearest = stacks.find(
|
|
9439
|
+
(stack) => ctx.server.moduleGraph.getModuleById(stack.file) && existsSync(stack.file)
|
|
9440
|
+
);
|
|
9217
9441
|
const errorProperties = getErrorProperties(e);
|
|
9218
9442
|
if (type)
|
|
9219
9443
|
printErrorType(type, ctx);
|
|
@@ -9227,12 +9451,12 @@ async function printError(error, ctx, options = {}) {
|
|
|
9227
9451
|
}
|
|
9228
9452
|
}
|
|
9229
9453
|
});
|
|
9230
|
-
if (e.cause) {
|
|
9454
|
+
if (e.cause && "name" in e.cause) {
|
|
9231
9455
|
e.cause.name = `Caused by: ${e.cause.name}`;
|
|
9232
9456
|
await printError(e.cause, ctx, { fullStack, showCodeFrame: false });
|
|
9233
9457
|
}
|
|
9234
9458
|
handleImportOutsideModuleError(e.stack || e.stackStr || "", ctx);
|
|
9235
|
-
if (e.showDiff) {
|
|
9459
|
+
if (e.showDiff || e.showDiff === void 0 && e.actual && e.expected) {
|
|
9236
9460
|
displayDiff(stringify$5(e.actual), stringify$5(e.expected), ctx.logger.console, {
|
|
9237
9461
|
outputTruncateLength: ctx.config.outputTruncateLength,
|
|
9238
9462
|
outputDiffLines: ctx.config.outputDiffLines
|
|
@@ -9281,7 +9505,8 @@ function handleImportOutsideModuleError(stack, ctx) {
|
|
|
9281
9505
|
name = name.split("/").slice(0, 2).join("/");
|
|
9282
9506
|
else
|
|
9283
9507
|
name = name.split("/")[0];
|
|
9284
|
-
ctx.logger.error(picocolors.exports.yellow(
|
|
9508
|
+
ctx.logger.error(picocolors.exports.yellow(
|
|
9509
|
+
`Module ${path} seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue to the package ${picocolors.exports.bold(`"${name}"`)} asking them to ship the file in .mjs extension or add "type": "module" in their package.json.
|
|
9285
9510
|
|
|
9286
9511
|
As a temporary workaround you can try to inline the package by updating your config:
|
|
9287
9512
|
|
|
@@ -9294,7 +9519,8 @@ As a temporary workaround you can try to inline the package by updating your con
|
|
|
9294
9519
|
}
|
|
9295
9520
|
}
|
|
9296
9521
|
}
|
|
9297
|
-
`)
|
|
9522
|
+
`)
|
|
9523
|
+
));
|
|
9298
9524
|
}
|
|
9299
9525
|
function displayDiff(actual, expected, console, options) {
|
|
9300
9526
|
console.error(picocolors.exports.gray(unifiedDiff(actual, expected, options)) + "\n");
|
|
@@ -9421,9 +9647,11 @@ class Logger {
|
|
|
9421
9647
|
if (config.watchExclude)
|
|
9422
9648
|
this.console.error(picocolors.exports.dim("watch exclude: ") + picocolors.exports.yellow(config.watchExclude.join(comma)));
|
|
9423
9649
|
if (config.passWithNoTests)
|
|
9424
|
-
this.log(
|
|
9650
|
+
this.log(`No ${config.mode} files found, exiting with code 0
|
|
9651
|
+
`);
|
|
9425
9652
|
else
|
|
9426
|
-
this.error(picocolors.exports.red(
|
|
9653
|
+
this.error(picocolors.exports.red(`
|
|
9654
|
+
No ${config.mode} files found, exiting with code 1`));
|
|
9427
9655
|
}
|
|
9428
9656
|
printBanner() {
|
|
9429
9657
|
var _a, _b, _c;
|
|
@@ -9442,9 +9670,11 @@ class Logger {
|
|
|
9442
9670
|
this.log();
|
|
9443
9671
|
}
|
|
9444
9672
|
async printUnhandledErrors(errors) {
|
|
9445
|
-
const errorMessage = picocolors.exports.red(picocolors.exports.bold(
|
|
9673
|
+
const errorMessage = picocolors.exports.red(picocolors.exports.bold(
|
|
9674
|
+
`
|
|
9446
9675
|
Vitest caught ${errors.length} unhandled error${errors.length > 1 ? "s" : ""} during the test run.
|
|
9447
|
-
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.`
|
|
9676
|
+
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.`
|
|
9677
|
+
));
|
|
9448
9678
|
this.log(picocolors.exports.red(divider(picocolors.exports.bold(picocolors.exports.inverse(" Unhandled Errors ")))));
|
|
9449
9679
|
this.log(errorMessage);
|
|
9450
9680
|
await Promise.all(errors.map(async (err) => {
|
|
@@ -9456,7 +9686,8 @@ This might cause false positive tests. Resolve unhandled errors to make sure you
|
|
|
9456
9686
|
|
|
9457
9687
|
const WATCHER_DEBOUNCE = 100;
|
|
9458
9688
|
class Vitest {
|
|
9459
|
-
constructor() {
|
|
9689
|
+
constructor(mode) {
|
|
9690
|
+
this.mode = mode;
|
|
9460
9691
|
this.config = void 0;
|
|
9461
9692
|
this.server = void 0;
|
|
9462
9693
|
this.state = void 0;
|
|
@@ -9480,7 +9711,7 @@ class Vitest {
|
|
|
9480
9711
|
this.restartsCount += 1;
|
|
9481
9712
|
(_b = this.pool) == null ? void 0 : _b.close();
|
|
9482
9713
|
this.pool = void 0;
|
|
9483
|
-
const resolved = resolveConfig(options, server.config);
|
|
9714
|
+
const resolved = resolveConfig(this.mode, options, server.config);
|
|
9484
9715
|
this.server = server;
|
|
9485
9716
|
this.config = resolved;
|
|
9486
9717
|
this.state = new StateManager();
|
|
@@ -9515,9 +9746,8 @@ class Vitest {
|
|
|
9515
9746
|
}
|
|
9516
9747
|
});
|
|
9517
9748
|
}
|
|
9518
|
-
this.reporters = await createReporters(resolved.reporters, this.runner);
|
|
9749
|
+
this.reporters = resolved.mode === "benchmark" ? await createBenchmarkReporters(toArray$1((_c = resolved.benchmark) == null ? void 0 : _c.reporters), this.runner) : await createReporters(resolved.reporters, this.runner);
|
|
9519
9750
|
this.runningPromise = void 0;
|
|
9520
|
-
await ((_c = this.coverageProvider) == null ? void 0 : _c.clean(this.config.coverage.clean));
|
|
9521
9751
|
this.cache.results.setConfig(resolved.root, resolved.cache);
|
|
9522
9752
|
try {
|
|
9523
9753
|
await this.cache.results.readFromCache();
|
|
@@ -9536,29 +9766,36 @@ class Vitest {
|
|
|
9536
9766
|
return this.coverageProvider;
|
|
9537
9767
|
}
|
|
9538
9768
|
getSerializableConfig() {
|
|
9539
|
-
return deepMerge(
|
|
9540
|
-
|
|
9541
|
-
|
|
9542
|
-
|
|
9543
|
-
|
|
9544
|
-
|
|
9769
|
+
return deepMerge(
|
|
9770
|
+
{
|
|
9771
|
+
...this.config,
|
|
9772
|
+
reporters: [],
|
|
9773
|
+
snapshotOptions: {
|
|
9774
|
+
...this.config.snapshotOptions,
|
|
9775
|
+
resolveSnapshotPath: void 0
|
|
9776
|
+
},
|
|
9777
|
+
onConsoleLog: void 0,
|
|
9778
|
+
sequence: {
|
|
9779
|
+
...this.config.sequence,
|
|
9780
|
+
sequencer: void 0
|
|
9781
|
+
}
|
|
9545
9782
|
},
|
|
9546
|
-
|
|
9547
|
-
|
|
9548
|
-
...this.config.sequence,
|
|
9549
|
-
sequencer: void 0
|
|
9550
|
-
}
|
|
9551
|
-
}, this.configOverride || {});
|
|
9783
|
+
this.configOverride || {}
|
|
9784
|
+
);
|
|
9552
9785
|
}
|
|
9553
9786
|
async start(filters) {
|
|
9787
|
+
var _a;
|
|
9554
9788
|
try {
|
|
9555
9789
|
await this.initCoverageProvider();
|
|
9790
|
+
await ((_a = this.coverageProvider) == null ? void 0 : _a.clean(this.config.coverage.clean));
|
|
9556
9791
|
} catch (e) {
|
|
9557
9792
|
this.logger.error(e);
|
|
9558
9793
|
process.exit(1);
|
|
9559
9794
|
}
|
|
9560
9795
|
await this.report("onInit", this);
|
|
9561
|
-
const files = await this.filterTestsBySource(
|
|
9796
|
+
const files = await this.filterTestsBySource(
|
|
9797
|
+
await this.globTestFiles(filters)
|
|
9798
|
+
);
|
|
9562
9799
|
if (!files.length) {
|
|
9563
9800
|
const exitCode = this.config.passWithNoTests ? 0 : 1;
|
|
9564
9801
|
this.logger.printNoTestFound(filters);
|
|
@@ -9594,7 +9831,7 @@ class Vitest {
|
|
|
9594
9831
|
}
|
|
9595
9832
|
async filterTestsBySource(tests) {
|
|
9596
9833
|
if (this.config.changed && !this.config.related) {
|
|
9597
|
-
const { VitestGit } = await import('./chunk-node-git.
|
|
9834
|
+
const { VitestGit } = await import('./chunk-node-git.a44b4872.mjs');
|
|
9598
9835
|
const vitestGit = new VitestGit(this.config.root);
|
|
9599
9836
|
const related2 = await vitestGit.findChangedFiles({
|
|
9600
9837
|
changedSince: this.config.changed
|
|
@@ -9613,10 +9850,12 @@ class Vitest {
|
|
|
9613
9850
|
return tests;
|
|
9614
9851
|
if (!related.length)
|
|
9615
9852
|
return [];
|
|
9616
|
-
const testDeps = await Promise.all(
|
|
9617
|
-
|
|
9618
|
-
|
|
9619
|
-
|
|
9853
|
+
const testDeps = await Promise.all(
|
|
9854
|
+
tests.map(async (filepath) => {
|
|
9855
|
+
const deps = await this.getTestDependencies(filepath);
|
|
9856
|
+
return [filepath, deps];
|
|
9857
|
+
})
|
|
9858
|
+
);
|
|
9620
9859
|
const runningTests = [];
|
|
9621
9860
|
for (const [filepath, deps] of testDeps) {
|
|
9622
9861
|
if (deps.size && related.some((path) => path === filepath || deps.has(path)))
|
|
@@ -9662,6 +9901,13 @@ class Vitest {
|
|
|
9662
9901
|
this.config.testNamePattern = pattern ? new RegExp(pattern) : void 0;
|
|
9663
9902
|
await this.rerunFiles(files, trigger);
|
|
9664
9903
|
}
|
|
9904
|
+
async changeFilenamePattern(pattern) {
|
|
9905
|
+
const files = this.state.getFilepaths();
|
|
9906
|
+
if (!pattern)
|
|
9907
|
+
return await this.rerunFiles(files, "reset filename pattern");
|
|
9908
|
+
const filteredFiles = await this.globTestFiles([pattern]);
|
|
9909
|
+
await this.rerunFiles(filteredFiles, "change filename pattern");
|
|
9910
|
+
}
|
|
9665
9911
|
async rerunFailed() {
|
|
9666
9912
|
await this.rerunFiles(this.state.getFailedFilepaths(), "rerun failed");
|
|
9667
9913
|
}
|
|
@@ -9800,22 +10046,26 @@ class Vitest {
|
|
|
9800
10046
|
async report(name, ...args) {
|
|
9801
10047
|
await Promise.all(this.reporters.map((r) => {
|
|
9802
10048
|
var _a;
|
|
9803
|
-
return (_a = r[name]) == null ? void 0 : _a.call(
|
|
10049
|
+
return (_a = r[name]) == null ? void 0 : _a.call(
|
|
10050
|
+
r,
|
|
10051
|
+
...args
|
|
10052
|
+
);
|
|
9804
10053
|
}));
|
|
9805
10054
|
}
|
|
9806
10055
|
async globTestFiles(filters = []) {
|
|
10056
|
+
const { include, exclude, includeSource } = this.config;
|
|
9807
10057
|
const globOptions = {
|
|
9808
10058
|
absolute: true,
|
|
9809
10059
|
cwd: this.config.dir || this.config.root,
|
|
9810
|
-
ignore:
|
|
10060
|
+
ignore: exclude
|
|
9811
10061
|
};
|
|
9812
|
-
let testFiles = await out(
|
|
10062
|
+
let testFiles = await out(include, globOptions);
|
|
9813
10063
|
if (filters.length && process.platform === "win32")
|
|
9814
10064
|
filters = filters.map((f) => toNamespacedPath(f));
|
|
9815
10065
|
if (filters.length)
|
|
9816
10066
|
testFiles = testFiles.filter((i) => filters.some((f) => i.includes(f)));
|
|
9817
|
-
if (
|
|
9818
|
-
let files = await out(
|
|
10067
|
+
if (includeSource) {
|
|
10068
|
+
let files = await out(includeSource, globOptions);
|
|
9819
10069
|
if (filters.length)
|
|
9820
10070
|
files = files.filter((i) => filters.some((f) => i.includes(f)));
|
|
9821
10071
|
await Promise.all(files.map(async (file) => {
|
|
@@ -9851,13 +10101,27 @@ class Vitest {
|
|
|
9851
10101
|
}
|
|
9852
10102
|
}
|
|
9853
10103
|
|
|
10104
|
+
function generateCssFilenameHash(filepath) {
|
|
10105
|
+
return createHash("md5").update(filepath).digest("hex").slice(0, 6);
|
|
10106
|
+
}
|
|
10107
|
+
function generateScopedClassName(strategy, name, filename) {
|
|
10108
|
+
if (strategy === "scoped")
|
|
10109
|
+
return null;
|
|
10110
|
+
if (strategy === "non-scoped")
|
|
10111
|
+
return name;
|
|
10112
|
+
const hash = generateCssFilenameHash(filename);
|
|
10113
|
+
return `_${name}_${hash}`;
|
|
10114
|
+
}
|
|
10115
|
+
|
|
9854
10116
|
const EnvReplacerPlugin = () => {
|
|
9855
10117
|
return {
|
|
9856
10118
|
name: "vitest:env-replacer",
|
|
9857
10119
|
enforce: "pre",
|
|
9858
10120
|
transform(code) {
|
|
10121
|
+
if (!/\bimport\.meta\.env\b/g.test(code))
|
|
10122
|
+
return null;
|
|
9859
10123
|
let s = null;
|
|
9860
|
-
const envs = code.matchAll(/\bimport\.meta\.env\b/g);
|
|
10124
|
+
const envs = stripLiteral(code).matchAll(/\bimport\.meta\.env\b/g);
|
|
9861
10125
|
for (const env of envs) {
|
|
9862
10126
|
s || (s = new MagicString(code));
|
|
9863
10127
|
const startIndex = env.index;
|
|
@@ -10054,9 +10318,19 @@ function getIndexStatus(code, from) {
|
|
|
10054
10318
|
|
|
10055
10319
|
const cssLangs = "\\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\\?)";
|
|
10056
10320
|
const cssLangRE = new RegExp(cssLangs);
|
|
10321
|
+
const cssModuleRE = new RegExp(`\\.module${cssLangs}`);
|
|
10057
10322
|
const isCSS = (id) => {
|
|
10058
10323
|
return cssLangRE.test(id);
|
|
10059
10324
|
};
|
|
10325
|
+
const isCSSModule = (id) => {
|
|
10326
|
+
return cssModuleRE.test(id);
|
|
10327
|
+
};
|
|
10328
|
+
const getCSSModuleProxyReturn = (strategy, filename) => {
|
|
10329
|
+
if (strategy === "non-scoped")
|
|
10330
|
+
return "style";
|
|
10331
|
+
const hash = generateCssFilenameHash(filename);
|
|
10332
|
+
return `\`_\${style}_${hash}\``;
|
|
10333
|
+
};
|
|
10060
10334
|
function CSSEnablerPlugin(ctx) {
|
|
10061
10335
|
const shouldProcessCSS = (id) => {
|
|
10062
10336
|
const { css } = ctx.config;
|
|
@@ -10068,16 +10342,38 @@ function CSSEnablerPlugin(ctx) {
|
|
|
10068
10342
|
return true;
|
|
10069
10343
|
return false;
|
|
10070
10344
|
};
|
|
10071
|
-
return
|
|
10072
|
-
|
|
10073
|
-
|
|
10074
|
-
|
|
10075
|
-
|
|
10076
|
-
|
|
10077
|
-
|
|
10345
|
+
return [
|
|
10346
|
+
{
|
|
10347
|
+
name: "vitest:css-disable",
|
|
10348
|
+
enforce: "pre",
|
|
10349
|
+
transform(code, id) {
|
|
10350
|
+
if (!isCSS(id))
|
|
10351
|
+
return;
|
|
10352
|
+
if (!shouldProcessCSS(id))
|
|
10353
|
+
return { code: "" };
|
|
10354
|
+
}
|
|
10355
|
+
},
|
|
10356
|
+
{
|
|
10357
|
+
name: "vitest:css-empty-post",
|
|
10358
|
+
enforce: "post",
|
|
10359
|
+
transform(_, id) {
|
|
10360
|
+
var _a;
|
|
10361
|
+
if (!isCSS(id) || shouldProcessCSS(id))
|
|
10362
|
+
return;
|
|
10363
|
+
if (isCSSModule(id)) {
|
|
10364
|
+
const scopeStrategy = typeof ctx.config.css !== "boolean" && ((_a = ctx.config.css.modules) == null ? void 0 : _a.classNameStrategy) || "stable";
|
|
10365
|
+
const proxyReturn = getCSSModuleProxyReturn(scopeStrategy, relative(ctx.config.root, id));
|
|
10366
|
+
const code = `export default new Proxy(Object.create(null), {
|
|
10367
|
+
get(_, style) {
|
|
10368
|
+
return ${proxyReturn};
|
|
10369
|
+
},
|
|
10370
|
+
})`;
|
|
10371
|
+
return { code };
|
|
10372
|
+
}
|
|
10078
10373
|
return { code: "" };
|
|
10374
|
+
}
|
|
10079
10375
|
}
|
|
10080
|
-
|
|
10376
|
+
];
|
|
10081
10377
|
}
|
|
10082
10378
|
|
|
10083
10379
|
function CoverageTransform(ctx) {
|
|
@@ -10090,15 +10386,17 @@ function CoverageTransform(ctx) {
|
|
|
10090
10386
|
};
|
|
10091
10387
|
}
|
|
10092
10388
|
|
|
10093
|
-
async function VitestPlugin(options = {}, ctx = new Vitest()) {
|
|
10094
|
-
|
|
10389
|
+
async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
|
|
10390
|
+
const getRoot = () => {
|
|
10095
10391
|
var _a;
|
|
10096
|
-
|
|
10392
|
+
return ((_a = ctx.config) == null ? void 0 : _a.root) || options.root || process.cwd();
|
|
10393
|
+
};
|
|
10394
|
+
async function UIPlugin() {
|
|
10395
|
+
await ensurePackageInstalled("@vitest/ui", getRoot());
|
|
10097
10396
|
return (await import('@vitest/ui')).default(options.uiBase);
|
|
10098
10397
|
}
|
|
10099
10398
|
async function BrowserPlugin() {
|
|
10100
|
-
|
|
10101
|
-
await ensurePackageInstalled("@vitest/browser", ((_a = ctx.config) == null ? void 0 : _a.root) || options.root || process.cwd());
|
|
10399
|
+
await ensurePackageInstalled("@vitest/browser", getRoot());
|
|
10102
10400
|
return (await import('@vitest/browser')).default("/");
|
|
10103
10401
|
}
|
|
10104
10402
|
return [
|
|
@@ -10109,6 +10407,7 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
|
|
|
10109
10407
|
this.meta.watchMode = false;
|
|
10110
10408
|
},
|
|
10111
10409
|
config(viteConfig) {
|
|
10410
|
+
var _a, _b, _c;
|
|
10112
10411
|
const preOptions = deepMerge({}, configDefaults, options, viteConfig.test ?? {});
|
|
10113
10412
|
preOptions.api = resolveApiConfig(preOptions);
|
|
10114
10413
|
if (viteConfig.define) {
|
|
@@ -10158,6 +10457,15 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
|
|
|
10158
10457
|
preTransformRequests: false
|
|
10159
10458
|
}
|
|
10160
10459
|
};
|
|
10460
|
+
const classNameStrategy = preOptions.css && ((_b = (_a = preOptions.css) == null ? void 0 : _a.modules) == null ? void 0 : _b.classNameStrategy);
|
|
10461
|
+
if (classNameStrategy !== "scoped") {
|
|
10462
|
+
config.css ?? (config.css = {});
|
|
10463
|
+
(_c = config.css).modules ?? (_c.modules = {});
|
|
10464
|
+
config.css.modules.generateScopedName = (name, filename) => {
|
|
10465
|
+
const root = getRoot();
|
|
10466
|
+
return generateScopedClassName(classNameStrategy, name, relative(root, filename));
|
|
10467
|
+
};
|
|
10468
|
+
}
|
|
10161
10469
|
if (!options.browser) {
|
|
10162
10470
|
Object.assign(config, {
|
|
10163
10471
|
cacheDir: void 0,
|
|
@@ -10176,7 +10484,12 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
|
|
|
10176
10484
|
viteConfigTest.run = true;
|
|
10177
10485
|
if ("alias" in viteConfigTest)
|
|
10178
10486
|
delete viteConfigTest.alias;
|
|
10179
|
-
options = deepMerge(
|
|
10487
|
+
options = deepMerge(
|
|
10488
|
+
{},
|
|
10489
|
+
configDefaults,
|
|
10490
|
+
viteConfigTest,
|
|
10491
|
+
options
|
|
10492
|
+
);
|
|
10180
10493
|
options.api = resolveApiConfig(options);
|
|
10181
10494
|
const { PROD, DEV, ...envs } = viteConfig.env;
|
|
10182
10495
|
(_a = process.env).PROD ?? (_a.PROD = PROD ? "1" : "");
|
|
@@ -10189,7 +10502,7 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
|
|
|
10189
10502
|
try {
|
|
10190
10503
|
await ctx.setServer(options, server);
|
|
10191
10504
|
if (options.api && options.watch)
|
|
10192
|
-
(await import('./chunk-api-setup.
|
|
10505
|
+
(await import('./chunk-api-setup.11cfd513.mjs')).setup(ctx);
|
|
10193
10506
|
} catch (err) {
|
|
10194
10507
|
ctx.logger.printError(err, true);
|
|
10195
10508
|
process.exit(1);
|
|
@@ -10202,21 +10515,21 @@ async function VitestPlugin(options = {}, ctx = new Vitest()) {
|
|
|
10202
10515
|
MocksPlugin(),
|
|
10203
10516
|
GlobalSetupPlugin(ctx),
|
|
10204
10517
|
...options.browser ? await BrowserPlugin() : [],
|
|
10205
|
-
CSSEnablerPlugin(ctx),
|
|
10518
|
+
...CSSEnablerPlugin(ctx),
|
|
10206
10519
|
CoverageTransform(ctx),
|
|
10207
10520
|
options.ui ? await UIPlugin() : null
|
|
10208
10521
|
].filter(notNullish);
|
|
10209
10522
|
}
|
|
10210
10523
|
|
|
10211
|
-
async function createVitest(options, viteOverrides = {}) {
|
|
10524
|
+
async function createVitest(mode, options, viteOverrides = {}) {
|
|
10212
10525
|
var _a;
|
|
10213
|
-
const ctx = new Vitest();
|
|
10526
|
+
const ctx = new Vitest(mode);
|
|
10214
10527
|
const root = resolve(options.root || process.cwd());
|
|
10215
10528
|
const configPath = options.config ? resolve(root, options.config) : await findUp(configFiles, { cwd: root });
|
|
10216
10529
|
const config = {
|
|
10217
10530
|
logLevel: "error",
|
|
10218
10531
|
configFile: configPath,
|
|
10219
|
-
mode: options.mode || process.env.NODE_ENV ||
|
|
10532
|
+
mode: options.mode || process.env.NODE_ENV || mode,
|
|
10220
10533
|
plugins: await VitestPlugin(options, ctx)
|
|
10221
10534
|
};
|
|
10222
10535
|
const server = await createServer(mergeConfig(config, mergeConfig(viteOverrides, { root: options.root })));
|
|
@@ -10231,16 +10544,20 @@ const keys = [
|
|
|
10231
10544
|
["a", "rerun all tests"],
|
|
10232
10545
|
["f", "rerun only failed tests"],
|
|
10233
10546
|
["u", "update snapshot"],
|
|
10547
|
+
["p", "filter by a filename"],
|
|
10234
10548
|
["t", "filter by a test name regex pattern"],
|
|
10235
10549
|
["q", "quit"]
|
|
10236
10550
|
];
|
|
10237
10551
|
function printShortcutsHelp() {
|
|
10238
|
-
stdout().write(
|
|
10552
|
+
stdout().write(
|
|
10553
|
+
`
|
|
10239
10554
|
${picocolors.exports.bold(" Watch Usage")}
|
|
10240
10555
|
${keys.map((i) => picocolors.exports.dim(" press ") + picocolors.exports.reset(picocolors.exports.bold(i[0])) + picocolors.exports.dim(` to ${i[1]}`)).join("\n")}
|
|
10241
|
-
`
|
|
10556
|
+
`
|
|
10557
|
+
);
|
|
10242
10558
|
}
|
|
10243
10559
|
function registerConsoleShortcuts(ctx) {
|
|
10560
|
+
let latestFilename = "";
|
|
10244
10561
|
async function _keypressHandler(str, key) {
|
|
10245
10562
|
if (str === "" || str === "\x1B" || key && key.ctrl && key.name === "c")
|
|
10246
10563
|
return ctx.exit(true);
|
|
@@ -10257,6 +10574,8 @@ function registerConsoleShortcuts(ctx) {
|
|
|
10257
10574
|
return ctx.rerunFailed();
|
|
10258
10575
|
if (name === "t")
|
|
10259
10576
|
return inputNamePattern();
|
|
10577
|
+
if (name === "p")
|
|
10578
|
+
return inputFilePattern();
|
|
10260
10579
|
if (name === "q")
|
|
10261
10580
|
return ctx.exit(true);
|
|
10262
10581
|
}
|
|
@@ -10274,6 +10593,18 @@ function registerConsoleShortcuts(ctx) {
|
|
|
10274
10593
|
await ctx.changeNamePattern(filter, void 0, "change pattern");
|
|
10275
10594
|
on();
|
|
10276
10595
|
}
|
|
10596
|
+
async function inputFilePattern() {
|
|
10597
|
+
off();
|
|
10598
|
+
const { filter = "" } = await prompts([{
|
|
10599
|
+
name: "filter",
|
|
10600
|
+
type: "text",
|
|
10601
|
+
message: "Input filename pattern",
|
|
10602
|
+
initial: latestFilename
|
|
10603
|
+
}]);
|
|
10604
|
+
latestFilename = filter;
|
|
10605
|
+
await ctx.changeFilenamePattern(filter);
|
|
10606
|
+
on();
|
|
10607
|
+
}
|
|
10277
10608
|
let rl;
|
|
10278
10609
|
function on() {
|
|
10279
10610
|
off();
|
|
@@ -10293,7 +10624,7 @@ function registerConsoleShortcuts(ctx) {
|
|
|
10293
10624
|
on();
|
|
10294
10625
|
}
|
|
10295
10626
|
|
|
10296
|
-
async function startVitest(cliFilters, options, viteOverrides) {
|
|
10627
|
+
async function startVitest(mode, cliFilters, options, viteOverrides) {
|
|
10297
10628
|
var _a;
|
|
10298
10629
|
process.env.TEST = "true";
|
|
10299
10630
|
process.env.VITEST = "true";
|
|
@@ -10309,8 +10640,8 @@ async function startVitest(cliFilters, options, viteOverrides) {
|
|
|
10309
10640
|
}
|
|
10310
10641
|
if (typeof options.coverage === "boolean")
|
|
10311
10642
|
options.coverage = { enabled: options.coverage };
|
|
10312
|
-
const ctx = await createVitest(options, viteOverrides);
|
|
10313
|
-
if (ctx.config.coverage.enabled) {
|
|
10643
|
+
const ctx = await createVitest(mode, options, viteOverrides);
|
|
10644
|
+
if (mode !== "benchmark" && ctx.config.coverage.enabled) {
|
|
10314
10645
|
const provider = ctx.config.coverage.provider || "c8";
|
|
10315
10646
|
if (typeof provider === "string") {
|
|
10316
10647
|
const requiredPackages = CoverageProviderMap[provider];
|
|
@@ -10320,12 +10651,10 @@ async function startVitest(cliFilters, options, viteOverrides) {
|
|
|
10320
10651
|
}
|
|
10321
10652
|
}
|
|
10322
10653
|
}
|
|
10323
|
-
|
|
10324
|
-
|
|
10325
|
-
|
|
10326
|
-
|
|
10327
|
-
return false;
|
|
10328
|
-
}
|
|
10654
|
+
const environmentPackage = getEnvPackageName(ctx.config.environment);
|
|
10655
|
+
if (environmentPackage && !await ensurePackageInstalled(environmentPackage, root)) {
|
|
10656
|
+
process.exitCode = 1;
|
|
10657
|
+
return false;
|
|
10329
10658
|
}
|
|
10330
10659
|
if (process.stdin.isTTY && ctx.config.watch)
|
|
10331
10660
|
registerConsoleShortcuts(ctx);
|