vitest 0.29.7 → 0.30.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 (60) hide show
  1. package/LICENSE.md +3 -266
  2. package/dist/browser.d.ts +16 -4
  3. package/dist/browser.js +5 -4
  4. package/dist/child.js +12 -17
  5. package/dist/{chunk-api-setup.ac7748ac.js → chunk-api-setup.6662587e.js} +65 -51
  6. package/dist/{chunk-install-pkg.863031f2.js → chunk-install-pkg.6450b372.js} +33 -32
  7. package/dist/chunk-integrations-globals.d419838f.js +26 -0
  8. package/dist/{chunk-node-git.ed5bded8.js → chunk-node-git.4c43bd73.js} +4 -2
  9. package/dist/cli-wrapper.js +6 -5
  10. package/dist/cli.js +27 -26
  11. package/dist/config.cjs +15 -7
  12. package/dist/config.d.ts +15 -8
  13. package/dist/config.js +10 -6
  14. package/dist/coverage.d.ts +5 -2
  15. package/dist/coverage.js +6 -0
  16. package/dist/entry.js +35 -34
  17. package/dist/environments.d.ts +5 -2
  18. package/dist/environments.js +1 -1
  19. package/dist/index.d.ts +17 -21
  20. package/dist/index.js +9 -10
  21. package/dist/loader.js +396 -12
  22. package/dist/node.d.ts +9 -7
  23. package/dist/node.js +28 -30
  24. package/dist/runners.d.ts +5 -2
  25. package/dist/runners.js +34 -30
  26. package/dist/{types-fafda418.d.ts → types-f03c83c4.d.ts} +243 -317
  27. package/dist/utils.d.ts +1 -0
  28. package/dist/utils.js +1 -0
  29. package/dist/{chunk-node-pkg.f9696901.js → vendor-cli-api.c04eaa34.js} +3858 -5514
  30. package/dist/vendor-constants.538d9b49.js +54 -0
  31. package/dist/{chunk-integrations-coverage.e0a6acd2.js → vendor-coverage.a585b712.js} +5 -5
  32. package/dist/{chunk-runtime-mocker.344fec90.js → vendor-execute.8eaab47b.js} +9 -12
  33. package/dist/vendor-global.6795f91f.js +8 -0
  34. package/dist/vendor-index.4f82d248.js +161 -0
  35. package/dist/{chunk-env-node.affdd278.js → vendor-index.75f2b63d.js} +9 -2
  36. package/dist/{chunk-integrations-utils.d7c85bd9.js → vendor-index.81b9e499.js} +22 -21
  37. package/dist/{vendor-index.2cbcdd1e.js → vendor-index.c1e09929.js} +458 -373
  38. package/dist/vendor-index.fad2598b.js +44 -0
  39. package/dist/{vendor-index.534e612c.js → vendor-index.fc98d30f.js} +2 -2
  40. package/dist/{chunk-runtime-inspector.b1427a10.js → vendor-inspector.47fc8cbb.js} +5 -2
  41. package/dist/{chunk-runtime-rpc.1b5714dc.js → vendor-rpc.4d3d7a54.js} +5 -5
  42. package/dist/{chunk-integrations-run-once.a2b4758b.js → vendor-run-once.69ce7172.js} +3 -2
  43. package/dist/{chunk-runtime-setup.a49dc2f9.js → vendor-setup.common.cef38f4e.js} +2 -2
  44. package/dist/vendor-tasks.042d6084.js +14 -0
  45. package/dist/{chunk-utils-import.39ffe9c5.js → vendor-vi.a3ff54b1.js} +262 -3147
  46. package/dist/worker.js +13 -19
  47. package/package.json +40 -34
  48. package/utils.d.ts +1 -0
  49. package/dist/chunk-constants.bc18a549.js +0 -36
  50. package/dist/chunk-integrations-globals.a473e88a.js +0 -27
  51. package/dist/chunk-snapshot-env.a347d647.js +0 -11
  52. package/dist/chunk-utils-base.81f83dbd.js +0 -88
  53. package/dist/chunk-utils-env.04ffbef7.js +0 -70
  54. package/dist/chunk-utils-tasks.b41c8284.js +0 -107
  55. package/dist/env-afee91f0.d.ts +0 -10
  56. package/dist/vendor-index.783e7f3e.js +0 -71
  57. package/dist/vendor-index.bdee400f.js +0 -396
  58. package/dist/vendor-magic-string.es.b3bc5745.js +0 -1591
  59. /package/dist/{vendor-_commonjsHelpers.addc3445.js → vendor-_commonjsHelpers.76cdd49e.js} +0 -0
  60. /package/dist/{chunk-paths.e36446b4.js → vendor-paths.84fc7a99.js} +0 -0
