vitest 0.29.8 → 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.
- package/LICENSE.md +2 -81
- package/dist/browser.d.ts +5 -3
- package/dist/browser.js +5 -6
- package/dist/child.js +12 -16
- package/dist/{chunk-api-setup.3aabe9ac.js → chunk-api-setup.6662587e.js} +53 -48
- package/dist/{chunk-install-pkg.6aa7cf6d.js → chunk-install-pkg.6450b372.js} +32 -32
- package/dist/chunk-integrations-globals.d419838f.js +26 -0
- package/dist/{chunk-node-git.ed5bded8.js → chunk-node-git.4c43bd73.js} +4 -2
- package/dist/cli-wrapper.js +6 -5
- package/dist/cli.js +26 -26
- package/dist/config.cjs +15 -2
- package/dist/config.d.ts +15 -4
- package/dist/config.js +10 -1
- package/dist/coverage.d.ts +5 -2
- package/dist/coverage.js +6 -0
- package/dist/entry.js +34 -34
- package/dist/environments.d.ts +5 -2
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +11 -10
- package/dist/index.js +9 -11
- package/dist/loader.js +396 -13
- package/dist/node.d.ts +9 -7
- package/dist/node.js +27 -30
- package/dist/runners.d.ts +5 -2
- package/dist/runners.js +34 -31
- package/dist/{types-94cfe4b4.d.ts → types-f03c83c4.d.ts} +225 -306
- package/dist/{chunk-node-pkg.30d8b37e.js → vendor-cli-api.c04eaa34.js} +3845 -3326
- package/dist/vendor-constants.538d9b49.js +54 -0
- package/dist/{chunk-runtime-mocker.3283818a.js → vendor-execute.8eaab47b.js} +9 -12
- package/dist/{chunk-utils-base.b5ddfcc9.js → vendor-index.4f82d248.js} +80 -10
- package/dist/{chunk-env-node.affdd278.js → vendor-index.75f2b63d.js} +9 -2
- package/dist/{chunk-integrations-utils.23c19408.js → vendor-index.81b9e499.js} +22 -21
- package/dist/{vendor-index.2cbcdd1e.js → vendor-index.c1e09929.js} +458 -373
- package/dist/vendor-index.fad2598b.js +44 -0
- package/dist/{vendor-index.534e612c.js → vendor-index.fc98d30f.js} +2 -2
- package/dist/{chunk-runtime-inspector.b1427a10.js → vendor-inspector.47fc8cbb.js} +5 -2
- package/dist/{chunk-runtime-rpc.d6aa57f8.js → vendor-rpc.4d3d7a54.js} +5 -5
- package/dist/{chunk-integrations-run-once.ea614f17.js → vendor-run-once.69ce7172.js} +3 -3
- package/dist/{chunk-runtime-setup.5d504677.js → vendor-setup.common.cef38f4e.js} +2 -2
- package/dist/vendor-tasks.042d6084.js +14 -0
- package/dist/{chunk-utils-import.e488ace3.js → vendor-vi.a3ff54b1.js} +73 -2957
- package/dist/worker.js +13 -18
- package/package.json +29 -34
- package/dist/chunk-constants.bc18a549.js +0 -36
- package/dist/chunk-integrations-globals.49802775.js +0 -28
- package/dist/chunk-snapshot-env.a347d647.js +0 -11
- package/dist/chunk-utils-env.6b856dbf.js +0 -64
- package/dist/chunk-utils-tasks.8781fd71.js +0 -107
- package/dist/env-afee91f0.d.ts +0 -10
- package/dist/vendor-index.783e7f3e.js +0 -71
- package/dist/vendor-index.bdee400f.js +0 -396
- package/dist/vendor-magic-string.es.b3bc5745.js +0 -1591
- /package/dist/{vendor-_commonjsHelpers.addc3445.js → vendor-_commonjsHelpers.76cdd49e.js} +0 -0
- /package/dist/{chunk-integrations-coverage.d93ee824.js → vendor-coverage.a585b712.js} +0 -0
- /package/dist/{chunk-utils-global.fd174983.js → vendor-global.6795f91f.js} +0 -0
- /package/dist/{chunk-paths.e36446b4.js → vendor-paths.84fc7a99.js} +0 -0
package/dist/worker.js
CHANGED
|
@@ -1,28 +1,19 @@
|
|
|
1
|
-
import { c as createBirpc } from './vendor-index.
|
|
1
|
+
import { c as createBirpc } from './vendor-index.4f82d248.js';
|
|
2
2
|
import { workerId } from 'tinypool';
|
|
3
|
-
import { g as getWorkerState } from './
|
|
4
|
-
import { s as startViteNode, m as moduleCache, a as mockMap } from './
|
|
5
|
-
import { s as setupInspect } from './
|
|
6
|
-
import { a as rpcDone } from './
|
|
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';
|
|
7
|
+
import '@vitest/utils';
|
|
7
8
|
import 'node:url';
|
|
8
9
|
import 'vite-node/client';
|
|
9
10
|
import 'vite-node/utils';
|
|
10
11
|
import 'pathe';
|
|
11
|
-
import './vendor-index.bdee400f.js';
|
|
12
|
-
import 'acorn';
|
|
13
|
-
import 'node:module';
|
|
14
|
-
import 'node:fs';
|
|
15
|
-
import 'node:assert';
|
|
16
|
-
import 'node:process';
|
|
17
|
-
import 'node:path';
|
|
18
|
-
import 'node:v8';
|
|
19
|
-
import 'node:util';
|
|
20
12
|
import '@vitest/runner/utils';
|
|
21
|
-
import './
|
|
22
|
-
import '
|
|
23
|
-
import './chunk-utils-base.b5ddfcc9.js';
|
|
13
|
+
import './vendor-paths.84fc7a99.js';
|
|
14
|
+
import 'node:fs';
|
|
24
15
|
import '@vitest/spy';
|
|
25
|
-
import 'node:
|
|
16
|
+
import 'node:module';
|
|
26
17
|
|
|
27
18
|
function init(ctx) {
|
|
28
19
|
if (typeof __vitest_worker__ !== "undefined" && ctx.config.threads && ctx.config.isolate)
|
|
@@ -36,6 +27,10 @@ function init(ctx) {
|
|
|
36
27
|
moduleCache,
|
|
37
28
|
config,
|
|
38
29
|
mockMap,
|
|
30
|
+
durations: {
|
|
31
|
+
environment: 0,
|
|
32
|
+
prepare: performance.now()
|
|
33
|
+
},
|
|
39
34
|
rpc: createBirpc(
|
|
40
35
|
{},
|
|
41
36
|
{
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitest",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
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",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"*.cjs"
|
|
91
91
|
],
|
|
92
92
|
"engines": {
|
|
93
|
-
"node": ">=v14.
|
|
93
|
+
"node": ">=v14.18.0"
|
|
94
94
|
},
|
|
95
95
|
"peerDependencies": {
|
|
96
96
|
"@edge-runtime/vm": "*",
|
|
@@ -132,71 +132,66 @@
|
|
|
132
132
|
"@types/chai": "^4.3.4",
|
|
133
133
|
"@types/chai-subset": "^1.3.3",
|
|
134
134
|
"@types/node": "*",
|
|
135
|
-
"acorn": "^8.8.
|
|
135
|
+
"acorn": "^8.8.2",
|
|
136
136
|
"acorn-walk": "^8.2.0",
|
|
137
137
|
"cac": "^6.7.14",
|
|
138
138
|
"chai": "^4.3.7",
|
|
139
|
+
"concordance": "^5.0.4",
|
|
139
140
|
"debug": "^4.3.4",
|
|
140
|
-
"local-pkg": "^0.4.
|
|
141
|
+
"local-pkg": "^0.4.3",
|
|
142
|
+
"magic-string": "^0.30.0",
|
|
141
143
|
"pathe": "^1.1.0",
|
|
142
144
|
"picocolors": "^1.0.0",
|
|
143
145
|
"source-map": "^0.6.1",
|
|
144
|
-
"std-env": "^3.3.
|
|
145
|
-
"strip-literal": "^1.0.
|
|
146
|
-
"tinybench": "^2.
|
|
146
|
+
"std-env": "^3.3.2",
|
|
147
|
+
"strip-literal": "^1.0.1",
|
|
148
|
+
"tinybench": "^2.4.0",
|
|
147
149
|
"tinypool": "^0.4.0",
|
|
148
|
-
"tinyspy": "^1.0.2",
|
|
149
150
|
"vite": "^3.0.0 || ^4.0.0",
|
|
150
151
|
"why-is-node-running": "^2.2.2",
|
|
151
|
-
"
|
|
152
|
-
"
|
|
153
|
-
"@vitest/expect": "0.
|
|
154
|
-
"@vitest/
|
|
155
|
-
"@vitest/utils": "0.
|
|
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"
|
|
156
158
|
},
|
|
157
159
|
"devDependencies": {
|
|
158
160
|
"@ampproject/remapping": "^2.2.0",
|
|
159
161
|
"@antfu/install-pkg": "^0.1.1",
|
|
160
|
-
"@edge-runtime/vm": "2.
|
|
162
|
+
"@edge-runtime/vm": "2.1.2",
|
|
161
163
|
"@sinonjs/fake-timers": "^10.0.2",
|
|
162
|
-
"@types/diff": "^5.0.
|
|
164
|
+
"@types/diff": "^5.0.3",
|
|
163
165
|
"@types/istanbul-lib-coverage": "^2.0.4",
|
|
164
166
|
"@types/istanbul-reports": "^3.0.1",
|
|
165
|
-
"@types/jsdom": "^21.1.
|
|
167
|
+
"@types/jsdom": "^21.1.1",
|
|
166
168
|
"@types/micromatch": "^4.0.2",
|
|
167
|
-
"@types/
|
|
168
|
-
"@types/prompts": "^2.4.2",
|
|
169
|
+
"@types/prompts": "^2.4.4",
|
|
169
170
|
"@types/sinonjs__fake-timers": "^8.1.2",
|
|
170
|
-
"birpc": "
|
|
171
|
+
"birpc": "0.2.3",
|
|
171
172
|
"chai-subset": "^1.6.0",
|
|
172
173
|
"cli-truncate": "^3.1.0",
|
|
173
|
-
"diff": "^5.1.0",
|
|
174
174
|
"event-target-polyfill": "^0.0.3",
|
|
175
|
-
"execa": "^7.
|
|
175
|
+
"execa": "^7.1.1",
|
|
176
176
|
"expect-type": "^0.15.0",
|
|
177
177
|
"fast-glob": "^3.2.12",
|
|
178
178
|
"find-up": "^6.3.0",
|
|
179
179
|
"flatted": "^3.2.7",
|
|
180
|
-
"get-tsconfig": "^4.
|
|
181
|
-
"happy-dom": "^8.
|
|
182
|
-
"jsdom": "^21.1.
|
|
180
|
+
"get-tsconfig": "^4.5.0",
|
|
181
|
+
"happy-dom": "^8.9.0",
|
|
182
|
+
"jsdom": "^21.1.1",
|
|
183
183
|
"log-update": "^5.0.1",
|
|
184
|
-
"magic-string": "^0.27.0",
|
|
185
184
|
"micromatch": "^4.0.5",
|
|
186
|
-
"mlly": "^1.
|
|
187
|
-
"natural-compare": "^1.4.0",
|
|
185
|
+
"mlly": "^1.2.0",
|
|
188
186
|
"p-limit": "^4.0.0",
|
|
189
|
-
"pkg-types": "^1.0.
|
|
190
|
-
"playwright": "^1.
|
|
187
|
+
"pkg-types": "^1.0.2",
|
|
188
|
+
"playwright": "^1.32.2",
|
|
191
189
|
"pretty-format": "^27.5.1",
|
|
192
190
|
"prompts": "^2.4.2",
|
|
193
|
-
"rollup": "^2.79.1",
|
|
194
191
|
"safaridriver": "^0.0.4",
|
|
195
192
|
"strip-ansi": "^7.0.1",
|
|
196
|
-
"
|
|
197
|
-
"
|
|
198
|
-
"ws": "^8.12.0",
|
|
199
|
-
"x-default-browser": "^0.5.2"
|
|
193
|
+
"webdriverio": "^8.6.9",
|
|
194
|
+
"ws": "^8.13.0"
|
|
200
195
|
},
|
|
201
196
|
"scripts": {
|
|
202
197
|
"build": "rimraf dist && rollup -c",
|
|
@@ -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,28 +0,0 @@
|
|
|
1
|
-
import { g as globalApis } from './chunk-constants.bc18a549.js';
|
|
2
|
-
import { i as index } from './chunk-integrations-utils.23c19408.js';
|
|
3
|
-
import '@vitest/runner';
|
|
4
|
-
import './chunk-utils-import.e488ace3.js';
|
|
5
|
-
import '@vitest/runner/utils';
|
|
6
|
-
import '@vitest/utils';
|
|
7
|
-
import './chunk-utils-env.6b856dbf.js';
|
|
8
|
-
import 'pathe';
|
|
9
|
-
import 'std-env';
|
|
10
|
-
import './chunk-utils-global.fd174983.js';
|
|
11
|
-
import 'chai';
|
|
12
|
-
import './vendor-_commonjsHelpers.addc3445.js';
|
|
13
|
-
import '@vitest/expect';
|
|
14
|
-
import './chunk-runtime-rpc.d6aa57f8.js';
|
|
15
|
-
import './chunk-snapshot-env.a347d647.js';
|
|
16
|
-
import './chunk-utils-base.b5ddfcc9.js';
|
|
17
|
-
import './chunk-utils-tasks.8781fd71.js';
|
|
18
|
-
import 'util';
|
|
19
|
-
import '@vitest/spy';
|
|
20
|
-
import './chunk-integrations-run-once.ea614f17.js';
|
|
21
|
-
|
|
22
|
-
function registerApiGlobally() {
|
|
23
|
-
globalApis.forEach((api) => {
|
|
24
|
-
globalThis[api] = index[api];
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
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,64 +0,0 @@
|
|
|
1
|
-
import { relative } from 'pathe';
|
|
2
|
-
import 'std-env';
|
|
3
|
-
import '@vitest/runner/utils';
|
|
4
|
-
import { g as getWorkerState } from './chunk-utils-global.fd174983.js';
|
|
5
|
-
import '@vitest/utils';
|
|
6
|
-
|
|
7
|
-
var _a;
|
|
8
|
-
const isNode = typeof process < "u" && typeof process.stdout < "u" && !((_a = process.versions) == null ? void 0 : _a.deno) && !globalThis.window;
|
|
9
|
-
|
|
10
|
-
const isWindows = isNode && process.platform === "win32";
|
|
11
|
-
const getRunMode = () => getWorkerState().config.mode;
|
|
12
|
-
const isRunningInBenchmark = () => getRunMode() === "benchmark";
|
|
13
|
-
const relativePath = relative;
|
|
14
|
-
function resetModules(modules, resetMocks = false) {
|
|
15
|
-
const skipPaths = [
|
|
16
|
-
/\/vitest\/dist\//,
|
|
17
|
-
/\/vite-node\/dist\//,
|
|
18
|
-
/vitest-virtual-\w+\/dist/,
|
|
19
|
-
/@vitest\/dist/,
|
|
20
|
-
...!resetMocks ? [/^mock:/] : []
|
|
21
|
-
];
|
|
22
|
-
modules.forEach((mod, path) => {
|
|
23
|
-
if (skipPaths.some((re) => re.test(path)))
|
|
24
|
-
return;
|
|
25
|
-
modules.invalidateModule(mod);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
function removeUndefinedValues(obj) {
|
|
29
|
-
for (const key in Object.keys(obj)) {
|
|
30
|
-
if (obj[key] === void 0)
|
|
31
|
-
delete obj[key];
|
|
32
|
-
}
|
|
33
|
-
return obj;
|
|
34
|
-
}
|
|
35
|
-
function getCallLastIndex(code) {
|
|
36
|
-
let charIndex = -1;
|
|
37
|
-
let inString = null;
|
|
38
|
-
let startedBracers = 0;
|
|
39
|
-
let endedBracers = 0;
|
|
40
|
-
let beforeChar = null;
|
|
41
|
-
while (charIndex <= code.length) {
|
|
42
|
-
beforeChar = code[charIndex];
|
|
43
|
-
charIndex++;
|
|
44
|
-
const char = code[charIndex];
|
|
45
|
-
const isCharString = char === '"' || char === "'" || char === "`";
|
|
46
|
-
if (isCharString && beforeChar !== "\\") {
|
|
47
|
-
if (inString === char)
|
|
48
|
-
inString = null;
|
|
49
|
-
else if (!inString)
|
|
50
|
-
inString = char;
|
|
51
|
-
}
|
|
52
|
-
if (!inString) {
|
|
53
|
-
if (char === "(")
|
|
54
|
-
startedBracers++;
|
|
55
|
-
if (char === ")")
|
|
56
|
-
endedBracers++;
|
|
57
|
-
}
|
|
58
|
-
if (startedBracers && endedBracers && startedBracers === endedBracers)
|
|
59
|
-
return charIndex;
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export { isNode as a, relativePath as b, removeUndefinedValues as c, isWindows as d, getCallLastIndex 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 { a as isPrimitive, n as notNullish } from './chunk-utils-base.b5ddfcc9.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 || isPrimitive(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 };
|
package/dist/env-afee91f0.d.ts
DELETED
|
@@ -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 };
|