vitest 4.0.15 → 4.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +1 -1
- package/dist/chunks/{base.CTp-EStD.js → base.Bin-9uYm.js} +4 -3
- package/dist/chunks/{browser.d.DBzUq_Na.d.ts → browser.d.Bz3lxTX-.d.ts} +1 -1
- package/dist/chunks/{cac.BNNpZQl7.js → cac.BGonGPac.js} +3 -3
- package/dist/chunks/{cli-api.C7sYjHmQ.js → cli-api.BKg19Fvw.js} +51 -31
- package/dist/chunks/{coverage.CtyeYmKM.js → coverage.BuJUwVtg.js} +2 -1
- package/dist/chunks/{index.bFLgAE-Z.js → index.6Qv1eEA6.js} +2 -2
- package/dist/chunks/index.Chj8NDwU.js +206 -0
- package/dist/chunks/{init-forks.CKEYp90N.js → init-forks.v9UONQS6.js} +1 -1
- package/dist/chunks/{init-threads.D8Ok07M7.js → init-threads.DqYg3Trk.js} +1 -1
- package/dist/chunks/{init.B04saIIg.js → init.KmQZdqFg.js} +2 -2
- package/dist/chunks/{modules.DJPjQW6m.js → modules.BJuCwlRJ.js} +4 -3
- package/dist/chunks/{plugin.d.CY7CUjf-.d.ts → plugin.d.v1sC_bv1.d.ts} +1 -1
- package/dist/chunks/{reporters.d.OXEK7y4s.d.ts → reporters.d.Rsi0PyxX.d.ts} +2 -2
- package/dist/chunks/{rpc.BytlcPfC.js → rpc.BoxB0q7B.js} +1 -1
- package/dist/chunks/{startModuleRunner.Iz2V0ESw.js → startModuleRunner.DpqpB8k3.js} +1 -1
- package/dist/chunks/{test.BT8LKgU9.js → test.B8ej_ZHS.js} +1 -1
- package/dist/chunks/{vm.BwmD1Rql.js → vm.qFl6P1nF.js} +2 -2
- package/dist/chunks/worker.d.5JNaocaN.d.ts +254 -0
- package/dist/cli.js +1 -1
- package/dist/config.d.ts +5 -5
- package/dist/coverage.d.ts +3 -3
- package/dist/coverage.js +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/module-evaluator.js +2 -10
- package/dist/module-runner.js +2 -2
- package/dist/node.d.ts +16 -9
- package/dist/node.js +8 -8
- package/dist/reporters.d.ts +3 -3
- package/dist/runners.js +3 -3
- package/dist/worker.d.ts +4 -2
- package/dist/worker.js +8 -8
- package/dist/workers/forks.js +9 -9
- package/dist/workers/runVmTests.js +4 -4
- package/dist/workers/threads.js +9 -9
- package/dist/workers/vmForks.js +7 -7
- package/dist/workers/vmThreads.js +7 -7
- package/package.json +13 -13
- package/dist/chunks/index.0kCJoeWi.js +0 -220
- package/dist/chunks/worker.d.B4A26qg6.d.ts +0 -238
package/dist/browser.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { collectTests, startTests } from '@vitest/runner';
|
|
|
5
5
|
import * as _vitest_spy from '@vitest/spy';
|
|
6
6
|
export { _vitest_spy as SpyModule };
|
|
7
7
|
export { LoupeOptions, ParsedStack, StringifyOptions } from '@vitest/utils';
|
|
8
|
-
export { format, inspect, stringify } from '@vitest/utils/display';
|
|
8
|
+
export { browserFormat, format, inspect, stringify } from '@vitest/utils/display';
|
|
9
9
|
export { processError } from '@vitest/utils/error';
|
|
10
10
|
export { getType } from '@vitest/utils/helpers';
|
|
11
11
|
export { DecodedMap, getOriginalPosition } from '@vitest/utils/source-map';
|
package/dist/browser.js
CHANGED
|
@@ -2,7 +2,7 @@ export { l as loadDiffConfig, b as loadSnapshotSerializers, c as setupCommonEnv,
|
|
|
2
2
|
export { collectTests, startTests } from '@vitest/runner';
|
|
3
3
|
import * as spyModule from '@vitest/spy';
|
|
4
4
|
export { spyModule as SpyModule };
|
|
5
|
-
export { format, inspect, stringify } from '@vitest/utils/display';
|
|
5
|
+
export { browserFormat, format, inspect, stringify } from '@vitest/utils/display';
|
|
6
6
|
export { processError } from '@vitest/utils/error';
|
|
7
7
|
export { getType } from '@vitest/utils/helpers';
|
|
8
8
|
export { DecodedMap, getOriginalPosition } from '@vitest/utils/source-map';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { runInThisContext } from 'node:vm';
|
|
2
2
|
import * as spyModule from '@vitest/spy';
|
|
3
|
-
import { r as resolveTestRunner, a as resolveSnapshotEnvironment, s as setupChaiConfig } from './index.
|
|
4
|
-
import { l as loadEnvironment } from './init.
|
|
3
|
+
import { r as resolveTestRunner, a as resolveSnapshotEnvironment, s as setupChaiConfig } from './index.6Qv1eEA6.js';
|
|
4
|
+
import { l as loadEnvironment } from './init.KmQZdqFg.js';
|
|
5
5
|
import { V as VitestEvaluatedModules } from './evaluatedModules.Dg1zASAC.js';
|
|
6
|
-
import { s as startVitestModuleRunner, c as createNodeImportMeta } from './startModuleRunner.
|
|
6
|
+
import { s as startVitestModuleRunner, c as createNodeImportMeta } from './startModuleRunner.DpqpB8k3.js';
|
|
7
7
|
import { performance as performance$1 } from 'node:perf_hooks';
|
|
8
8
|
import { startTests, collectTests } from '@vitest/runner';
|
|
9
9
|
import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.Cm-kSBVi.js';
|
|
@@ -104,6 +104,7 @@ function startModuleRunner(options) {
|
|
|
104
104
|
}
|
|
105
105
|
let _currentEnvironment;
|
|
106
106
|
let _environmentTime;
|
|
107
|
+
/** @experimental */
|
|
107
108
|
async function setupEnvironment(context) {
|
|
108
109
|
const startTime = performance.now();
|
|
109
110
|
const { environment: { name: environmentName, options: environmentOptions }, rpc, config } = context;
|
|
@@ -619,7 +619,7 @@ class CAC extends EventEmitter {
|
|
|
619
619
|
|
|
620
620
|
const cac = (name = "") => new CAC(name);
|
|
621
621
|
|
|
622
|
-
var version = "4.0.
|
|
622
|
+
var version = "4.0.16";
|
|
623
623
|
|
|
624
624
|
const apiConfig = (port) => ({
|
|
625
625
|
port: {
|
|
@@ -1356,7 +1356,7 @@ function normalizeCliOptions(cliFilters, argv) {
|
|
|
1356
1356
|
}
|
|
1357
1357
|
async function start(mode, cliFilters, options) {
|
|
1358
1358
|
try {
|
|
1359
|
-
const { startVitest } = await import('./cli-api.
|
|
1359
|
+
const { startVitest } = await import('./cli-api.BKg19Fvw.js').then(function (n) { return n.q; });
|
|
1360
1360
|
const ctx = await startVitest(mode, cliFilters.map(normalize), normalizeCliOptions(cliFilters, options));
|
|
1361
1361
|
if (!ctx.shouldKeepServer()) await ctx.exit();
|
|
1362
1362
|
} catch (e) {
|
|
@@ -1378,7 +1378,7 @@ async function init(project) {
|
|
|
1378
1378
|
}
|
|
1379
1379
|
async function collect(mode, cliFilters, options) {
|
|
1380
1380
|
try {
|
|
1381
|
-
const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.
|
|
1381
|
+
const { prepareVitest, processCollected, outputFileList } = await import('./cli-api.BKg19Fvw.js').then(function (n) { return n.q; });
|
|
1382
1382
|
const ctx = await prepareVitest(mode, {
|
|
1383
1383
|
...normalizeCliOptions(cliFilters, options),
|
|
1384
1384
|
watch: false,
|
|
@@ -2,19 +2,19 @@ import fs, { promises, existsSync, mkdirSync, readFileSync, statSync, readdirSyn
|
|
|
2
2
|
import { relative, resolve, dirname, join, extname, normalize, basename, isAbsolute } from 'pathe';
|
|
3
3
|
import { C as CoverageProviderMap } from './coverage.D_JHT54q.js';
|
|
4
4
|
import path, { resolve as resolve$1 } from 'node:path';
|
|
5
|
-
import { noop, createDefer, slash,
|
|
5
|
+
import { noop, createDefer, slash, withTrailingSlash, cleanUrl, wrapId, isExternalUrl, unwrapId, toArray, deepMerge, nanoid, deepClone, isPrimitive, notNullish } from '@vitest/utils/helpers';
|
|
6
6
|
import { a as any, p as prompt } from './index.D4KonVSU.js';
|
|
7
|
-
import { h as hash, R as RandomSequencer, i as isPackageExists, c as isBrowserEnabled, r as resolveConfig, g as getCoverageProvider, a as resolveApiServerConfig, d as resolveModule } from './coverage.
|
|
7
|
+
import { h as hash, R as RandomSequencer, i as isPackageExists, c as isBrowserEnabled, r as resolveConfig, g as getCoverageProvider, a as resolveApiServerConfig, d as resolveModule } from './coverage.BuJUwVtg.js';
|
|
8
8
|
import * as vite from 'vite';
|
|
9
|
-
import { isFileServingAllowed, parseAst, searchForWorkspaceRoot, fetchModule, version, mergeConfig, createServer } from 'vite';
|
|
9
|
+
import { isFileServingAllowed as isFileServingAllowed$1, parseAst, searchForWorkspaceRoot, fetchModule, version, mergeConfig, createServer, isFileLoadingAllowed, normalizePath } from 'vite';
|
|
10
10
|
import { A as API_PATH, c as configFiles, d as defaultBrowserPort, a as defaultPort } from './constants.D_Q9UYh-.js';
|
|
11
11
|
import * as nodeos from 'node:os';
|
|
12
12
|
import nodeos__default, { tmpdir } from 'node:os';
|
|
13
13
|
import { generateHash as generateHash$1, createTaskName, calculateSuiteHash, someTasksAreOnly, interpretTaskModes, hasFailed, generateFileHash, limitConcurrency, createFileTask as createFileTask$1, getTasks, isTestCase } from '@vitest/runner/utils';
|
|
14
14
|
import { SnapshotManager } from '@vitest/snapshot/manager';
|
|
15
|
-
import { v as version$1 } from './cac.
|
|
15
|
+
import { v as version$1 } from './cac.BGonGPac.js';
|
|
16
16
|
import { performance as performance$1 } from 'node:perf_hooks';
|
|
17
|
-
import { c as createBirpc } from './index.
|
|
17
|
+
import { c as createBirpc } from './index.Chj8NDwU.js';
|
|
18
18
|
import { p as parse, d as stringify, e as createIndexLocationsMap, h as TraceMap, o as originalPositionFor, i as ancestor, j as printError, f as formatProjectName, w as withLabel, k as errorBanner, l as divider, m as Typechecker, n as generateCodeFrame, q as escapeRegExp, r as createDefinesScript, R as ReportersMap, u as groupBy, B as BlobReporter, v as readBlobs, x as convertTasksToEvents, H as HangingProcessReporter, y as wildcardPatternToRegExp, z as stdout } from './index.456_DGfR.js';
|
|
19
19
|
import require$$0$3 from 'events';
|
|
20
20
|
import require$$1$1 from 'https';
|
|
@@ -42,7 +42,7 @@ import url, { fileURLToPath, pathToFileURL } from 'node:url';
|
|
|
42
42
|
import { i as isTTY, a as isWindows } from './env.D4Lgay0q.js';
|
|
43
43
|
import { isatty } from 'node:tty';
|
|
44
44
|
import EventEmitter$1, { EventEmitter } from 'node:events';
|
|
45
|
-
import { t as toBuiltin, i as isBuiltin } from './modules.
|
|
45
|
+
import { t as toBuiltin, i as isBuiltin } from './modules.BJuCwlRJ.js';
|
|
46
46
|
import { fork } from 'node:child_process';
|
|
47
47
|
import { Worker } from 'node:worker_threads';
|
|
48
48
|
import pm from 'picomatch';
|
|
@@ -5175,7 +5175,7 @@ function setup(ctx, _server) {
|
|
|
5175
5175
|
async getExternalResult(moduleId, testFileTaskId) {
|
|
5176
5176
|
const testModule = ctx.state.getReportedEntityById(testFileTaskId);
|
|
5177
5177
|
if (!testModule) return;
|
|
5178
|
-
if (!isFileServingAllowed(testModule.project.vite.config, moduleId)) return;
|
|
5178
|
+
if (!isFileServingAllowed$1(testModule.project.vite.config, moduleId)) return;
|
|
5179
5179
|
const result = {};
|
|
5180
5180
|
try {
|
|
5181
5181
|
result.source = await promises.readFile(moduleId, "utf-8");
|
|
@@ -5185,7 +5185,7 @@ function setup(ctx, _server) {
|
|
|
5185
5185
|
async getTransformResult(projectName, moduleId, testFileTaskId, browser = false) {
|
|
5186
5186
|
const project = ctx.getProjectByName(projectName);
|
|
5187
5187
|
const testModule = ctx.state.getReportedEntityById(testFileTaskId);
|
|
5188
|
-
if (!testModule || !isFileServingAllowed(project.vite.config, moduleId)) return;
|
|
5188
|
+
if (!testModule || !isFileServingAllowed$1(project.vite.config, moduleId)) return;
|
|
5189
5189
|
const environment = getTestFileEnvironment(project, testModule.moduleId, browser);
|
|
5190
5190
|
const moduleNode = environment?.moduleGraph.getModuleById(moduleId);
|
|
5191
5191
|
if (!environment || !moduleNode?.transformResult) return;
|
|
@@ -6082,6 +6082,28 @@ function tryStatSync(file) {
|
|
|
6082
6082
|
} catch {}
|
|
6083
6083
|
}
|
|
6084
6084
|
|
|
6085
|
+
// this is copy pasted from vite
|
|
6086
|
+
function normalizeResolvedIdToUrl(environment, resolvedId) {
|
|
6087
|
+
const root = environment.config.root;
|
|
6088
|
+
const depsOptimizer = environment.depsOptimizer;
|
|
6089
|
+
let url;
|
|
6090
|
+
// normalize all imports into resolved URLs
|
|
6091
|
+
// e.g. `import 'foo'` -> `import '/@fs/.../node_modules/foo/index.js'`
|
|
6092
|
+
if (resolvedId.startsWith(withTrailingSlash(root)))
|
|
6093
|
+
// in root: infer short absolute path from root
|
|
6094
|
+
url = resolvedId.slice(root.length);
|
|
6095
|
+
else if (depsOptimizer?.isOptimizedDepFile(resolvedId) || resolvedId !== "/@react-refresh" && path.isAbsolute(resolvedId) && existsSync(cleanUrl(resolvedId)))
|
|
6096
|
+
// an optimized deps may not yet exists in the filesystem, or
|
|
6097
|
+
// a regular file exists but is out of root: rewrite to absolute /@fs/ paths
|
|
6098
|
+
url = path.posix.join("/@fs/", resolvedId);
|
|
6099
|
+
else url = resolvedId;
|
|
6100
|
+
// if the resolved id is not a valid browser import specifier,
|
|
6101
|
+
// prefix it to make it valid. We will strip this before feeding it
|
|
6102
|
+
// back into the transform pipeline
|
|
6103
|
+
if (url[0] !== "." && url[0] !== "/") url = wrapId(resolvedId);
|
|
6104
|
+
return url;
|
|
6105
|
+
}
|
|
6106
|
+
|
|
6085
6107
|
const saveCachePromises = /* @__PURE__ */ new Map();
|
|
6086
6108
|
const readFilePromises = /* @__PURE__ */ new Map();
|
|
6087
6109
|
class ModuleFetcher {
|
|
@@ -6117,6 +6139,11 @@ class ModuleFetcher {
|
|
|
6117
6139
|
type: "network"
|
|
6118
6140
|
};
|
|
6119
6141
|
}
|
|
6142
|
+
// handle unresolved id of dynamic import skipped by Vite import analysis
|
|
6143
|
+
if (url[0] !== "/") {
|
|
6144
|
+
const resolved = await environment.pluginContainer.resolveId(url, importer);
|
|
6145
|
+
if (resolved) url = normalizeResolvedIdToUrl(environment, resolved.id);
|
|
6146
|
+
}
|
|
6120
6147
|
const moduleGraphModule = await environment.moduleGraph.ensureEntryFromUrl(unwrapId(url));
|
|
6121
6148
|
const cached = !!moduleGraphModule.transformResult;
|
|
6122
6149
|
if (moduleGraphModule.file) trace.setAttribute("code.file.path", moduleGraphModule.file);
|
|
@@ -6374,28 +6401,6 @@ function handleRollupError(e) {
|
|
|
6374
6401
|
throw e;
|
|
6375
6402
|
}
|
|
6376
6403
|
|
|
6377
|
-
// this is copy pasted from vite
|
|
6378
|
-
function normalizeResolvedIdToUrl(environment, resolvedId) {
|
|
6379
|
-
const root = environment.config.root;
|
|
6380
|
-
const depsOptimizer = environment.depsOptimizer;
|
|
6381
|
-
let url;
|
|
6382
|
-
// normalize all imports into resolved URLs
|
|
6383
|
-
// e.g. `import 'foo'` -> `import '/@fs/.../node_modules/foo/index.js'`
|
|
6384
|
-
if (resolvedId.startsWith(withTrailingSlash(root)))
|
|
6385
|
-
// in root: infer short absolute path from root
|
|
6386
|
-
url = resolvedId.slice(root.length);
|
|
6387
|
-
else if (depsOptimizer?.isOptimizedDepFile(resolvedId) || resolvedId !== "/@react-refresh" && path.isAbsolute(resolvedId) && existsSync(cleanUrl(resolvedId)))
|
|
6388
|
-
// an optimized deps may not yet exists in the filesystem, or
|
|
6389
|
-
// a regular file exists but is out of root: rewrite to absolute /@fs/ paths
|
|
6390
|
-
url = path.posix.join("/@fs/", resolvedId);
|
|
6391
|
-
else url = resolvedId;
|
|
6392
|
-
// if the resolved id is not a valid browser import specifier,
|
|
6393
|
-
// prefix it to make it valid. We will strip this before feeding it
|
|
6394
|
-
// back into the transform pipeline
|
|
6395
|
-
if (url[0] !== "." && url[0] !== "/") url = wrapId(resolvedId);
|
|
6396
|
-
return url;
|
|
6397
|
-
}
|
|
6398
|
-
|
|
6399
6404
|
class ServerModuleRunner extends ModuleRunner {
|
|
6400
6405
|
constructor(environment, fetcher, config) {
|
|
6401
6406
|
super({
|
|
@@ -9811,6 +9816,21 @@ async function createViteServer(inlineConfig) {
|
|
|
9811
9816
|
console.error = error;
|
|
9812
9817
|
return server;
|
|
9813
9818
|
}
|
|
9819
|
+
function isFileServingAllowed(configOrUrl, urlOrServer) {
|
|
9820
|
+
const config = typeof urlOrServer === "string" ? configOrUrl : urlOrServer.config;
|
|
9821
|
+
const url = typeof urlOrServer === "string" ? urlOrServer : configOrUrl;
|
|
9822
|
+
if (!config.server.fs.strict) return true;
|
|
9823
|
+
return isFileLoadingAllowed(config, fsPathFromUrl(url));
|
|
9824
|
+
}
|
|
9825
|
+
const FS_PREFIX = "/@fs/";
|
|
9826
|
+
const VOLUME_RE = /^[A-Z]:/i;
|
|
9827
|
+
function fsPathFromId(id) {
|
|
9828
|
+
const fsPath = normalizePath(id.startsWith(FS_PREFIX) ? id.slice(5) : id);
|
|
9829
|
+
return fsPath[0] === "/" || VOLUME_RE.test(fsPath) ? fsPath : `/${fsPath}`;
|
|
9830
|
+
}
|
|
9831
|
+
function fsPathFromUrl(url) {
|
|
9832
|
+
return fsPathFromId(cleanUrl(url));
|
|
9833
|
+
}
|
|
9814
9834
|
|
|
9815
9835
|
class TestProject {
|
|
9816
9836
|
/**
|
|
@@ -13567,4 +13587,4 @@ var cliApi = /*#__PURE__*/Object.freeze({
|
|
|
13567
13587
|
startVitest: startVitest
|
|
13568
13588
|
});
|
|
13569
13589
|
|
|
13570
|
-
export { FilesNotFoundError as F, GitNotFoundError as G, ThreadsPoolWorker as T, Vitest as V, VitestPlugin as a, VitestPackageInstaller as b, createVitest as c, createMethodsRPC as d, escapeTestName as e, ForksPoolWorker as f, getFilePoolName as g, TypecheckPoolWorker as h, isValidApiRequest as i, VmForksPoolWorker as j, VmThreadsPoolWorker as k, experimental_getRunnerTask as l, registerConsoleShortcuts as m,
|
|
13590
|
+
export { FilesNotFoundError as F, GitNotFoundError as G, ThreadsPoolWorker as T, Vitest as V, VitestPlugin as a, VitestPackageInstaller as b, createVitest as c, createMethodsRPC as d, escapeTestName as e, ForksPoolWorker as f, getFilePoolName as g, TypecheckPoolWorker as h, isValidApiRequest as i, VmForksPoolWorker as j, VmThreadsPoolWorker as k, experimental_getRunnerTask as l, registerConsoleShortcuts as m, isFileServingAllowed as n, createViteLogger as o, createDebugger as p, cliApi as q, resolveFsAllow as r, startVitest as s };
|
|
@@ -2474,6 +2474,7 @@ function resolveConfig$1(vitest, options, viteConfig) {
|
|
|
2474
2474
|
resolved.pool = options.pool.name;
|
|
2475
2475
|
resolved.poolRunner = options.pool;
|
|
2476
2476
|
}
|
|
2477
|
+
if ("poolOptions" in resolved) logger.deprecate("`test.poolOptions` was removed in Vitest 4. All previous `poolOptions` are now top-level options. Please, refer to the migration guide: https://vitest.dev/guide/migration#pool-rework");
|
|
2477
2478
|
resolved.pool ??= "forks";
|
|
2478
2479
|
resolved.project = toArray(resolved.project);
|
|
2479
2480
|
resolved.provide ??= {};
|
|
@@ -2790,7 +2791,7 @@ function resolveConfig$1(vitest, options, viteConfig) {
|
|
|
2790
2791
|
const userFolder = resolved.server.debug?.dump || process.env.VITEST_DEBUG_DUMP;
|
|
2791
2792
|
resolved.dumpDir = resolve(resolved.root, typeof userFolder === "string" && userFolder !== "true" ? userFolder : ".vitest-dump", resolved.name || "root");
|
|
2792
2793
|
}
|
|
2793
|
-
resolved.testTimeout ??= resolved.browser.enabled ?
|
|
2794
|
+
resolved.testTimeout ??= resolved.browser.enabled ? 15e3 : 5e3;
|
|
2794
2795
|
resolved.hookTimeout ??= resolved.browser.enabled ? 3e4 : 1e4;
|
|
2795
2796
|
resolved.experimental ??= {};
|
|
2796
2797
|
if (resolved.experimental.openTelemetry?.sdkPath) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { chai } from '@vitest/expect';
|
|
2
2
|
import { l as loadDiffConfig, b as loadSnapshotSerializers, t as takeCoverageInsideWorker } from './setup-common.Cm-kSBVi.js';
|
|
3
|
-
import { r as rpc } from './rpc.
|
|
3
|
+
import { r as rpc } from './rpc.BoxB0q7B.js';
|
|
4
4
|
import { g as getWorkerState } from './utils.DvEY5TfP.js';
|
|
5
|
-
import { V as VitestTestRunner, N as NodeBenchmarkRunner } from './test.
|
|
5
|
+
import { V as VitestTestRunner, N as NodeBenchmarkRunner } from './test.B8ej_ZHS.js';
|
|
6
6
|
|
|
7
7
|
function setupChaiConfig(config) {
|
|
8
8
|
Object.assign(chai.config, config);
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
//#region src/messages.ts
|
|
2
|
+
const TYPE_REQUEST = "q";
|
|
3
|
+
const TYPE_RESPONSE = "s";
|
|
4
|
+
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/utils.ts
|
|
7
|
+
function createPromiseWithResolvers() {
|
|
8
|
+
let resolve;
|
|
9
|
+
let reject;
|
|
10
|
+
return {
|
|
11
|
+
promise: new Promise((res, rej) => {
|
|
12
|
+
resolve = res;
|
|
13
|
+
reject = rej;
|
|
14
|
+
}),
|
|
15
|
+
resolve,
|
|
16
|
+
reject
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const random = Math.random.bind(Math);
|
|
20
|
+
const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
21
|
+
function nanoid(size = 21) {
|
|
22
|
+
let id = "";
|
|
23
|
+
let i = size;
|
|
24
|
+
while (i--) id += urlAlphabet[random() * 64 | 0];
|
|
25
|
+
return id;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/main.ts
|
|
30
|
+
const DEFAULT_TIMEOUT = 6e4;
|
|
31
|
+
const defaultSerialize = (i) => i;
|
|
32
|
+
const defaultDeserialize = defaultSerialize;
|
|
33
|
+
const { clearTimeout, setTimeout } = globalThis;
|
|
34
|
+
function createBirpc($functions, options) {
|
|
35
|
+
const { post, on, off = () => {}, eventNames = [], serialize = defaultSerialize, deserialize = defaultDeserialize, resolver, bind = "rpc", timeout = DEFAULT_TIMEOUT, proxify = true } = options;
|
|
36
|
+
let $closed = false;
|
|
37
|
+
const _rpcPromiseMap = /* @__PURE__ */ new Map();
|
|
38
|
+
let _promiseInit;
|
|
39
|
+
let rpc;
|
|
40
|
+
async function _call(method, args, event, optional) {
|
|
41
|
+
if ($closed) throw new Error(`[birpc] rpc is closed, cannot call "${method}"`);
|
|
42
|
+
const req = {
|
|
43
|
+
m: method,
|
|
44
|
+
a: args,
|
|
45
|
+
t: TYPE_REQUEST
|
|
46
|
+
};
|
|
47
|
+
if (optional) req.o = true;
|
|
48
|
+
const send = async (_req) => post(serialize(_req));
|
|
49
|
+
if (event) {
|
|
50
|
+
await send(req);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (_promiseInit) try {
|
|
54
|
+
await _promiseInit;
|
|
55
|
+
} finally {
|
|
56
|
+
_promiseInit = void 0;
|
|
57
|
+
}
|
|
58
|
+
let { promise, resolve, reject } = createPromiseWithResolvers();
|
|
59
|
+
const id = nanoid();
|
|
60
|
+
req.i = id;
|
|
61
|
+
let timeoutId;
|
|
62
|
+
async function handler(newReq = req) {
|
|
63
|
+
if (timeout >= 0) {
|
|
64
|
+
timeoutId = setTimeout(() => {
|
|
65
|
+
try {
|
|
66
|
+
if (options.onTimeoutError?.call(rpc, method, args) !== true) throw new Error(`[birpc] timeout on calling "${method}"`);
|
|
67
|
+
} catch (e) {
|
|
68
|
+
reject(e);
|
|
69
|
+
}
|
|
70
|
+
_rpcPromiseMap.delete(id);
|
|
71
|
+
}, timeout);
|
|
72
|
+
if (typeof timeoutId === "object") timeoutId = timeoutId.unref?.();
|
|
73
|
+
}
|
|
74
|
+
_rpcPromiseMap.set(id, {
|
|
75
|
+
resolve,
|
|
76
|
+
reject,
|
|
77
|
+
timeoutId,
|
|
78
|
+
method
|
|
79
|
+
});
|
|
80
|
+
await send(newReq);
|
|
81
|
+
return promise;
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
if (options.onRequest) await options.onRequest.call(rpc, req, handler, resolve);
|
|
85
|
+
else await handler();
|
|
86
|
+
} catch (e) {
|
|
87
|
+
if (options.onGeneralError?.call(rpc, e) !== true) throw e;
|
|
88
|
+
return;
|
|
89
|
+
} finally {
|
|
90
|
+
clearTimeout(timeoutId);
|
|
91
|
+
_rpcPromiseMap.delete(id);
|
|
92
|
+
}
|
|
93
|
+
return promise;
|
|
94
|
+
}
|
|
95
|
+
const builtinMethods = {
|
|
96
|
+
$call: (method, ...args) => _call(method, args, false),
|
|
97
|
+
$callOptional: (method, ...args) => _call(method, args, false, true),
|
|
98
|
+
$callEvent: (method, ...args) => _call(method, args, true),
|
|
99
|
+
$callRaw: (options$1) => _call(options$1.method, options$1.args, options$1.event, options$1.optional),
|
|
100
|
+
$rejectPendingCalls,
|
|
101
|
+
get $closed() {
|
|
102
|
+
return $closed;
|
|
103
|
+
},
|
|
104
|
+
get $meta() {
|
|
105
|
+
return options.meta;
|
|
106
|
+
},
|
|
107
|
+
$close,
|
|
108
|
+
$functions
|
|
109
|
+
};
|
|
110
|
+
if (proxify) rpc = new Proxy({}, { get(_, method) {
|
|
111
|
+
if (Object.prototype.hasOwnProperty.call(builtinMethods, method)) return builtinMethods[method];
|
|
112
|
+
if (method === "then" && !eventNames.includes("then") && !("then" in $functions)) return void 0;
|
|
113
|
+
const sendEvent = (...args) => _call(method, args, true);
|
|
114
|
+
if (eventNames.includes(method)) {
|
|
115
|
+
sendEvent.asEvent = sendEvent;
|
|
116
|
+
return sendEvent;
|
|
117
|
+
}
|
|
118
|
+
const sendCall = (...args) => _call(method, args, false);
|
|
119
|
+
sendCall.asEvent = sendEvent;
|
|
120
|
+
return sendCall;
|
|
121
|
+
} });
|
|
122
|
+
else rpc = builtinMethods;
|
|
123
|
+
function $close(customError) {
|
|
124
|
+
$closed = true;
|
|
125
|
+
_rpcPromiseMap.forEach(({ reject, method }) => {
|
|
126
|
+
const error = /* @__PURE__ */ new Error(`[birpc] rpc is closed, cannot call "${method}"`);
|
|
127
|
+
if (customError) {
|
|
128
|
+
customError.cause ??= error;
|
|
129
|
+
return reject(customError);
|
|
130
|
+
}
|
|
131
|
+
reject(error);
|
|
132
|
+
});
|
|
133
|
+
_rpcPromiseMap.clear();
|
|
134
|
+
off(onMessage);
|
|
135
|
+
}
|
|
136
|
+
function $rejectPendingCalls(handler) {
|
|
137
|
+
const handlerResults = Array.from(_rpcPromiseMap.values()).map(({ method, reject }) => {
|
|
138
|
+
if (!handler) return reject(/* @__PURE__ */ new Error(`[birpc]: rejected pending call "${method}".`));
|
|
139
|
+
return handler({
|
|
140
|
+
method,
|
|
141
|
+
reject
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
_rpcPromiseMap.clear();
|
|
145
|
+
return handlerResults;
|
|
146
|
+
}
|
|
147
|
+
async function onMessage(data, ...extra) {
|
|
148
|
+
let msg;
|
|
149
|
+
try {
|
|
150
|
+
msg = deserialize(data);
|
|
151
|
+
} catch (e) {
|
|
152
|
+
if (options.onGeneralError?.call(rpc, e) !== true) throw e;
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (msg.t === TYPE_REQUEST) {
|
|
156
|
+
const { m: method, a: args, o: optional } = msg;
|
|
157
|
+
let result, error;
|
|
158
|
+
let fn = await (resolver ? resolver.call(rpc, method, $functions[method]) : $functions[method]);
|
|
159
|
+
if (optional) fn ||= () => void 0;
|
|
160
|
+
if (!fn) error = /* @__PURE__ */ new Error(`[birpc] function "${method}" not found`);
|
|
161
|
+
else try {
|
|
162
|
+
result = await fn.apply(bind === "rpc" ? rpc : $functions, args);
|
|
163
|
+
} catch (e) {
|
|
164
|
+
error = e;
|
|
165
|
+
}
|
|
166
|
+
if (msg.i) {
|
|
167
|
+
if (error && options.onFunctionError) {
|
|
168
|
+
if (options.onFunctionError.call(rpc, error, method, args) === true) return;
|
|
169
|
+
}
|
|
170
|
+
if (!error) try {
|
|
171
|
+
await post(serialize({
|
|
172
|
+
t: TYPE_RESPONSE,
|
|
173
|
+
i: msg.i,
|
|
174
|
+
r: result
|
|
175
|
+
}), ...extra);
|
|
176
|
+
return;
|
|
177
|
+
} catch (e) {
|
|
178
|
+
error = e;
|
|
179
|
+
if (options.onGeneralError?.call(rpc, e, method, args) !== true) throw e;
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
await post(serialize({
|
|
183
|
+
t: TYPE_RESPONSE,
|
|
184
|
+
i: msg.i,
|
|
185
|
+
e: error
|
|
186
|
+
}), ...extra);
|
|
187
|
+
} catch (e) {
|
|
188
|
+
if (options.onGeneralError?.call(rpc, e, method, args) !== true) throw e;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
} else {
|
|
192
|
+
const { i: ack, r: result, e: error } = msg;
|
|
193
|
+
const promise = _rpcPromiseMap.get(ack);
|
|
194
|
+
if (promise) {
|
|
195
|
+
clearTimeout(promise.timeoutId);
|
|
196
|
+
if (error) promise.reject(error);
|
|
197
|
+
else promise.resolve(result);
|
|
198
|
+
}
|
|
199
|
+
_rpcPromiseMap.delete(ack);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
_promiseInit = on(onMessage);
|
|
203
|
+
return rpc;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export { createBirpc as c };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isMainThread, parentPort } from 'node:worker_threads';
|
|
2
|
-
import { i as init } from './init.
|
|
2
|
+
import { i as init } from './init.KmQZdqFg.js';
|
|
3
3
|
|
|
4
4
|
if (isMainThread || !parentPort) throw new Error("Expected worker to be run in node:worker_threads");
|
|
5
5
|
function workerInit(options) {
|
|
@@ -3,11 +3,11 @@ import { isBuiltin } from 'node:module';
|
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
4
|
import { resolve } from 'pathe';
|
|
5
5
|
import { ModuleRunner } from 'vite/module-runner';
|
|
6
|
-
import { b as VitestTransport } from './startModuleRunner.
|
|
6
|
+
import { b as VitestTransport } from './startModuleRunner.DpqpB8k3.js';
|
|
7
7
|
import { e as environments } from './index.BspFP3mn.js';
|
|
8
8
|
import { serializeError } from '@vitest/utils/error';
|
|
9
9
|
import { T as Traces } from './traces.U4xDYhzZ.js';
|
|
10
|
-
import { o as onCancel, a as rpcDone, c as createRuntimeRpc } from './rpc.
|
|
10
|
+
import { o as onCancel, a as rpcDone, c as createRuntimeRpc } from './rpc.BoxB0q7B.js';
|
|
11
11
|
import { createStackString, parseStacktrace } from '@vitest/utils/source-map';
|
|
12
12
|
import { s as setupInspect } from './inspector.CvyFGlXm.js';
|
|
13
13
|
import { V as VitestEvaluatedModules } from './evaluatedModules.Dg1zASAC.js';
|
|
@@ -10,10 +10,11 @@ const NPM_BUILTIN_NAMESPACE = "npm:";
|
|
|
10
10
|
const BUN_BUILTIN_NAMESPACE = "bun:";
|
|
11
11
|
// Some runtimes like Bun injects namespaced modules here, which is not a node builtin
|
|
12
12
|
const nodeBuiltins = builtinModules.filter((id) => !id.includes(":"));
|
|
13
|
+
const { bun: isBun, deno: isDeno } = process.versions;
|
|
13
14
|
// TODO: Use `isBuiltin` from `node:module`, but Deno doesn't support it
|
|
14
15
|
function isBuiltin(id) {
|
|
15
|
-
if (
|
|
16
|
-
if (
|
|
16
|
+
if (isDeno && id.startsWith(NPM_BUILTIN_NAMESPACE)) return true;
|
|
17
|
+
if (isBun && id.startsWith(BUN_BUILTIN_NAMESPACE)) return true;
|
|
17
18
|
return isNodeBuiltin(id);
|
|
18
19
|
}
|
|
19
20
|
function isNodeBuiltin(id) {
|
|
@@ -28,7 +29,7 @@ function isBrowserExternal(id) {
|
|
|
28
29
|
function toBuiltin(id) {
|
|
29
30
|
if (id.startsWith(browserExternalId)) id = id.slice(browserExternalLength);
|
|
30
31
|
if (id.startsWith(NPM_BUILTIN_NAMESPACE) || id.startsWith(BUN_BUILTIN_NAMESPACE) || id.startsWith(NODE_BUILTIN_NAMESPACE)) return id;
|
|
31
|
-
if (
|
|
32
|
+
if (isDeno || isBun) return id;
|
|
32
33
|
return `node:${id}`;
|
|
33
34
|
}
|
|
34
35
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DevEnvironment } from 'vite';
|
|
2
|
-
import { V as Vitest, T as TestProject, b as TestProjectConfiguration } from './reporters.d.
|
|
2
|
+
import { V as Vitest, T as TestProject, b as TestProjectConfiguration } from './reporters.d.Rsi0PyxX.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Generate a unique cache identifier.
|
|
@@ -3,7 +3,7 @@ import { TestError, SerializedError, Arrayable, ParsedStack, Awaitable } from '@
|
|
|
3
3
|
import { A as AfterSuiteRunMeta, U as UserConsoleLog, P as ProvidedContext, L as LabelColor } from './rpc.d.RH3apGEf.js';
|
|
4
4
|
import { Writable } from 'node:stream';
|
|
5
5
|
import { DevEnvironment, TransformResult as TransformResult$1, ViteDevServer, Plugin, UserConfig as UserConfig$1, DepOptimizationConfig, ServerOptions, ConfigEnv, AliasOptions } from 'vite';
|
|
6
|
-
import { S as SerializedTestSpecification, c as SourceModuleDiagnostic, B as BrowserTesterOptions } from './browser.d.
|
|
6
|
+
import { S as SerializedTestSpecification, c as SourceModuleDiagnostic, B as BrowserTesterOptions } from './browser.d.Bz3lxTX-.js';
|
|
7
7
|
import { MockedModule } from '@vitest/mocker';
|
|
8
8
|
import { StackTraceParserOptions } from '@vitest/utils/source-map';
|
|
9
9
|
import { BrowserCommands } from 'vitest/browser';
|
|
@@ -13,7 +13,7 @@ import { SnapshotSummary, SnapshotStateOptions } from '@vitest/snapshot';
|
|
|
13
13
|
import { SerializedDiffOptions } from '@vitest/utils/diff';
|
|
14
14
|
import { chai } from '@vitest/expect';
|
|
15
15
|
import { happyDomTypes, jsdomTypes } from 'vitest/optional-types.js';
|
|
16
|
-
import { c as ContextTestEnvironment, d as WorkerExecuteContext, e as WorkerTestEnvironment } from './worker.d.
|
|
16
|
+
import { c as ContextTestEnvironment, d as WorkerExecuteContext, e as WorkerTestEnvironment } from './worker.d.5JNaocaN.js';
|
|
17
17
|
import { O as OTELCarrier } from './traces.d.402V_yFI.js';
|
|
18
18
|
import { B as BenchmarkResult } from './benchmark.d.DAaHLpsq.js';
|
|
19
19
|
import { a as RuntimeCoverageProviderModule } from './coverage.d.BZtK59WP.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import { isBareImport } from '@vitest/utils/helpers';
|
|
3
|
-
import { i as isBuiltin, a as isBrowserExternal, t as toBuiltin } from './modules.
|
|
3
|
+
import { i as isBuiltin, a as isBrowserExternal, t as toBuiltin } from './modules.BJuCwlRJ.js';
|
|
4
4
|
import { pathToFileURL } from 'node:url';
|
|
5
5
|
import { normalize as normalize$1, join as join$1 } from 'pathe';
|
|
6
6
|
import { distDir } from '../path.js';
|
|
@@ -8,7 +8,7 @@ import { getTests, getNames, getTestName } from '@vitest/runner/utils';
|
|
|
8
8
|
import { processError } from '@vitest/utils/error';
|
|
9
9
|
import { normalize } from 'pathe';
|
|
10
10
|
import { a as getSnapshotClient, i as inject, c as createExpect, v as vi } from './vi.2VT5v0um.js';
|
|
11
|
-
import { r as rpc } from './rpc.
|
|
11
|
+
import { r as rpc } from './rpc.BoxB0q7B.js';
|
|
12
12
|
|
|
13
13
|
function createBenchmarkResult(name) {
|
|
14
14
|
return {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
2
2
|
import vm, { isContext, runInContext } from 'node:vm';
|
|
3
3
|
import { dirname, basename, extname, normalize, resolve } from 'pathe';
|
|
4
|
-
import { l as loadEnvironment } from './init.
|
|
4
|
+
import { l as loadEnvironment } from './init.KmQZdqFg.js';
|
|
5
5
|
import { distDir } from '../path.js';
|
|
6
6
|
import { createCustomConsole } from './console.Cf-YriPC.js';
|
|
7
7
|
import fs from 'node:fs';
|
|
@@ -11,7 +11,7 @@ import { findNearestPackageData } from '@vitest/utils/resolver';
|
|
|
11
11
|
import { dirname as dirname$1 } from 'node:path';
|
|
12
12
|
import { CSS_LANGS_RE, KNOWN_ASSET_RE } from '@vitest/utils/constants';
|
|
13
13
|
import { getDefaultRequestStubs } from '../module-evaluator.js';
|
|
14
|
-
import { s as startVitestModuleRunner, c as createNodeImportMeta, a as VITEST_VM_CONTEXT_SYMBOL } from './startModuleRunner.
|
|
14
|
+
import { s as startVitestModuleRunner, c as createNodeImportMeta, a as VITEST_VM_CONTEXT_SYMBOL } from './startModuleRunner.DpqpB8k3.js';
|
|
15
15
|
import { p as provideWorkerState } from './utils.DvEY5TfP.js';
|
|
16
16
|
|
|
17
17
|
function interopCommonJsModule(interopDefault, mod) {
|