package/dist/worker.js CHANGED
@@ -1,29 +1,19 @@
1
- import { c as createBirpc } from './vendor-index.783e7f3e.js';
1
+ import { c as createBirpc } from './vendor-index.4f82d248.js';
2
2
  import { workerId } from 'tinypool';
3
- import { g as getWorkerState } from './chunk-utils-env.04ffbef7.js';
4
- import { s as startViteNode, m as moduleCache, a as mockMap } from './chunk-runtime-mocker.344fec90.js';
5
- import { s as setupInspect } from './chunk-runtime-inspector.b1427a10.js';
6
- import { a as rpcDone } from './chunk-runtime-rpc.1b5714dc.js';
7
- import 'pathe';
8
- import 'std-env';
9
- import '@vitest/runner/utils';
3
+ import { g as getWorkerState } from './vendor-global.6795f91f.js';
4
+ import { s as startViteNode, m as moduleCache, a as mockMap } from './vendor-execute.8eaab47b.js';
5
+ import { s as setupInspect } from './vendor-inspector.47fc8cbb.js';
6
+ import { a as rpcDone } from './vendor-rpc.4d3d7a54.js';
10
7
  import '@vitest/utils';
11
8
  import 'node:url';
12
9
  import 'vite-node/client';
13
10
  import 'vite-node/utils';
14
- import './vendor-index.bdee400f.js';
15
- import 'acorn';
16
- import 'node:module';
11
+ import 'pathe';
12
+ import '@vitest/runner/utils';
13
+ import './vendor-paths.84fc7a99.js';
17
14
  import 'node:fs';
18
- import 'node:assert';
19
- import 'node:process';
20
- import 'node:path';
21
- import 'node:v8';
22
- import 'node:util';
23
- import './chunk-paths.e36446b4.js';
24
- import './chunk-utils-base.81f83dbd.js';
25
15
  import '@vitest/spy';
26
- import 'node:inspector';
16
+ import 'node:module';
27
17
 
