vitest 0.20.1 → 0.21.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 (32) hide show
  1. package/dist/browser.d.ts +9 -1882
  2. package/dist/browser.mjs +7 -7
  3. package/dist/{chunk-api-setup.7c4c8879.mjs → chunk-api-setup.89eb0e7a.mjs} +5 -5
  4. package/dist/{chunk-constants.16825f0c.mjs → chunk-constants.9da1ef26.mjs} +1 -1
  5. package/dist/{chunk-defaults.1c51d585.mjs → chunk-defaults.8390340d.mjs} +2 -2
  6. package/dist/{chunk-integrations-globals.56a11010.mjs → chunk-integrations-globals.a798d352.mjs} +6 -6
  7. package/dist/{chunk-mock-date.9160e13b.mjs → chunk-mock-date.ea3b3121.mjs} +10 -7
  8. package/dist/{chunk-node-git.43dbdd42.mjs → chunk-node-git.e0dc0a7e.mjs} +1 -1
  9. package/dist/{chunk-runtime-chain.b6c2cdbc.mjs → chunk-runtime-chain.44b4224d.mjs} +30 -21
  10. package/dist/{chunk-runtime-error.0aa0dc06.mjs → chunk-runtime-error.95e53764.mjs} +12 -11
  11. package/dist/{chunk-runtime-hooks.3ee34848.mjs → chunk-runtime-hooks.291644ec.mjs} +4 -4
  12. package/dist/{chunk-runtime-mocker.0a8f7c5e.mjs → chunk-runtime-mocker.6190d6a3.mjs} +19 -11
  13. package/dist/{chunk-runtime-rpc.dbf0b31d.mjs → chunk-runtime-rpc.fc50dcc0.mjs} +1 -1
  14. package/dist/{chunk-utils-source-map.8198ebd9.mjs → chunk-utils-source-map.d307e4ea.mjs} +1 -1
  15. package/dist/{chunk-vite-node-client.a247c2c2.mjs → chunk-vite-node-client.b59ba135.mjs} +2 -2
  16. package/dist/{chunk-vite-node-debug.c5887932.mjs → chunk-vite-node-debug.dbce2e1f.mjs} +1 -1
  17. package/dist/{chunk-vite-node-externalize.fce5b934.mjs → chunk-vite-node-externalize.80bed9b3.mjs} +36 -19
  18. package/dist/{chunk-vite-node-utils.9dfd1e3f.mjs → chunk-vite-node-utils.96438e82.mjs} +2 -2
  19. package/dist/cli.mjs +7 -7
  20. package/dist/config.d.ts +2 -67
  21. package/dist/entry.mjs +7 -7
  22. package/dist/global-644546f7.d.ts +1777 -0
  23. package/dist/index-3f764034.d.ts +164 -0
  24. package/dist/index.d.ts +29 -1898
  25. package/dist/index.mjs +5 -5
  26. package/dist/loader.mjs +72 -15
  27. package/dist/mocker-5e2a8e41.d.ts +3 -0
  28. package/dist/node.d.ts +7 -1662
  29. package/dist/node.mjs +8 -8
  30. package/dist/suite.mjs +4 -4
  31. package/dist/worker.mjs +6 -6
  32. package/package.json +10 -10
package/dist/index.mjs CHANGED
@@ -1,18 +1,18 @@
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.3ee34848.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.44b4224d.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.291644ec.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.ea3b3121.mjs';
8
8
  import 'path';
9
9
  import 'tty';
10
10
  import 'local-pkg';
11
11
  import './vendor-_commonjsHelpers.4da45ef5.mjs';
12
- import './chunk-runtime-rpc.dbf0b31d.mjs';
12
+ import './chunk-runtime-rpc.fc50dcc0.mjs';
13
13
  import './chunk-utils-global.fa20c2f6.mjs';
14
14
  import './chunk-utils-timers.b48455ed.mjs';
15
15
  import 'fs';
16
- import './chunk-utils-source-map.8198ebd9.mjs';
16
+ import './chunk-utils-source-map.d307e4ea.mjs';
17
17
  import './spy.mjs';
18
18
  import 'tinyspy';
