vitest 1.0.0-beta.2 → 1.0.0-beta.4

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.
Files changed (53) hide show
  1. package/LICENSE.md +17 -29
  2. package/dist/browser.d.ts +1 -2
  3. package/dist/browser.js +3 -3
  4. package/dist/child.js +13 -7
  5. package/dist/{chunk-api-setup.5d9a93c7.js → chunk-api-setup.6d19ab38.js} +6 -4
  6. package/dist/{chunk-install-pkg.43d58972.js → chunk-install-pkg.e1d6323e.js} +12 -14
  7. package/dist/{chunk-integrations-globals.9df12d91.js → chunk-integrations-globals.2b099e04.js} +6 -6
  8. package/dist/{chunk-node-git.2f1df48f.js → chunk-node-git.6c12e560.js} +1 -1
  9. package/dist/cli-wrapper.js +1 -1
  10. package/dist/cli.js +16 -20
  11. package/dist/config.cjs +1 -0
  12. package/dist/config.d.ts +2 -3
  13. package/dist/config.js +1 -0
  14. package/dist/coverage.d.ts +1 -2
  15. package/dist/coverage.js +2 -2
  16. package/dist/entry-vm.js +8 -8
  17. package/dist/entry.js +8 -8
  18. package/dist/environments.d.ts +1 -2
  19. package/dist/environments.js +1 -13
  20. package/dist/execute.d.ts +2 -3
  21. package/dist/execute.js +1 -2
  22. package/dist/index.d.ts +232 -59
  23. package/dist/index.js +7 -7
  24. package/dist/node.d.ts +10 -4
  25. package/dist/node.js +16 -18
  26. package/dist/{reporters-d10f25e1.d.ts → reporters-50c2bd49.d.ts} +100 -35
  27. package/dist/reporters.d.ts +1 -2
  28. package/dist/reporters.js +3 -3
  29. package/dist/runners.d.ts +3 -3
  30. package/dist/runners.js +37 -41
  31. package/dist/{suite-919dd548.d.ts → suite-ad69b7cd.d.ts} +1 -1
  32. package/dist/suite.d.ts +2 -3
  33. package/dist/suite.js +3 -3
  34. package/dist/{vendor-benchmark.44931cfa.js → vendor-benchmark.b6befc50.js} +1 -1
  35. package/dist/{vendor-environments.094f240c.js → vendor-environments.dcc4a34e.js} +4 -37
  36. package/dist/{vendor-execute.07d1a420.js → vendor-execute.157302d6.js} +3 -3
  37. package/dist/vendor-global.c3664e75.js +14 -0
  38. package/dist/{vendor-index.29282562.js → vendor-index.2b92937b.js} +1 -1
  39. package/dist/{vendor-index.d36f5516.js → vendor-index.57925a34.js} +8 -3
  40. package/dist/{vendor-index.68ecee35.js → vendor-index.72df742e.js} +11 -4
  41. package/dist/{vendor-index.e006069f.js → vendor-index.8efe7746.js} +371 -371
  42. package/dist/{vendor-index.0b5b3600.js → vendor-loader.9c966f23.js} +36 -9
  43. package/dist/{vendor-node.e5a35bfe.js → vendor-node.65461b16.js} +2660 -2021
  44. package/dist/{vendor-reporters.2953082e.js → vendor-reporters.d24d80a4.js} +42 -25
  45. package/dist/{vendor-rpc.cbd8e972.js → vendor-rpc.171f65fb.js} +1 -1
  46. package/dist/{vendor-run-once.3e5ef7d7.js → vendor-run-once.fb836747.js} +1 -1
  47. package/dist/{vendor-vi.d30b47ae.js → vendor-vi.3baa7c4a.js} +32 -35
  48. package/dist/vm.js +14 -8
  49. package/dist/worker.js +14 -8
  50. package/package.json +12 -28
  51. package/dist/loader.js +0 -100
  52. package/dist/vendor-global.97e4527c.js +0 -9
  53. package/dist/vendor-index.98139333.js +0 -129
