vitest 3.1.3 → 3.2.0-beta.2
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 +0 -232
- package/dist/browser.d.ts +4 -2
- package/dist/browser.js +3 -4
- package/dist/chunks/{base.DslwPSCy.js → base.DwtwORaC.js} +2 -2
- package/dist/chunks/{cac.BN2e7cE1.js → cac.I9MLYfT-.js} +14 -10
- package/dist/chunks/{cli-api.Bti1vevt.js → cli-api.d6IK1pnk.js} +945 -852
- package/dist/chunks/{coverage.87S59-Sl.js → coverage.OGU09Jbh.js} +129 -4216
- package/dist/chunks/{creator.CuL7xDWI.js → creator.DGAdZ4Hj.js} +18 -39
- package/dist/chunks/{environment.d.Dmw5ulng.d.ts → environment.d.D8YDy2v5.d.ts} +2 -1
- package/dist/chunks/{execute.BpmIjFTD.js → execute.JlGHLJZT.js} +3 -5
- package/dist/chunks/{global.d.CXRAxnWc.d.ts → global.d.BPa1eL3O.d.ts} +17 -12
- package/dist/chunks/{globals.CZAEe_Gf.js → globals.CpxW8ccg.js} +2 -3
- package/dist/chunks/{index.Bw6JxgX8.js → index.CK1YOQaa.js} +7 -7
- package/dist/chunks/{index.De2FqGmR.js → index.CV36oG_L.js} +896 -957
- package/dist/chunks/{index.B0uVAVvx.js → index.CfXMNXHg.js} +2 -14
- package/dist/chunks/index.CmC5OK9L.js +275 -0
- package/dist/chunks/{index.Cu2UlluP.js → index.DswW_LEs.js} +2 -2
- package/dist/chunks/{index.DBIGubLC.js → index.X0nbfr6-.js} +7 -7
- package/dist/chunks/{reporters.d.DG9VKi4m.d.ts → reporters.d.CLC9rhKy.d.ts} +68 -11
- package/dist/chunks/{runBaseTests.BV8m0B-u.js → runBaseTests.Dn2vyej_.js} +5 -6
- package/dist/chunks/{setup-common.AQcDs321.js → setup-common.CYo3Y0dD.js} +1 -3
- package/dist/chunks/typechecker.DnTrplSJ.js +897 -0
- package/dist/chunks/{vi.ClIskdbk.js → vi.BFR5YIgu.js} +3 -0
- package/dist/chunks/{vite.d.D3ndlJcw.d.ts → vite.d.CBZ3M_ru.d.ts} +1 -1
- package/dist/chunks/{vm.CuLHT1BG.js → vm.C1HHjtNS.js} +1 -1
- package/dist/chunks/{worker.d.CHGSOG0s.d.ts → worker.d.CoCI7hzP.d.ts} +1 -1
- package/dist/chunks/{worker.d.C-KN07Ls.d.ts → worker.d.D5Xdi-Zr.d.ts} +1 -1
- package/dist/cli.js +20 -1
- package/dist/config.cjs +3 -0
- package/dist/config.d.ts +8 -5
- package/dist/config.js +3 -0
- package/dist/coverage.d.ts +3 -3
- package/dist/coverage.js +4 -7
- package/dist/environments.d.ts +2 -2
- package/dist/execute.d.ts +2 -2
- package/dist/execute.js +1 -1
- package/dist/index.d.ts +45 -32
- package/dist/index.js +2 -3
- package/dist/node.d.ts +8 -8
- package/dist/node.js +16 -18
- package/dist/reporters.d.ts +3 -3
- package/dist/reporters.js +14 -14
- package/dist/runners.d.ts +1 -1
- package/dist/runners.js +2 -2
- package/dist/workers/forks.js +2 -2
- package/dist/workers/runVmTests.js +5 -6
- package/dist/workers/threads.js +2 -2
- package/dist/workers/vmForks.js +2 -2
- package/dist/workers/vmThreads.js +2 -2
- package/dist/workers.d.ts +3 -3
- package/dist/workers.js +3 -3
- package/package.json +15 -19
- package/dist/chunks/run-once.Dimr7O9f.js +0 -47
- package/dist/chunks/typechecker.DYQbn8uK.js +0 -956
- package/dist/chunks/utils.Cc45eY3L.js +0 -200
- package/dist/utils.d.ts +0 -3
- package/dist/utils.js +0 -2
|
@@ -1,956 +0,0 @@
|
|
|
1
|
-
import { writeFile, rm } from 'node:fs/promises';
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
import { TraceMap, generatedPositionFor, eachMapping } from '@vitest/utils/source-map';
|
|
4
|
-
import { relative, basename, dirname, resolve, join, extname } from 'pathe';
|
|
5
|
-
import { x as x$1 } from 'tinyexec';
|
|
6
|
-
import { getTests, generateHash, calculateSuiteHash, someTasksAreOnly, interpretTaskModes } from '@vitest/runner/utils';
|
|
7
|
-
import '@vitest/utils';
|
|
8
|
-
import { parseAstAsync } from 'vite';
|
|
9
|
-
import nodeos__default from 'node:os';
|
|
10
|
-
import url from 'node:url';
|
|
11
|
-
import p$1 from 'node:path';
|
|
12
|
-
import fs from 'node:fs';
|
|
13
|
-
import ve from 'node:module';
|
|
14
|
-
import Ae from 'fs';
|
|
15
|
-
|
|
16
|
-
function hasFailedSnapshot(suite) {
|
|
17
|
-
return getTests(suite).some((s) => {
|
|
18
|
-
return s.result?.errors?.some((e) => typeof e?.message === "string" && e.message.match(/Snapshot .* mismatched/));
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
function convertTasksToEvents(file, onTask) {
|
|
22
|
-
const packs = [];
|
|
23
|
-
const events = [];
|
|
24
|
-
function visit(suite) {
|
|
25
|
-
onTask?.(suite);
|
|
26
|
-
packs.push([
|
|
27
|
-
suite.id,
|
|
28
|
-
suite.result,
|
|
29
|
-
suite.meta
|
|
30
|
-
]);
|
|
31
|
-
events.push([suite.id, "suite-prepare"]);
|
|
32
|
-
suite.tasks.forEach((task) => {
|
|
33
|
-
if (task.type === "suite") {
|
|
34
|
-
visit(task);
|
|
35
|
-
} else {
|
|
36
|
-
onTask?.(task);
|
|
37
|
-
if (suite.mode !== "skip" && suite.mode !== "todo") {
|
|
38
|
-
packs.push([
|
|
39
|
-
task.id,
|
|
40
|
-
task.result,
|
|
41
|
-
task.meta
|
|
42
|
-
]);
|
|
43
|
-
events.push([task.id, "test-prepare"], [task.id, "test-finished"]);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
events.push([suite.id, "suite-finished"]);
|
|
48
|
-
}
|
|
49
|
-
visit(file);
|
|
50
|
-
return {
|
|
51
|
-
packs,
|
|
52
|
-
events
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const REGEXP_WRAP_PREFIX = "$$vitest:";
|
|
57
|
-
function getOutputFile(config, reporter) {
|
|
58
|
-
if (!config?.outputFile) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
if (typeof config.outputFile === "string") {
|
|
62
|
-
return config.outputFile;
|
|
63
|
-
}
|
|
64
|
-
return config.outputFile[reporter];
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Prepares `SerializedConfig` for serialization, e.g. `node:v8.serialize`
|
|
68
|
-
*/
|
|
69
|
-
function wrapSerializableConfig(config) {
|
|
70
|
-
let testNamePattern = config.testNamePattern;
|
|
71
|
-
let defines = config.defines;
|
|
72
|
-
if (testNamePattern && typeof testNamePattern !== "string") {
|
|
73
|
-
testNamePattern = `${REGEXP_WRAP_PREFIX}${testNamePattern.toString()}`;
|
|
74
|
-
}
|
|
75
|
-
if (defines) {
|
|
76
|
-
defines = {
|
|
77
|
-
keys: Object.keys(defines),
|
|
78
|
-
original: defines
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
return {
|
|
82
|
-
...config,
|
|
83
|
-
testNamePattern,
|
|
84
|
-
defines
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// AST walker module for ESTree compatible trees
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
// An ancestor walk keeps an array of ancestor nodes (including the
|
|
92
|
-
// current node) and passes them to the callback as third parameter
|
|
93
|
-
// (and also as state parameter when no other state is present).
|
|
94
|
-
function ancestor(node, visitors, baseVisitor, state, override) {
|
|
95
|
-
var ancestors = [];
|
|
96
|
-
if (!baseVisitor) { baseVisitor = base
|
|
97
|
-
; }(function c(node, st, override) {
|
|
98
|
-
var type = override || node.type;
|
|
99
|
-
var isNew = node !== ancestors[ancestors.length - 1];
|
|
100
|
-
if (isNew) { ancestors.push(node); }
|
|
101
|
-
baseVisitor[type](node, st, c);
|
|
102
|
-
if (visitors[type]) { visitors[type](node, st || ancestors, ancestors); }
|
|
103
|
-
if (isNew) { ancestors.pop(); }
|
|
104
|
-
})(node, state, override);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function skipThrough(node, st, c) { c(node, st); }
|
|
108
|
-
function ignore(_node, _st, _c) {}
|
|
109
|
-
|
|
110
|
-
// Node walkers.
|
|
111
|
-
|
|
112
|
-
var base = {};
|
|
113
|
-
|
|
114
|
-
base.Program = base.BlockStatement = base.StaticBlock = function (node, st, c) {
|
|
115
|
-
for (var i = 0, list = node.body; i < list.length; i += 1)
|
|
116
|
-
{
|
|
117
|
-
var stmt = list[i];
|
|
118
|
-
|
|
119
|
-
c(stmt, st, "Statement");
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
base.Statement = skipThrough;
|
|
123
|
-
base.EmptyStatement = ignore;
|
|
124
|
-
base.ExpressionStatement = base.ParenthesizedExpression = base.ChainExpression =
|
|
125
|
-
function (node, st, c) { return c(node.expression, st, "Expression"); };
|
|
126
|
-
base.IfStatement = function (node, st, c) {
|
|
127
|
-
c(node.test, st, "Expression");
|
|
128
|
-
c(node.consequent, st, "Statement");
|
|
129
|
-
if (node.alternate) { c(node.alternate, st, "Statement"); }
|
|
130
|
-
};
|
|
131
|
-
base.LabeledStatement = function (node, st, c) { return c(node.body, st, "Statement"); };
|
|
132
|
-
base.BreakStatement = base.ContinueStatement = ignore;
|
|
133
|
-
base.WithStatement = function (node, st, c) {
|
|
134
|
-
c(node.object, st, "Expression");
|
|
135
|
-
c(node.body, st, "Statement");
|
|
136
|
-
};
|
|
137
|
-
base.SwitchStatement = function (node, st, c) {
|
|
138
|
-
c(node.discriminant, st, "Expression");
|
|
139
|
-
for (var i = 0, list = node.cases; i < list.length; i += 1) {
|
|
140
|
-
var cs = list[i];
|
|
141
|
-
|
|
142
|
-
c(cs, st);
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
base.SwitchCase = function (node, st, c) {
|
|
146
|
-
if (node.test) { c(node.test, st, "Expression"); }
|
|
147
|
-
for (var i = 0, list = node.consequent; i < list.length; i += 1)
|
|
148
|
-
{
|
|
149
|
-
var cons = list[i];
|
|
150
|
-
|
|
151
|
-
c(cons, st, "Statement");
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
base.ReturnStatement = base.YieldExpression = base.AwaitExpression = function (node, st, c) {
|
|
155
|
-
if (node.argument) { c(node.argument, st, "Expression"); }
|
|
156
|
-
};
|
|
157
|
-
base.ThrowStatement = base.SpreadElement =
|
|
158
|
-
function (node, st, c) { return c(node.argument, st, "Expression"); };
|
|
159
|
-
base.TryStatement = function (node, st, c) {
|
|
160
|
-
c(node.block, st, "Statement");
|
|
161
|
-
if (node.handler) { c(node.handler, st); }
|
|
162
|
-
if (node.finalizer) { c(node.finalizer, st, "Statement"); }
|
|
163
|
-
};
|
|
164
|
-
base.CatchClause = function (node, st, c) {
|
|
165
|
-
if (node.param) { c(node.param, st, "Pattern"); }
|
|
166
|
-
c(node.body, st, "Statement");
|
|
167
|
-
};
|
|
168
|
-
base.WhileStatement = base.DoWhileStatement = function (node, st, c) {
|
|
169
|
-
c(node.test, st, "Expression");
|
|
170
|
-
c(node.body, st, "Statement");
|
|
171
|
-
};
|
|
172
|
-
base.ForStatement = function (node, st, c) {
|
|
173
|
-
if (node.init) { c(node.init, st, "ForInit"); }
|
|
174
|
-
if (node.test) { c(node.test, st, "Expression"); }
|
|
175
|
-
if (node.update) { c(node.update, st, "Expression"); }
|
|
176
|
-
c(node.body, st, "Statement");
|
|
177
|
-
};
|
|
178
|
-
base.ForInStatement = base.ForOfStatement = function (node, st, c) {
|
|
179
|
-
c(node.left, st, "ForInit");
|
|
180
|
-
c(node.right, st, "Expression");
|
|
181
|
-
c(node.body, st, "Statement");
|
|
182
|
-
};
|
|
183
|
-
base.ForInit = function (node, st, c) {
|
|
184
|
-
if (node.type === "VariableDeclaration") { c(node, st); }
|
|
185
|
-
else { c(node, st, "Expression"); }
|
|
186
|
-
};
|
|
187
|
-
base.DebuggerStatement = ignore;
|
|
188
|
-
|
|
189
|
-
base.FunctionDeclaration = function (node, st, c) { return c(node, st, "Function"); };
|
|
190
|
-
base.VariableDeclaration = function (node, st, c) {
|
|
191
|
-
for (var i = 0, list = node.declarations; i < list.length; i += 1)
|
|
192
|
-
{
|
|
193
|
-
var decl = list[i];
|
|
194
|
-
|
|
195
|
-
c(decl, st);
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
base.VariableDeclarator = function (node, st, c) {
|
|
199
|
-
c(node.id, st, "Pattern");
|
|
200
|
-
if (node.init) { c(node.init, st, "Expression"); }
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
base.Function = function (node, st, c) {
|
|
204
|
-
if (node.id) { c(node.id, st, "Pattern"); }
|
|
205
|
-
for (var i = 0, list = node.params; i < list.length; i += 1)
|
|
206
|
-
{
|
|
207
|
-
var param = list[i];
|
|
208
|
-
|
|
209
|
-
c(param, st, "Pattern");
|
|
210
|
-
}
|
|
211
|
-
c(node.body, st, node.expression ? "Expression" : "Statement");
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
base.Pattern = function (node, st, c) {
|
|
215
|
-
if (node.type === "Identifier")
|
|
216
|
-
{ c(node, st, "VariablePattern"); }
|
|
217
|
-
else if (node.type === "MemberExpression")
|
|
218
|
-
{ c(node, st, "MemberPattern"); }
|
|
219
|
-
else
|
|
220
|
-
{ c(node, st); }
|
|
221
|
-
};
|
|
222
|
-
base.VariablePattern = ignore;
|
|
223
|
-
base.MemberPattern = skipThrough;
|
|
224
|
-
base.RestElement = function (node, st, c) { return c(node.argument, st, "Pattern"); };
|
|
225
|
-
base.ArrayPattern = function (node, st, c) {
|
|
226
|
-
for (var i = 0, list = node.elements; i < list.length; i += 1) {
|
|
227
|
-
var elt = list[i];
|
|
228
|
-
|
|
229
|
-
if (elt) { c(elt, st, "Pattern"); }
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
base.ObjectPattern = function (node, st, c) {
|
|
233
|
-
for (var i = 0, list = node.properties; i < list.length; i += 1) {
|
|
234
|
-
var prop = list[i];
|
|
235
|
-
|
|
236
|
-
if (prop.type === "Property") {
|
|
237
|
-
if (prop.computed) { c(prop.key, st, "Expression"); }
|
|
238
|
-
c(prop.value, st, "Pattern");
|
|
239
|
-
} else if (prop.type === "RestElement") {
|
|
240
|
-
c(prop.argument, st, "Pattern");
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
base.Expression = skipThrough;
|
|
246
|
-
base.ThisExpression = base.Super = base.MetaProperty = ignore;
|
|
247
|
-
base.ArrayExpression = function (node, st, c) {
|
|
248
|
-
for (var i = 0, list = node.elements; i < list.length; i += 1) {
|
|
249
|
-
var elt = list[i];
|
|
250
|
-
|
|
251
|
-
if (elt) { c(elt, st, "Expression"); }
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
base.ObjectExpression = function (node, st, c) {
|
|
255
|
-
for (var i = 0, list = node.properties; i < list.length; i += 1)
|
|
256
|
-
{
|
|
257
|
-
var prop = list[i];
|
|
258
|
-
|
|
259
|
-
c(prop, st);
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
base.FunctionExpression = base.ArrowFunctionExpression = base.FunctionDeclaration;
|
|
263
|
-
base.SequenceExpression = function (node, st, c) {
|
|
264
|
-
for (var i = 0, list = node.expressions; i < list.length; i += 1)
|
|
265
|
-
{
|
|
266
|
-
var expr = list[i];
|
|
267
|
-
|
|
268
|
-
c(expr, st, "Expression");
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
base.TemplateLiteral = function (node, st, c) {
|
|
272
|
-
for (var i = 0, list = node.quasis; i < list.length; i += 1)
|
|
273
|
-
{
|
|
274
|
-
var quasi = list[i];
|
|
275
|
-
|
|
276
|
-
c(quasi, st);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
for (var i$1 = 0, list$1 = node.expressions; i$1 < list$1.length; i$1 += 1)
|
|
280
|
-
{
|
|
281
|
-
var expr = list$1[i$1];
|
|
282
|
-
|
|
283
|
-
c(expr, st, "Expression");
|
|
284
|
-
}
|
|
285
|
-
};
|
|
286
|
-
base.TemplateElement = ignore;
|
|
287
|
-
base.UnaryExpression = base.UpdateExpression = function (node, st, c) {
|
|
288
|
-
c(node.argument, st, "Expression");
|
|
289
|
-
};
|
|
290
|
-
base.BinaryExpression = base.LogicalExpression = function (node, st, c) {
|
|
291
|
-
c(node.left, st, "Expression");
|
|
292
|
-
c(node.right, st, "Expression");
|
|
293
|
-
};
|
|
294
|
-
base.AssignmentExpression = base.AssignmentPattern = function (node, st, c) {
|
|
295
|
-
c(node.left, st, "Pattern");
|
|
296
|
-
c(node.right, st, "Expression");
|
|
297
|
-
};
|
|
298
|
-
base.ConditionalExpression = function (node, st, c) {
|
|
299
|
-
c(node.test, st, "Expression");
|
|
300
|
-
c(node.consequent, st, "Expression");
|
|
301
|
-
c(node.alternate, st, "Expression");
|
|
302
|
-
};
|
|
303
|
-
base.NewExpression = base.CallExpression = function (node, st, c) {
|
|
304
|
-
c(node.callee, st, "Expression");
|
|
305
|
-
if (node.arguments)
|
|
306
|
-
{ for (var i = 0, list = node.arguments; i < list.length; i += 1)
|
|
307
|
-
{
|
|
308
|
-
var arg = list[i];
|
|
309
|
-
|
|
310
|
-
c(arg, st, "Expression");
|
|
311
|
-
} }
|
|
312
|
-
};
|
|
313
|
-
base.MemberExpression = function (node, st, c) {
|
|
314
|
-
c(node.object, st, "Expression");
|
|
315
|
-
if (node.computed) { c(node.property, st, "Expression"); }
|
|
316
|
-
};
|
|
317
|
-
base.ExportNamedDeclaration = base.ExportDefaultDeclaration = function (node, st, c) {
|
|
318
|
-
if (node.declaration)
|
|
319
|
-
{ c(node.declaration, st, node.type === "ExportNamedDeclaration" || node.declaration.id ? "Statement" : "Expression"); }
|
|
320
|
-
if (node.source) { c(node.source, st, "Expression"); }
|
|
321
|
-
};
|
|
322
|
-
base.ExportAllDeclaration = function (node, st, c) {
|
|
323
|
-
if (node.exported)
|
|
324
|
-
{ c(node.exported, st); }
|
|
325
|
-
c(node.source, st, "Expression");
|
|
326
|
-
};
|
|
327
|
-
base.ImportDeclaration = function (node, st, c) {
|
|
328
|
-
for (var i = 0, list = node.specifiers; i < list.length; i += 1)
|
|
329
|
-
{
|
|
330
|
-
var spec = list[i];
|
|
331
|
-
|
|
332
|
-
c(spec, st);
|
|
333
|
-
}
|
|
334
|
-
c(node.source, st, "Expression");
|
|
335
|
-
};
|
|
336
|
-
base.ImportExpression = function (node, st, c) {
|
|
337
|
-
c(node.source, st, "Expression");
|
|
338
|
-
};
|
|
339
|
-
base.ImportSpecifier = base.ImportDefaultSpecifier = base.ImportNamespaceSpecifier = base.Identifier = base.PrivateIdentifier = base.Literal = ignore;
|
|
340
|
-
|
|
341
|
-
base.TaggedTemplateExpression = function (node, st, c) {
|
|
342
|
-
c(node.tag, st, "Expression");
|
|
343
|
-
c(node.quasi, st, "Expression");
|
|
344
|
-
};
|
|
345
|
-
base.ClassDeclaration = base.ClassExpression = function (node, st, c) { return c(node, st, "Class"); };
|
|
346
|
-
base.Class = function (node, st, c) {
|
|
347
|
-
if (node.id) { c(node.id, st, "Pattern"); }
|
|
348
|
-
if (node.superClass) { c(node.superClass, st, "Expression"); }
|
|
349
|
-
c(node.body, st);
|
|
350
|
-
};
|
|
351
|
-
base.ClassBody = function (node, st, c) {
|
|
352
|
-
for (var i = 0, list = node.body; i < list.length; i += 1)
|
|
353
|
-
{
|
|
354
|
-
var elt = list[i];
|
|
355
|
-
|
|
356
|
-
c(elt, st);
|
|
357
|
-
}
|
|
358
|
-
};
|
|
359
|
-
base.MethodDefinition = base.PropertyDefinition = base.Property = function (node, st, c) {
|
|
360
|
-
if (node.computed) { c(node.key, st, "Expression"); }
|
|
361
|
-
if (node.value) { c(node.value, st, "Expression"); }
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
async function collectTests(ctx, filepath) {
|
|
365
|
-
const request = await ctx.vitenode.transformRequest(filepath, filepath);
|
|
366
|
-
if (!request) {
|
|
367
|
-
return null;
|
|
368
|
-
}
|
|
369
|
-
const ast = await parseAstAsync(request.code);
|
|
370
|
-
const testFilepath = relative(ctx.config.root, filepath);
|
|
371
|
-
const projectName = ctx.name;
|
|
372
|
-
const typecheckSubprojectName = projectName ? `${projectName}:__typecheck__` : "__typecheck__";
|
|
373
|
-
const file = {
|
|
374
|
-
filepath,
|
|
375
|
-
type: "suite",
|
|
376
|
-
id: generateHash(`${testFilepath}${typecheckSubprojectName}`),
|
|
377
|
-
name: testFilepath,
|
|
378
|
-
mode: "run",
|
|
379
|
-
tasks: [],
|
|
380
|
-
start: ast.start,
|
|
381
|
-
end: ast.end,
|
|
382
|
-
projectName,
|
|
383
|
-
meta: { typecheck: true },
|
|
384
|
-
file: null
|
|
385
|
-
};
|
|
386
|
-
file.file = file;
|
|
387
|
-
const definitions = [];
|
|
388
|
-
const getName = (callee) => {
|
|
389
|
-
if (!callee) {
|
|
390
|
-
return null;
|
|
391
|
-
}
|
|
392
|
-
if (callee.type === "Identifier") {
|
|
393
|
-
return callee.name;
|
|
394
|
-
}
|
|
395
|
-
if (callee.type === "CallExpression") {
|
|
396
|
-
return getName(callee.callee);
|
|
397
|
-
}
|
|
398
|
-
if (callee.type === "TaggedTemplateExpression") {
|
|
399
|
-
return getName(callee.tag);
|
|
400
|
-
}
|
|
401
|
-
if (callee.type === "MemberExpression") {
|
|
402
|
-
if (callee.object?.type === "Identifier" && [
|
|
403
|
-
"it",
|
|
404
|
-
"test",
|
|
405
|
-
"describe",
|
|
406
|
-
"suite"
|
|
407
|
-
].includes(callee.object.name)) {
|
|
408
|
-
return callee.object?.name;
|
|
409
|
-
}
|
|
410
|
-
if (callee.object?.name?.startsWith("__vite_ssr_")) {
|
|
411
|
-
return getName(callee.property);
|
|
412
|
-
}
|
|
413
|
-
return getName(callee.object?.property);
|
|
414
|
-
}
|
|
415
|
-
if (callee.type === "SequenceExpression" && callee.expressions.length === 2) {
|
|
416
|
-
const [e0, e1] = callee.expressions;
|
|
417
|
-
if (e0.type === "Literal" && e0.value === 0) {
|
|
418
|
-
return getName(e1);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
return null;
|
|
422
|
-
};
|
|
423
|
-
ancestor(ast, { CallExpression(node) {
|
|
424
|
-
const { callee } = node;
|
|
425
|
-
const name = getName(callee);
|
|
426
|
-
if (!name) {
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
if (![
|
|
430
|
-
"it",
|
|
431
|
-
"test",
|
|
432
|
-
"describe",
|
|
433
|
-
"suite"
|
|
434
|
-
].includes(name)) {
|
|
435
|
-
return;
|
|
436
|
-
}
|
|
437
|
-
const property = callee?.property?.name;
|
|
438
|
-
let mode = !property || property === name ? "run" : property;
|
|
439
|
-
if ([
|
|
440
|
-
"each",
|
|
441
|
-
"for",
|
|
442
|
-
"skipIf",
|
|
443
|
-
"runIf"
|
|
444
|
-
].includes(mode)) {
|
|
445
|
-
return;
|
|
446
|
-
}
|
|
447
|
-
let start;
|
|
448
|
-
const end = node.end;
|
|
449
|
-
if (callee.type === "CallExpression") {
|
|
450
|
-
start = callee.end;
|
|
451
|
-
} else if (callee.type === "TaggedTemplateExpression") {
|
|
452
|
-
start = callee.end + 1;
|
|
453
|
-
} else {
|
|
454
|
-
start = node.start;
|
|
455
|
-
}
|
|
456
|
-
const { arguments: [messageNode] } = node;
|
|
457
|
-
const isQuoted = messageNode?.type === "Literal" || messageNode?.type === "TemplateLiteral";
|
|
458
|
-
const message = isQuoted ? request.code.slice(messageNode.start + 1, messageNode.end - 1) : request.code.slice(messageNode.start, messageNode.end);
|
|
459
|
-
if (mode === "skipIf" || mode === "runIf") {
|
|
460
|
-
mode = "skip";
|
|
461
|
-
}
|
|
462
|
-
definitions.push({
|
|
463
|
-
start,
|
|
464
|
-
end,
|
|
465
|
-
name: message,
|
|
466
|
-
type: name === "it" || name === "test" ? "test" : "suite",
|
|
467
|
-
mode,
|
|
468
|
-
task: null
|
|
469
|
-
});
|
|
470
|
-
} });
|
|
471
|
-
let lastSuite = file;
|
|
472
|
-
const updateLatestSuite = (index) => {
|
|
473
|
-
while (lastSuite.suite && lastSuite.end < index) {
|
|
474
|
-
lastSuite = lastSuite.suite;
|
|
475
|
-
}
|
|
476
|
-
return lastSuite;
|
|
477
|
-
};
|
|
478
|
-
definitions.sort((a, b) => a.start - b.start).forEach((definition) => {
|
|
479
|
-
const latestSuite = updateLatestSuite(definition.start);
|
|
480
|
-
let mode = definition.mode;
|
|
481
|
-
if (latestSuite.mode !== "run") {
|
|
482
|
-
mode = latestSuite.mode;
|
|
483
|
-
}
|
|
484
|
-
if (definition.type === "suite") {
|
|
485
|
-
const task = {
|
|
486
|
-
type: definition.type,
|
|
487
|
-
id: "",
|
|
488
|
-
suite: latestSuite,
|
|
489
|
-
file,
|
|
490
|
-
tasks: [],
|
|
491
|
-
mode,
|
|
492
|
-
name: definition.name,
|
|
493
|
-
end: definition.end,
|
|
494
|
-
start: definition.start,
|
|
495
|
-
meta: { typecheck: true }
|
|
496
|
-
};
|
|
497
|
-
definition.task = task;
|
|
498
|
-
latestSuite.tasks.push(task);
|
|
499
|
-
lastSuite = task;
|
|
500
|
-
return;
|
|
501
|
-
}
|
|
502
|
-
const task = {
|
|
503
|
-
type: definition.type,
|
|
504
|
-
id: "",
|
|
505
|
-
suite: latestSuite,
|
|
506
|
-
file,
|
|
507
|
-
mode,
|
|
508
|
-
timeout: 0,
|
|
509
|
-
context: {},
|
|
510
|
-
name: definition.name,
|
|
511
|
-
end: definition.end,
|
|
512
|
-
start: definition.start,
|
|
513
|
-
meta: { typecheck: true }
|
|
514
|
-
};
|
|
515
|
-
definition.task = task;
|
|
516
|
-
latestSuite.tasks.push(task);
|
|
517
|
-
});
|
|
518
|
-
calculateSuiteHash(file);
|
|
519
|
-
const hasOnly = someTasksAreOnly(file);
|
|
520
|
-
interpretTaskModes(file, ctx.config.testNamePattern, undefined, hasOnly, false, ctx.config.allowOnly);
|
|
521
|
-
return {
|
|
522
|
-
file,
|
|
523
|
-
parsed: request.code,
|
|
524
|
-
filepath,
|
|
525
|
-
map: request.map,
|
|
526
|
-
definitions
|
|
527
|
-
};
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
const A=r=>r!==null&&typeof r=="object",a=(r,t)=>Object.assign(new Error(`[${r}]: ${t}`),{code:r}),_="ERR_INVALID_PACKAGE_CONFIG",E$1="ERR_INVALID_PACKAGE_TARGET",I="ERR_PACKAGE_PATH_NOT_EXPORTED",R=/^\d+$/,O$1=/^(\.{1,2}|node_modules)$/i,w=/\/|\\/;var h$1=(r=>(r.Export="exports",r.Import="imports",r))(h$1||{});const f=(r,t,e,o,c)=>{if(t==null)return [];if(typeof t=="string"){const[n,...i]=t.split(w);if(n===".."||i.some(l=>O$1.test(l)))throw a(E$1,`Invalid "${r}" target "${t}" defined in the package config`);return [c?t.replace(/\*/g,c):t]}if(Array.isArray(t))return t.flatMap(n=>f(r,n,e,o,c));if(A(t)){for(const n of Object.keys(t)){if(R.test(n))throw a(_,"Cannot contain numeric property keys");if(n==="default"||o.includes(n))return f(r,t[n],e,o,c)}return []}throw a(E$1,`Invalid "${r}" target "${t}"`)},s="*",m=(r,t)=>{const e=r.indexOf(s),o=t.indexOf(s);return e===o?t.length>r.length:o>e};function d(r,t){if(!t.includes(s)&&r.hasOwnProperty(t))return [t];let e,o;for(const c of Object.keys(r))if(c.includes(s)){const[n,i,l]=c.split(s);if(l===void 0&&t.startsWith(n)&&t.endsWith(i)){const g=t.slice(n.length,-i.length||void 0);g&&(!e||m(e,c))&&(e=c,o=g);}}return [e,o]}const p=r=>Object.keys(r).reduce((t,e)=>{const o=e===""||e[0]!==".";if(t===void 0||t===o)return o;throw a(_,'"exports" cannot contain some keys starting with "." and some not')},void 0),u=/^\w+:/,v=(r,t,e)=>{if(!r)throw new Error('"exports" is required');t=t===""?".":`./${t}`,(typeof r=="string"||Array.isArray(r)||A(r)&&p(r))&&(r={".":r});const[o,c]=d(r,t),n=f(h$1.Export,r[o],t,e,c);if(n.length===0)throw a(I,t==="."?'No "exports" main defined':`Package subpath '${t}' is not defined by "exports"`);for(const i of n)if(!i.startsWith("./")&&!u.test(i))throw a(E$1,`Invalid "exports" target "${i}" defined in the package config`);return n};
|
|
531
|
-
|
|
532
|
-
var de=Object.defineProperty;var o=(e,t)=>de(e,"name",{value:t,configurable:true});function E(e){return e.startsWith("\\\\?\\")?e:e.replace(/\\/g,"/")}o(E,"slash");const O=o(e=>{const t=fs[e];return (s,...n)=>{const l=`${e}:${n.join(":")}`;let i=s==null?void 0:s.get(l);return i===void 0&&(i=Reflect.apply(t,fs,n),s==null||s.set(l,i)),i}},"cacheFs"),B=O("existsSync"),_e=O("readFileSync"),W=O("statSync"),le=o((e,t,s)=>{for(;;){const n=p$1.posix.join(e,t);if(B(s,n))return n;const l=p$1.dirname(e);if(l===e)return;e=l;}},"findUp"),G=/^\.{1,2}(\/.*)?$/,Q=o(e=>{const t=E(e);return G.test(t)?t:`./${t}`},"normalizeRelativePath");function je(e,t=false){const s=e.length;let n=0,l="",i=0,u=16,f=0,r=0,g=0,T=0,b=0;function _(c,k){let m=0,F=0;for(;m<c;){let j=e.charCodeAt(n);if(j>=48&&j<=57)F=F*16+j-48;else if(j>=65&&j<=70)F=F*16+j-65+10;else if(j>=97&&j<=102)F=F*16+j-97+10;else break;n++,m++;}return m<c&&(F=-1),F}o(_,"scanHexDigits");function d(c){n=c,l="",i=0,u=16,b=0;}o(d,"setPosition");function A(){let c=n;if(e.charCodeAt(n)===48)n++;else for(n++;n<e.length&&h(e.charCodeAt(n));)n++;if(n<e.length&&e.charCodeAt(n)===46)if(n++,n<e.length&&h(e.charCodeAt(n)))for(n++;n<e.length&&h(e.charCodeAt(n));)n++;else return b=3,e.substring(c,n);let k=n;if(n<e.length&&(e.charCodeAt(n)===69||e.charCodeAt(n)===101))if(n++,(n<e.length&&e.charCodeAt(n)===43||e.charCodeAt(n)===45)&&n++,n<e.length&&h(e.charCodeAt(n))){for(n++;n<e.length&&h(e.charCodeAt(n));)n++;k=n;}else b=3;return e.substring(c,k)}o(A,"scanNumber");function w(){let c="",k=n;for(;;){if(n>=s){c+=e.substring(k,n),b=2;break}const m=e.charCodeAt(n);if(m===34){c+=e.substring(k,n),n++;break}if(m===92){if(c+=e.substring(k,n),n++,n>=s){b=2;break}switch(e.charCodeAt(n++)){case 34:c+='"';break;case 92:c+="\\";break;case 47:c+="/";break;case 98:c+="\b";break;case 102:c+="\f";break;case 110:c+=`
|
|
533
|
-
`;break;case 114:c+="\r";break;case 116:c+=" ";break;case 117:const j=_(4);j>=0?c+=String.fromCharCode(j):b=4;break;default:b=5;}k=n;continue}if(m>=0&&m<=31)if(N(m)){c+=e.substring(k,n),b=2;break}else b=6;n++;}return c}o(w,"scanString");function y(){if(l="",b=0,i=n,r=f,T=g,n>=s)return i=s,u=17;let c=e.charCodeAt(n);if(H(c)){do n++,l+=String.fromCharCode(c),c=e.charCodeAt(n);while(H(c));return u=15}if(N(c))return n++,l+=String.fromCharCode(c),c===13&&e.charCodeAt(n)===10&&(n++,l+=`
|
|
534
|
-
`),f++,g=n,u=14;switch(c){case 123:return n++,u=1;case 125:return n++,u=2;case 91:return n++,u=3;case 93:return n++,u=4;case 58:return n++,u=6;case 44:return n++,u=5;case 34:return n++,l=w(),u=10;case 47:const k=n-1;if(e.charCodeAt(n+1)===47){for(n+=2;n<s&&!N(e.charCodeAt(n));)n++;return l=e.substring(k,n),u=12}if(e.charCodeAt(n+1)===42){n+=2;const m=s-1;let F=false;for(;n<m;){const j=e.charCodeAt(n);if(j===42&&e.charCodeAt(n+1)===47){n+=2,F=true;break}n++,N(j)&&(j===13&&e.charCodeAt(n)===10&&n++,f++,g=n);}return F||(n++,b=1),l=e.substring(k,n),u=13}return l+=String.fromCharCode(c),n++,u=16;case 45:if(l+=String.fromCharCode(c),n++,n===s||!h(e.charCodeAt(n)))return u=16;case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return l+=A(),u=11;default:for(;n<s&&I(c);)n++,c=e.charCodeAt(n);if(i!==n){switch(l=e.substring(i,n),l){case "true":return u=8;case "false":return u=9;case "null":return u=7}return u=16}return l+=String.fromCharCode(c),n++,u=16}}o(y,"scanNext");function I(c){if(H(c)||N(c))return false;switch(c){case 125:case 93:case 123:case 91:case 34:case 58:case 44:case 47:return false}return true}o(I,"isUnknownContentCharacter");function L(){let c;do c=y();while(c>=12&&c<=15);return c}return o(L,"scanNextNonTrivia"),{setPosition:d,getPosition:o(()=>n,"getPosition"),scan:t?L:y,getToken:o(()=>u,"getToken"),getTokenValue:o(()=>l,"getTokenValue"),getTokenOffset:o(()=>i,"getTokenOffset"),getTokenLength:o(()=>n-i,"getTokenLength"),getTokenStartLine:o(()=>r,"getTokenStartLine"),getTokenStartCharacter:o(()=>i-T,"getTokenStartCharacter"),getTokenError:o(()=>b,"getTokenError")}}o(je,"createScanner");function H(e){return e===32||e===9}o(H,"isWhiteSpace");function N(e){return e===10||e===13}o(N,"isLineBreak");function h(e){return e>=48&&e<=57}o(h,"isDigit");var ie;((function(e){e[e.lineFeed=10]="lineFeed",e[e.carriageReturn=13]="carriageReturn",e[e.space=32]="space",e[e._0=48]="_0",e[e._1=49]="_1",e[e._2=50]="_2",e[e._3=51]="_3",e[e._4=52]="_4",e[e._5=53]="_5",e[e._6=54]="_6",e[e._7=55]="_7",e[e._8=56]="_8",e[e._9=57]="_9",e[e.a=97]="a",e[e.b=98]="b",e[e.c=99]="c",e[e.d=100]="d",e[e.e=101]="e",e[e.f=102]="f",e[e.g=103]="g",e[e.h=104]="h",e[e.i=105]="i",e[e.j=106]="j",e[e.k=107]="k",e[e.l=108]="l",e[e.m=109]="m",e[e.n=110]="n",e[e.o=111]="o",e[e.p=112]="p",e[e.q=113]="q",e[e.r=114]="r",e[e.s=115]="s",e[e.t=116]="t",e[e.u=117]="u",e[e.v=118]="v",e[e.w=119]="w",e[e.x=120]="x",e[e.y=121]="y",e[e.z=122]="z",e[e.A=65]="A",e[e.B=66]="B",e[e.C=67]="C",e[e.D=68]="D",e[e.E=69]="E",e[e.F=70]="F",e[e.G=71]="G",e[e.H=72]="H",e[e.I=73]="I",e[e.J=74]="J",e[e.K=75]="K",e[e.L=76]="L",e[e.M=77]="M",e[e.N=78]="N",e[e.O=79]="O",e[e.P=80]="P",e[e.Q=81]="Q",e[e.R=82]="R",e[e.S=83]="S",e[e.T=84]="T",e[e.U=85]="U",e[e.V=86]="V",e[e.W=87]="W",e[e.X=88]="X",e[e.Y=89]="Y",e[e.Z=90]="Z",e[e.asterisk=42]="asterisk",e[e.backslash=92]="backslash",e[e.closeBrace=125]="closeBrace",e[e.closeBracket=93]="closeBracket",e[e.colon=58]="colon",e[e.comma=44]="comma",e[e.dot=46]="dot",e[e.doubleQuote=34]="doubleQuote",e[e.minus=45]="minus",e[e.openBrace=123]="openBrace",e[e.openBracket=91]="openBracket",e[e.plus=43]="plus",e[e.slash=47]="slash",e[e.formFeed=12]="formFeed",e[e.tab=9]="tab";}))(ie||(ie={})),new Array(20).fill(0).map((e,t)=>" ".repeat(t));const x=200;new Array(x).fill(0).map((e,t)=>`
|
|
535
|
-
`+" ".repeat(t)),new Array(x).fill(0).map((e,t)=>"\r"+" ".repeat(t)),new Array(x).fill(0).map((e,t)=>`\r
|
|
536
|
-
`+" ".repeat(t)),new Array(x).fill(0).map((e,t)=>`
|
|
537
|
-
`+" ".repeat(t)),new Array(x).fill(0).map((e,t)=>"\r"+" ".repeat(t)),new Array(x).fill(0).map((e,t)=>`\r
|
|
538
|
-
`+" ".repeat(t));var M;(function(e){e.DEFAULT={allowTrailingComma:false};})(M||(M={}));function ye(e,t=[],s=M.DEFAULT){let n=null,l=[];const i=[];function u(r){Array.isArray(l)?l.push(r):n!==null&&(l[n]=r);}return o(u,"onValue"),Fe(e,{onObjectBegin:o(()=>{const r={};u(r),i.push(l),l=r,n=null;},"onObjectBegin"),onObjectProperty:o(r=>{n=r;},"onObjectProperty"),onObjectEnd:o(()=>{l=i.pop();},"onObjectEnd"),onArrayBegin:o(()=>{const r=[];u(r),i.push(l),l=r,n=null;},"onArrayBegin"),onArrayEnd:o(()=>{l=i.pop();},"onArrayEnd"),onLiteralValue:u,onError:o((r,g,T)=>{t.push({error:r,offset:g,length:T});},"onError")},s),l[0]}o(ye,"parse$1");function Fe(e,t,s=M.DEFAULT){const n=je(e,false),l=[];function i(v){return v?()=>v(n.getTokenOffset(),n.getTokenLength(),n.getTokenStartLine(),n.getTokenStartCharacter()):()=>true}o(i,"toNoArgVisit");function u(v){return v?()=>v(n.getTokenOffset(),n.getTokenLength(),n.getTokenStartLine(),n.getTokenStartCharacter(),()=>l.slice()):()=>true}o(u,"toNoArgVisitWithPath");function f(v){return v?D=>v(D,n.getTokenOffset(),n.getTokenLength(),n.getTokenStartLine(),n.getTokenStartCharacter()):()=>true}o(f,"toOneArgVisit");function r(v){return v?D=>v(D,n.getTokenOffset(),n.getTokenLength(),n.getTokenStartLine(),n.getTokenStartCharacter(),()=>l.slice()):()=>true}o(r,"toOneArgVisitWithPath");const g=u(t.onObjectBegin),T=r(t.onObjectProperty),b=i(t.onObjectEnd),_=u(t.onArrayBegin),d=i(t.onArrayEnd),A=r(t.onLiteralValue),w=f(t.onSeparator),y=i(t.onComment),I=f(t.onError),L=s&&s.disallowComments,c=s&&s.allowTrailingComma;function k(){for(;;){const v=n.scan();switch(n.getTokenError()){case 4:m(14);break;case 5:m(15);break;case 3:m(13);break;case 1:L||m(11);break;case 2:m(12);break;case 6:m(16);break}switch(v){case 12:case 13:L?m(10):y();break;case 16:m(1);break;case 15:case 14:break;default:return v}}}o(k,"scanNext");function m(v,D=[],te=[]){if(I(v),D.length+te.length>0){let P=n.getToken();for(;P!==17;){if(D.indexOf(P)!==-1){k();break}else if(te.indexOf(P)!==-1)break;P=k();}}}o(m,"handleError");function F(v){const D=n.getTokenValue();return v?A(D):(T(D),l.push(D)),k(),true}o(F,"parseString");function j(){switch(n.getToken()){case 11:const v=n.getTokenValue();let D=Number(v);isNaN(D)&&(m(2),D=0),A(D);break;case 7:A(null);break;case 8:A(true);break;case 9:A(false);break;default:return false}return k(),true}o(j,"parseLiteral");function S(){return n.getToken()!==10?(m(3,[],[2,5]),false):(F(false),n.getToken()===6?(w(":"),k(),U()||m(4,[],[2,5])):m(5,[],[2,5]),l.pop(),true)}o(S,"parseProperty");function R(){g(),k();let v=false;for(;n.getToken()!==2&&n.getToken()!==17;){if(n.getToken()===5){if(v||m(4,[],[]),w(","),k(),n.getToken()===2&&c)break}else v&&m(6,[],[]);S()||m(4,[],[2,5]),v=true;}return b(),n.getToken()!==2?m(7,[2],[]):k(),true}o(R,"parseObject");function a(){_(),k();let v=true,D=false;for(;n.getToken()!==4&&n.getToken()!==17;){if(n.getToken()===5){if(D||m(4,[],[]),w(","),k(),n.getToken()===4&&c)break}else D&&m(6,[],[]);v?(l.push(0),v=false):l[l.length-1]++,U()||m(4,[],[4,5]),D=true;}return d(),v||l.pop(),n.getToken()!==4?m(8,[4],[]):k(),true}o(a,"parseArray");function U(){switch(n.getToken()){case 3:return a();case 1:return R();case 10:return F(true);default:return j()}}return o(U,"parseValue"),k(),n.getToken()===17?s.allowEmptyContent?true:(m(4,[],[]),false):U()?(n.getToken()!==17&&m(9,[],[]),true):(m(4,[],[]),false)}o(Fe,"visit");var oe;(function(e){e[e.None=0]="None",e[e.UnexpectedEndOfComment=1]="UnexpectedEndOfComment",e[e.UnexpectedEndOfString=2]="UnexpectedEndOfString",e[e.UnexpectedEndOfNumber=3]="UnexpectedEndOfNumber",e[e.InvalidUnicode=4]="InvalidUnicode",e[e.InvalidEscapeCharacter=5]="InvalidEscapeCharacter",e[e.InvalidCharacter=6]="InvalidCharacter";})(oe||(oe={}));var ue;(function(e){e[e.OpenBraceToken=1]="OpenBraceToken",e[e.CloseBraceToken=2]="CloseBraceToken",e[e.OpenBracketToken=3]="OpenBracketToken",e[e.CloseBracketToken=4]="CloseBracketToken",e[e.CommaToken=5]="CommaToken",e[e.ColonToken=6]="ColonToken",e[e.NullKeyword=7]="NullKeyword",e[e.TrueKeyword=8]="TrueKeyword",e[e.FalseKeyword=9]="FalseKeyword",e[e.StringLiteral=10]="StringLiteral",e[e.NumericLiteral=11]="NumericLiteral",e[e.LineCommentTrivia=12]="LineCommentTrivia",e[e.BlockCommentTrivia=13]="BlockCommentTrivia",e[e.LineBreakTrivia=14]="LineBreakTrivia",e[e.Trivia=15]="Trivia",e[e.Unknown=16]="Unknown",e[e.EOF=17]="EOF";})(ue||(ue={}));const De=ye;var re;(function(e){e[e.InvalidSymbol=1]="InvalidSymbol",e[e.InvalidNumberFormat=2]="InvalidNumberFormat",e[e.PropertyNameExpected=3]="PropertyNameExpected",e[e.ValueExpected=4]="ValueExpected",e[e.ColonExpected=5]="ColonExpected",e[e.CommaExpected=6]="CommaExpected",e[e.CloseBraceExpected=7]="CloseBraceExpected",e[e.CloseBracketExpected=8]="CloseBracketExpected",e[e.EndOfFileExpected=9]="EndOfFileExpected",e[e.InvalidCommentToken=10]="InvalidCommentToken",e[e.UnexpectedEndOfComment=11]="UnexpectedEndOfComment",e[e.UnexpectedEndOfString=12]="UnexpectedEndOfString",e[e.UnexpectedEndOfNumber=13]="UnexpectedEndOfNumber",e[e.InvalidUnicode=14]="InvalidUnicode",e[e.InvalidEscapeCharacter=15]="InvalidEscapeCharacter",e[e.InvalidCharacter=16]="InvalidCharacter";})(re||(re={}));const fe=o((e,t)=>De(_e(t,e,"utf8")),"readJsonc"),X=Symbol("implicitBaseUrl"),$="${configDir}",Ee=o(()=>{const{findPnpApi:e}=ve;return e&&e(process.cwd())},"getPnpApi"),Y=o((e,t,s,n)=>{const l=`resolveFromPackageJsonPath:${e}:${t}:${s}`;if(n!=null&&n.has(l))return n.get(l);const i=fe(e,n);if(!i)return;let u=t||"tsconfig.json";if(!s&&i.exports)try{const[f]=v(i.exports,t,["require","types"]);u=f;}catch{return false}else !t&&i.tsconfig&&(u=i.tsconfig);return u=p$1.join(e,"..",u),n==null||n.set(l,u),u},"resolveFromPackageJsonPath"),Z="package.json",q="tsconfig.json",Be=o((e,t,s)=>{let n=e;if(e===".."&&(n=p$1.join(n,q)),e[0]==="."&&(n=p$1.resolve(t,n)),p$1.isAbsolute(n)){if(B(s,n)){if(W(s,n).isFile())return n}else if(!n.endsWith(".json")){const d=`${n}.json`;if(B(s,d))return d}return}const[l,...i]=e.split("/"),u=l[0]==="@"?`${l}/${i.shift()}`:l,f=i.join("/"),r=Ee();if(r){const{resolveRequest:d}=r;try{if(u===e){const A=d(p$1.join(u,Z),t);if(A){const w=Y(A,f,!1,s);if(w&&B(s,w))return w}}else {let A;try{A=d(e,t,{extensions:[".json"]});}catch{A=d(p$1.join(e,q),t);}if(A)return A}}catch{}}const g=le(p$1.resolve(t),p$1.join("node_modules",u),s);if(!g||!W(s,g).isDirectory())return;const T=p$1.join(g,Z);if(B(s,T)){const d=Y(T,f,false,s);if(d===false)return;if(d&&B(s,d)&&W(s,d).isFile())return d}const b=p$1.join(g,f),_=b.endsWith(".json");if(!_){const d=`${b}.json`;if(B(s,d))return d}if(B(s,b)){if(W(s,b).isDirectory()){const d=p$1.join(b,Z);if(B(s,d)){const w=Y(d,"",true,s);if(w&&B(s,w))return w}const A=p$1.join(b,q);if(B(s,A))return A}else if(_)return b}},"resolveExtendsPath"),K=o((e,t)=>Q(p$1.relative(e,t)),"pathRelative"),ce=["files","include","exclude"],Ie=o((e,t,s,n)=>{const l=Be(e,t,n);if(!l)throw new Error(`File '${e}' not found.`);if(s.has(l))throw new Error(`Circularity detected while resolving configuration: ${l}`);s.add(l);const i=p$1.dirname(l),u=ae(l,n,s);delete u.references;const{compilerOptions:f}=u;if(f){const{baseUrl:r}=f;r&&!r.startsWith($)&&(f.baseUrl=E(p$1.relative(t,p$1.join(i,r)))||"./");let{outDir:g}=f;g&&(g.startsWith($)||(g=p$1.relative(t,p$1.join(i,g))),f.outDir=E(g)||"./");}for(const r of ce){const g=u[r];g&&(u[r]=g.map(T=>T.startsWith($)?T:E(p$1.relative(t,p$1.join(i,T)))));}return u},"resolveExtends"),Le=["outDir","declarationDir"],ae=o((e,t,s=new Set)=>{let n;try{n=fe(e,t)||{};}catch{throw new Error(`Cannot resolve tsconfig at path: ${e}`)}if(typeof n!="object")throw new SyntaxError(`Failed to parse tsconfig at: ${e}`);const l=p$1.dirname(e);if(n.compilerOptions){const{compilerOptions:i}=n;i.paths&&!i.baseUrl&&(i[X]=l);}if(n.extends){const i=Array.isArray(n.extends)?n.extends:[n.extends];delete n.extends;for(const u of i.reverse()){const f=Ie(u,l,new Set(s),t),r={...f,...n,compilerOptions:{...f.compilerOptions,...n.compilerOptions}};f.watchOptions&&(r.watchOptions={...f.watchOptions,...n.watchOptions}),n=r;}}if(n.compilerOptions){const{compilerOptions:i}=n,u=["baseUrl","rootDir"];for(const f of u){const r=i[f];if(r&&!r.startsWith($)){const g=p$1.resolve(l,r),T=K(l,g);i[f]=T;}}for(const f of Le){let r=i[f];r&&(Array.isArray(n.exclude)||(n.exclude=[]),n.exclude.includes(r)||n.exclude.push(r),r.startsWith($)||(r=Q(r)),i[f]=r);}}else n.compilerOptions={};if(n.include?(n.include=n.include.map(E),n.files&&delete n.files):n.files&&(n.files=n.files.map(i=>i.startsWith($)?i:Q(i))),n.watchOptions){const{watchOptions:i}=n;i.excludeDirectories&&(i.excludeDirectories=i.excludeDirectories.map(u=>E(p$1.resolve(l,u))));}return n},"_parseTsconfig"),V=o((e,t)=>{if(e.startsWith($))return E(p$1.join(t,e.slice($.length)))},"interpolateConfigDir"),$e=["outDir","declarationDir","outFile","rootDir","baseUrl","tsBuildInfoFile"],Ue=o(e=>{if(e.strict){const a=["noImplicitAny","noImplicitThis","strictNullChecks","strictFunctionTypes","strictBindCallApply","strictPropertyInitialization","strictBuiltinIteratorReturn","alwaysStrict","useUnknownInCatchVariables"];for(const U of a)e[U]===void 0&&(e[U]=true);}if(e.target){let a=e.target.toLowerCase();a==="es2015"&&(a="es6"),e.target=a,a==="esnext"&&((e.module)!=null||(e.module="es6"),(e.moduleResolution)!=null||(e.moduleResolution="classic"),(e.useDefineForClassFields)!=null||(e.useDefineForClassFields=true)),(a==="es6"||a==="es2016"||a==="es2017"||a==="es2018"||a==="es2019"||a==="es2020"||a==="es2021"||a==="es2022"||a==="es2023"||a==="es2024")&&((e.module)!=null||(e.module="es6"),(e.moduleResolution)!=null||(e.moduleResolution="classic")),(a==="es2022"||a==="es2023"||a==="es2024")&&((e.useDefineForClassFields)!=null||(e.useDefineForClassFields=true));}if(e.module){let a=e.module.toLowerCase();a==="es2015"&&(a="es6"),e.module=a,(a==="es6"||a==="es2020"||a==="es2022"||a==="esnext"||a==="none"||a==="system"||a==="umd"||a==="amd")&&((e.moduleResolution)!=null||(e.moduleResolution="classic")),a==="system"&&((e.allowSyntheticDefaultImports)!=null||(e.allowSyntheticDefaultImports=true)),(a==="node16"||a==="nodenext"||a==="preserve")&&((e.esModuleInterop)!=null||(e.esModuleInterop=true),(e.allowSyntheticDefaultImports)!=null||(e.allowSyntheticDefaultImports=true)),(a==="node16"||a==="nodenext")&&((e.moduleDetection)!=null||(e.moduleDetection="force"),(e.useDefineForClassFields)!=null||(e.useDefineForClassFields=true)),a==="node16"&&((e.target)!=null||(e.target="es2022"),(e.moduleResolution)!=null||(e.moduleResolution="node16")),a==="nodenext"&&((e.target)!=null||(e.target="esnext"),(e.moduleResolution)!=null||(e.moduleResolution="nodenext")),a==="preserve"&&((e.moduleResolution)!=null||(e.moduleResolution="bundler"));}if(e.moduleResolution){let a=e.moduleResolution.toLowerCase();a==="node"&&(a="node10"),e.moduleResolution=a,(a==="node16"||a==="nodenext"||a==="bundler")&&((e.resolvePackageJsonExports)!=null||(e.resolvePackageJsonExports=true),(e.resolvePackageJsonImports)!=null||(e.resolvePackageJsonImports=true)),a==="bundler"&&((e.allowSyntheticDefaultImports)!=null||(e.allowSyntheticDefaultImports=true),(e.resolveJsonModule)!=null||(e.resolveJsonModule=true));}e.esModuleInterop&&((e.allowSyntheticDefaultImports)!=null||(e.allowSyntheticDefaultImports=true)),e.verbatimModuleSyntax&&((e.isolatedModules)!=null||(e.isolatedModules=true),(e.preserveConstEnums)!=null||(e.preserveConstEnums=true)),e.isolatedModules&&((e.preserveConstEnums)!=null||(e.preserveConstEnums=true));},"normalizeCompilerOptions"),ge=o((e,t=new Map)=>{const s=p$1.resolve(e),n=ae(s,t),l=p$1.dirname(s),{compilerOptions:i}=n;if(i){for(const f of $e){const r=i[f];if(r){const g=V(r,l);i[f]=g?K(l,g):r;}}for(const f of ["rootDirs","typeRoots"]){const r=i[f];r&&(i[f]=r.map(g=>{const T=V(g,l);return T?K(l,T):g}));}const{paths:u}=i;if(u)for(const f of Object.keys(u))u[f]=u[f].map(r=>{var g;return (g=V(r,l))!=null?g:r});Ue(i);}for(const u of ce){const f=n[u];f&&(n[u]=f.map(r=>{var g;return (g=V(r,l))!=null?g:r}));}return n},"parseTsconfig"),he=o((e=process.cwd(),t="tsconfig.json",s=new Map)=>{const n=le(E(e),t,s);if(!n)return null;const l=ge(n,s);return {path:n,config:l}},"getTsconfig"),xe=/\*/g,me=o((e,t)=>{const s=e.match(xe);if(s&&s.length>1)throw new Error(t)},"assertStarCount"),Ne=o(e=>{if(e.includes("*")){const[t,s]=e.split("*");return {prefix:t,suffix:s}}return e},"parsePattern"),Se=o(({prefix:e,suffix:t},s)=>s.startsWith(e)&&s.endsWith(t),"isPatternMatch"),Re=o((e,t,s)=>Object.entries(e).map(([n,l])=>(me(n,`Pattern '${n}' can have at most one '*' character.`),{pattern:Ne(n),substitutions:l.map(i=>{if(me(i,`Substitution '${i}' in pattern '${n}' can have at most one '*' character.`),!t&&!G.test(i))throw new Error("Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'?");return p$1.resolve(s,i)})})),"parsePaths");o(e=>{const{compilerOptions:t}=e.config;if(!t)return null;const{baseUrl:s,paths:n}=t;if(!s&&!n)return null;const l=X in t&&t[X],i=p$1.resolve(p$1.dirname(e.path),s||l||"."),u=n?Re(n,s,i):[];return f=>{if(G.test(f))return [];const r=[];for(const _ of u){if(_.pattern===f)return _.substitutions.map(E);typeof _.pattern!="string"&&r.push(_);}let g,T=-1;for(const _ of r)Se(_.pattern,f)&&_.pattern.prefix.length>T&&(T=_.pattern.prefix.length,g=_);if(!g)return s?[E(p$1.join(i,f))]:[];const b=f.slice(g.pattern.prefix.length,f.length-g.pattern.suffix.length);return g.substitutions.map(_=>E(_.replace("*",b)))}},"createPathsMatcher");const pe=o(e=>{let t="";for(let s=0;s<e.length;s+=1){const n=e[s],l=n.toUpperCase();t+=n===l?n.toLowerCase():l;}return t},"s"),We=65,Me=97,Ve=o(()=>Math.floor(Math.random()*26),"m"),Je=o(e=>Array.from({length:e},()=>String.fromCodePoint(Ve()+(Math.random()>.5?We:Me))).join(""),"S"),ze=o((e=Ae)=>{const t=process.execPath;if(e.existsSync(t))return !e.existsSync(pe(t));const s=`/${Je(10)}`;e.writeFileSync(s,"");const n=!e.existsSync(pe(s));return e.unlinkSync(s),n},"l"),{join:J}=p$1.posix,C={ts:[".ts",".tsx",".d.ts"],cts:[".cts",".d.cts"],mts:[".mts",".d.mts"]},Oe=o(e=>{const t=[...C.ts],s=[...C.cts],n=[...C.mts];return e!=null&&e.allowJs&&(t.push(".js",".jsx"),s.push(".cjs"),n.push(".mjs")),[...t,...s,...n]},"getSupportedExtensions"),Ge=o(e=>{const t=[];if(!e)return t;const{outDir:s,declarationDir:n}=e;return s&&t.push(s),n&&t.push(n),t},"getDefaultExcludeSpec"),ke=o(e=>e.replaceAll(/[.*+?^${}()|[\]\\]/g,String.raw`\$&`),"escapeForRegexp"),Qe=["node_modules","bower_components","jspm_packages"],ee=`(?!(${Qe.join("|")})(/|$))`,He=/(?:^|\/)[^.*?]+$/,we="**/*",z="[^/]",ne="[^./]",be=process.platform==="win32";o(({config:e,path:t},s=ze())=>{if("extends"in e)throw new Error("tsconfig#extends must be resolved. Use getTsconfig or parseTsconfig to resolve it.");if(!p$1.isAbsolute(t))throw new Error("The tsconfig path must be absolute");be&&(t=E(t));const n=p$1.dirname(t),{files:l,include:i,exclude:u,compilerOptions:f}=e,r=l==null?void 0:l.map(w=>J(n,w)),g=Oe(f),T=s?"":"i",_=(u||Ge(f)).map(w=>{const y=J(n,w),I=ke(y).replaceAll(String.raw`\*\*/`,"(.+/)?").replaceAll(String.raw`\*`,`${z}*`).replaceAll(String.raw`\?`,z);return new RegExp(`^${I}($|/)`,T)}),d=l||i?i:[we],A=d?d.map(w=>{let y=J(n,w);He.test(y)&&(y=J(y,we));const I=ke(y).replaceAll(String.raw`/\*\*`,`(/${ee}${ne}${z}*)*?`).replaceAll(/(\/)?\\\*/g,(L,c)=>{const k=`(${ne}|(\\.(?!min\\.js$))?)*`;return c?`/${ee}${ne}${k}`:k}).replaceAll(/(\/)?\\\?/g,(L,c)=>{const k=z;return c?`/${ee}${k}`:k});return new RegExp(`^${I}$`,T)}):void 0;return w=>{if(!p$1.isAbsolute(w))throw new Error("filePath must be absolute");if(be&&(w=E(w)),r!=null&&r.includes(w))return e;if(!(!g.some(y=>w.endsWith(y))||_.some(y=>y.test(w)))&&A&&A.some(y=>y.test(w)))return e}},"createFilesMatcher");
|
|
539
|
-
|
|
540
|
-
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
|
|
541
|
-
const newLineRegExp = /\r?\n/;
|
|
542
|
-
const errCodeRegExp = /error TS(?<errCode>\d+)/;
|
|
543
|
-
async function makeTscErrorInfo(errInfo) {
|
|
544
|
-
const [errFilePathPos = "", ...errMsgRawArr] = errInfo.split(":");
|
|
545
|
-
if (!errFilePathPos || errMsgRawArr.length === 0 || errMsgRawArr.join("").length === 0) {
|
|
546
|
-
return ["unknown filepath", null];
|
|
547
|
-
}
|
|
548
|
-
const errMsgRaw = errMsgRawArr.join("").trim();
|
|
549
|
-
const [errFilePath, errPos] = errFilePathPos.slice(0, -1).split("(");
|
|
550
|
-
if (!errFilePath || !errPos) {
|
|
551
|
-
return ["unknown filepath", null];
|
|
552
|
-
}
|
|
553
|
-
const [errLine, errCol] = errPos.split(",");
|
|
554
|
-
if (!errLine || !errCol) {
|
|
555
|
-
return [errFilePath, null];
|
|
556
|
-
}
|
|
557
|
-
const execArr = errCodeRegExp.exec(errMsgRaw);
|
|
558
|
-
if (!execArr) {
|
|
559
|
-
return [errFilePath, null];
|
|
560
|
-
}
|
|
561
|
-
const errCodeStr = execArr.groups?.errCode ?? "";
|
|
562
|
-
if (!errCodeStr) {
|
|
563
|
-
return [errFilePath, null];
|
|
564
|
-
}
|
|
565
|
-
const line = Number(errLine);
|
|
566
|
-
const col = Number(errCol);
|
|
567
|
-
const errCode = Number(errCodeStr);
|
|
568
|
-
return [errFilePath, {
|
|
569
|
-
filePath: errFilePath,
|
|
570
|
-
errCode,
|
|
571
|
-
line,
|
|
572
|
-
column: col,
|
|
573
|
-
errMsg: errMsgRaw.slice(`error TS${errCode} `.length)
|
|
574
|
-
}];
|
|
575
|
-
}
|
|
576
|
-
async function getTsconfig(root, config) {
|
|
577
|
-
const configName = config.tsconfig ? basename(config.tsconfig) : undefined;
|
|
578
|
-
const configSearchPath = config.tsconfig ? dirname(resolve(root, config.tsconfig)) : root;
|
|
579
|
-
const tsconfig = he(configSearchPath, configName);
|
|
580
|
-
if (!tsconfig) {
|
|
581
|
-
throw new Error("no tsconfig.json found");
|
|
582
|
-
}
|
|
583
|
-
const tsconfigName = basename(tsconfig.path, ".json");
|
|
584
|
-
const tempTsConfigName = `${tsconfigName}.vitest-temp.json`;
|
|
585
|
-
const tempTsbuildinfoName = `${tsconfigName}.tmp.tsbuildinfo`;
|
|
586
|
-
const tempConfigPath = join(dirname(tsconfig.path), tempTsConfigName);
|
|
587
|
-
try {
|
|
588
|
-
const tmpTsConfig = { ...tsconfig.config };
|
|
589
|
-
tmpTsConfig.compilerOptions = tmpTsConfig.compilerOptions || {};
|
|
590
|
-
tmpTsConfig.compilerOptions.emitDeclarationOnly = false;
|
|
591
|
-
tmpTsConfig.compilerOptions.incremental = true;
|
|
592
|
-
tmpTsConfig.compilerOptions.tsBuildInfoFile = join(process.versions.pnp ? join(nodeos__default.tmpdir(), "vitest") : __dirname, tempTsbuildinfoName);
|
|
593
|
-
const tsconfigFinalContent = JSON.stringify(tmpTsConfig, null, 2);
|
|
594
|
-
await writeFile(tempConfigPath, tsconfigFinalContent);
|
|
595
|
-
return {
|
|
596
|
-
path: tempConfigPath,
|
|
597
|
-
config: tmpTsConfig
|
|
598
|
-
};
|
|
599
|
-
} catch (err) {
|
|
600
|
-
throw new Error(`failed to write ${tempTsConfigName}`, { cause: err });
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
async function getRawErrsMapFromTsCompile(tscErrorStdout) {
|
|
604
|
-
const rawErrsMap = new Map();
|
|
605
|
-
const infos = await Promise.all(tscErrorStdout.split(newLineRegExp).reduce((prev, next) => {
|
|
606
|
-
if (!next) {
|
|
607
|
-
return prev;
|
|
608
|
-
} else if (!next.startsWith(" ")) {
|
|
609
|
-
prev.push(next);
|
|
610
|
-
} else {
|
|
611
|
-
prev[prev.length - 1] += `\n${next}`;
|
|
612
|
-
}
|
|
613
|
-
return prev;
|
|
614
|
-
}, []).map((errInfoLine) => makeTscErrorInfo(errInfoLine)));
|
|
615
|
-
infos.forEach(([errFilePath, errInfo]) => {
|
|
616
|
-
if (!errInfo) {
|
|
617
|
-
return;
|
|
618
|
-
}
|
|
619
|
-
if (!rawErrsMap.has(errFilePath)) {
|
|
620
|
-
rawErrsMap.set(errFilePath, [errInfo]);
|
|
621
|
-
} else {
|
|
622
|
-
rawErrsMap.get(errFilePath)?.push(errInfo);
|
|
623
|
-
}
|
|
624
|
-
});
|
|
625
|
-
return rawErrsMap;
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
function createIndexMap(source) {
|
|
629
|
-
const map = new Map();
|
|
630
|
-
let index = 0;
|
|
631
|
-
let line = 1;
|
|
632
|
-
let column = 1;
|
|
633
|
-
for (const char of source) {
|
|
634
|
-
map.set(`${line}:${column}`, index++);
|
|
635
|
-
if (char === "\n" || char === "\r\n") {
|
|
636
|
-
line++;
|
|
637
|
-
column = 0;
|
|
638
|
-
} else {
|
|
639
|
-
column++;
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
return map;
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
class TypeCheckError extends Error {
|
|
646
|
-
name = "TypeCheckError";
|
|
647
|
-
constructor(message, stacks) {
|
|
648
|
-
super(message);
|
|
649
|
-
this.message = message;
|
|
650
|
-
this.stacks = stacks;
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
class Typechecker {
|
|
654
|
-
_onParseStart;
|
|
655
|
-
_onParseEnd;
|
|
656
|
-
_onWatcherRerun;
|
|
657
|
-
_result = {
|
|
658
|
-
files: [],
|
|
659
|
-
sourceErrors: [],
|
|
660
|
-
time: 0
|
|
661
|
-
};
|
|
662
|
-
_startTime = 0;
|
|
663
|
-
_output = "";
|
|
664
|
-
_tests = {};
|
|
665
|
-
tempConfigPath;
|
|
666
|
-
allowJs;
|
|
667
|
-
process;
|
|
668
|
-
files = [];
|
|
669
|
-
constructor(ctx) {
|
|
670
|
-
this.ctx = ctx;
|
|
671
|
-
}
|
|
672
|
-
setFiles(files) {
|
|
673
|
-
this.files = files;
|
|
674
|
-
}
|
|
675
|
-
onParseStart(fn) {
|
|
676
|
-
this._onParseStart = fn;
|
|
677
|
-
}
|
|
678
|
-
onParseEnd(fn) {
|
|
679
|
-
this._onParseEnd = fn;
|
|
680
|
-
}
|
|
681
|
-
onWatcherRerun(fn) {
|
|
682
|
-
this._onWatcherRerun = fn;
|
|
683
|
-
}
|
|
684
|
-
async collectFileTests(filepath) {
|
|
685
|
-
return collectTests(this.ctx, filepath);
|
|
686
|
-
}
|
|
687
|
-
getFiles() {
|
|
688
|
-
return this.files.filter((filename) => {
|
|
689
|
-
const extension = extname(filename);
|
|
690
|
-
return extension !== ".js" || this.allowJs;
|
|
691
|
-
});
|
|
692
|
-
}
|
|
693
|
-
async collectTests() {
|
|
694
|
-
const tests = (await Promise.all(this.getFiles().map((filepath) => this.collectFileTests(filepath)))).reduce((acc, data) => {
|
|
695
|
-
if (!data) {
|
|
696
|
-
return acc;
|
|
697
|
-
}
|
|
698
|
-
acc[data.filepath] = data;
|
|
699
|
-
return acc;
|
|
700
|
-
}, {});
|
|
701
|
-
this._tests = tests;
|
|
702
|
-
return tests;
|
|
703
|
-
}
|
|
704
|
-
markPassed(file) {
|
|
705
|
-
if (!file.result?.state) {
|
|
706
|
-
file.result = { state: "pass" };
|
|
707
|
-
}
|
|
708
|
-
const markTasks = (tasks) => {
|
|
709
|
-
for (const task of tasks) {
|
|
710
|
-
if ("tasks" in task) {
|
|
711
|
-
markTasks(task.tasks);
|
|
712
|
-
}
|
|
713
|
-
if (!task.result?.state && (task.mode === "run" || task.mode === "queued")) {
|
|
714
|
-
task.result = { state: "pass" };
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
};
|
|
718
|
-
markTasks(file.tasks);
|
|
719
|
-
}
|
|
720
|
-
async prepareResults(output) {
|
|
721
|
-
const typeErrors = await this.parseTscLikeOutput(output);
|
|
722
|
-
const testFiles = new Set(this.getFiles());
|
|
723
|
-
if (!this._tests) {
|
|
724
|
-
this._tests = await this.collectTests();
|
|
725
|
-
}
|
|
726
|
-
const sourceErrors = [];
|
|
727
|
-
const files = [];
|
|
728
|
-
testFiles.forEach((path) => {
|
|
729
|
-
const { file, definitions, map, parsed } = this._tests[path];
|
|
730
|
-
const errors = typeErrors.get(path);
|
|
731
|
-
files.push(file);
|
|
732
|
-
if (!errors) {
|
|
733
|
-
this.markPassed(file);
|
|
734
|
-
return;
|
|
735
|
-
}
|
|
736
|
-
const sortedDefinitions = [...definitions.sort((a, b) => b.start - a.start)];
|
|
737
|
-
const traceMap = map && new TraceMap(map);
|
|
738
|
-
const indexMap = createIndexMap(parsed);
|
|
739
|
-
const markState = (task, state) => {
|
|
740
|
-
task.result = { state: task.mode === "run" || task.mode === "only" ? state : task.mode };
|
|
741
|
-
if (task.suite) {
|
|
742
|
-
markState(task.suite, state);
|
|
743
|
-
} else if (task.file && task !== task.file) {
|
|
744
|
-
markState(task.file, state);
|
|
745
|
-
}
|
|
746
|
-
};
|
|
747
|
-
errors.forEach(({ error, originalError }) => {
|
|
748
|
-
const processedPos = traceMap ? findGeneratedPosition(traceMap, {
|
|
749
|
-
line: originalError.line,
|
|
750
|
-
column: originalError.column,
|
|
751
|
-
source: basename(path)
|
|
752
|
-
}) : originalError;
|
|
753
|
-
const line = processedPos.line ?? originalError.line;
|
|
754
|
-
const column = processedPos.column ?? originalError.column;
|
|
755
|
-
const index = indexMap.get(`${line}:${column}`);
|
|
756
|
-
const definition = index != null && sortedDefinitions.find((def) => def.start <= index && def.end >= index);
|
|
757
|
-
const suite = definition ? definition.task : file;
|
|
758
|
-
const state = suite.mode === "run" || suite.mode === "only" ? "fail" : suite.mode;
|
|
759
|
-
const errors = suite.result?.errors || [];
|
|
760
|
-
suite.result = {
|
|
761
|
-
state,
|
|
762
|
-
errors
|
|
763
|
-
};
|
|
764
|
-
errors.push(error);
|
|
765
|
-
if (state === "fail") {
|
|
766
|
-
if (suite.suite) {
|
|
767
|
-
markState(suite.suite, "fail");
|
|
768
|
-
} else if (suite.file && suite !== suite.file) {
|
|
769
|
-
markState(suite.file, "fail");
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
});
|
|
773
|
-
this.markPassed(file);
|
|
774
|
-
});
|
|
775
|
-
typeErrors.forEach((errors, path) => {
|
|
776
|
-
if (!testFiles.has(path)) {
|
|
777
|
-
sourceErrors.push(...errors.map(({ error }) => error));
|
|
778
|
-
}
|
|
779
|
-
});
|
|
780
|
-
return {
|
|
781
|
-
files,
|
|
782
|
-
sourceErrors,
|
|
783
|
-
time: performance.now() - this._startTime
|
|
784
|
-
};
|
|
785
|
-
}
|
|
786
|
-
async parseTscLikeOutput(output) {
|
|
787
|
-
const errorsMap = await getRawErrsMapFromTsCompile(output);
|
|
788
|
-
const typesErrors = new Map();
|
|
789
|
-
errorsMap.forEach((errors, path) => {
|
|
790
|
-
const filepath = resolve(this.ctx.config.root, path);
|
|
791
|
-
const suiteErrors = errors.map((info) => {
|
|
792
|
-
const limit = Error.stackTraceLimit;
|
|
793
|
-
Error.stackTraceLimit = 0;
|
|
794
|
-
const errMsg = info.errMsg.replace(/\r?\n\s*(Type .* has no call signatures)/g, " $1");
|
|
795
|
-
const error = new TypeCheckError(errMsg, [{
|
|
796
|
-
file: filepath,
|
|
797
|
-
line: info.line,
|
|
798
|
-
column: info.column,
|
|
799
|
-
method: ""
|
|
800
|
-
}]);
|
|
801
|
-
Error.stackTraceLimit = limit;
|
|
802
|
-
return {
|
|
803
|
-
originalError: info,
|
|
804
|
-
error: {
|
|
805
|
-
name: error.name,
|
|
806
|
-
nameStr: String(error.name),
|
|
807
|
-
message: errMsg,
|
|
808
|
-
stacks: error.stacks,
|
|
809
|
-
stack: "",
|
|
810
|
-
stackStr: ""
|
|
811
|
-
}
|
|
812
|
-
};
|
|
813
|
-
});
|
|
814
|
-
typesErrors.set(filepath, suiteErrors);
|
|
815
|
-
});
|
|
816
|
-
return typesErrors;
|
|
817
|
-
}
|
|
818
|
-
async clear() {
|
|
819
|
-
if (this.tempConfigPath) {
|
|
820
|
-
await rm(this.tempConfigPath, { force: true });
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
async stop() {
|
|
824
|
-
await this.clear();
|
|
825
|
-
this.process?.kill();
|
|
826
|
-
this.process = undefined;
|
|
827
|
-
}
|
|
828
|
-
async ensurePackageInstalled(ctx, checker) {
|
|
829
|
-
if (checker !== "tsc" && checker !== "vue-tsc") {
|
|
830
|
-
return;
|
|
831
|
-
}
|
|
832
|
-
const packageName = checker === "tsc" ? "typescript" : "vue-tsc";
|
|
833
|
-
await ctx.packageInstaller.ensureInstalled(packageName, ctx.config.root);
|
|
834
|
-
}
|
|
835
|
-
async prepare() {
|
|
836
|
-
const { root, typecheck } = this.ctx.config;
|
|
837
|
-
const { config, path } = await getTsconfig(root, typecheck);
|
|
838
|
-
this.tempConfigPath = path;
|
|
839
|
-
this.allowJs = typecheck.allowJs || config.allowJs || false;
|
|
840
|
-
}
|
|
841
|
-
getExitCode() {
|
|
842
|
-
return this.process?.exitCode != null && this.process.exitCode;
|
|
843
|
-
}
|
|
844
|
-
getOutput() {
|
|
845
|
-
return this._output;
|
|
846
|
-
}
|
|
847
|
-
async start() {
|
|
848
|
-
if (this.process) {
|
|
849
|
-
return;
|
|
850
|
-
}
|
|
851
|
-
if (!this.tempConfigPath) {
|
|
852
|
-
throw new Error("tsconfig was not initialized");
|
|
853
|
-
}
|
|
854
|
-
const { root, watch, typecheck } = this.ctx.config;
|
|
855
|
-
const args = [
|
|
856
|
-
"--noEmit",
|
|
857
|
-
"--pretty",
|
|
858
|
-
"false",
|
|
859
|
-
"-p",
|
|
860
|
-
this.tempConfigPath
|
|
861
|
-
];
|
|
862
|
-
if (watch) {
|
|
863
|
-
args.push("--watch");
|
|
864
|
-
}
|
|
865
|
-
if (typecheck.allowJs) {
|
|
866
|
-
args.push("--allowJs", "--checkJs");
|
|
867
|
-
}
|
|
868
|
-
this._output = "";
|
|
869
|
-
this._startTime = performance.now();
|
|
870
|
-
const child = x$1(typecheck.checker, args, {
|
|
871
|
-
nodeOptions: {
|
|
872
|
-
cwd: root,
|
|
873
|
-
stdio: "pipe"
|
|
874
|
-
},
|
|
875
|
-
throwOnError: false
|
|
876
|
-
});
|
|
877
|
-
this.process = child.process;
|
|
878
|
-
await this._onParseStart?.();
|
|
879
|
-
let rerunTriggered = false;
|
|
880
|
-
child.process?.stdout?.on("data", (chunk) => {
|
|
881
|
-
this._output += chunk;
|
|
882
|
-
if (!watch) {
|
|
883
|
-
return;
|
|
884
|
-
}
|
|
885
|
-
if (this._output.includes("File change detected") && !rerunTriggered) {
|
|
886
|
-
this._onWatcherRerun?.();
|
|
887
|
-
this._startTime = performance.now();
|
|
888
|
-
this._result.sourceErrors = [];
|
|
889
|
-
this._result.files = [];
|
|
890
|
-
this._tests = null;
|
|
891
|
-
rerunTriggered = true;
|
|
892
|
-
}
|
|
893
|
-
if (/Found \w+ errors*. Watching for/.test(this._output)) {
|
|
894
|
-
rerunTriggered = false;
|
|
895
|
-
this.prepareResults(this._output).then((result) => {
|
|
896
|
-
this._result = result;
|
|
897
|
-
this._onParseEnd?.(result);
|
|
898
|
-
});
|
|
899
|
-
this._output = "";
|
|
900
|
-
}
|
|
901
|
-
});
|
|
902
|
-
if (!watch) {
|
|
903
|
-
await child;
|
|
904
|
-
this._result = await this.prepareResults(this._output);
|
|
905
|
-
await this._onParseEnd?.(this._result);
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
getResult() {
|
|
909
|
-
return this._result;
|
|
910
|
-
}
|
|
911
|
-
getTestFiles() {
|
|
912
|
-
return Object.values(this._tests || {}).map((i) => i.file);
|
|
913
|
-
}
|
|
914
|
-
getTestPacksAndEvents() {
|
|
915
|
-
const packs = [];
|
|
916
|
-
const events = [];
|
|
917
|
-
for (const { file } of Object.values(this._tests || {})) {
|
|
918
|
-
const result = convertTasksToEvents(file);
|
|
919
|
-
packs.push(...result.packs);
|
|
920
|
-
events.push(...result.events);
|
|
921
|
-
}
|
|
922
|
-
return {
|
|
923
|
-
packs,
|
|
924
|
-
events
|
|
925
|
-
};
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
function findGeneratedPosition(traceMap, { line, column, source }) {
|
|
929
|
-
const found = generatedPositionFor(traceMap, {
|
|
930
|
-
line,
|
|
931
|
-
column,
|
|
932
|
-
source
|
|
933
|
-
});
|
|
934
|
-
if (found.line !== null) {
|
|
935
|
-
return found;
|
|
936
|
-
}
|
|
937
|
-
const mappings = [];
|
|
938
|
-
eachMapping(traceMap, (m) => {
|
|
939
|
-
if (m.source === source && m.originalLine !== null && m.originalColumn !== null && (line === m.originalLine ? column < m.originalColumn : line < m.originalLine)) {
|
|
940
|
-
mappings.push(m);
|
|
941
|
-
}
|
|
942
|
-
});
|
|
943
|
-
const next = mappings.sort((a, b) => a.originalLine === b.originalLine ? a.originalColumn - b.originalColumn : a.originalLine - b.originalLine).at(0);
|
|
944
|
-
if (next) {
|
|
945
|
-
return {
|
|
946
|
-
line: next.generatedLine,
|
|
947
|
-
column: next.generatedColumn
|
|
948
|
-
};
|
|
949
|
-
}
|
|
950
|
-
return {
|
|
951
|
-
line: null,
|
|
952
|
-
column: null
|
|
953
|
-
};
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
export { TypeCheckError as T, Typechecker as a, convertTasksToEvents as c, getOutputFile as g, hasFailedSnapshot as h, wrapSerializableConfig as w };
|