vitest 4.1.12 → 5.1.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 +192 -10
- package/browser/context.d.ts +7 -1
- package/browser/context.js +5 -5
- package/config.d.ts +0 -2
- package/dist/browser.d.ts +52 -21
- package/dist/browser.js +12 -13
- package/dist/chunks/{acorn.B2iPLyUM.js → acorn.C1kjbUFw.js} +30 -30
- package/dist/chunks/{base.B6Opl8PE.js → base.Cof-UHJf.js} +81 -52
- package/dist/chunks/{browser.d.BcoexmFG.d.ts → browser.d.C7tWgUvw.d.ts} +17 -14
- package/dist/chunks/{cac.DzDtg8hz.js → cac.BYbt0aJp.js} +143 -87
- package/dist/chunks/{cli-api.B0Pz1_R7.js → cli-api.COfZo8lK.js} +7160 -7189
- package/dist/chunks/config.d.B3YV4t0O.d.ts +3873 -0
- package/dist/chunks/{console.3WNpx0tS.js → console.CQZ877Hi.js} +69 -63
- package/dist/chunks/{constants.CPYnjOGj.js → constants.DLYM6cZY.js} +2 -2
- package/dist/chunks/coverage.9iqXE2gN.js +26 -0
- package/dist/chunks/{coverage.CTzCuANN.js → coverage.jGCktcGP.js} +7 -2
- package/dist/chunks/{creator.DgVhQm5q.js → creator.DHWmytIK.js} +65 -28
- package/dist/chunks/{defaults.9aQKnqFk.js → defaults.B1FCaFfh.js} +16 -9
- package/dist/chunks/display.BlTmubjj.js +194 -0
- package/dist/chunks/doctor.B-oPbwps.js +465 -0
- package/dist/chunks/{env.D4Lgay0q.js → env.BKKtU2WC.js} +2 -1
- package/dist/chunks/{environment.d.CrsxCzP1.d.ts → environment.d.BFQtFKdZ.d.ts} +9 -1
- package/dist/chunks/globals.ZKtKSkEf.js +29 -0
- package/dist/chunks/index.Bi0NXYPf.js +1708 -0
- package/dist/chunks/{index.CMESou6r.js → index.BoyTG_B7.js} +82 -81
- package/dist/chunks/index.CZzC1gGg.js +8501 -0
- package/dist/chunks/index.D0heQG4v.js +1318 -0
- package/dist/chunks/index.Di8au7q4.js +15665 -0
- package/dist/chunks/{index.Chj8NDwU.js → index.DmDMHCg8.js} +6 -12
- package/dist/chunks/{index.DXx9Dtk7.js → index.w_oBZ9N8.js} +25 -12
- package/dist/chunks/{init-forks.H5ZuobOQ.js → init-forks.BaDXQSD8.js} +7 -10
- package/dist/chunks/{init-threads.6kl1khcL.js → init-threads.ZX_Vov0z.js} +1 -1
- package/dist/chunks/{init.k9zZ9sLh.js → init.CO4AB7HZ.js} +113 -38
- package/dist/chunks/module-dependencies._2Eei3FO.js +71 -0
- package/dist/chunks/{native.DPzPHdi5.js → native.upB-V0CK.js} +50 -37
- package/dist/chunks/{nativeModuleMocker.BkNfQMkH.js → nativeModuleMocker.Dh5azSB4.js} +48 -19
- package/dist/chunks/{index.BCY_7LL2.js → nativeModuleRunner.9xPIMzi7.js} +110 -42
- package/dist/chunks/node.B9mkVmLH.js +47 -0
- package/dist/chunks/offset.Dy-5Fdfn.js +24 -0
- package/dist/chunks/pathe.M-eThtNZ.zq3TM4NT.js +492 -0
- package/dist/chunks/{reporters.d.DtoKVV2s.d.ts → plugin.d.LRFSN46m.d.ts} +2573 -1453
- package/dist/chunks/plugins.DPQHVT0p.js +37 -0
- package/dist/chunks/rawSnapshot.DqSiqIEx.js +356 -0
- package/dist/chunks/resolver.BzpmeQeT.js +48 -0
- package/dist/chunks/rpc.Uhkwr2NM.js +93 -0
- package/dist/chunks/rpc.d.3FOhdFx8.d.ts +75 -0
- package/dist/chunks/run.CjdgFZiW.js +4231 -0
- package/dist/chunks/setup-common.CqAQCXzx.js +36 -0
- package/dist/chunks/source-map.DakdQc29.js +1788 -0
- package/dist/chunks/source-map.d.BkG8YK_3.d.ts +89 -0
- package/dist/chunks/spy.DDMXghXv.js +509 -0
- package/dist/chunks/task-utils.d.D-gFPNFi.d.ts +144 -0
- package/dist/chunks/tinyrainbow.Do8I1XRG.js +88 -0
- package/dist/chunks/{utils.BS4fH3nR.js → utils.BBk_icFG.js} +50 -52
- package/dist/chunks/{utils.BX5Fg8C4.js → utils.DYj33du9.js} +1 -17
- package/dist/chunks/vm.b4MbCAJQ.js +1329 -0
- package/dist/chunks/{worker.d.ZpHpO4yb.d.ts → worker.d.CyJRpyfZ.d.ts} +34 -19
- package/dist/cli.js +5 -6
- package/dist/config.cjs +9 -6
- package/dist/config.d.ts +27 -25
- package/dist/config.js +3 -3
- package/dist/index.d.ts +471 -38
- package/dist/index.js +18 -19
- package/dist/module-evaluator.d.ts +64 -5
- package/dist/module-evaluator.js +122 -62
- package/dist/node.d.ts +355 -87
- package/dist/node.js +49 -73
- package/dist/runtime.d.ts +43 -6
- package/dist/runtime.js +7 -9
- package/dist/spy.js +1 -1
- package/dist/task-utils.js +290 -0
- package/dist/{chunks/traces.DT5aQ62U.js → traces.js} +3 -2
- package/dist/worker.d.ts +8 -10
- package/dist/worker.js +33 -43
- package/dist/workers/forks.js +30 -40
- package/dist/workers/runVmTests.js +66 -43
- package/dist/workers/threads.js +30 -40
- package/dist/workers/vmForks.js +19 -20
- package/dist/workers/vmThreads.js +19 -20
- package/globals.d.ts +19 -19
- package/index.cjs +3 -3
- package/optional-runtime-types.d.ts +1 -1
- package/optional-types.d.ts +1 -1
- package/package.json +59 -74
- package/suppress-warnings.cjs +1 -1
- package/dist/chunks/_commonjsHelpers.D26ty3Ew.js +0 -6
- package/dist/chunks/benchmark.CX_oY03V.js +0 -40
- package/dist/chunks/benchmark.d.DAaHLpsq.d.ts +0 -24
- package/dist/chunks/config.d.A1h_Y6Jt.d.ts +0 -232
- package/dist/chunks/coverage.DM_a_rWm.js +0 -1087
- package/dist/chunks/coverage.d.BZtK59WP.d.ts +0 -37
- package/dist/chunks/evaluatedModules.Dg1zASAC.js +0 -17
- package/dist/chunks/global.d.DVsSRdQ5.d.ts +0 -100
- package/dist/chunks/globals.Dj1TGiMC.js +0 -31
- package/dist/chunks/index.DC7d2Pf8.js +0 -729
- package/dist/chunks/index.DdgEv5B1.js +0 -42
- package/dist/chunks/index.UpGiHP7g.js +0 -4255
- package/dist/chunks/index.og1WyBLx.js +0 -6358
- package/dist/chunks/nativeModuleRunner.BIakptoF.js +0 -36
- package/dist/chunks/node.COQbm6gK.js +0 -14
- package/dist/chunks/plugin.d.DwFIiJ7i.d.ts +0 -38
- package/dist/chunks/rpc.MzXet3jl.js +0 -144
- package/dist/chunks/rpc.d.B_8sPU0w.d.ts +0 -30
- package/dist/chunks/setup-common.DYx3LtFI.js +0 -60
- package/dist/chunks/startVitestModuleRunner.DB-7oCpn.js +0 -740
- package/dist/chunks/suite.d.udJtyAgw.d.ts +0 -10
- package/dist/chunks/test.DNmyFkvJ.js +0 -4430
- package/dist/chunks/traces.d.D2T_R8rx.d.ts +0 -60
- package/dist/chunks/vm.CXMd5FHa.js +0 -785
- package/dist/coverage.d.ts +0 -123
- package/dist/coverage.js +0 -27
- package/dist/environments.d.ts +0 -22
- package/dist/environments.js +0 -5
- package/dist/reporters.d.ts +0 -27
- package/dist/reporters.js +0 -26
- package/dist/runners.d.ts +0 -70
- package/dist/runners.js +0 -19
- package/dist/snapshot.d.ts +0 -9
- package/dist/snapshot.js +0 -6
- package/dist/suite.d.ts +0 -5
- package/dist/suite.js +0 -8
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { fileURLToPath as fileURLToPath$1, pathToFileURL as pathToFileURL$1 } from 'node:url';
|
|
2
|
+
import fs__default, { statSync, realpathSync } from 'node:fs';
|
|
2
3
|
import { builtinModules, createRequire } from 'node:module';
|
|
3
4
|
import path, { win32, dirname, join } from 'node:path';
|
|
4
5
|
import process$1 from 'node:process';
|
|
5
|
-
import fs
|
|
6
|
-
import { fileURLToPath as fileURLToPath$1, pathToFileURL as pathToFileURL$1, URL as URL$1 } from 'node:url';
|
|
7
|
-
import { isAbsolute } from 'pathe';
|
|
6
|
+
import fs from 'node:fs/promises';
|
|
8
7
|
import assert from 'node:assert';
|
|
9
8
|
import v8 from 'node:v8';
|
|
10
9
|
import { format, inspect } from 'node:util';
|
|
10
|
+
import { i as isAbsolute, r as resolve } from './pathe.M-eThtNZ.zq3TM4NT.js';
|
|
11
|
+
import { ModuleRunner } from 'vite/module-runner';
|
|
11
12
|
|
|
12
13
|
const JOIN_LEADING_SLASH_RE = /^\.?\//;
|
|
13
14
|
function withTrailingSlash(input = "", respectQueryAndFragment) {
|
|
@@ -98,7 +99,7 @@ codes.ERR_INVALID_ARG_TYPE = createError(
|
|
|
98
99
|
* @param {unknown} actual
|
|
99
100
|
*/
|
|
100
101
|
(name, expected, actual) => {
|
|
101
|
-
assert(typeof name === 'string', "'name' must be a string");
|
|
102
|
+
assert.ok(typeof name === 'string', "'name' must be a string");
|
|
102
103
|
if (!Array.isArray(expected)) {
|
|
103
104
|
expected = [expected];
|
|
104
105
|
}
|
|
@@ -122,7 +123,7 @@ codes.ERR_INVALID_ARG_TYPE = createError(
|
|
|
122
123
|
const other = [];
|
|
123
124
|
|
|
124
125
|
for (const value of expected) {
|
|
125
|
-
assert(
|
|
126
|
+
assert.ok(
|
|
126
127
|
typeof value === 'string',
|
|
127
128
|
'All expected entries have to be of type string'
|
|
128
129
|
);
|
|
@@ -130,7 +131,7 @@ codes.ERR_INVALID_ARG_TYPE = createError(
|
|
|
130
131
|
if (kTypes.has(value)) {
|
|
131
132
|
types.push(value.toLowerCase());
|
|
132
133
|
} else if (classRegExp.exec(value) === null) {
|
|
133
|
-
assert(
|
|
134
|
+
assert.ok(
|
|
134
135
|
value !== 'object',
|
|
135
136
|
'The value "object" should be written as "Object"'
|
|
136
137
|
);
|
|
@@ -225,7 +226,7 @@ codes.ERR_INVALID_PACKAGE_TARGET = createError(
|
|
|
225
226
|
target.length > 0 &&
|
|
226
227
|
!target.startsWith('./');
|
|
227
228
|
if (key === '.') {
|
|
228
|
-
assert(isImport === false);
|
|
229
|
+
assert.ok(isImport === false);
|
|
229
230
|
return (
|
|
230
231
|
`Invalid "exports" main target ${JSON.stringify(target)} defined ` +
|
|
231
232
|
`in the package config ${packagePath}package.json${
|
|
@@ -475,10 +476,10 @@ const captureLargerStackTrace = hideStackFrames(
|
|
|
475
476
|
*/
|
|
476
477
|
function getMessage(key, parameters, self) {
|
|
477
478
|
const message = messages.get(key);
|
|
478
|
-
assert(message !== undefined, 'expected `message` to be found');
|
|
479
|
+
assert.ok(message !== undefined, 'expected `message` to be found');
|
|
479
480
|
|
|
480
481
|
if (typeof message === 'function') {
|
|
481
|
-
assert(
|
|
482
|
+
assert.ok(
|
|
482
483
|
message.length <= parameters.length, // Default options do not count.
|
|
483
484
|
`Code: ${key}; The provided arguments length (${parameters.length}) does not ` +
|
|
484
485
|
`match the required ones (${message.length}).`
|
|
@@ -489,7 +490,7 @@ function getMessage(key, parameters, self) {
|
|
|
489
490
|
const regex = /%[dfijoOs]/g;
|
|
490
491
|
let expectedLength = 0;
|
|
491
492
|
while (regex.exec(message) !== null) expectedLength++;
|
|
492
|
-
assert(
|
|
493
|
+
assert.ok(
|
|
493
494
|
expectedLength === parameters.length,
|
|
494
495
|
`Code: ${key}; The provided arguments length (${parameters.length}) does not ` +
|
|
495
496
|
`match the required ones (${expectedLength}).`
|
|
@@ -533,7 +534,7 @@ function determineSpecificType(value) {
|
|
|
533
534
|
|
|
534
535
|
// Manually “tree shaken” from:
|
|
535
536
|
// <https://github.com/nodejs/node/blob/7c3dce0/lib/internal/modules/package_json_reader.js>
|
|
536
|
-
// Last checked on: Apr 29,
|
|
537
|
+
// Last checked on: Apr 29, 2024.
|
|
537
538
|
// Removed the native dependency.
|
|
538
539
|
// Also: no need to cache, we do that in resolve already.
|
|
539
540
|
|
|
@@ -561,7 +562,7 @@ function read(jsonPath, {base, specifier}) {
|
|
|
561
562
|
let string;
|
|
562
563
|
|
|
563
564
|
try {
|
|
564
|
-
string =
|
|
565
|
+
string = fs__default.readFileSync(path.toNamespacedPath(jsonPath), 'utf8');
|
|
565
566
|
} catch (error) {
|
|
566
567
|
const exception = /** @type {ErrnoException} */ (error);
|
|
567
568
|
|
|
@@ -692,7 +693,7 @@ function getPackageType(url) {
|
|
|
692
693
|
|
|
693
694
|
// Manually “tree shaken” from:
|
|
694
695
|
// <https://github.com/nodejs/node/blob/7c3dce0/lib/internal/modules/esm/get_format.js>
|
|
695
|
-
// Last checked on: Apr 29,
|
|
696
|
+
// Last checked on: Apr 29, 2024.
|
|
696
697
|
|
|
697
698
|
|
|
698
699
|
const {ERR_UNKNOWN_FILE_EXTENSION} = codes;
|
|
@@ -847,9 +848,36 @@ function defaultGetFormatWithoutErrors(url, context) {
|
|
|
847
848
|
return protocolHandlers[protocol](url, context, true) || null
|
|
848
849
|
}
|
|
849
850
|
|
|
851
|
+
// Manually “tree shaken” from:
|
|
852
|
+
// <https://github.com/nodejs/node/blob/81a9a97/lib/internal/modules/esm/utils.js>
|
|
853
|
+
// Last checked on: Apr 29, 2024.
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
// In Node itself these values are populated from CLI arguments, before any
|
|
857
|
+
// user code runs.
|
|
858
|
+
// Here we just define the defaults.
|
|
859
|
+
const DEFAULT_CONDITIONS = Object.freeze(['node', 'import']);
|
|
860
|
+
const DEFAULT_CONDITIONS_SET$1 = new Set(DEFAULT_CONDITIONS);
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* Returns the default conditions for ES module loading, as a Set.
|
|
864
|
+
*/
|
|
865
|
+
function getDefaultConditionsSet() {
|
|
866
|
+
return DEFAULT_CONDITIONS_SET$1
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* @param {Array<string>} [conditions]
|
|
871
|
+
* @returns {Set<string>}
|
|
872
|
+
*/
|
|
873
|
+
function getConditionsSet(conditions) {
|
|
874
|
+
|
|
875
|
+
return getDefaultConditionsSet()
|
|
876
|
+
}
|
|
877
|
+
|
|
850
878
|
// Manually “tree shaken” from:
|
|
851
879
|
// <https://github.com/nodejs/node/blob/81a9a97/lib/internal/modules/esm/resolve.js>
|
|
852
|
-
// Last checked on: Apr 29,
|
|
880
|
+
// Last checked on: Apr 29, 2024.
|
|
853
881
|
|
|
854
882
|
|
|
855
883
|
const RegExpPrototypeSymbolReplace = RegExp.prototype[Symbol.replace];
|
|
@@ -937,7 +965,7 @@ function emitLegacyIndexDeprecation(url, packageJsonUrl, base, main) {
|
|
|
937
965
|
const format = defaultGetFormatWithoutErrors(url, {parentURL: base.href});
|
|
938
966
|
if (format !== 'module') return
|
|
939
967
|
const urlPath = fileURLToPath$1(url.href);
|
|
940
|
-
const packagePath = fileURLToPath$1(new URL
|
|
968
|
+
const packagePath = fileURLToPath$1(new URL('.', packageJsonUrl));
|
|
941
969
|
const basePath = fileURLToPath$1(base);
|
|
942
970
|
if (!main) {
|
|
943
971
|
process$1.emitWarning(
|
|
@@ -1003,7 +1031,7 @@ function legacyMainResolve(packageJsonUrl, packageConfig, base) {
|
|
|
1003
1031
|
/** @type {URL | undefined} */
|
|
1004
1032
|
let guess;
|
|
1005
1033
|
if (packageConfig.main !== undefined) {
|
|
1006
|
-
guess = new URL
|
|
1034
|
+
guess = new URL(packageConfig.main, packageJsonUrl);
|
|
1007
1035
|
// Note: fs check redundances will be handled by Descriptor cache here.
|
|
1008
1036
|
if (fileExists(guess)) return guess
|
|
1009
1037
|
|
|
@@ -1018,7 +1046,7 @@ function legacyMainResolve(packageJsonUrl, packageConfig, base) {
|
|
|
1018
1046
|
let i = -1;
|
|
1019
1047
|
|
|
1020
1048
|
while (++i < tries.length) {
|
|
1021
|
-
guess = new URL
|
|
1049
|
+
guess = new URL(tries[i], packageJsonUrl);
|
|
1022
1050
|
if (fileExists(guess)) break
|
|
1023
1051
|
guess = undefined;
|
|
1024
1052
|
}
|
|
@@ -1039,7 +1067,7 @@ function legacyMainResolve(packageJsonUrl, packageConfig, base) {
|
|
|
1039
1067
|
let i = -1;
|
|
1040
1068
|
|
|
1041
1069
|
while (++i < tries.length) {
|
|
1042
|
-
guess = new URL
|
|
1070
|
+
guess = new URL(tries[i], packageJsonUrl);
|
|
1043
1071
|
if (fileExists(guess)) break
|
|
1044
1072
|
guess = undefined;
|
|
1045
1073
|
}
|
|
@@ -1051,7 +1079,7 @@ function legacyMainResolve(packageJsonUrl, packageConfig, base) {
|
|
|
1051
1079
|
|
|
1052
1080
|
// Not found.
|
|
1053
1081
|
throw new ERR_MODULE_NOT_FOUND(
|
|
1054
|
-
fileURLToPath$1(new URL
|
|
1082
|
+
fileURLToPath$1(new URL('.', packageJsonUrl)),
|
|
1055
1083
|
fileURLToPath$1(base)
|
|
1056
1084
|
)
|
|
1057
1085
|
}
|
|
@@ -1125,7 +1153,7 @@ function finalizeResolution(resolved, base, preserveSymlinks) {
|
|
|
1125
1153
|
function importNotDefined(specifier, packageJsonUrl, base) {
|
|
1126
1154
|
return new ERR_PACKAGE_IMPORT_NOT_DEFINED(
|
|
1127
1155
|
specifier,
|
|
1128
|
-
packageJsonUrl && fileURLToPath$1(new URL
|
|
1156
|
+
packageJsonUrl && fileURLToPath$1(new URL('.', packageJsonUrl)),
|
|
1129
1157
|
fileURLToPath$1(base)
|
|
1130
1158
|
)
|
|
1131
1159
|
}
|
|
@@ -1138,7 +1166,7 @@ function importNotDefined(specifier, packageJsonUrl, base) {
|
|
|
1138
1166
|
*/
|
|
1139
1167
|
function exportsNotFound(subpath, packageJsonUrl, base) {
|
|
1140
1168
|
return new ERR_PACKAGE_PATH_NOT_EXPORTED(
|
|
1141
|
-
fileURLToPath$1(new URL
|
|
1169
|
+
fileURLToPath$1(new URL('.', packageJsonUrl)),
|
|
1142
1170
|
subpath,
|
|
1143
1171
|
base && fileURLToPath$1(base)
|
|
1144
1172
|
)
|
|
@@ -1178,7 +1206,7 @@ function invalidPackageTarget(subpath, target, packageJsonUrl, internal, base) {
|
|
|
1178
1206
|
: `${target}`;
|
|
1179
1207
|
|
|
1180
1208
|
return new ERR_INVALID_PACKAGE_TARGET(
|
|
1181
|
-
fileURLToPath$1(new URL
|
|
1209
|
+
fileURLToPath$1(new URL('.', packageJsonUrl)),
|
|
1182
1210
|
subpath,
|
|
1183
1211
|
target,
|
|
1184
1212
|
internal,
|
|
@@ -1217,7 +1245,7 @@ function resolvePackageTargetString(
|
|
|
1217
1245
|
let isURL = false;
|
|
1218
1246
|
|
|
1219
1247
|
try {
|
|
1220
|
-
new URL
|
|
1248
|
+
new URL(target);
|
|
1221
1249
|
isURL = true;
|
|
1222
1250
|
} catch {
|
|
1223
1251
|
// Continue regardless of error.
|
|
@@ -1267,9 +1295,9 @@ function resolvePackageTargetString(
|
|
|
1267
1295
|
}
|
|
1268
1296
|
}
|
|
1269
1297
|
|
|
1270
|
-
const resolved = new URL
|
|
1298
|
+
const resolved = new URL(target, packageJsonUrl);
|
|
1271
1299
|
const resolvedPath = resolved.pathname;
|
|
1272
|
-
const packagePath = new URL
|
|
1300
|
+
const packagePath = new URL('.', packageJsonUrl).pathname;
|
|
1273
1301
|
|
|
1274
1302
|
if (!resolvedPath.startsWith(packagePath))
|
|
1275
1303
|
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base)
|
|
@@ -1305,7 +1333,7 @@ function resolvePackageTargetString(
|
|
|
1305
1333
|
}
|
|
1306
1334
|
|
|
1307
1335
|
if (pattern) {
|
|
1308
|
-
return new URL
|
|
1336
|
+
return new URL(
|
|
1309
1337
|
RegExpPrototypeSymbolReplace.call(
|
|
1310
1338
|
patternRegEx,
|
|
1311
1339
|
resolved.href,
|
|
@@ -1314,7 +1342,7 @@ function resolvePackageTargetString(
|
|
|
1314
1342
|
)
|
|
1315
1343
|
}
|
|
1316
1344
|
|
|
1317
|
-
return new URL
|
|
1345
|
+
return new URL(subpath, resolved)
|
|
1318
1346
|
}
|
|
1319
1347
|
|
|
1320
1348
|
/**
|
|
@@ -1793,7 +1821,7 @@ function parsePackageName(specifier, base) {
|
|
|
1793
1821
|
*/
|
|
1794
1822
|
function packageResolve(specifier, base, conditions) {
|
|
1795
1823
|
if (builtinModules.includes(specifier)) {
|
|
1796
|
-
return new URL
|
|
1824
|
+
return new URL('node:' + specifier)
|
|
1797
1825
|
}
|
|
1798
1826
|
|
|
1799
1827
|
const {packageName, packageSubpath, isScoped} = parsePackageName(
|
|
@@ -1823,7 +1851,7 @@ function packageResolve(specifier, base, conditions) {
|
|
|
1823
1851
|
}
|
|
1824
1852
|
}
|
|
1825
1853
|
|
|
1826
|
-
let packageJsonUrl = new URL
|
|
1854
|
+
let packageJsonUrl = new URL(
|
|
1827
1855
|
'./node_modules/' + packageName + '/package.json',
|
|
1828
1856
|
base
|
|
1829
1857
|
);
|
|
@@ -1834,7 +1862,7 @@ function packageResolve(specifier, base, conditions) {
|
|
|
1834
1862
|
const stat = tryStatSync(packageJsonPath.slice(0, -13));
|
|
1835
1863
|
if (!stat || !stat.isDirectory()) {
|
|
1836
1864
|
lastPath = packageJsonPath;
|
|
1837
|
-
packageJsonUrl = new URL
|
|
1865
|
+
packageJsonUrl = new URL(
|
|
1838
1866
|
(isScoped ? '../../../../node_modules/' : '../../../node_modules/') +
|
|
1839
1867
|
packageName +
|
|
1840
1868
|
'/package.json',
|
|
@@ -1860,7 +1888,7 @@ function packageResolve(specifier, base, conditions) {
|
|
|
1860
1888
|
return legacyMainResolve(packageJsonUrl, packageConfig, base)
|
|
1861
1889
|
}
|
|
1862
1890
|
|
|
1863
|
-
return new URL
|
|
1891
|
+
return new URL(packageSubpath, packageJsonUrl)
|
|
1864
1892
|
// Cross-platform root check.
|
|
1865
1893
|
} while (packageJsonPath.length !== lastPath.length)
|
|
1866
1894
|
|
|
@@ -1913,6 +1941,10 @@ function shouldBeTreatedAsRelativeOrAbsolutePath(specifier) {
|
|
|
1913
1941
|
function moduleResolve(specifier, base, conditions, preserveSymlinks) {
|
|
1914
1942
|
// Note: The Node code supports `base` as a string (in this internal API) too,
|
|
1915
1943
|
// we don’t.
|
|
1944
|
+
if (conditions === undefined) {
|
|
1945
|
+
conditions = getConditionsSet();
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1916
1948
|
const protocol = base.protocol;
|
|
1917
1949
|
const isData = protocol === 'data:';
|
|
1918
1950
|
const isRemote = isData || protocol === 'http:' || protocol === 'https:';
|
|
@@ -1923,7 +1955,7 @@ function moduleResolve(specifier, base, conditions, preserveSymlinks) {
|
|
|
1923
1955
|
|
|
1924
1956
|
if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) {
|
|
1925
1957
|
try {
|
|
1926
|
-
resolved = new URL
|
|
1958
|
+
resolved = new URL(specifier, base);
|
|
1927
1959
|
} catch (error_) {
|
|
1928
1960
|
const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
|
|
1929
1961
|
error.cause = error_;
|
|
@@ -1933,7 +1965,7 @@ function moduleResolve(specifier, base, conditions, preserveSymlinks) {
|
|
|
1933
1965
|
resolved = packageImportsResolve(specifier, base, conditions);
|
|
1934
1966
|
} else {
|
|
1935
1967
|
try {
|
|
1936
|
-
resolved = new URL
|
|
1968
|
+
resolved = new URL(specifier);
|
|
1937
1969
|
} catch (error_) {
|
|
1938
1970
|
// Note: actual code uses `canBeRequiredWithoutScheme`.
|
|
1939
1971
|
if (isRemote && !builtinModules.includes(specifier)) {
|
|
@@ -1946,7 +1978,7 @@ function moduleResolve(specifier, base, conditions, preserveSymlinks) {
|
|
|
1946
1978
|
}
|
|
1947
1979
|
}
|
|
1948
1980
|
|
|
1949
|
-
assert(resolved !== undefined, 'expected to be defined');
|
|
1981
|
+
assert.ok(resolved !== undefined, 'expected to be defined');
|
|
1950
1982
|
|
|
1951
1983
|
if (resolved.protocol !== 'file:') {
|
|
1952
1984
|
return resolved
|
|
@@ -2194,7 +2226,7 @@ async function findUp$1(name, {
|
|
|
2194
2226
|
while (directory) {
|
|
2195
2227
|
const filePath = isAbsoluteName ? name : path.join(directory, name);
|
|
2196
2228
|
try {
|
|
2197
|
-
const stats = await fs
|
|
2229
|
+
const stats = await fs.stat(filePath); // eslint-disable-line no-await-in-loop
|
|
2198
2230
|
if ((type === 'file' && stats.isFile()) || (type === 'directory' && stats.isDirectory())) {
|
|
2199
2231
|
return filePath;
|
|
2200
2232
|
}
|
|
@@ -2222,7 +2254,7 @@ function findUpSync(name, {
|
|
|
2222
2254
|
const filePath = isAbsoluteName ? name : path.join(directory, name);
|
|
2223
2255
|
|
|
2224
2256
|
try {
|
|
2225
|
-
const stats =
|
|
2257
|
+
const stats = fs__default.statSync(filePath, {throwIfNoEntry: false});
|
|
2226
2258
|
if ((type === 'file' && stats?.isFile()) || (type === 'directory' && stats?.isDirectory())) {
|
|
2227
2259
|
return filePath;
|
|
2228
2260
|
}
|
|
@@ -2273,8 +2305,8 @@ function getPackageJsonPath(name, options = {}) {
|
|
|
2273
2305
|
return searchPackageJSON(entry);
|
|
2274
2306
|
}
|
|
2275
2307
|
const readFile = quansync({
|
|
2276
|
-
async: (id) =>
|
|
2277
|
-
sync: (id) =>
|
|
2308
|
+
async: (id) => fs__default.promises.readFile(id, "utf8"),
|
|
2309
|
+
sync: (id) => fs__default.readFileSync(id, "utf8")
|
|
2278
2310
|
});
|
|
2279
2311
|
const getPackageInfo = quansync(function* (name, options = {}) {
|
|
2280
2312
|
const packageJsonPath = getPackageJsonPath(name, options);
|
|
@@ -2313,7 +2345,7 @@ function searchPackageJSON(dir) {
|
|
|
2313
2345
|
return;
|
|
2314
2346
|
dir = newDir;
|
|
2315
2347
|
packageJsonPath = join(dir, "package.json");
|
|
2316
|
-
if (
|
|
2348
|
+
if (fs__default.existsSync(packageJsonPath))
|
|
2317
2349
|
break;
|
|
2318
2350
|
}
|
|
2319
2351
|
return packageJsonPath;
|
|
@@ -2324,7 +2356,7 @@ const findUp = quansync({
|
|
|
2324
2356
|
});
|
|
2325
2357
|
const loadPackageJSON = quansync(function* (cwd = process$1.cwd()) {
|
|
2326
2358
|
const path = yield findUp("package.json", { cwd });
|
|
2327
|
-
if (!path || !
|
|
2359
|
+
if (!path || !fs__default.existsSync(path))
|
|
2328
2360
|
return null;
|
|
2329
2361
|
return JSON.parse(yield readFile(path));
|
|
2330
2362
|
});
|
|
@@ -2335,4 +2367,40 @@ const isPackageListed = quansync(function* (name, cwd) {
|
|
|
2335
2367
|
});
|
|
2336
2368
|
isPackageListed.sync;
|
|
2337
2369
|
|
|
2338
|
-
|
|
2370
|
+
class NativeModuleRunner extends ModuleRunner {
|
|
2371
|
+
root;
|
|
2372
|
+
/**
|
|
2373
|
+
* @internal
|
|
2374
|
+
*/
|
|
2375
|
+
mocker;
|
|
2376
|
+
constructor(root, mocker) {
|
|
2377
|
+
super({
|
|
2378
|
+
hmr: false,
|
|
2379
|
+
sourcemapInterceptor: false,
|
|
2380
|
+
transport: { invoke() {
|
|
2381
|
+
throw new Error("Unexpected `invoke`");
|
|
2382
|
+
} }
|
|
2383
|
+
});
|
|
2384
|
+
this.root = root;
|
|
2385
|
+
this.mocker = mocker;
|
|
2386
|
+
if (mocker) Object.defineProperty(globalThis, "__vitest_mocker__", {
|
|
2387
|
+
configurable: true,
|
|
2388
|
+
writable: true,
|
|
2389
|
+
value: mocker
|
|
2390
|
+
});
|
|
2391
|
+
}
|
|
2392
|
+
async import(moduleId) {
|
|
2393
|
+
const path = resolveModule(moduleId, { paths: [this.root] }) ?? resolve(this.root, moduleId);
|
|
2394
|
+
// resolveModule doesn't keep the query params, so we need to add them back
|
|
2395
|
+
let queryParams = "";
|
|
2396
|
+
if (moduleId.includes("?") && !path.includes("?")) queryParams = moduleId.slice(moduleId.indexOf("?"));
|
|
2397
|
+
return import(pathToFileURL$1(path + queryParams).toString());
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2400
|
+
|
|
2401
|
+
var nativeModuleRunner = /*#__PURE__*/Object.freeze({
|
|
2402
|
+
__proto__: null,
|
|
2403
|
+
NativeModuleRunner: NativeModuleRunner
|
|
2404
|
+
});
|
|
2405
|
+
|
|
2406
|
+
export { NativeModuleRunner as N, isPackageExists as i, nativeModuleRunner as n, resolveModule as r };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { g as getWorkerState } from './utils.DYj33du9.js';
|
|
2
|
+
import { promises, existsSync } from 'node:fs';
|
|
3
|
+
import { i as isAbsolute, r as resolve, d as dirname, j as join, b as basename } from './pathe.M-eThtNZ.zq3TM4NT.js';
|
|
4
|
+
|
|
5
|
+
class NodeSnapshotEnvironment {
|
|
6
|
+
options;
|
|
7
|
+
constructor(options = {}) {
|
|
8
|
+
this.options = options;
|
|
9
|
+
}
|
|
10
|
+
getVersion() {
|
|
11
|
+
return "1";
|
|
12
|
+
}
|
|
13
|
+
getHeader() {
|
|
14
|
+
return `// Snapshot v${this.getVersion()}`;
|
|
15
|
+
}
|
|
16
|
+
async resolveRawPath(testPath, rawPath) {
|
|
17
|
+
return isAbsolute(rawPath) ? rawPath : resolve(dirname(testPath), rawPath);
|
|
18
|
+
}
|
|
19
|
+
async resolvePath(filepath) {
|
|
20
|
+
return join(join(dirname(filepath), this.options.snapshotsDirName ?? "__snapshots__"), `${basename(filepath)}.snap`);
|
|
21
|
+
}
|
|
22
|
+
async prepareDirectory(dirPath) {
|
|
23
|
+
await promises.mkdir(dirPath, { recursive: true });
|
|
24
|
+
}
|
|
25
|
+
async saveSnapshotFile(filepath, snapshot) {
|
|
26
|
+
await promises.mkdir(dirname(filepath), { recursive: true });
|
|
27
|
+
await promises.writeFile(filepath, snapshot, "utf-8");
|
|
28
|
+
}
|
|
29
|
+
async readSnapshotFile(filepath) {
|
|
30
|
+
if (!existsSync(filepath)) return null;
|
|
31
|
+
return promises.readFile(filepath, "utf-8");
|
|
32
|
+
}
|
|
33
|
+
async removeSnapshotFile(filepath) {
|
|
34
|
+
if (existsSync(filepath)) await promises.unlink(filepath);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
class VitestNodeSnapshotEnvironment extends NodeSnapshotEnvironment {
|
|
39
|
+
getHeader() {
|
|
40
|
+
return `// Vitest Snapshot v${this.getVersion()}, https://vitest.dev/guide/snapshot.html`;
|
|
41
|
+
}
|
|
42
|
+
resolvePath(filepath) {
|
|
43
|
+
return getWorkerState().rpc.resolveSnapshotPath(filepath);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { VitestNodeSnapshotEnvironment };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const lineSplitRE = /\r?\n/;
|
|
2
|
+
function positionToOffset(source, lineNumber, columnNumber) {
|
|
3
|
+
const lines = source.split(lineSplitRE);
|
|
4
|
+
const nl = /\r\n/.test(source) ? 2 : 1;
|
|
5
|
+
let start = 0;
|
|
6
|
+
if (lineNumber > lines.length) return source.length;
|
|
7
|
+
for (let i = 0; i < lineNumber - 1; i++) start += lines[i].length + nl;
|
|
8
|
+
return start + columnNumber;
|
|
9
|
+
}
|
|
10
|
+
function offsetToLineNumber(source, offset) {
|
|
11
|
+
if (offset > source.length) throw new Error(`offset is longer than source length! offset ${offset} > length ${source.length}`);
|
|
12
|
+
const lines = source.split(lineSplitRE);
|
|
13
|
+
const nl = /\r\n/.test(source) ? 2 : 1;
|
|
14
|
+
let counted = 0;
|
|
15
|
+
let line = 0;
|
|
16
|
+
for (; line < lines.length; line++) {
|
|
17
|
+
const lineLength = lines[line].length + nl;
|
|
18
|
+
if (counted + lineLength >= offset) break;
|
|
19
|
+
counted += lineLength;
|
|
20
|
+
}
|
|
21
|
+
return line + 1;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { lineSplitRE as l, offsetToLineNumber as o, positionToOffset as p };
|