package/dist/loader.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { pathToFileURL } from 'url';
2
- import { i as isNodeBuiltin, d as normalizeModuleId } from './chunk-vite-node-utils.9dfd1e3f.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.96438e82.mjs';
4
+ import './chunk-mock-date.ea3b3121.mjs';
4
5
  import { g as getWorkerState } from './chunk-utils-global.fa20c2f6.mjs';
5
6
  import 'module';
6
7
  import 'path';
@@ -10,26 +11,82 @@ import 'util';
10
11
  import 'tty';
11
12
  import 'local-pkg';
12
13
 
14
+ var ModuleFormat = /* @__PURE__ */ ((ModuleFormat2) => {
15
+ ModuleFormat2["Builtin"] = "builtin";
16
+ ModuleFormat2["Commonjs"] = "commonjs";
17
+ ModuleFormat2["Json"] = "json";
18
+ ModuleFormat2["Module"] = "module";
19
+ ModuleFormat2["Wasm"] = "wasm";
20
+ return ModuleFormat2;
21
+ })(ModuleFormat || {});
22
+
23
+ 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;
24
+ function hasESMSyntax(code) {
25
+ return ESM_RE.test(code);
26
+ }
27
+ const cache = /* @__PURE__ */ new Map();
28
+ const getPotentialSource = async (filepath, result) => {
29
+ var _a;
30
+ if (!result.url.startsWith("file://") || result.format === "module")
31
+ return null;
32
+ let source = (_a = cache.get(result.url)) == null ? void 0 : _a.source;
33
+ if (source == null)
34
+ source = await readFile(filepath, "utf8");
35
+ return source;
36
+ };
37
+ const detectESM = (url, source) => {
38
+ const cached = cache.get(url);
39
+ if (cached)
40
+ return cached.isPseudoESM;
41
+ if (!source)
42
+ return false;
43
+ return hasESMSyntax(source) && !hasCJSSyntax(source);
44
+ };
13
45
  const resolve = async (url, context, next) => {
14
46
  const { parentURL } = context;
15
- if (!parentURL || !parentURL.includes("node_modules") || isNodeBuiltin(url))
47
+ const state = getWorkerState();
48
+ const resolver = state == null ? void 0 : state.rpc.resolveId;
49
+ if (!parentURL || isNodeBuiltin(url) || !resolver)
16
50
  return next(url, context, next);
17
51
  const id = normalizeModuleId(url);
18
52
  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
- };
27
- }
53
+ const resolved = await resolver(id, importer);
54
+ let result;
55
+ let filepath;
56
+ if (resolved) {
57
+ const resolvedUrl = pathToFileURL(resolved.id).toString();
58
+ filepath = resolved.id;
59
+ result = {
60
+ url: resolvedUrl,
61
+ shortCircuit: true
62
+ };
63
+ } else {
64
+ const { url: resolvedUrl, format } = await next(url, context, next);
65
+ filepath = new URL(resolvedUrl).pathname;
66
+ result = {
67
+ url: resolvedUrl,
68
+ format,
69
+ shortCircuit: true
70
+ };
28
71
  }
29
- return next(url, context, next);
72
+ const source = await getPotentialSource(filepath, result);
73
+ const isPseudoESM = detectESM(result.url, source);
74
+ if (typeof source === "string")
75
+ cache.set(result.url, { isPseudoESM, source });
76
+ if (isPseudoESM)
77
+ result.format = ModuleFormat.Module;
78
+ return result;
30
79
  };
31
- const load = (url, context, next) => {
32
- return next(url, context, next);
80
+ const load = async (url, context, next) => {
81
+ const result = await next(url, context, next);
82
+ const cached = cache.get(url);
83
+ if ((cached == null ? void 0 : cached.isPseudoESM) && result.format !== "module") {
84
+ return {
85
+ source: cached.source,
86
+ format: ModuleFormat.Module
87
+ };
88
+ }
89
+ return result;
33
90
  };
34
91
 
35
92
  export { load, resolve };
@@ -0,0 +1,3 @@
1
+ declare type MockMap = Map<string, Record<string, string | null | (() => unknown)>>;
2
+
3
+ export { MockMap as M };