28
18
  function init(ctx) {
29
19
  if (typeof __vitest_worker__ !== "undefined" && ctx.config.threads && ctx.config.isolate)
@@ -37,6 +27,10 @@ function init(ctx) {
37
27
  moduleCache,
38
28
  config,
39
29
  mockMap,
30
+ durations: {
31
+ environment: 0,
32
+ prepare: performance.now()
33
+ },
40
34
  rpc: createBirpc(
41
35
  {},
42
36
  {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vitest",
3
3
  "type": "module",
4
- "version": "0.29.7",
4
+ "version": "0.30.0",
5
5
  "description": "A blazing fast unit test framework powered by Vite",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -61,6 +61,10 @@
61
61
  "types": "./dist/environments.d.ts",
62
62
  "import": "./dist/environments.js"
63
63
  },
64
+ "./utils": {
65
+ "types": "./dist/utils.d.ts",
66
+ "import": "./dist/utils.js"
67
+ },
64
68
  "./config": {
65
69
  "types": "./config.d.ts",
66
70
  "require": "./dist/config.cjs",
@@ -86,14 +90,17 @@
86
90
  "*.cjs"
87
91
  ],
88
92
  "engines": {
89
- "node": ">=v14.16.0"
93
+ "node": ">=v14.18.0"
90
94
  },
91
95
  "peerDependencies": {
92
96
  "@edge-runtime/vm": "*",
93
97
  "@vitest/browser": "*",
94
98
  "@vitest/ui": "*",
95
99
  "happy-dom": "*",
96
- "jsdom": "*"
100
+ "jsdom": "*",
101
+ "playwright": "*",
102
+ "safaridriver": "*",
103
+ "webdriverio": "*"
97
104
  },
98
105
  "peerDependenciesMeta": {
99
106
  "@vitest/ui": {
@@ -114,6 +121,9 @@
114
121
  "safaridriver": {
115
122
  "optional": true
116
123
  },
124
+ "playwright": {
125
+ "optional": true
126
+ },
117
127
  "@edge-runtime/vm": {
118
128
  "optional": true
119
129
  }
@@ -122,70 +132,66 @@
122
132
  "@types/chai": "^4.3.4",
123
133
  "@types/chai-subset": "^1.3.3",
124
134
  "@types/node": "*",
125
- "acorn": "^8.8.1",
135
+ "acorn": "^8.8.2",
126
136
  "acorn-walk": "^8.2.0",
127
137
  "cac": "^6.7.14",
128
138
  "chai": "^4.3.7",
139
+ "concordance": "^5.0.4",
129
140
  "debug": "^4.3.4",
130
- "local-pkg": "^0.4.2",
141
+ "local-pkg": "^0.4.3",
142
+ "magic-string": "^0.30.0",
131
143
  "pathe": "^1.1.0",
132
144
  "picocolors": "^1.0.0",
133
145
  "source-map": "^0.6.1",
134
- "std-env": "^3.3.1",
135
- "strip-literal": "^1.0.0",
136
- "tinybench": "^2.3.1",
146
+ "std-env": "^3.3.2",
147
+ "strip-literal": "^1.0.1",
148
+ "tinybench": "^2.4.0",
137
149
  "tinypool": "^0.4.0",
138
- "tinyspy": "^1.0.2",
139
150
  "vite": "^3.0.0 || ^4.0.0",
140
151
  "why-is-node-running": "^2.2.2",
141
- "@vitest/utils": "0.29.7",
142
- "vite-node": "0.29.7",
143
- "@vitest/expect": "0.29.7",
144
- "@vitest/spy": "0.29.7",
145
- "@vitest/runner": "0.29.7"
152
+ "vite-node": "0.30.0",
153
+ "@vitest/spy": "0.30.0",
154
+ "@vitest/expect": "0.30.0",
155
+ "@vitest/runner": "0.30.0",
156
+ "@vitest/utils": "0.30.0",
157
+ "@vitest/snapshot": "0.30.0"
146
158
  },
147
159
  "devDependencies": {
148
160
  "@ampproject/remapping": "^2.2.0",
149
161
  "@antfu/install-pkg": "^0.1.1",
150
- "@edge-runtime/vm": "2.0.2",
162
+ "@edge-runtime/vm": "2.1.2",
151
163
  "@sinonjs/fake-timers": "^10.0.2",
152
- "@types/diff": "^5.0.2",
164
+ "@types/diff": "^5.0.3",
153
165
  "@types/istanbul-lib-coverage": "^2.0.4",
154
166
  "@types/istanbul-reports": "^3.0.1",
155
- "@types/jsdom": "^21.1.0",
167
+ "@types/jsdom": "^21.1.1",
156
168
  "@types/micromatch": "^4.0.2",
157
- "@types/natural-compare": "^1.4.1",
158
- "@types/prompts": "^2.4.2",
169
+ "@types/prompts": "^2.4.4",
159
170
  "@types/sinonjs__fake-timers": "^8.1.2",
160
- "birpc": "^0.2.3",
171
+ "birpc": "0.2.3",
161
172
  "chai-subset": "^1.6.0",
162
173
  "cli-truncate": "^3.1.0",
163
- "diff": "^5.1.0",
164
174
  "event-target-polyfill": "^0.0.3",
165
- "execa": "^7.0.0",
175
+ "execa": "^7.1.1",
166
176
  "expect-type": "^0.15.0",
167
177
  "fast-glob": "^3.2.12",
168
178
  "find-up": "^6.3.0",
169
179
  "flatted": "^3.2.7",
170
- "get-tsconfig": "^4.3.0",
171
- "happy-dom": "^8.3.2",
172
- "jsdom": "^21.1.0",
180
+ "get-tsconfig": "^4.5.0",
181
+ "happy-dom": "^8.9.0",
182
+ "jsdom": "^21.1.1",
173
183
  "log-update": "^5.0.1",
174
- "magic-string": "^0.27.0",
175
184
  "micromatch": "^4.0.5",
176
- "mlly": "^1.1.0",
177
- "natural-compare": "^1.4.0",
185
+ "mlly": "^1.2.0",
178
186
  "p-limit": "^4.0.0",
179
- "pkg-types": "^1.0.1",
187
+ "pkg-types": "^1.0.2",
188
+ "playwright": "^1.32.2",
180
189
  "pretty-format": "^27.5.1",
181
190
  "prompts": "^2.4.2",
182
- "rollup": "^2.79.1",
183
191
  "safaridriver": "^0.0.4",
184
192
  "strip-ansi": "^7.0.1",
185
- "typescript": "^4.9.4",
186
- "webdriverio": "^8.5.5",
187
- "ws": "^8.12.0",
188
- "x-default-browser": "^0.5.2"
193
+ "webdriverio": "^8.6.9",
194
+ "ws": "^8.13.0"
189
195
  },
190
196
  "scripts": {
191
197
  "build": "rimraf dist && rollup -c",
package/utils.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/utils.js'
@@ -1,36 +0,0 @@
1
- const defaultPort = 51204;
2
- const EXIT_CODE_RESTART = 43;
3
- const API_PATH = "/__vitest_api__";
4
- const configFiles = [
5
- "vitest.config.ts",
6
- "vitest.config.mts",
7
- "vitest.config.cts",
8
- "vitest.config.js",
9
- "vitest.config.mjs",
10
- "vitest.config.cjs",
11
- "vite.config.ts",
12
- "vite.config.mts",
13
- "vite.config.cts",
14
- "vite.config.js",
15
- "vite.config.mjs",
16
- "vite.config.cjs"
17
- ];
18
- const globalApis = [
19
- "suite",
20
- "test",
21
- "describe",
22
- "it",
23
- "chai",
24
- "expect",
25
- "assert",
26
- "expectTypeOf",
27
- "assertType",
28
- "vitest",
29
- "vi",
30
- "beforeAll",
31
- "afterAll",
32
- "beforeEach",
33
- "afterEach"
34
- ];
35
-
36
- export { API_PATH as A, EXIT_CODE_RESTART as E, configFiles as c, defaultPort as d, globalApis as g };
@@ -1,27 +0,0 @@
1
- import { g as globalApis } from './chunk-constants.bc18a549.js';
2
- import { i as index } from './chunk-integrations-utils.d7c85bd9.js';
3
- import '@vitest/runner';
4
- import './chunk-utils-import.39ffe9c5.js';
5
- import '@vitest/runner/utils';
6
- import '@vitest/utils';
7
- import './chunk-utils-env.04ffbef7.js';
8
- import 'pathe';
9
- import 'std-env';
10
- import 'chai';
11
- import './vendor-_commonjsHelpers.addc3445.js';
12
- import '@vitest/expect';
13
- import './chunk-runtime-rpc.1b5714dc.js';
14
- import './chunk-snapshot-env.a347d647.js';
15
- import './chunk-utils-base.81f83dbd.js';
16
- import './chunk-utils-tasks.b41c8284.js';
17
- import 'util';
18
- import '@vitest/spy';
19
- import './chunk-integrations-run-once.a2b4758b.js';
20
-
21
- function registerApiGlobally() {
22
- globalApis.forEach((api) => {
23
- globalThis[api] = index[api];
24
- });
25
- }
26
-
27
- export { registerApiGlobally };
@@ -1,11 +0,0 @@
1
- let _snapshotEnvironment;
2
- function setupSnapshotEnvironment(environment) {
3
- _snapshotEnvironment = environment;
4
- }
5
- function getSnapshotEnvironment() {
6
- if (!_snapshotEnvironment)
7
- throw new Error("Snapshot environment is not setup");
8
- return _snapshotEnvironment;
9
- }
10
-
11
- export { getSnapshotEnvironment as g, setupSnapshotEnvironment as s };
@@ -1,88 +0,0 @@
1
- function isFinalObj(obj) {
2
- return obj === Object.prototype || obj === Function.prototype || obj === RegExp.prototype;
3
- }
4
- function collectOwnProperties(obj, collector) {
5
- const collect = typeof collector === "function" ? collector : (key) => collector.add(key);
6
- Object.getOwnPropertyNames(obj).forEach(collect);
7
- Object.getOwnPropertySymbols(obj).forEach(collect);
8
- }
9
- function groupBy(collection, iteratee) {
10
- return collection.reduce((acc, item) => {
11
- const key = iteratee(item);
12
- acc[key] || (acc[key] = []);
13
- acc[key].push(item);
14
- return acc;
15
- }, {});
16
- }
17
- function getAllMockableProperties(obj, isModule) {
18
- const allProps = /* @__PURE__ */ new Map();
19
- let curr = obj;
20
- do {
21
- if (isFinalObj(curr))
22
- break;
23
- collectOwnProperties(curr, (key) => {
24
- const descriptor = Object.getOwnPropertyDescriptor(curr, key);
25
- if (descriptor)
26
- allProps.set(key, { key, descriptor });
27
- });
28
- } while (curr = Object.getPrototypeOf(curr));
29
- if (isModule && !allProps.has("default") && "default" in obj) {
30
- const descriptor = Object.getOwnPropertyDescriptor(obj, "default");
31
- if (descriptor)
32
- allProps.set("default", { key: "default", descriptor });
33
- }
34
- return Array.from(allProps.values());
35
- }
36
- function notNullish(v) {
37
- return v != null;
38
- }
39
- function slash(str) {
40
- return str.replace(/\\/g, "/");
41
- }
42
- const noop = () => {
43
- };
44
- function toArray(array) {
45
- if (array === null || array === void 0)
46
- array = [];
47
- if (Array.isArray(array))
48
- return array;
49
- return [array];
50
- }
51
- const toString = (v) => Object.prototype.toString.call(v);
52
- const isPlainObject = (val) => toString(val) === "[object Object]" && (!val.constructor || val.constructor.name === "Object");
53
- function isObject(item) {
54
- return item != null && typeof item === "object" && !Array.isArray(item);
55
- }
56
- function deepMerge(target, ...sources) {
57
- if (!sources.length)
58
- return target;
59
- const source = sources.shift();
60
- if (source === void 0)
61
- return target;
62
- if (isMergeableObject(target) && isMergeableObject(source)) {
63
- Object.keys(source).forEach((key) => {
64
- if (isMergeableObject(source[key])) {
65
- if (!target[key])
66
- target[key] = {};
67
- deepMerge(target[key], source[key]);
68
- } else {
69
- target[key] = source[key];
70
- }
71
- });
72
- }
73
- return deepMerge(target, ...sources);
74
- }
75
- function isMergeableObject(item) {
76
- return isPlainObject(item) && !Array.isArray(item);
77
- }
78
- function stdout() {
79
- return console._stdout || process.stdout;
80
- }
81
- function getEnvironmentTransformMode(config, environment) {
82
- var _a, _b;
83
- if (!((_b = (_a = config.deps) == null ? void 0 : _a.experimentalOptimizer) == null ? void 0 : _b.enabled))
84
- return void 0;
85
- return environment === "happy-dom" || environment === "jsdom" ? "web" : "ssr";
86
- }
87
-
88
- export { getEnvironmentTransformMode as a, noop as b, stdout as c, deepMerge as d, getAllMockableProperties as e, groupBy as g, isObject as i, notNullish as n, slash as s, toArray as t };
@@ -1,70 +0,0 @@
1
- import { relative } from 'pathe';
2
- import 'std-env';
3
- import '@vitest/runner/utils';
4
- import '@vitest/utils';
5
-
6
- var _a;
7
- const isNode = typeof process < "u" && typeof process.stdout < "u" && !((_a = process.versions) == null ? void 0 : _a.deno) && !globalThis.window;
8
-
9
- function getWorkerState() {
10
- return globalThis.__vitest_worker__;
11
- }
12
- function getCurrentEnvironment() {
13
- return globalThis.__vitest_environment__;
14
- }
15
-
16
- const isWindows = isNode && process.platform === "win32";
17
- const getRunMode = () => getWorkerState().config.mode;
18
- const isRunningInBenchmark = () => getRunMode() === "benchmark";
19
- const relativePath = relative;
20
- function resetModules(modules, resetMocks = false) {
21
- const skipPaths = [
22
- /\/vitest\/dist\//,
23
- /\/vite-node\/dist\//,
24
- /vitest-virtual-\w+\/dist/,
25
- /@vitest\/dist/,
26
- ...!resetMocks ? [/^mock:/] : []
27
- ];
28
- modules.forEach((mod, path) => {
29
- if (skipPaths.some((re) => re.test(path)))
30
- return;
31
- modules.invalidateModule(mod);
32
- });
33
- }
34
- function removeUndefinedValues(obj) {
35
- for (const key in Object.keys(obj)) {
36
- if (obj[key] === void 0)
37
- delete obj[key];
38
- }
39
- return obj;
40
- }
41
- function getCallLastIndex(code) {
42
- let charIndex = -1;
43
- let inString = null;
44
- let startedBracers = 0;
45
- let endedBracers = 0;
46
- let beforeChar = null;
47
- while (charIndex <= code.length) {
48
- beforeChar = code[charIndex];
49
- charIndex++;
50
- const char = code[charIndex];
51
- const isCharString = char === '"' || char === "'" || char === "`";
52
- if (isCharString && beforeChar !== "\\") {
53
- if (inString === char)
54
- inString = null;
55
- else if (!inString)
56
- inString = char;
57
- }
58
- if (!inString) {
59
- if (char === "(")
60
- startedBracers++;
61
- if (char === ")")
62
- endedBracers++;
63
- }
64
- if (startedBracers && endedBracers && startedBracers === endedBracers)
65
- return charIndex;
66
- }
67
- return null;
68
- }
69
-
70
- export { getCallLastIndex as a, getCurrentEnvironment as b, isNode as c, relativePath as d, removeUndefinedValues as e, isWindows as f, getWorkerState as g, isRunningInBenchmark as i, resetModules as r };
@@ -1,107 +0,0 @@
1
- import { getNames, getTests } from '@vitest/runner/utils';
2
- import { resolve } from 'pathe';
3
- import { n as notNullish } from './chunk-utils-base.81f83dbd.js';
4
-
5
- function hasFailedSnapshot(suite) {
6
- return getTests(suite).some((s) => {
7
- var _a, _b;
8
- return (_b = (_a = s.result) == null ? void 0 : _a.errors) == null ? void 0 : _b.some((e) => e && e.message && e.message.match(/Snapshot .* mismatched/));
9
- });
10
- }
11
- function getFullName(task, separator = " > ") {
12
- return getNames(task).join(separator);
13
- }
14
-
15
- const lineSplitRE = /\r?\n/;
16
- const stackIgnorePatterns = [
17
- "node:internal",
18
- /\/packages\/\w+\/dist\//,
19
- /\/@vitest\/\w+\/dist\//,
20
- "/vitest/dist/",
21
- "/vitest/src/",
22
- "/vite-node/dist/",
23
- "/vite-node/src/",
24
- "/node_modules/chai/",
25
- "/node_modules/tinypool/",
26
- "/node_modules/tinyspy/"
27
- ];
28
- function extractLocation(urlLike) {
29
- if (!urlLike.includes(":"))
30
- return [urlLike];
31
- const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
32
- const parts = regExp.exec(urlLike.replace(/[()]/g, ""));
33
- if (!parts)
34
- return [urlLike];
35
- return [parts[1], parts[2] || void 0, parts[3] || void 0];
36
- }
37
- function parseSingleStack(raw) {
38
- let line = raw.trim();
39
- if (line.includes("(eval "))
40
- line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
41
- let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
42
- const location = sanitizedLine.match(/ (\(.+\)$)/);
43
- sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
44
- const [url, lineNumber, columnNumber] = extractLocation(location ? location[1] : sanitizedLine);
45
- let method = location && sanitizedLine || "";
46
- let file = url && ["eval", "<anonymous>"].includes(url) ? void 0 : url;
47
- if (!file || !lineNumber || !columnNumber)
48
- return null;
49
- if (method.startsWith("async "))
50
- method = method.slice(6);
51
- if (file.startsWith("file://"))
52
- file = file.slice(7);
53
- file = resolve(file);
54
- return {
55
- method,
56
- file,
57
- line: parseInt(lineNumber),
58
- column: parseInt(columnNumber)
59
- };
60
- }
61
- function parseStacktrace(stack, full = false) {
62
- const stackFrames = stack.split("\n").map((raw) => {
63
- const stack2 = parseSingleStack(raw);
64
- if (!stack2 || !full && stackIgnorePatterns.some((p) => stack2.file.match(p)))
65
- return null;
66
- return stack2;
67
- }).filter(notNullish);
68
- return stackFrames;
69
- }
70
- function parseErrorStacktrace(e, full = false) {
71
- if (!e)
72
- return [];
73
- if (e.stacks)
74
- return e.stacks;
75
- const stackStr = e.stack || e.stackStr || "";
76
- const stackFrames = parseStacktrace(stackStr, full);
77
- e.stacks = stackFrames;
78
- return stackFrames;
79
- }
80
- function positionToOffset(source, lineNumber, columnNumber) {
81
- const lines = source.split(lineSplitRE);
82
- let start = 0;
83
- if (lineNumber > lines.length)
84
- return source.length;
85
- for (let i = 0; i < lineNumber - 1; i++)
86
- start += lines[i].length + 1;
87
- return start + columnNumber;
88
- }
89
- function offsetToLineNumber(source, offset) {
90
- if (offset > source.length) {
91
- throw new Error(
92
- `offset is longer than source length! offset ${offset} > length ${source.length}`
93
- );
94
- }
95
- const lines = source.split(lineSplitRE);
96
- let counted = 0;
97
- let line = 0;
98
- for (; line < lines.length; line++) {
99
- const lineLength = lines[line].length + 1;
100
- if (counted + lineLength >= offset)
101
- break;
102
- counted += lineLength;
103
- }
104
- return line + 1;
105
- }
106
-
107
- export { parseErrorStacktrace as a, parseSingleStack as b, getFullName as g, hasFailedSnapshot as h, lineSplitRE as l, offsetToLineNumber as o, positionToOffset as p };
@@ -1,10 +0,0 @@
1
- interface SnapshotEnvironment {
2
- resolvePath(filepath: string): Promise<string>;
3
- prepareDirectory(filepath: string): Promise<void>;
4
- saveSnapshotFile(filepath: string, snapshot: string): Promise<void>;
5
- readSnapshotFile(filepath: string): Promise<string | null>;
6
- removeSnapshotFile(filepath: string): Promise<void>;
7
- }
8
- declare function setupSnapshotEnvironment(environment: SnapshotEnvironment): void;
9
-
10
- export { SnapshotEnvironment as S, setupSnapshotEnvironment as s };
@@ -1,71 +0,0 @@
1
- const DEFAULT_TIMEOUT = 6e4;
2
- function createBirpc(functions, options) {
3
- const {
4
- post,
5
- on,
6
- eventNames = [],
7
- serialize = (i) => i,
8
- deserialize = (i) => i,
9
- timeout = DEFAULT_TIMEOUT
10
- } = options;
11
- const rpcPromiseMap = /* @__PURE__ */ new Map();
12
- const rpc = new Proxy({}, {
13
- get(_, method) {
14
- const sendEvent = (...args) => {
15
- post(serialize({ m: method, a: args, t: "q" }));
16
- };
17
- if (eventNames.includes(method)) {
18
- sendEvent.asEvent = sendEvent;
19
- return sendEvent;
20
- }
21
- const sendCall = (...args) => {
22
- return new Promise((resolve, reject) => {
23
- const id = nanoid();
24
- rpcPromiseMap.set(id, { resolve, reject });
25
- post(serialize({ m: method, a: args, i: id, t: "q" }));
26
- if (timeout >= 0) {
27
- setTimeout(() => {
28
- reject(new Error(`[birpc] timeout on calling "${method}"`));
29
- rpcPromiseMap.delete(id);
30
- }, timeout);
31
- }
32
- });
33
- };
34
- sendCall.asEvent = sendEvent;
35
- return sendCall;
36
- }
37
- });
38
- on(async (data, ...extra) => {
39
- const msg = deserialize(data);
40
- if (msg.t === "q") {
41
- const { m: method, a: args } = msg;
42
- let result, error;
43
- try {
44
- result = await functions[method].apply(rpc, args);
45
- } catch (e) {
46
- error = e;
47
- }
48
- if (msg.i)
49
- post(serialize({ t: "s", i: msg.i, r: result, e: error }), ...extra);
50
- } else {
51
- const { i: ack, r: result, e: error } = msg;
52
- const promise = rpcPromiseMap.get(ack);
53
- if (error)
54
- promise?.reject(error);
55
- else
56
- promise?.resolve(result);
57
- rpcPromiseMap.delete(ack);
58
- }
59
- });
60
- return rpc;
61
- }
62
- const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
63
- function nanoid(size = 21) {
64
- let id = "";
65
- let i = size;
66
- while (i--)
67
- id += urlAlphabet[Math.random() * 64 | 0];
68
- return id;
69
- }
70
-
71
- export { createBirpc as c };