vitest 0.20.3 → 0.22.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.
Files changed (44) hide show
  1. package/LICENSE.md +61 -4
  2. package/dist/browser.d.ts +8 -1902
  3. package/dist/browser.mjs +8 -9
  4. package/dist/{chunk-api-setup.9bff74bb.mjs → chunk-api-setup.ecd02c18.mjs} +8 -7
  5. package/dist/{chunk-constants.16825f0c.mjs → chunk-constants.d3f8437b.mjs} +4 -4
  6. package/dist/{chunk-install-pkg.6c6dc0c2.mjs → chunk-install-pkg.3aa3eae6.mjs} +3 -2
  7. package/dist/{chunk-defaults.6698a2d3.mjs → chunk-integrations-coverage.d205bd87.mjs} +23 -152
  8. package/dist/{chunk-integrations-globals.c5b78414.mjs → chunk-integrations-globals.e81d2091.mjs} +7 -6
  9. package/dist/{chunk-mock-date.9160e13b.mjs → chunk-mock-date.debe9954.mjs} +16 -74
  10. package/dist/chunk-node-git.71b74da4.mjs +80 -0
  11. package/dist/{chunk-runtime-chain.b6c2cdbc.mjs → chunk-runtime-chain.6e363ba2.mjs} +31 -21
  12. package/dist/{chunk-runtime-error.034e03ba.mjs → chunk-runtime-error.975bd80a.mjs} +14 -12
  13. package/dist/{chunk-runtime-hooks.a8401528.mjs → chunk-runtime-hooks.4789e99d.mjs} +3 -3
  14. package/dist/{chunk-runtime-mocker.653847b2.mjs → chunk-runtime-mocker.c91d29ce.mjs} +34 -12
  15. package/dist/{chunk-runtime-rpc.dbf0b31d.mjs → chunk-runtime-rpc.29488183.mjs} +1 -1
  16. package/dist/{chunk-utils-source-map.8198ebd9.mjs → chunk-utils-source-map.2a082ffd.mjs} +2 -1
  17. package/dist/{chunk-vite-node-client.115caed2.mjs → chunk-vite-node-client.d1ead698.mjs} +7 -3
  18. package/dist/{chunk-vite-node-debug.c5887932.mjs → chunk-vite-node-debug.ff1d2a9f.mjs} +3 -2
  19. package/dist/{chunk-vite-node-externalize.91ae6e85.mjs → chunk-vite-node-externalize.3a38c8af.mjs} +167 -39
  20. package/dist/chunk-vite-node-utils.d8e5ff7b.mjs +6921 -0
  21. package/dist/cli-wrapper.mjs +107 -0
  22. package/dist/cli.mjs +16 -14
  23. package/dist/config.cjs +3 -0
  24. package/dist/config.d.ts +7 -69
  25. package/dist/config.mjs +2 -1
  26. package/dist/entry.mjs +8 -9
  27. package/dist/global-74489cc9.d.ts +2098 -0
  28. package/dist/index-9eded9ec.d.ts +116 -0
  29. package/dist/index.d.ts +9 -1928
  30. package/dist/index.mjs +6 -5
  31. package/dist/loader.mjs +74 -17
  32. package/dist/node.d.ts +7 -1682
  33. package/dist/node.mjs +15 -13
  34. package/dist/suite.mjs +5 -4
  35. package/dist/{vendor-index.61438b77.mjs → vendor-index.29636037.mjs} +1 -61
  36. package/dist/{vendor-index.62ce5c33.mjs → vendor-index.2ae8040a.mjs} +0 -0
  37. package/dist/vendor-index.9d9196cc.mjs +61 -0
  38. package/dist/{vendor-index.de788b6a.mjs → vendor-index.ae96af6e.mjs} +14 -14
  39. package/dist/{chunk-node-git.43dbdd42.mjs → vendor-index.fbec8a81.mjs} +5 -73
  40. package/dist/vendor-picocolors.807856aa.mjs +64 -0
  41. package/dist/worker.mjs +7 -6
  42. package/package.json +8 -12
  43. package/vitest.mjs +1 -1
  44. package/dist/chunk-vite-node-utils.7e46948f.mjs +0 -1114
package/dist/index.mjs CHANGED
@@ -1,18 +1,19 @@
1
- export { c as createExpect, d as describe, b as expect, i as it, s as suite, t as test } from './chunk-runtime-chain.b6c2cdbc.mjs';
2
- export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, h as getRunningMode, f as isFirstRun, j as isWatchMode, e as runOnce, v as vi, g as vitest, w as withCallback } from './chunk-runtime-hooks.a8401528.mjs';
1
+ export { c as createExpect, d as describe, b as expect, i as it, s as suite, t as test } from './chunk-runtime-chain.6e363ba2.mjs';
2
+ export { a as afterAll, d as afterEach, b as beforeAll, c as beforeEach, h as getRunningMode, f as isFirstRun, j as isWatchMode, e as runOnce, v as vi, g as vitest, w as withCallback } from './chunk-runtime-hooks.4789e99d.mjs';
3
3
  import * as chai from 'chai';
4
4
  export { chai };
5
5
  export { assert, should } from 'chai';
6
6
  import 'util';
7
- import './chunk-mock-date.9160e13b.mjs';
7
+ import './chunk-mock-date.debe9954.mjs';
8
8
  import 'path';
9
+ import './vendor-picocolors.807856aa.mjs';
9
10
  import 'tty';
10
11
  import 'local-pkg';
