vitest 0.0.113 → 0.0.117
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 +61 -33
- package/dist/cli.js +1112 -35
- package/dist/{constants-900abe4a.js → constants-080f26e8.js} +2 -2
- package/dist/{diff-9c43ab50.js → diff-80c47cfa.js} +1 -2
- package/dist/entry.js +68 -26
- package/dist/{global-75208c77.js → global-d95ee155.js} +8 -9
- package/dist/{index-09437c50.js → index-2b1f526f.js} +2 -2
- package/dist/{index-c3f2f9fe.js → index-33d800eb.js} +182 -111
- package/dist/{index-61c8686f.js → index-648e7ab2.js} +62 -62
- package/dist/index-6e709f57.js +781 -0
- package/dist/index-bf29f0e6.js +386 -0
- package/dist/{index-9f4b9905.js → index-ce49e384.js} +33 -800
- package/dist/index-e909c175.js +62 -0
- package/dist/index.d.ts +97 -35
- package/dist/index.js +6 -4
- package/dist/{jest-mock-a57b745c.js → jest-mock-4a754991.js} +1 -12
- package/dist/node.d.ts +87 -16
- package/dist/node.js +10 -9
- package/dist/rpc-8c7cc374.js +5 -0
- package/dist/setup-95b119ff.js +4318 -0
- package/dist/utils.js +2 -2
- package/dist/{vi-51946984.js → vi-39f06eb7.js} +30 -6
- package/dist/worker.js +25 -40
- package/package.json +7 -6
- package/vitest.mjs +1 -20
- package/dist/index-041e627e.js +0 -168
- package/dist/index-1488b423.js +0 -186
- package/dist/middleware-0ebc5238.js +0 -79
- package/dist/rpc-7de86f29.js +0 -10
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c, s as slash$1, a as isAbsolute, r as relative, d as dirname, b as basename, g as getFullName, h as hasFailed, f as getSuites, j as getTests, t as toArray, k as resolve, l as deepMerge, m as toFilePath, n as noop$1 } from './index-bf29f0e6.js';
|
|
2
2
|
import { createServer, mergeConfig } from 'vite';
|
|
3
3
|
import path$a from 'path';
|
|
4
4
|
import process$1 from 'process';
|
|
5
|
-
import fs$8, { promises } from 'fs';
|
|
5
|
+
import fs$8, { promises, existsSync } from 'fs';
|
|
6
6
|
import require$$0 from 'os';
|
|
7
7
|
import require$$0$1 from 'util';
|
|
8
8
|
import require$$0$2 from 'stream';
|
|
9
9
|
import require$$2 from 'events';
|
|
10
|
-
import {
|
|
11
|
-
import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-900abe4a.js';
|
|
10
|
+
import { d as defaultInclude, a as defaultExclude, b as defaultPort, c as distDir, e as configFiles } from './constants-080f26e8.js';
|
|
12
11
|
import MagicString from './magic-string.es-94000aea.js';
|
|
13
12
|
import { performance } from 'perf_hooks';
|
|
14
|
-
import { F as F_POINTER, a as F_DOWN, s as stripAnsi, b as F_LONG_DASH, c as F_DOWN_RIGHT, d as F_DOT, e as F_CHECK, f as F_CROSS, g as F_RIGHT, p as printError, h as stringWidth, i as ansiStyles, j as sliceAnsi, k as cliTruncate } from './diff-
|
|
15
|
-
import { o as onetime, s as signalExit } from './index-
|
|
16
|
-
import {
|
|
13
|
+
import { F as F_POINTER, a as F_DOWN, s as stripAnsi, b as F_LONG_DASH, c as F_DOWN_RIGHT, d as F_DOT, e as F_CHECK, f as F_CROSS, g as F_RIGHT, p as printError, h as stringWidth, i as ansiStyles, j as sliceAnsi, k as cliTruncate } from './diff-80c47cfa.js';
|
|
14
|
+
import { o as onetime, s as signalExit } from './index-648e7ab2.js';
|
|
15
|
+
import { createRequire } from 'module';
|
|
17
16
|
import { pathToFileURL } from 'url';
|
|
17
|
+
import { MessageChannel } from 'worker_threads';
|
|
18
18
|
import { Tinypool } from 'tinypool';
|
|
19
|
+
import { c as createBirpc } from './index-e909c175.js';
|
|
19
20
|
|
|
20
21
|
/*
|
|
21
22
|
How it works:
|
|
@@ -6965,13 +6966,16 @@ function elegantSpinner() {
|
|
|
6965
6966
|
}
|
|
6966
6967
|
|
|
6967
6968
|
class BaseReporter {
|
|
6968
|
-
constructor(
|
|
6969
|
-
this.ctx = ctx;
|
|
6969
|
+
constructor() {
|
|
6970
6970
|
this.start = 0;
|
|
6971
6971
|
this.end = 0;
|
|
6972
6972
|
this.isTTY = process.stdout.isTTY && !process.env.CI;
|
|
6973
|
+
this.ctx = void 0;
|
|
6973
6974
|
this.isFirstWatchRun = true;
|
|
6974
|
-
|
|
6975
|
+
}
|
|
6976
|
+
onInit(ctx) {
|
|
6977
|
+
this.ctx = ctx;
|
|
6978
|
+
const mode = this.ctx.config.watch ? c.blue(" WATCH ") : c.cyan(" RUN ");
|
|
6975
6979
|
this.ctx.log(`
|
|
6976
6980
|
${c.inverse(c.bold(mode))} ${c.gray(this.ctx.config.root)}
|
|
6977
6981
|
`);
|
|
@@ -6984,15 +6988,17 @@ ${c.inverse(c.bold(mode))} ${c.gray(this.ctx.config.root)}
|
|
|
6984
6988
|
this.end = performance.now();
|
|
6985
6989
|
await this.reportSummary(files);
|
|
6986
6990
|
}
|
|
6987
|
-
onTaskUpdate(
|
|
6991
|
+
onTaskUpdate(packs) {
|
|
6988
6992
|
var _a, _b, _c;
|
|
6989
6993
|
if (this.isTTY)
|
|
6990
6994
|
return;
|
|
6991
|
-
const
|
|
6992
|
-
|
|
6993
|
-
|
|
6994
|
-
|
|
6995
|
-
|
|
6995
|
+
for (const pack of packs) {
|
|
6996
|
+
const task = this.ctx.state.idMap[pack[0]];
|
|
6997
|
+
if (task.type === "test" && ((_a = task.result) == null ? void 0 : _a.state) && ((_b = task.result) == null ? void 0 : _b.state) !== "run") {
|
|
6998
|
+
this.ctx.log(` ${getStateSymbol(task)} ${getFullName(task)}`);
|
|
6999
|
+
if (task.result.state === "fail")
|
|
7000
|
+
this.ctx.log(c.red(` ${F_RIGHT} ${(_c = task.result.error) == null ? void 0 : _c.message}`));
|
|
7001
|
+
}
|
|
6996
7002
|
}
|
|
6997
7003
|
}
|
|
6998
7004
|
async onWatcherStart() {
|
|
@@ -7010,13 +7016,14 @@ ${c.bold(c.inverse(c.green(" PASS ")))}${c.green(" Waiting for file changes...")
|
|
|
7010
7016
|
}
|
|
7011
7017
|
async onWatcherRerun(files, trigger) {
|
|
7012
7018
|
this.watchFilters = files;
|
|
7013
|
-
|
|
7014
|
-
|
|
7015
|
-
|
|
7016
|
-
|
|
7017
|
-
}
|
|
7019
|
+
this.ctx.console.clear();
|
|
7020
|
+
this.ctx.log(c.blue("Re-running tests...") + (trigger ? c.dim(` [ ${this.relative(trigger)} ]
|
|
7021
|
+
`) : ""));
|
|
7022
|
+
this.start = performance.now();
|
|
7018
7023
|
}
|
|
7019
7024
|
onUserConsoleLog(log) {
|
|
7025
|
+
if (this.ctx.config.silent)
|
|
7026
|
+
return;
|
|
7020
7027
|
const task = log.taskId ? this.ctx.state.idMap[log.taskId] : void 0;
|
|
7021
7028
|
this.ctx.log(c.gray(log.type + c.dim(` | ${task ? getFullName(task) : "unknown test"}`)));
|
|
7022
7029
|
process[log.type].write(`${log.content}
|
|
@@ -7639,11 +7646,10 @@ function renderTree(tasks, options, level = 0) {
|
|
|
7639
7646
|
}
|
|
7640
7647
|
return output.slice(0, MAX_HEIGHT).join("\n");
|
|
7641
7648
|
}
|
|
7642
|
-
const createListRenderer = (_tasks, options
|
|
7649
|
+
const createListRenderer = (_tasks, options) => {
|
|
7643
7650
|
let tasks = _tasks;
|
|
7644
7651
|
let timer;
|
|
7645
|
-
const
|
|
7646
|
-
const log = createLogUpdate(stdout);
|
|
7652
|
+
const log = createLogUpdate(options.outputStream);
|
|
7647
7653
|
function update() {
|
|
7648
7654
|
log(renderTree(tasks, options));
|
|
7649
7655
|
}
|
|
@@ -7665,7 +7671,7 @@ const createListRenderer = (_tasks, options = {}) => {
|
|
|
7665
7671
|
timer = void 0;
|
|
7666
7672
|
}
|
|
7667
7673
|
log.clear();
|
|
7668
|
-
|
|
7674
|
+
options.outputStream.write(`${renderTree(tasks, options)}
|
|
7669
7675
|
`);
|
|
7670
7676
|
return this;
|
|
7671
7677
|
},
|
|
@@ -7680,8 +7686,9 @@ class DefaultReporter extends BaseReporter {
|
|
|
7680
7686
|
super(...arguments);
|
|
7681
7687
|
this.rendererOptions = {};
|
|
7682
7688
|
}
|
|
7683
|
-
|
|
7689
|
+
onCollected() {
|
|
7684
7690
|
if (this.isTTY) {
|
|
7691
|
+
this.rendererOptions.outputStream = this.ctx.outputStream;
|
|
7685
7692
|
const files = this.ctx.state.getFiles(this.watchFilters);
|
|
7686
7693
|
if (!this.renderer)
|
|
7687
7694
|
this.renderer = createListRenderer(files, this.rendererOptions).start();
|
|
@@ -7700,9 +7707,8 @@ class DefaultReporter extends BaseReporter {
|
|
|
7700
7707
|
}
|
|
7701
7708
|
async stopListRender() {
|
|
7702
7709
|
var _a;
|
|
7703
|
-
(_a = this.renderer) == null ? void 0 : _a.stop();
|
|
7710
|
+
await ((_a = this.renderer) == null ? void 0 : _a.stop());
|
|
7704
7711
|
this.renderer = void 0;
|
|
7705
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
7706
7712
|
}
|
|
7707
7713
|
async onWatcherRerun(files, trigger) {
|
|
7708
7714
|
await this.stopListRender();
|
|
@@ -7735,11 +7741,10 @@ function render(tasks) {
|
|
|
7735
7741
|
}
|
|
7736
7742
|
}).join("");
|
|
7737
7743
|
}
|
|
7738
|
-
const createDotRenderer = (_tasks) => {
|
|
7744
|
+
const createDotRenderer = (_tasks, options) => {
|
|
7739
7745
|
let tasks = _tasks;
|
|
7740
7746
|
let timer;
|
|
7741
|
-
const
|
|
7742
|
-
const log = createLogUpdate(stdout);
|
|
7747
|
+
const log = createLogUpdate(options.outputStream);
|
|
7743
7748
|
function update() {
|
|
7744
7749
|
log(render(tasks));
|
|
7745
7750
|
}
|
|
@@ -7761,7 +7766,7 @@ const createDotRenderer = (_tasks) => {
|
|
|
7761
7766
|
timer = void 0;
|
|
7762
7767
|
}
|
|
7763
7768
|
log.clear();
|
|
7764
|
-
|
|
7769
|
+
options.outputStream.write(`${render(tasks)}
|
|
7765
7770
|
`);
|
|
7766
7771
|
return this;
|
|
7767
7772
|
},
|
|
@@ -7772,11 +7777,11 @@ const createDotRenderer = (_tasks) => {
|
|
|
7772
7777
|
};
|
|
7773
7778
|
|
|
7774
7779
|
class DotReporter extends BaseReporter {
|
|
7775
|
-
|
|
7780
|
+
onCollected() {
|
|
7776
7781
|
if (this.isTTY) {
|
|
7777
7782
|
const files = this.ctx.state.getFiles(this.watchFilters);
|
|
7778
7783
|
if (!this.renderer)
|
|
7779
|
-
this.renderer = createDotRenderer(files).start();
|
|
7784
|
+
this.renderer = createDotRenderer(files, { outputStream: this.ctx.outputStream }).start();
|
|
7780
7785
|
else
|
|
7781
7786
|
this.renderer.update(files);
|
|
7782
7787
|
}
|
|
@@ -7808,8 +7813,8 @@ class DotReporter extends BaseReporter {
|
|
|
7808
7813
|
}
|
|
7809
7814
|
|
|
7810
7815
|
class VerboseReporter extends DefaultReporter {
|
|
7811
|
-
constructor(
|
|
7812
|
-
super(
|
|
7816
|
+
constructor() {
|
|
7817
|
+
super();
|
|
7813
7818
|
this.rendererOptions.renderSucceed = true;
|
|
7814
7819
|
}
|
|
7815
7820
|
}
|
|
@@ -7820,6 +7825,74 @@ const ReportersMap = {
|
|
|
7820
7825
|
dot: DotReporter
|
|
7821
7826
|
};
|
|
7822
7827
|
|
|
7828
|
+
var __defProp$1 = Object.defineProperty;
|
|
7829
|
+
var __defProps$1 = Object.defineProperties;
|
|
7830
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
7831
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
7832
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
7833
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
7834
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7835
|
+
var __spreadValues$1 = (a, b) => {
|
|
7836
|
+
for (var prop in b || (b = {}))
|
|
7837
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
7838
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
7839
|
+
if (__getOwnPropSymbols$1)
|
|
7840
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
7841
|
+
if (__propIsEnum$1.call(b, prop))
|
|
7842
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
7843
|
+
}
|
|
7844
|
+
return a;
|
|
7845
|
+
};
|
|
7846
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
7847
|
+
const defaultExcludes = [
|
|
7848
|
+
"coverage/**",
|
|
7849
|
+
"packages/*/test{,s}/**",
|
|
7850
|
+
"**/*.d.ts",
|
|
7851
|
+
"test{,s}/**",
|
|
7852
|
+
"test{,-*}.{js,cjs,mjs,ts,tsx,jsx}",
|
|
7853
|
+
"**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx}",
|
|
7854
|
+
"**/__tests__/**",
|
|
7855
|
+
"**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc}.config.{js,cjs,mjs,ts}",
|
|
7856
|
+
"**/.{eslint,mocha}rc.{js,cjs}"
|
|
7857
|
+
];
|
|
7858
|
+
function resolveC8Options(options, root) {
|
|
7859
|
+
const resolved = __spreadValues$1({
|
|
7860
|
+
enabled: false,
|
|
7861
|
+
clean: true,
|
|
7862
|
+
cleanOnRerun: false,
|
|
7863
|
+
reportsDirectory: "./coverage",
|
|
7864
|
+
excludeNodeModules: true,
|
|
7865
|
+
exclude: defaultExcludes,
|
|
7866
|
+
reporter: ["text", "html"],
|
|
7867
|
+
allowExternal: false
|
|
7868
|
+
}, options);
|
|
7869
|
+
resolved.reporter = toArray(resolved.reporter);
|
|
7870
|
+
resolved.reportsDirectory = resolve(root, resolved.reportsDirectory);
|
|
7871
|
+
resolved.tempDirectory = process.env.NODE_V8_COVERAGE || resolve(resolved.reportsDirectory, "tmp");
|
|
7872
|
+
return resolved;
|
|
7873
|
+
}
|
|
7874
|
+
async function cleanCoverage(options, clean = true) {
|
|
7875
|
+
if (clean && existsSync(options.reportsDirectory))
|
|
7876
|
+
await promises.rmdir(options.reportsDirectory, { recursive: true });
|
|
7877
|
+
if (!existsSync(options.tempDirectory))
|
|
7878
|
+
await promises.mkdir(options.tempDirectory, { recursive: true });
|
|
7879
|
+
}
|
|
7880
|
+
const require2 = createRequire(import.meta.url);
|
|
7881
|
+
async function reportCoverage(ctx) {
|
|
7882
|
+
const createReport = require2("c8/lib/report");
|
|
7883
|
+
const report = createReport(ctx.config.coverage);
|
|
7884
|
+
await report.getCoverageMapFromAllCoverageFiles();
|
|
7885
|
+
Array.from(ctx.visitedFilesMap.entries()).filter((i) => !i[0].includes("/node_modules/")).forEach(([file, map]) => {
|
|
7886
|
+
const url = pathToFileURL(file).href;
|
|
7887
|
+
report.sourceMapCache[url] = {
|
|
7888
|
+
data: __spreadProps$1(__spreadValues$1({}, map), {
|
|
7889
|
+
sources: map.sources.map((i) => pathToFileURL(i).href) || [url]
|
|
7890
|
+
})
|
|
7891
|
+
};
|
|
7892
|
+
});
|
|
7893
|
+
await report.run();
|
|
7894
|
+
}
|
|
7895
|
+
|
|
7823
7896
|
class StateManager {
|
|
7824
7897
|
constructor() {
|
|
7825
7898
|
this.filesMap = {};
|
|
@@ -7831,7 +7904,7 @@ class StateManager {
|
|
|
7831
7904
|
return keys.map((key) => this.filesMap[key]);
|
|
7832
7905
|
return Object.values(this.filesMap);
|
|
7833
7906
|
}
|
|
7834
|
-
collectFiles(files) {
|
|
7907
|
+
collectFiles(files = []) {
|
|
7835
7908
|
files.forEach((file) => {
|
|
7836
7909
|
this.filesMap[file.filepath] = file;
|
|
7837
7910
|
this.updateId(file);
|
|
@@ -7878,9 +7951,10 @@ function resolveConfig(options, viteConfig) {
|
|
|
7878
7951
|
var _a, _b;
|
|
7879
7952
|
if (options.dom)
|
|
7880
7953
|
options.environment = "happy-dom";
|
|
7881
|
-
const resolved = __spreadProps(__spreadValues(
|
|
7954
|
+
const resolved = __spreadProps(__spreadValues({}, deepMerge(options, viteConfig.test)), {
|
|
7882
7955
|
root: viteConfig.root
|
|
7883
7956
|
});
|
|
7957
|
+
resolved.coverage = resolveC8Options(resolved.coverage, resolved.root);
|
|
7884
7958
|
resolved.depsInline = [...((_a = resolved.deps) == null ? void 0 : _a.inline) || []];
|
|
7885
7959
|
resolved.depsExternal = [...((_b = resolved.deps) == null ? void 0 : _b.external) || []];
|
|
7886
7960
|
resolved.environment = resolved.environment || "node";
|
|
@@ -7893,6 +7967,7 @@ function resolveConfig(options, viteConfig) {
|
|
|
7893
7967
|
resolved.exclude = resolved.exclude ?? defaultExclude;
|
|
7894
7968
|
resolved.testTimeout = resolved.testTimeout ?? 5e3;
|
|
7895
7969
|
resolved.hookTimeout = resolved.hookTimeout ?? 1e4;
|
|
7970
|
+
resolved.isolate = resolved.isolate ?? true;
|
|
7896
7971
|
resolved.watchIgnore = resolved.watchIgnore ?? [/\/node_modules\//, /\/dist\//];
|
|
7897
7972
|
const CI = !!process.env.CI;
|
|
7898
7973
|
const UPDATE_SNAPSHOT = resolved.update || process.env.UPDATE_SNAPSHOT;
|
|
@@ -7928,20 +8003,8 @@ async function _transformRequest(ctx, id) {
|
|
|
7928
8003
|
if (result)
|
|
7929
8004
|
result = await ctx.server.ssrTransform(result.code, result.map, id);
|
|
7930
8005
|
}
|
|
7931
|
-
if (result && process.env.NODE_V8_COVERAGE)
|
|
7932
|
-
|
|
7933
|
-
return result;
|
|
7934
|
-
}
|
|
7935
|
-
let SOURCEMAPPING_URL = "sourceMa";
|
|
7936
|
-
SOURCEMAPPING_URL += "ppingURL";
|
|
7937
|
-
async function withInlineSourcemap(result) {
|
|
7938
|
-
const { code, map } = result;
|
|
7939
|
-
if (code.includes(`${SOURCEMAPPING_URL}=`))
|
|
7940
|
-
return result;
|
|
7941
|
-
if (map)
|
|
7942
|
-
result.code = `${code}
|
|
7943
|
-
|
|
7944
|
-
//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}`;
|
|
8006
|
+
if ((result == null ? void 0 : result.map) && process.env.NODE_V8_COVERAGE)
|
|
8007
|
+
ctx.visitedFilesMap.set(toFilePath(id, ctx.config.root), result.map);
|
|
7945
8008
|
return result;
|
|
7946
8009
|
}
|
|
7947
8010
|
|
|
@@ -7978,14 +8041,16 @@ function createFakePool(ctx) {
|
|
|
7978
8041
|
function createWorkerPool(ctx) {
|
|
7979
8042
|
const options = {
|
|
7980
8043
|
filename: workerPath,
|
|
7981
|
-
isolateWorkers: true,
|
|
7982
|
-
concurrentTasksPerWorker: 1,
|
|
7983
8044
|
useAtomics: false
|
|
7984
8045
|
};
|
|
7985
8046
|
if (ctx.config.maxThreads != null)
|
|
7986
8047
|
options.maxThreads = ctx.config.maxThreads;
|
|
7987
8048
|
if (ctx.config.minThreads != null)
|
|
7988
8049
|
options.minThreads = ctx.config.minThreads;
|
|
8050
|
+
if (ctx.config.isolate) {
|
|
8051
|
+
options.isolateWorkers = true;
|
|
8052
|
+
options.concurrentTasksPerWorker = 1;
|
|
8053
|
+
}
|
|
7989
8054
|
const pool = new Tinypool(options);
|
|
7990
8055
|
const runWithFiles = (name) => {
|
|
7991
8056
|
return async (files, invalidates) => {
|
|
@@ -8006,61 +8071,53 @@ function createWorkerPool(ctx) {
|
|
|
8006
8071
|
return {
|
|
8007
8072
|
runTests: runWithFiles("run"),
|
|
8008
8073
|
collectTests: runWithFiles("collect"),
|
|
8009
|
-
close: () =>
|
|
8074
|
+
close: async () => {
|
|
8075
|
+
}
|
|
8010
8076
|
};
|
|
8011
8077
|
}
|
|
8012
8078
|
function createChannel(ctx) {
|
|
8013
8079
|
const channel = new MessageChannel();
|
|
8014
8080
|
const port = channel.port2;
|
|
8015
8081
|
const workerPort = channel.port1;
|
|
8016
|
-
|
|
8017
|
-
|
|
8018
|
-
|
|
8019
|
-
|
|
8020
|
-
}
|
|
8021
|
-
|
|
8082
|
+
createBirpc({
|
|
8083
|
+
functions: {
|
|
8084
|
+
onWorkerExit(code) {
|
|
8085
|
+
process.exit(code || 1);
|
|
8086
|
+
},
|
|
8087
|
+
snapshotSaved(snapshot) {
|
|
8088
|
+
ctx.snapshot.add(snapshot);
|
|
8089
|
+
},
|
|
8090
|
+
async getSourceMap(id, force) {
|
|
8091
|
+
if (force) {
|
|
8092
|
+
const mod = ctx.server.moduleGraph.getModuleById(id);
|
|
8093
|
+
if (mod)
|
|
8094
|
+
ctx.server.moduleGraph.invalidateModule(mod);
|
|
8095
|
+
}
|
|
8096
|
+
const r = await transformRequest(ctx, id);
|
|
8097
|
+
return r == null ? void 0 : r.map;
|
|
8098
|
+
},
|
|
8099
|
+
async fetch(id) {
|
|
8100
|
+
const r = await transformRequest(ctx, id);
|
|
8101
|
+
return r == null ? void 0 : r.code;
|
|
8102
|
+
},
|
|
8103
|
+
onCollected(files) {
|
|
8104
|
+
ctx.state.collectFiles(files);
|
|
8105
|
+
ctx.report("onCollected", files);
|
|
8106
|
+
},
|
|
8107
|
+
onTaskUpdate(packs) {
|
|
8108
|
+
ctx.state.updateTasks(packs);
|
|
8109
|
+
ctx.report("onTaskUpdate", packs);
|
|
8110
|
+
},
|
|
8111
|
+
onUserLog(msg) {
|
|
8112
|
+
ctx.report("onUserConsoleLog", msg);
|
|
8022
8113
|
}
|
|
8114
|
+
},
|
|
8115
|
+
post(v) {
|
|
8116
|
+
port.postMessage(v);
|
|
8117
|
+
},
|
|
8118
|
+
on(fn) {
|
|
8119
|
+
port.on("message", fn);
|
|
8023
8120
|
}
|
|
8024
|
-
switch (method) {
|
|
8025
|
-
case "processExit":
|
|
8026
|
-
process.exit(args[0] || 1);
|
|
8027
|
-
return;
|
|
8028
|
-
case "snapshotSaved":
|
|
8029
|
-
return send(() => ctx.snapshot.add(args[0]));
|
|
8030
|
-
case "getSourceMap":
|
|
8031
|
-
return send(() => {
|
|
8032
|
-
const [id2, force] = args;
|
|
8033
|
-
if (force) {
|
|
8034
|
-
const mod = ctx.server.moduleGraph.getModuleById(id2);
|
|
8035
|
-
if (mod)
|
|
8036
|
-
ctx.server.moduleGraph.invalidateModule(mod);
|
|
8037
|
-
}
|
|
8038
|
-
return transformRequest(ctx, id2).then((r) => r == null ? void 0 : r.map);
|
|
8039
|
-
});
|
|
8040
|
-
case "fetch":
|
|
8041
|
-
return send(() => transformRequest(ctx, ...args).then((r) => r == null ? void 0 : r.code));
|
|
8042
|
-
case "onCollected":
|
|
8043
|
-
ctx.state.collectFiles(args[0]);
|
|
8044
|
-
ctx.reporters.forEach((r) => {
|
|
8045
|
-
var _a;
|
|
8046
|
-
return (_a = r.onStart) == null ? void 0 : _a.call(r, args[0].map((i) => i.filepath));
|
|
8047
|
-
});
|
|
8048
|
-
return;
|
|
8049
|
-
case "onTaskUpdate":
|
|
8050
|
-
ctx.state.updateTasks([args[0]]);
|
|
8051
|
-
ctx.reporters.forEach((r) => {
|
|
8052
|
-
var _a;
|
|
8053
|
-
return (_a = r.onTaskUpdate) == null ? void 0 : _a.call(r, args[0]);
|
|
8054
|
-
});
|
|
8055
|
-
return;
|
|
8056
|
-
case "log":
|
|
8057
|
-
ctx.reporters.forEach((r) => {
|
|
8058
|
-
var _a;
|
|
8059
|
-
return (_a = r.onUserConsoleLog) == null ? void 0 : _a.call(r, args[0]);
|
|
8060
|
-
});
|
|
8061
|
-
return;
|
|
8062
|
-
}
|
|
8063
|
-
console.error("Unhandled message", method, args);
|
|
8064
8121
|
});
|
|
8065
8122
|
return { workerPort, port };
|
|
8066
8123
|
}
|
|
@@ -8073,15 +8130,18 @@ class Vitest {
|
|
|
8073
8130
|
this.state = void 0;
|
|
8074
8131
|
this.snapshot = void 0;
|
|
8075
8132
|
this.reporters = void 0;
|
|
8133
|
+
this.outputStream = process.stdout;
|
|
8134
|
+
this.errorStream = process.stderr;
|
|
8076
8135
|
this.invalidates = /* @__PURE__ */ new Set();
|
|
8077
8136
|
this.changedTests = /* @__PURE__ */ new Set();
|
|
8137
|
+
this.visitedFilesMap = /* @__PURE__ */ new Map();
|
|
8078
8138
|
this.isFirstRun = true;
|
|
8079
8139
|
this.restartsCount = 0;
|
|
8080
8140
|
this._onRestartListeners = [];
|
|
8081
8141
|
this.unregisterWatcher = noop$1;
|
|
8082
8142
|
this.console = globalThis.console;
|
|
8083
8143
|
}
|
|
8084
|
-
setServer(options, server) {
|
|
8144
|
+
async setServer(options, server) {
|
|
8085
8145
|
var _a, _b;
|
|
8086
8146
|
(_a = this.unregisterWatcher) == null ? void 0 : _a.call(this);
|
|
8087
8147
|
clearTimeout(this._rerunTimer);
|
|
@@ -8098,18 +8158,21 @@ class Vitest {
|
|
|
8098
8158
|
const Reporter = ReportersMap[i];
|
|
8099
8159
|
if (!Reporter)
|
|
8100
8160
|
throw new Error(`Unknown reporter: ${i}`);
|
|
8101
|
-
return new Reporter(
|
|
8161
|
+
return new Reporter();
|
|
8102
8162
|
}
|
|
8103
8163
|
return i;
|
|
8104
8164
|
});
|
|
8105
|
-
if (!this.reporters.length
|
|
8106
|
-
this.reporters.push(new DefaultReporter(
|
|
8165
|
+
if (!this.reporters.length)
|
|
8166
|
+
this.reporters.push(new DefaultReporter());
|
|
8107
8167
|
if (this.config.watch)
|
|
8108
8168
|
this.registerWatcher();
|
|
8109
8169
|
this.runningPromise = void 0;
|
|
8110
8170
|
this._onRestartListeners.forEach((fn) => fn());
|
|
8171
|
+
if (resolved.coverage.enabled)
|
|
8172
|
+
await cleanCoverage(resolved.coverage, resolved.coverage.clean);
|
|
8111
8173
|
}
|
|
8112
8174
|
async start(filters) {
|
|
8175
|
+
this.report("onInit", this);
|
|
8113
8176
|
const files = await this.globTestFiles(filters);
|
|
8114
8177
|
if (!files.length) {
|
|
8115
8178
|
if (this.config.passWithNoTests)
|
|
@@ -8121,6 +8184,8 @@ class Vitest {
|
|
|
8121
8184
|
await this.runFiles(files);
|
|
8122
8185
|
if (this.config.watch)
|
|
8123
8186
|
await this.report("onWatcherStart");
|
|
8187
|
+
if (this.config.coverage.enabled)
|
|
8188
|
+
await reportCoverage(this);
|
|
8124
8189
|
}
|
|
8125
8190
|
async runFiles(files) {
|
|
8126
8191
|
await this.runningPromise;
|
|
@@ -8139,13 +8204,9 @@ class Vitest {
|
|
|
8139
8204
|
return await this.runningPromise;
|
|
8140
8205
|
}
|
|
8141
8206
|
log(...args) {
|
|
8142
|
-
if (this.config.silent)
|
|
8143
|
-
return;
|
|
8144
8207
|
this.console.log(...args);
|
|
8145
8208
|
}
|
|
8146
8209
|
error(...args) {
|
|
8147
|
-
if (this.config.silent)
|
|
8148
|
-
return;
|
|
8149
8210
|
this.console.error(...args);
|
|
8150
8211
|
}
|
|
8151
8212
|
async scheduleRerun(triggerId) {
|
|
@@ -8166,9 +8227,14 @@ class Vitest {
|
|
|
8166
8227
|
this.snapshot.clear();
|
|
8167
8228
|
const files = Array.from(this.changedTests);
|
|
8168
8229
|
this.changedTests.clear();
|
|
8230
|
+
this.log("return");
|
|
8231
|
+
if (this.config.coverage.enabled && this.config.coverage.cleanOnRerun)
|
|
8232
|
+
await cleanCoverage(this.config.coverage);
|
|
8169
8233
|
await this.report("onWatcherRerun", files, triggerId);
|
|
8170
8234
|
await this.runFiles(files);
|
|
8171
8235
|
await this.report("onWatcherStart");
|
|
8236
|
+
if (this.config.coverage.enabled)
|
|
8237
|
+
await reportCoverage(this);
|
|
8172
8238
|
}, WATCHER_DEBOUNCE);
|
|
8173
8239
|
}
|
|
8174
8240
|
registerWatcher() {
|
|
@@ -8266,10 +8332,10 @@ async function createVitest(options, viteOverrides = {}) {
|
|
|
8266
8332
|
async configureServer(server2) {
|
|
8267
8333
|
if (haveStarted)
|
|
8268
8334
|
await ctx.report("onServerRestart");
|
|
8269
|
-
ctx.setServer(options, server2);
|
|
8335
|
+
await ctx.setServer(options, server2);
|
|
8270
8336
|
haveStarted = true;
|
|
8271
8337
|
if (options.api)
|
|
8272
|
-
|
|
8338
|
+
(await import('./setup-95b119ff.js')).setup(ctx);
|
|
8273
8339
|
}
|
|
8274
8340
|
},
|
|
8275
8341
|
MocksPlugin()
|
|
@@ -8278,6 +8344,9 @@ async function createVitest(options, viteOverrides = {}) {
|
|
|
8278
8344
|
open: options.open,
|
|
8279
8345
|
strictPort: true
|
|
8280
8346
|
},
|
|
8347
|
+
build: {
|
|
8348
|
+
sourcemap: true
|
|
8349
|
+
},
|
|
8281
8350
|
optimizeDeps: {
|
|
8282
8351
|
exclude: [
|
|
8283
8352
|
"vitest"
|
|
@@ -8288,6 +8357,8 @@ async function createVitest(options, viteOverrides = {}) {
|
|
|
8288
8357
|
await server.pluginContainer.buildStart({});
|
|
8289
8358
|
if (options.api === true)
|
|
8290
8359
|
options.api = defaultPort;
|
|
8360
|
+
if (options.open && !options.api)
|
|
8361
|
+
options.api = defaultPort;
|
|
8291
8362
|
if (typeof options.api === "number")
|
|
8292
8363
|
await server.listen(options.api);
|
|
8293
8364
|
return ctx;
|
|
@@ -2,68 +2,6 @@ import { c as commonjsGlobal } from './_commonjsHelpers-c9e3b764.js';
|
|
|
2
2
|
import assert$1 from 'assert';
|
|
3
3
|
import require$$2 from 'events';
|
|
4
4
|
|
|
5
|
-
var onetime$2 = {exports: {}};
|
|
6
|
-
|
|
7
|
-
var mimicFn$2 = {exports: {}};
|
|
8
|
-
|
|
9
|
-
const mimicFn$1 = (to, from) => {
|
|
10
|
-
for (const prop of Reflect.ownKeys(from)) {
|
|
11
|
-
Object.defineProperty(to, prop, Object.getOwnPropertyDescriptor(from, prop));
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return to;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
mimicFn$2.exports = mimicFn$1;
|
|
18
|
-
// TODO: Remove this for the next major release
|
|
19
|
-
mimicFn$2.exports.default = mimicFn$1;
|
|
20
|
-
|
|
21
|
-
const mimicFn = mimicFn$2.exports;
|
|
22
|
-
|
|
23
|
-
const calledFunctions = new WeakMap();
|
|
24
|
-
|
|
25
|
-
const onetime = (function_, options = {}) => {
|
|
26
|
-
if (typeof function_ !== 'function') {
|
|
27
|
-
throw new TypeError('Expected a function');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
let returnValue;
|
|
31
|
-
let callCount = 0;
|
|
32
|
-
const functionName = function_.displayName || function_.name || '<anonymous>';
|
|
33
|
-
|
|
34
|
-
const onetime = function (...arguments_) {
|
|
35
|
-
calledFunctions.set(onetime, ++callCount);
|
|
36
|
-
|
|
37
|
-
if (callCount === 1) {
|
|
38
|
-
returnValue = function_.apply(this, arguments_);
|
|
39
|
-
function_ = null;
|
|
40
|
-
} else if (options.throw === true) {
|
|
41
|
-
throw new Error(`Function \`${functionName}\` can only be called once`);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return returnValue;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
mimicFn(onetime, function_);
|
|
48
|
-
calledFunctions.set(onetime, callCount);
|
|
49
|
-
|
|
50
|
-
return onetime;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
onetime$2.exports = onetime;
|
|
54
|
-
// TODO: Remove this for the next major release
|
|
55
|
-
onetime$2.exports.default = onetime;
|
|
56
|
-
|
|
57
|
-
onetime$2.exports.callCount = function_ => {
|
|
58
|
-
if (!calledFunctions.has(function_)) {
|
|
59
|
-
throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return calledFunctions.get(function_);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
var onetime$1 = onetime$2.exports;
|
|
66
|
-
|
|
67
5
|
var signalExit$1 = {exports: {}};
|
|
68
6
|
|
|
69
7
|
var signals$1 = {exports: {}};
|
|
@@ -327,4 +265,66 @@ if (!processOk(process$1)) {
|
|
|
327
265
|
|
|
328
266
|
var signalExit = signalExit$1.exports;
|
|
329
267
|
|
|
268
|
+
var onetime$2 = {exports: {}};
|
|
269
|
+
|
|
270
|
+
var mimicFn$2 = {exports: {}};
|
|
271
|
+
|
|
272
|
+
const mimicFn$1 = (to, from) => {
|
|
273
|
+
for (const prop of Reflect.ownKeys(from)) {
|
|
274
|
+
Object.defineProperty(to, prop, Object.getOwnPropertyDescriptor(from, prop));
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return to;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
mimicFn$2.exports = mimicFn$1;
|
|
281
|
+
// TODO: Remove this for the next major release
|
|
282
|
+
mimicFn$2.exports.default = mimicFn$1;
|
|
283
|
+
|
|
284
|
+
const mimicFn = mimicFn$2.exports;
|
|
285
|
+
|
|
286
|
+
const calledFunctions = new WeakMap();
|
|
287
|
+
|
|
288
|
+
const onetime = (function_, options = {}) => {
|
|
289
|
+
if (typeof function_ !== 'function') {
|
|
290
|
+
throw new TypeError('Expected a function');
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
let returnValue;
|
|
294
|
+
let callCount = 0;
|
|
295
|
+
const functionName = function_.displayName || function_.name || '<anonymous>';
|
|
296
|
+
|
|
297
|
+
const onetime = function (...arguments_) {
|
|
298
|
+
calledFunctions.set(onetime, ++callCount);
|
|
299
|
+
|
|
300
|
+
if (callCount === 1) {
|
|
301
|
+
returnValue = function_.apply(this, arguments_);
|
|
302
|
+
function_ = null;
|
|
303
|
+
} else if (options.throw === true) {
|
|
304
|
+
throw new Error(`Function \`${functionName}\` can only be called once`);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return returnValue;
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
mimicFn(onetime, function_);
|
|
311
|
+
calledFunctions.set(onetime, callCount);
|
|
312
|
+
|
|
313
|
+
return onetime;
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
onetime$2.exports = onetime;
|
|
317
|
+
// TODO: Remove this for the next major release
|
|
318
|
+
onetime$2.exports.default = onetime;
|
|
319
|
+
|
|
320
|
+
onetime$2.exports.callCount = function_ => {
|
|
321
|
+
if (!calledFunctions.has(function_)) {
|
|
322
|
+
throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return calledFunctions.get(function_);
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
var onetime$1 = onetime$2.exports;
|
|
329
|
+
|
|
330
330
|
export { signalExit$1 as a, onetime$2 as b, onetime$1 as o, signalExit as s };
|