vitest 0.27.3 → 0.28.0
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 +4 -93
- package/browser.d.ts +1 -1
- package/dist/browser.d.ts +11 -13
- package/dist/browser.js +9 -34
- package/dist/{chunk-api-setup.0a2398d8.js → chunk-api-setup.52751a38.js} +26 -12
- package/dist/chunk-constants.797d3ebf.js +42 -0
- package/dist/{chunk-install-pkg.7b006b3e.js → chunk-install-pkg.cfd23146.js} +51 -11
- package/dist/{vendor-index.57682f0c.js → chunk-integrations-coverage.48e6286b.js} +33 -4
- package/dist/chunk-integrations-globals.0d5f50f0.js +29 -0
- package/dist/chunk-integrations-run-once.38756e30.js +27 -0
- package/dist/chunk-integrations-utils.f1f6f1ed.js +118 -0
- package/dist/{chunk-node-git.59caac18.js → chunk-node-git.d9ad64ab.js} +6 -8
- package/dist/{chunk-snapshot-manager.d16903ef.js → chunk-node-pkg.dcdf4369.js} +7440 -172
- package/dist/{chunk-runtime-mocker.66533d65.js → chunk-runtime-mocker.03017e8c.js} +13 -12
- package/dist/{chunk-runtime-rpc.e79efa9a.js → chunk-runtime-rpc.9c0386cc.js} +3 -2
- package/dist/chunk-runtime-setup.d9302cfd.js +20 -0
- package/dist/chunk-snapshot-env.6457638e.js +11 -0
- package/dist/chunk-utils-base.977ae74f.js +77 -0
- package/dist/chunk-utils-env.860d90c2.js +6 -0
- package/dist/chunk-utils-global.442d1d33.js +73 -0
- package/dist/{chunk-utils-import.eb63557e.js → chunk-utils-import.9911c99d.js} +3289 -169
- package/dist/chunk-utils-tasks.1b603032.js +103 -0
- package/dist/cli-wrapper.js +7 -6
- package/dist/cli.js +16 -15
- package/dist/config.d.ts +7 -2
- package/dist/entry.js +233 -28
- package/dist/env-afee91f0.d.ts +10 -0
- package/dist/environments.d.ts +7 -2
- package/dist/index.d.ts +160 -11
- package/dist/index.js +17 -18
- package/dist/loader.js +6 -6
- package/dist/node.d.ts +9 -7
- package/dist/node.js +18 -17
- package/dist/runners-chunk.js +215 -0
- package/dist/runners.d.ts +39 -0
- package/dist/runners.js +18 -0
- package/dist/spy.js +1 -2
- package/dist/suite.d.ts +2 -0
- package/dist/suite.js +2 -19
- package/dist/{types-c1386a7d.d.ts → types-c800444e.d.ts} +160 -425
- package/dist/{vendor-index.e6c27006.js → vendor-index.618ca5a1.js} +1078 -10
- package/dist/{vendor-index.b0346fe4.js → vendor-index.bdee400f.js} +1 -0
- package/dist/worker.js +11 -13
- package/package.json +21 -12
- package/runners.d.ts +1 -0
- package/suite.d.ts +1 -0
- package/dist/chunk-integrations-coverage.18366936.js +0 -242
- package/dist/chunk-integrations-globals.59b4d460.js +0 -28
- package/dist/chunk-mock-date.91595ccd.js +0 -350
- package/dist/chunk-runtime-chain.07d16eac.js +0 -2594
- package/dist/chunk-runtime-error.f2062967.js +0 -144
- package/dist/chunk-runtime-setup.8ca273cd.js +0 -653
- package/dist/chunk-utils-env.4ebb0106.js +0 -229
- package/dist/chunk-utils-source-map.832515f7.js +0 -408
- package/dist/chunk-utils-timers.52534f96.js +0 -3573
- package/dist/index-2dd51af4.d.ts +0 -258
- package/dist/vendor-index.451e37bc.js +0 -1071
- package/dist/vendor-index.723a074f.js +0 -102
- package/dist/vendor-index.9c919048.js +0 -61
- package/dist/vendor-index.9f20a9be.js +0 -6291
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { getNames, getTests } from '@vitest/runner/utils';
|
|
2
|
+
import { resolve } from 'pathe';
|
|
3
|
+
import { n as notNullish } from './chunk-utils-base.977ae74f.js';
|
|
4
|
+
|
|
5
|
+
function hasFailedSnapshot(suite) {
|
|
6
|
+
return getTests(suite).some((s) => {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
return (_b = (_a = s.result) == null ? void 0 : _a.errors) == null ? void 0 : _b.some((e) => e.message.match(/Snapshot .* mismatched/));
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
function getFullName(task, separator = " > ") {
|
|
12
|
+
return getNames(task).join(separator);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const lineSplitRE = /\r?\n/;
|
|
16
|
+
const stackIgnorePatterns = [
|
|
17
|
+
"node:internal",
|
|
18
|
+
/\/packages\/\w+\/dist\//,
|
|
19
|
+
/\/@vitest\/\w+\/dist\//,
|
|
20
|
+
"/vitest/dist/",
|
|
21
|
+
"/vitest/src/",
|
|
22
|
+
"/vite-node/dist/",
|
|
23
|
+
"/vite-node/src/",
|
|
24
|
+
"/node_modules/chai/",
|
|
25
|
+
"/node_modules/tinypool/",
|
|
26
|
+
"/node_modules/tinyspy/"
|
|
27
|
+
];
|
|
28
|
+
function extractLocation(urlLike) {
|
|
29
|
+
if (!urlLike.includes(":"))
|
|
30
|
+
return [urlLike];
|
|
31
|
+
const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
|
|
32
|
+
const parts = regExp.exec(urlLike.replace(/[()]/g, ""));
|
|
33
|
+
if (!parts)
|
|
34
|
+
return [urlLike];
|
|
35
|
+
return [parts[1], parts[2] || void 0, parts[3] || void 0];
|
|
36
|
+
}
|
|
37
|
+
function parseSingleStack(raw) {
|
|
38
|
+
let line = raw.trim();
|
|
39
|
+
if (line.includes("(eval "))
|
|
40
|
+
line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
|
|
41
|
+
let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
|
|
42
|
+
const location = sanitizedLine.match(/ (\(.+\)$)/);
|
|
43
|
+
sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
|
|
44
|
+
const [url, lineNumber, columnNumber] = extractLocation(location ? location[1] : sanitizedLine);
|
|
45
|
+
let method = location && sanitizedLine || "";
|
|
46
|
+
let file = url && ["eval", "<anonymous>"].includes(url) ? void 0 : url;
|
|
47
|
+
if (!file || !lineNumber || !columnNumber)
|
|
48
|
+
return null;
|
|
49
|
+
if (method.startsWith("async "))
|
|
50
|
+
method = method.slice(6);
|
|
51
|
+
if (file.startsWith("file://"))
|
|
52
|
+
file = file.slice(7);
|
|
53
|
+
file = resolve(file);
|
|
54
|
+
return {
|
|
55
|
+
method,
|
|
56
|
+
file,
|
|
57
|
+
line: parseInt(lineNumber),
|
|
58
|
+
column: parseInt(columnNumber)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function parseStacktrace(e, full = false) {
|
|
62
|
+
if (!e)
|
|
63
|
+
return [];
|
|
64
|
+
if (e.stacks)
|
|
65
|
+
return e.stacks;
|
|
66
|
+
const stackStr = e.stack || e.stackStr || "";
|
|
67
|
+
const stackFrames = stackStr.split("\n").map((raw) => {
|
|
68
|
+
const stack = parseSingleStack(raw);
|
|
69
|
+
if (!stack || !full && stackIgnorePatterns.some((p) => stack.file.match(p)))
|
|
70
|
+
return null;
|
|
71
|
+
return stack;
|
|
72
|
+
}).filter(notNullish);
|
|
73
|
+
e.stacks = stackFrames;
|
|
74
|
+
return stackFrames;
|
|
75
|
+
}
|
|
76
|
+
function positionToOffset(source, lineNumber, columnNumber) {
|
|
77
|
+
const lines = source.split(lineSplitRE);
|
|
78
|
+
let start = 0;
|
|
79
|
+
if (lineNumber > lines.length)
|
|
80
|
+
return source.length;
|
|
81
|
+
for (let i = 0; i < lineNumber - 1; i++)
|
|
82
|
+
start += lines[i].length + 1;
|
|
83
|
+
return start + columnNumber;
|
|
84
|
+
}
|
|
85
|
+
function offsetToLineNumber(source, offset) {
|
|
86
|
+
if (offset > source.length) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
`offset is longer than source length! offset ${offset} > length ${source.length}`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
const lines = source.split(lineSplitRE);
|
|
92
|
+
let counted = 0;
|
|
93
|
+
let line = 0;
|
|
94
|
+
for (; line < lines.length; line++) {
|
|
95
|
+
const lineLength = lines[line].length + 1;
|
|
96
|
+
if (counted + lineLength >= offset)
|
|
97
|
+
break;
|
|
98
|
+
counted += lineLength;
|
|
99
|
+
}
|
|
100
|
+
return line + 1;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { parseStacktrace as a, parseSingleStack as b, getFullName as g, hasFailedSnapshot as h, lineSplitRE as l, offsetToLineNumber as o, positionToOffset as p };
|
package/dist/cli-wrapper.js
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import { fileURLToPath } from 'url';
|
|
2
2
|
import c from 'picocolors';
|
|
3
|
-
import { e as execa } from './vendor-index.
|
|
4
|
-
import { E as EXIT_CODE_RESTART } from './chunk-
|
|
3
|
+
import { e as execa } from './vendor-index.618ca5a1.js';
|
|
4
|
+
import { E as EXIT_CODE_RESTART } from './chunk-constants.797d3ebf.js';
|
|
5
5
|
import 'node:buffer';
|
|
6
6
|
import 'node:path';
|
|
7
7
|
import 'node:child_process';
|
|
8
8
|
import 'node:process';
|
|
9
|
-
import './vendor-index.e6c27006.js';
|
|
10
9
|
import 'child_process';
|
|
11
10
|
import 'path';
|
|
12
11
|
import './vendor-_commonjsHelpers.addc3445.js';
|
|
13
12
|
import 'fs';
|
|
13
|
+
import 'node:url';
|
|
14
|
+
import 'os';
|
|
15
|
+
import 'node:os';
|
|
14
16
|
import 'assert';
|
|
15
17
|
import 'events';
|
|
16
18
|
import 'buffer';
|
|
17
19
|
import 'stream';
|
|
18
20
|
import 'util';
|
|
19
|
-
import '
|
|
20
|
-
import '
|
|
21
|
-
import 'node:os';
|
|
21
|
+
import 'pathe';
|
|
22
|
+
import './chunk-utils-env.860d90c2.js';
|
|
22
23
|
import 'std-env';
|
|
23
24
|
|
|
24
25
|
const ENTRY = new URL("./cli.js", import.meta.url);
|
package/dist/cli.js
CHANGED
|
@@ -1,37 +1,39 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { normalize } from 'pathe';
|
|
2
2
|
import cac from 'cac';
|
|
3
3
|
import c from 'picocolors';
|
|
4
|
-
import { v as version, s as startVitest, d as divider } from './chunk-
|
|
4
|
+
import { v as version, s as startVitest, d as divider } from './chunk-node-pkg.dcdf4369.js';
|
|
5
|
+
import './chunk-constants.797d3ebf.js';
|
|
5
6
|
import 'node:url';
|
|
6
|
-
import '
|
|
7
|
+
import './chunk-utils-env.860d90c2.js';
|
|
7
8
|
import 'std-env';
|
|
8
|
-
import './chunk-integrations-coverage.
|
|
9
|
+
import './chunk-integrations-coverage.48e6286b.js';
|
|
9
10
|
import 'local-pkg';
|
|
11
|
+
import 'util';
|
|
12
|
+
import 'path';
|
|
10
13
|
import './chunk-env-node.ffd1183b.js';
|
|
11
14
|
import 'node:console';
|
|
12
|
-
import './chunk-mock-date.91595ccd.js';
|
|
13
|
-
import 'node:path';
|
|
14
15
|
import 'vite';
|
|
16
|
+
import 'node:path';
|
|
15
17
|
import 'node:process';
|
|
16
18
|
import 'node:fs';
|
|
17
19
|
import 'os';
|
|
18
|
-
import './vendor-index.57682f0c.js';
|
|
19
|
-
import 'util';
|
|
20
20
|
import 'stream';
|
|
21
21
|
import 'events';
|
|
22
22
|
import 'fs';
|
|
23
23
|
import './vendor-_commonjsHelpers.addc3445.js';
|
|
24
24
|
import 'vite-node/client';
|
|
25
25
|
import 'vite-node/server';
|
|
26
|
+
import './chunk-utils-global.442d1d33.js';
|
|
27
|
+
import '@vitest/runner/utils';
|
|
28
|
+
import '@vitest/utils';
|
|
26
29
|
import 'node:fs/promises';
|
|
27
|
-
import './vendor-index.
|
|
30
|
+
import './vendor-index.618ca5a1.js';
|
|
28
31
|
import 'node:buffer';
|
|
29
32
|
import 'node:child_process';
|
|
30
|
-
import './vendor-index.e6c27006.js';
|
|
31
33
|
import 'child_process';
|
|
34
|
+
import 'node:os';
|
|
32
35
|
import 'assert';
|
|
33
36
|
import 'buffer';
|
|
34
|
-
import 'node:os';
|
|
35
37
|
import 'source-map';
|
|
36
38
|
import 'module';
|
|
37
39
|
import 'acorn';
|
|
@@ -40,16 +42,15 @@ import 'node:worker_threads';
|
|
|
40
42
|
import 'tinypool';
|
|
41
43
|
import './vendor-index.783e7f3e.js';
|
|
42
44
|
import 'perf_hooks';
|
|
43
|
-
import './chunk-utils-
|
|
44
|
-
import './chunk-utils-
|
|
45
|
+
import './chunk-utils-base.977ae74f.js';
|
|
46
|
+
import './chunk-utils-tasks.1b603032.js';
|
|
45
47
|
import 'crypto';
|
|
46
48
|
import 'vite-node/utils';
|
|
47
|
-
import '
|
|
49
|
+
import '@vitest/utils/diff';
|
|
48
50
|
import 'node:crypto';
|
|
49
51
|
import './chunk-magic-string.3a794426.js';
|
|
50
52
|
import 'strip-literal';
|
|
51
53
|
import 'readline';
|
|
52
|
-
import './vendor-index.9f20a9be.js';
|
|
53
54
|
|
|
54
55
|
const cli = cac("vitest");
|
|
55
56
|
cli.version(version).option("-r, --root <path>", "Root path").option("-c, --config <path>", "Path to config file").option("-u, --update", "Update snapshot").option("-w, --watch", "Enable watch mode").option("-t, --testNamePattern <pattern>", "Run tests with full names matching the specified regexp pattern").option("--dir <path>", "Base directory to scan for the test files").option("--ui", "Enable UI").option("--open", "Open UI automatically (default: !process.env.CI))").option("--api [api]", "Serve API, available options: --api.port <port>, --api.host [host] and --api.strictPort").option("--threads", "Enabled threads (default: true)").option("--silent", "Silent console output from tests").option("--isolate", "Isolate environment for each test file (default: true)").option("--reporter <name>", "Specify reporters").option("--outputDiffMaxSize <length>", "Object diff output max size (default: 10000)").option("--outputDiffMaxLines <length>", "Max lines in diff output window (default: 50)").option("--outputTruncateLength <length>", "Diff output line length (default: 80)").option("--outputDiffLines <lines>", "Number of lines in single diff (default: 15)").option("--outputFile <filename/-s>", "Write test results to a file when supporter reporter is also specified, use cac's dot notation for individual outputs of multiple reporters").option("--coverage", "Enable coverage report").option("--run", "Disable watch mode").option("--mode <name>", "Override Vite mode (default: test)").option("--globals", "Inject apis globally").option("--dom", "Mock browser api with happy-dom").option("--browser", "Run tests in browser").option("--environment <env>", "Specify runner environment (default: node)").option("--passWithNoTests", "Pass when no tests found").option("--logHeapUsage", "Show the size of heap for each test").option("--allowOnly", "Allow tests and suites that are marked as only (default: !process.env.CI)").option("--dangerouslyIgnoreUnhandledErrors", "Ignore any unhandled errors that occur").option("--shard <shard>", "Test suite shard to execute in a format of <index>/<count>").option("--changed [since]", "Run tests that are affected by the changed files (default: false)").option("--sequence <options>", "Define in what order to run tests (use --sequence.shuffle to run tests in random order)").option("--segfaultRetry <times>", "Return tests on segment fault (default: 0)", { default: 0 }).option("--no-color", "Removes colors from the console output").option("--inspect", "Enable Node.js inspector").option("--inspect-brk", "Enable Node.js inspector with break").help();
|
package/dist/config.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { UserConfig as UserConfig$2, ConfigEnv } from 'vite';
|
|
2
2
|
export { ConfigEnv } from 'vite';
|
|
3
|
-
import {
|
|
3
|
+
import { a1 as ResolvedCoverageOptions, U as UserConfig$1, a4 as CoverageC8Options, _ as CoverageProviderModule, a2 as BaseCoverageOptions, a3 as CoverageIstanbulOptions, $ as CoverageReporter, F as FakeTimerInstallOpts } from './types-c800444e.js';
|
|
4
|
+
import '@vitest/expect';
|
|
5
|
+
import '@vitest/runner/types';
|
|
6
|
+
import '@vitest/runner';
|
|
7
|
+
import '@vitest/runner/utils';
|
|
8
|
+
import '@vitest/utils';
|
|
4
9
|
import 'tinybench';
|
|
5
10
|
import 'vite-node/client';
|
|
6
11
|
import 'vite-node/server';
|
|
12
|
+
import 'node:worker_threads';
|
|
7
13
|
import 'vite-node';
|
|
8
14
|
import 'node:fs';
|
|
9
|
-
import 'node:worker_threads';
|
|
10
15
|
|
|
11
16
|
declare const defaultInclude: string[];
|
|
12
17
|
declare const defaultExclude: string[];
|
package/dist/entry.js
CHANGED
|
@@ -1,31 +1,206 @@
|
|
|
1
|
-
import { promises } from 'node:fs';
|
|
2
|
-
import { m as micromatch_1 } from './
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { a as
|
|
6
|
-
import {
|
|
1
|
+
import { promises, existsSync } from 'node:fs';
|
|
2
|
+
import { m as micromatch_1, t as takeCoverageInsideWorker } from './chunk-integrations-coverage.48e6286b.js';
|
|
3
|
+
import { startTests } from '@vitest/runner';
|
|
4
|
+
import { g as getWorkerState, r as resetModules } from './chunk-utils-global.442d1d33.js';
|
|
5
|
+
import { R as RealDate, g as globalExpect, a as vi } from './chunk-utils-import.9911c99d.js';
|
|
6
|
+
import { e as environments, a as envs } from './chunk-env-node.ffd1183b.js';
|
|
7
|
+
import { createRequire } from 'node:module';
|
|
8
|
+
import c from 'picocolors';
|
|
9
|
+
import { installSourcemapsSupport } from 'vite-node/source-map';
|
|
10
|
+
import { setColors, getSafeTimers } from '@vitest/utils';
|
|
11
|
+
import { i as index } from './chunk-integrations-utils.f1f6f1ed.js';
|
|
12
|
+
import { s as setupSnapshotEnvironment } from './chunk-snapshot-env.6457638e.js';
|
|
13
|
+
import { r as rpc } from './chunk-runtime-rpc.9c0386cc.js';
|
|
14
|
+
import { s as setupCommonEnv } from './chunk-runtime-setup.d9302cfd.js';
|
|
15
|
+
import { V as VitestTestRunner, N as NodeBenchmarkRunner } from './runners-chunk.js';
|
|
16
|
+
import 'local-pkg';
|
|
7
17
|
import 'util';
|
|
8
18
|
import 'path';
|
|
9
|
-
import '
|
|
10
|
-
import '
|
|
11
|
-
import 'local-pkg';
|
|
12
|
-
import './chunk-utils-env.4ebb0106.js';
|
|
13
|
-
import 'node:url';
|
|
19
|
+
import 'pathe';
|
|
20
|
+
import './chunk-utils-env.860d90c2.js';
|
|
14
21
|
import 'std-env';
|
|
15
|
-
import '
|
|
22
|
+
import '@vitest/runner/utils';
|
|
16
23
|
import 'chai';
|
|
17
24
|
import './vendor-_commonjsHelpers.addc3445.js';
|
|
18
|
-
import '
|
|
19
|
-
import './
|
|
20
|
-
import '
|
|
21
|
-
import '
|
|
22
|
-
import './chunk-runtime-rpc.e79efa9a.js';
|
|
23
|
-
import 'fs';
|
|
25
|
+
import '@vitest/expect';
|
|
26
|
+
import './chunk-utils-base.977ae74f.js';
|
|
27
|
+
import './chunk-utils-tasks.1b603032.js';
|
|
28
|
+
import '@vitest/spy';
|
|
24
29
|
import 'node:console';
|
|
25
|
-
import '
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
import './chunk-integrations-run-once.38756e30.js';
|
|
31
|
+
|
|
32
|
+
class NodeSnapshotEnvironment {
|
|
33
|
+
resolvePath(filepath) {
|
|
34
|
+
return rpc().resolveSnapshotPath(filepath);
|
|
35
|
+
}
|
|
36
|
+
async prepareDirectory(filepath) {
|
|
37
|
+
await promises.mkdir(filepath, { recursive: true });
|
|
38
|
+
}
|
|
39
|
+
async saveSnapshotFile(filepath, snapshot) {
|
|
40
|
+
await promises.writeFile(filepath, snapshot, "utf-8");
|
|
41
|
+
}
|
|
42
|
+
async readSnapshotFile(filepath) {
|
|
43
|
+
if (!existsSync(filepath))
|
|
44
|
+
return null;
|
|
45
|
+
return promises.readFile(filepath, "utf-8");
|
|
46
|
+
}
|
|
47
|
+
async removeSnapshotFile(filepath) {
|
|
48
|
+
if (existsSync(filepath))
|
|
49
|
+
await promises.unlink(filepath);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let globalSetup = false;
|
|
54
|
+
async function setupGlobalEnv(config) {
|
|
55
|
+
await setupCommonEnv(config);
|
|
56
|
+
Object.defineProperty(globalThis, "__vitest_index__", {
|
|
57
|
+
value: index,
|
|
58
|
+
enumerable: false
|
|
59
|
+
});
|
|
60
|
+
if (globalSetup)
|
|
61
|
+
return;
|
|
62
|
+
globalSetup = true;
|
|
63
|
+
setupSnapshotEnvironment(new NodeSnapshotEnvironment());
|
|
64
|
+
setColors(c);
|
|
65
|
+
const require = createRequire(import.meta.url);
|
|
66
|
+
require.extensions[".css"] = () => ({});
|
|
67
|
+
require.extensions[".scss"] = () => ({});
|
|
68
|
+
require.extensions[".sass"] = () => ({});
|
|
69
|
+
const state = getWorkerState();
|
|
70
|
+
installSourcemapsSupport({
|
|
71
|
+
getSourceMap: (source) => state.moduleCache.getSourceMap(source)
|
|
72
|
+
});
|
|
73
|
+
await setupConsoleLogSpy();
|
|
74
|
+
}
|
|
75
|
+
async function setupConsoleLogSpy() {
|
|
76
|
+
const stdoutBuffer = /* @__PURE__ */ new Map();
|
|
77
|
+
const stderrBuffer = /* @__PURE__ */ new Map();
|
|
78
|
+
const timers = /* @__PURE__ */ new Map();
|
|
79
|
+
const unknownTestId = "__vitest__unknown_test__";
|
|
80
|
+
const { Writable } = await import('node:stream');
|
|
81
|
+
const { Console } = await import('node:console');
|
|
82
|
+
const { setTimeout, clearTimeout } = getSafeTimers();
|
|
83
|
+
function schedule(taskId) {
|
|
84
|
+
const timer = timers.get(taskId);
|
|
85
|
+
const { stdoutTime, stderrTime } = timer;
|
|
86
|
+
clearTimeout(timer.timer);
|
|
87
|
+
timer.timer = setTimeout(() => {
|
|
88
|
+
if (stderrTime < stdoutTime) {
|
|
89
|
+
sendStderr(taskId);
|
|
90
|
+
sendStdout(taskId);
|
|
91
|
+
} else {
|
|
92
|
+
sendStdout(taskId);
|
|
93
|
+
sendStderr(taskId);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function sendStdout(taskId) {
|
|
98
|
+
const buffer = stdoutBuffer.get(taskId);
|
|
99
|
+
if (!buffer)
|
|
100
|
+
return;
|
|
101
|
+
const content = buffer.map((i) => String(i)).join("");
|
|
102
|
+
if (!content.trim())
|
|
103
|
+
return;
|
|
104
|
+
const timer = timers.get(taskId);
|
|
105
|
+
rpc().onUserConsoleLog({
|
|
106
|
+
type: "stdout",
|
|
107
|
+
content,
|
|
108
|
+
taskId,
|
|
109
|
+
time: timer.stdoutTime || RealDate.now(),
|
|
110
|
+
size: buffer.length
|
|
111
|
+
});
|
|
112
|
+
stdoutBuffer.set(taskId, []);
|
|
113
|
+
timer.stdoutTime = 0;
|
|
114
|
+
}
|
|
115
|
+
function sendStderr(taskId) {
|
|
116
|
+
const buffer = stderrBuffer.get(taskId);
|
|
117
|
+
if (!buffer)
|
|
118
|
+
return;
|
|
119
|
+
const content = buffer.map((i) => String(i)).join("");
|
|
120
|
+
if (!content.trim())
|
|
121
|
+
return;
|
|
122
|
+
const timer = timers.get(taskId);
|
|
123
|
+
rpc().onUserConsoleLog({
|
|
124
|
+
type: "stderr",
|
|
125
|
+
content,
|
|
126
|
+
taskId,
|
|
127
|
+
time: timer.stderrTime || RealDate.now(),
|
|
128
|
+
size: buffer.length
|
|
129
|
+
});
|
|
130
|
+
stderrBuffer.set(taskId, []);
|
|
131
|
+
timer.stderrTime = 0;
|
|
132
|
+
}
|
|
133
|
+
const stdout = new Writable({
|
|
134
|
+
write(data, encoding, callback) {
|
|
135
|
+
var _a, _b;
|
|
136
|
+
const id = ((_b = (_a = getWorkerState()) == null ? void 0 : _a.current) == null ? void 0 : _b.id) ?? unknownTestId;
|
|
137
|
+
let timer = timers.get(id);
|
|
138
|
+
if (timer) {
|
|
139
|
+
timer.stdoutTime = timer.stdoutTime || RealDate.now();
|
|
140
|
+
} else {
|
|
141
|
+
timer = { stdoutTime: RealDate.now(), stderrTime: RealDate.now(), timer: 0 };
|
|
142
|
+
timers.set(id, timer);
|
|
143
|
+
}
|
|
144
|
+
let buffer = stdoutBuffer.get(id);
|
|
145
|
+
if (!buffer) {
|
|
146
|
+
buffer = [];
|
|
147
|
+
stdoutBuffer.set(id, buffer);
|
|
148
|
+
}
|
|
149
|
+
buffer.push(data);
|
|
150
|
+
schedule(id);
|
|
151
|
+
callback();
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
const stderr = new Writable({
|
|
155
|
+
write(data, encoding, callback) {
|
|
156
|
+
var _a, _b;
|
|
157
|
+
const id = ((_b = (_a = getWorkerState()) == null ? void 0 : _a.current) == null ? void 0 : _b.id) ?? unknownTestId;
|
|
158
|
+
let timer = timers.get(id);
|
|
159
|
+
if (timer) {
|
|
160
|
+
timer.stderrTime = timer.stderrTime || RealDate.now();
|
|
161
|
+
} else {
|
|
162
|
+
timer = { stderrTime: RealDate.now(), stdoutTime: RealDate.now(), timer: 0 };
|
|
163
|
+
timers.set(id, timer);
|
|
164
|
+
}
|
|
165
|
+
let buffer = stderrBuffer.get(id);
|
|
166
|
+
if (!buffer) {
|
|
167
|
+
buffer = [];
|
|
168
|
+
stderrBuffer.set(id, buffer);
|
|
169
|
+
}
|
|
170
|
+
buffer.push(data);
|
|
171
|
+
schedule(id);
|
|
172
|
+
callback();
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
globalThis.console = new Console({
|
|
176
|
+
stdout,
|
|
177
|
+
stderr,
|
|
178
|
+
colorMode: true,
|
|
179
|
+
groupIndentation: 2
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
async function loadEnvironment(name) {
|
|
183
|
+
const pkg = await import(`vitest-environment-${name}`);
|
|
184
|
+
if (!pkg || !pkg.default || typeof pkg.default !== "object" || typeof pkg.default.setup !== "function") {
|
|
185
|
+
throw new Error(
|
|
186
|
+
`Environment "${name}" is not a valid environment. Package "vitest-environment-${name}" should have default export with "setup" method.`
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
return pkg.default;
|
|
190
|
+
}
|
|
191
|
+
async function withEnv(name, options, fn) {
|
|
192
|
+
const config = environments[name] || await loadEnvironment(name);
|
|
193
|
+
globalThis.__vitest_environment__ = config.name || name;
|
|
194
|
+
globalExpect.setState({
|
|
195
|
+
environment: config.name || name || "node"
|
|
196
|
+
});
|
|
197
|
+
const env = await config.setup(globalThis, options);
|
|
198
|
+
try {
|
|
199
|
+
await fn();
|
|
200
|
+
} finally {
|
|
201
|
+
await env.teardown(globalThis);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
29
204
|
|
|
30
205
|
function groupBy(collection, iteratee) {
|
|
31
206
|
return collection.reduce((acc, item) => {
|
|
@@ -35,14 +210,44 @@ function groupBy(collection, iteratee) {
|
|
|
35
210
|
return acc;
|
|
36
211
|
}, {});
|
|
37
212
|
}
|
|
213
|
+
async function getTestRunnerConstructor(config) {
|
|
214
|
+
if (!config.runner)
|
|
215
|
+
return config.mode === "test" ? VitestTestRunner : NodeBenchmarkRunner;
|
|
216
|
+
const mod = await import(config.runner);
|
|
217
|
+
if (!mod.default && typeof mod.default !== "function")
|
|
218
|
+
throw new Error(`Runner must export a default function, but got ${typeof mod.default} imported from ${config.runner}`);
|
|
219
|
+
return mod.default;
|
|
220
|
+
}
|
|
221
|
+
async function getTestRunner(config) {
|
|
222
|
+
const TestRunner = await getTestRunnerConstructor(config);
|
|
223
|
+
const testRunner = new TestRunner(config);
|
|
224
|
+
if (!testRunner.config)
|
|
225
|
+
testRunner.config = config;
|
|
226
|
+
if (!testRunner.importFile)
|
|
227
|
+
throw new Error('Runner must implement "importFile" method.');
|
|
228
|
+
const originalOnTaskUpdate = testRunner.onTaskUpdate;
|
|
229
|
+
testRunner.onTaskUpdate = async (task) => {
|
|
230
|
+
const p = rpc().onTaskUpdate(task);
|
|
231
|
+
await (originalOnTaskUpdate == null ? void 0 : originalOnTaskUpdate.call(testRunner, task));
|
|
232
|
+
return p;
|
|
233
|
+
};
|
|
234
|
+
const originalOnCollected = testRunner.onCollected;
|
|
235
|
+
testRunner.onCollected = async (files) => {
|
|
236
|
+
rpc().onCollected(files);
|
|
237
|
+
await (originalOnCollected == null ? void 0 : originalOnCollected.call(testRunner, files));
|
|
238
|
+
};
|
|
239
|
+
const originalOnAfterRun = testRunner.onAfterRun;
|
|
240
|
+
testRunner.onAfterRun = async (files) => {
|
|
241
|
+
const coverage = await takeCoverageInsideWorker(config.coverage);
|
|
242
|
+
rpc().onAfterSuiteRun({ coverage });
|
|
243
|
+
await (originalOnAfterRun == null ? void 0 : originalOnAfterRun.call(testRunner, files));
|
|
244
|
+
};
|
|
245
|
+
return testRunner;
|
|
246
|
+
}
|
|
38
247
|
async function run(files, config) {
|
|
39
248
|
await setupGlobalEnv(config);
|
|
40
249
|
const workerState = getWorkerState();
|
|
41
|
-
|
|
42
|
-
workerState.mockMap.clear();
|
|
43
|
-
await startTests(files, config);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
250
|
+
const runner = await getTestRunner(config);
|
|
46
251
|
const filesWithEnv = await Promise.all(files.map(async (file) => {
|
|
47
252
|
var _a, _b;
|
|
48
253
|
const code = await promises.readFile(file, "utf-8");
|
|
@@ -85,7 +290,7 @@ async function run(files, config) {
|
|
|
85
290
|
resetModules(workerState.moduleCache, true);
|
|
86
291
|
}
|
|
87
292
|
workerState.filepath = file;
|
|
88
|
-
await startTests([file],
|
|
293
|
+
await startTests([file], runner);
|
|
89
294
|
workerState.filepath = void 0;
|
|
90
295
|
vi.resetConfig();
|
|
91
296
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface SnapshotEnvironment {
|
|
2
|
+
resolvePath(filepath: string): Promise<string>;
|
|
3
|
+
prepareDirectory(filepath: string): Promise<void>;
|
|
4
|
+
saveSnapshotFile(filepath: string, snapshot: string): Promise<void>;
|
|
5
|
+
readSnapshotFile(filepath: string): Promise<string | null>;
|
|
6
|
+
removeSnapshotFile(filepath: string): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
declare function setupSnapshotEnvironment(environment: SnapshotEnvironment): void;
|
|
9
|
+
|
|
10
|
+
export { SnapshotEnvironment as S, setupSnapshotEnvironment as s };
|
package/dist/environments.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { P as Environment } from './types-c800444e.js';
|
|
2
|
+
import '@vitest/expect';
|
|
2
3
|
import 'vite';
|
|
4
|
+
import '@vitest/runner/types';
|
|
5
|
+
import '@vitest/runner';
|
|
6
|
+
import '@vitest/runner/utils';
|
|
7
|
+
import '@vitest/utils';
|
|
3
8
|
import 'tinybench';
|
|
4
9
|
import 'vite-node/client';
|
|
5
10
|
import 'vite-node/server';
|
|
11
|
+
import 'node:worker_threads';
|
|
6
12
|
import 'vite-node';
|
|
7
13
|
import 'node:fs';
|
|
8
|
-
import 'node:worker_threads';
|
|
9
14
|
|
|
10
15
|
declare const environments: {
|
|
11
16
|
node: Environment;
|