11
12
  import './vendor-_commonjsHelpers.4da45ef5.mjs';
12
- import './chunk-runtime-rpc.dbf0b31d.mjs';
13
+ import './chunk-runtime-rpc.29488183.mjs';
13
14
  import './chunk-utils-global.fa20c2f6.mjs';
14
15
  import './chunk-utils-timers.b48455ed.mjs';
15
16
  import 'fs';
16
- import './chunk-utils-source-map.8198ebd9.mjs';
17
+ import './chunk-utils-source-map.2a082ffd.mjs';
17
18
  import './spy.mjs';
18
19
  import 'tinyspy';
package/dist/loader.mjs CHANGED
@@ -1,36 +1,93 @@
1
1
  import { pathToFileURL } from 'url';
2
- import { i as isNodeBuiltin, d as normalizeModuleId } from './chunk-vite-node-utils.7e46948f.mjs';
3
- import './chunk-mock-date.9160e13b.mjs';
2
+ import { readFile } from 'fs/promises';
3
+ import { i as isNodeBuiltin, d as normalizeModuleId, h as hasCJSSyntax } from './chunk-vite-node-utils.d8e5ff7b.mjs';
4
+ import './chunk-mock-date.debe9954.mjs';
4
5
  import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
5
6
  import 'module';
6
- import 'path';
7
7
  import 'fs';
8
+ import 'path';
8
9
  import 'assert';
9
10
  import 'util';
11
+ import './vendor-picocolors.807856aa.mjs';
10
12
  import 'tty';
11
13
  import 'local-pkg';
12
14
 
15
+ var ModuleFormat = /* @__PURE__ */ ((ModuleFormat2) => {
16
+ ModuleFormat2["Builtin"] = "builtin";
17
+ ModuleFormat2["Commonjs"] = "commonjs";
18
+ ModuleFormat2["Json"] = "json";
19
+ ModuleFormat2["Module"] = "module";
20
+ ModuleFormat2["Wasm"] = "wasm";
21
+ return ModuleFormat2;
22
+ })(ModuleFormat || {});
23
+
24
+ const ESM_RE = /([\s;}]|^)(import[\w,{}\s*]*from|import\s*['"*{]|export\b\s*(?:[*{]|default|class|type|function|const|var|let|async function)|import\.meta\b)/m;
25
+ function hasESMSyntax(code) {
26
+ return ESM_RE.test(code);
27
+ }
28
+ const cache = /* @__PURE__ */ new Map();
29
+ const getPotentialSource = async (filepath, result) => {
30
+ var _a;
31
+ if (!result.url.startsWith("file://") || result.format === "module")
32
+ return null;
33
+ let source = (_a = cache.get(result.url)) == null ? void 0 : _a.source;
34
+ if (source == null)
35
+ source = await readFile(filepath, "utf8");
36
+ return source;
37
+ };
38
+ const detectESM = (url, source) => {
39
+ const cached = cache.get(url);
40
+ if (cached)
41
+ return cached.isPseudoESM;
42
+ if (!source)
43
+ return false;
44
+ return hasESMSyntax(source) && !hasCJSSyntax(source);
45
+ };
13
46
  const resolve = async (url, context, next) => {
14
47
  const { parentURL } = context;
15
- if (!parentURL || !parentURL.includes("node_modules") || isNodeBuiltin(url))
48
+ const state = getWorkerState();
49
+ const resolver = state == null ? void 0 : state.rpc.resolveId;
50
+ if (!parentURL || isNodeBuiltin(url) || !resolver)
16
51
  return next(url, context, next);
17
52
  const id = normalizeModuleId(url);
18
53
  const importer = normalizeModuleId(parentURL);
19
- const state = getWorkerState();
20
- const resolver = state == null ? void 0 : state.rpc.resolveId;
21
- if (resolver) {
22
- const resolved = await resolver(id, importer);
23
- if (resolved) {
24
- return {
25
- url: pathToFileURL(resolved.id).toString(),
26
- shortCircuit: true
27
- };
28
- }
54
+ const resolved = await resolver(id, importer);
55
+ let result;
56
+ let filepath;
57
+ if (resolved) {
58
+ const resolvedUrl = pathToFileURL(resolved.id).toString();
59
+ filepath = resolved.id;
60
+ result = {
61
+ url: resolvedUrl,
62
+ shortCircuit: true
63
+ };
64
+ } else {
65
+ const { url: resolvedUrl, format } = await next(url, context, next);
66
+ filepath = new URL(resolvedUrl).pathname;
67
+ result = {
68
+ url: resolvedUrl,
69
+ format,
70
+ shortCircuit: true
71
+ };
29
72
  }
30
- return next(url, context, next);
73
+ const source = await getPotentialSource(filepath, result);
74
+ const isPseudoESM = detectESM(result.url, source);
75
+ if (typeof source === "string")
76
+ cache.set(result.url, { isPseudoESM, source });
77
+ if (isPseudoESM)
78
+ result.format = ModuleFormat.Module;
79
+ return result;
31
80
  };
32
- const load = (url, context, next) => {
33
- return next(url, context, next);
81
+ const load = async (url, context, next) => {
82
+ const result = await next(url, context, next);
83
+ const cached = cache.get(url);
84
+ if ((cached == null ? void 0 : cached.isPseudoESM) && result.format !== "module") {
85
+ return {
86
+ source: cached.source,
87
+ format: ModuleFormat.Module
88
+ };
89
+ }
90
+ return result;
34
91
  };
35
92
 
36
93
  export { load, resolve };