@@ -1,13 +1,15 @@
1
+ import { isAbsolute, resolve, normalize } from 'pathe';
1
2
  import 'acorn';
2
3
  import { builtinModules } from 'node:module';
3
4
  import fs, { existsSync, realpathSync, statSync, Stats } from 'node:fs';
4
5
  import { pathToFileURL, fileURLToPath as fileURLToPath$1, URL as URL$1 } from 'node:url';
5
- import { isAbsolute } from 'pathe';
6
6
  import assert from 'node:assert';
7
7
  import process$1 from 'node:process';
8
8
  import path from 'node:path';
9
9
  import v8 from 'node:v8';
10
10
  import { format, inspect } from 'node:util';
11
+ import { ViteNodeRunner } from 'vite-node/client';
12
+ import { e as environments } from './vendor-environments.dcc4a34e.js';
11
13
 
12
14
  const TRAILING_SLASH_RE = /\/$|\/\?/;
13
15
  function hasTrailingSlash(input = "", queryParameters = false) {
@@ -1959,10 +1961,6 @@ function normalizeid(id) {
1959
1961
  }
1960
1962
  return "file://" + encodeURI(normalizeSlash(id));
1961
1963
  }
1962
- function isNodeBuiltin(id = "") {
1963
- id = id.replace(/^node:/, "").split("/")[0];
1964
- return BUILTIN_MODULES.has(id);
1965
- }
1966
1964
 
1967
1965
  const DEFAULT_CONDITIONS_SET = /* @__PURE__ */ new Set(["node", "import"]);
1968
1966
  const DEFAULT_URL = pathToFileURL(process.cwd());
@@ -2054,9 +2052,38 @@ function resolvePathSync(id, options) {
2054
2052
  function resolvePath(id, options) {
2055
2053
  return pcall(resolvePathSync, id, options);
2056
2054
  }
2057
- const CJS_RE = /([\s;]|^)(module.exports\b|exports\.\w|require\s*\(|global\.\w)/m;
2058
- function hasCJSSyntax(code) {
2059
- return CJS_RE.test(code);
2055
+
2056
+ function isBuiltinEnvironment(env) {
2057
+ return env in environments;
2058
+ }
2059
+ const _loaders = /* @__PURE__ */ new Map();
2060
+ async function createEnvironmentLoader(options) {
2061
+ if (!_loaders.has(options.root)) {
2062
+ const loader = new ViteNodeRunner(options);
2063
+ await loader.executeId("/@vite/env");
2064
+ _loaders.set(options.root, loader);
2065
+ }
2066
+ return _loaders.get(options.root);
2067
+ }
2068
+ async function loadEnvironment(name, options) {
2069
+ if (isBuiltinEnvironment(name))
2070
+ return environments[name];
2071
+ const loader = await createEnvironmentLoader(options);
2072
+ const root = loader.root;
2073
+ const packageId = name[0] === "." || name[0] === "/" ? resolve(root, name) : await resolvePath(`vitest-environment-${name}`, { url: [root] }) ?? resolve(root, name);
2074
+ const pkg = await loader.executeId(normalize(packageId));
2075
+ if (!pkg || !pkg.default || typeof pkg.default !== "object") {
2076
+ throw new TypeError(
2077
+ `Environment "${name}" is not a valid environment. Path "${packageId}" should export default object with a "setup" or/and "setupVM" method.`
2078
+ );
2079
+ }
2080
+ const environment = pkg.default;
2081
+ if (environment.transformMode !== "web" && environment.transformMode !== "ssr") {
2082
+ throw new TypeError(
2083
+ `Environment "${name}" is not a valid environment. Path "${packageId}" should export default object with a "transformMode" method equal to "ssr" or "web".`
2084
+ );
2085
+ }
2086
+ return environment;
2060
2087
  }
2061
2088
 
2062
- export { hasCJSSyntax as h, isNodeBuiltin as i, resolvePath as r };
2089
+ export { loadEnvironment as l };