vitest 3.0.9 → 3.1.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/dist/browser.js +4 -4
- package/dist/chunks/base.CylSMlTD.js +41 -0
- package/dist/chunks/benchmark.BKUatJGy.js +39 -0
- package/dist/chunks/cac.JtTXbKz0.js +1525 -0
- package/dist/chunks/{cli-api.Ckwz_xSb.js → cli-api.BTtPTYMs.js} +4638 -5072
- package/dist/chunks/console.D6t261w0.js +173 -0
- package/dist/chunks/constants.BZZyIeIE.js +43 -0
- package/dist/chunks/coverage.0iPg4Wrz.js +33 -0
- package/dist/chunks/{coverage.gV8doR2Y.js → coverage.C2ohxaN0.js} +2216 -2479
- package/dist/chunks/creator.BEXek7yQ.js +640 -0
- package/dist/chunks/date.CDOsz-HY.js +53 -0
- package/dist/chunks/defaults.DmfNPoe5.js +114 -0
- package/dist/chunks/{env.D4Lgay0q.js → env.Dq0hM4Xv.js} +1 -1
- package/dist/chunks/execute.DZKwfrTs.js +791 -0
- package/dist/chunks/git.DXfdBEfR.js +74 -0
- package/dist/chunks/{globals.BEpDe-k3.js → globals.DCbUWjip.js} +10 -10
- package/dist/chunks/{index.D7Ny8f_s.js → index.BDobFbcz.js} +6 -7
- package/dist/chunks/index.DFXFpH3w.js +607 -0
- package/dist/chunks/index.VfYQ6MXY.js +104 -0
- package/dist/chunks/index.ZIOEXBQB.js +2382 -0
- package/dist/chunks/inspector.DbDkSkFn.js +54 -0
- package/dist/chunks/node.IqGoMrm4.js +15 -0
- package/dist/chunks/{reporters.d.CqBhtcTq.d.ts → reporters.d.5g6jXhoW.d.ts} +25 -8
- package/dist/chunks/rpc.DGgL5dw7.js +92 -0
- package/dist/chunks/run-once.I7PpBOk1.js +47 -0
- package/dist/chunks/runBaseTests.CqmKSG99.js +134 -0
- package/dist/chunks/setup-common.DEGDGBiA.js +88 -0
- package/dist/chunks/{typechecker.BlF3eHsb.js → typechecker.C2IpOhid.js} +620 -622
- package/dist/chunks/utils.BfxieIyZ.js +66 -0
- package/dist/chunks/utils.CtocqOoE.js +72 -0
- package/dist/chunks/utils.OLmtDstN.js +194 -0
- package/dist/chunks/{vi.nSCvwQ7l.js → vi.B-PuvDzu.js} +878 -1019
- package/dist/chunks/vite.d.Dh1jE-_V.d.ts +23 -0
- package/dist/chunks/vm.BW5voG-u.js +789 -0
- package/dist/cli.js +2 -2
- package/dist/config.cjs +97 -103
- package/dist/config.d.ts +3 -3
- package/dist/config.js +6 -6
- package/dist/coverage.d.ts +1 -1
- package/dist/coverage.js +6 -6
- package/dist/environments.js +1 -1
- package/dist/execute.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -6
- package/dist/node.d.ts +3 -3
- package/dist/node.js +36 -45
- package/dist/path.js +1 -4
- package/dist/reporters.d.ts +1 -1
- package/dist/reporters.js +4 -4
- package/dist/runners.js +231 -267
- package/dist/snapshot.js +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker.js +98 -114
- package/dist/workers/forks.js +22 -22
- package/dist/workers/runVmTests.js +61 -66
- package/dist/workers/threads.js +13 -13
- package/dist/workers/vmForks.js +24 -24
- package/dist/workers/vmThreads.js +15 -15
- package/dist/workers.js +10 -10
- package/package.json +11 -11
- package/dist/chunks/base.DV59CbtV.js +0 -45
- package/dist/chunks/benchmark.DL72EVN-.js +0 -40
- package/dist/chunks/cac.CeVHgzve.js +0 -1659
- package/dist/chunks/console.CN7AiMGV.js +0 -179
- package/dist/chunks/constants.DTYd6dNH.js +0 -46
- package/dist/chunks/coverage.A3sS5-Wm.js +0 -40
- package/dist/chunks/creator.BsBnpTzI.js +0 -670
- package/dist/chunks/date.W2xKR2qe.js +0 -53
- package/dist/chunks/defaults.C2Ndd9wx.js +0 -119
- package/dist/chunks/execute.eDH0aFFd.js +0 -839
- package/dist/chunks/git.B5SDxu-n.js +0 -69
- package/dist/chunks/index.B8tIoLPT.js +0 -2526
- package/dist/chunks/index.K90BXFOx.js +0 -658
- package/dist/chunks/index.uXkkC4xl.js +0 -111
- package/dist/chunks/inspector.DKLceBVD.js +0 -54
- package/dist/chunks/node.AKq966Jp.js +0 -15
- package/dist/chunks/rpc.TVf73xOu.js +0 -102
- package/dist/chunks/run-once.2ogXb3JV.js +0 -28
- package/dist/chunks/runBaseTests.BVrL_ow3.js +0 -142
- package/dist/chunks/setup-common.CPvtqi8q.js +0 -96
- package/dist/chunks/utils.C8RiOc4B.js +0 -77
- package/dist/chunks/utils.Cn0zI1t3.js +0 -68
- package/dist/chunks/utils.bLM2atbD.js +0 -198
- package/dist/chunks/vite.d.BUZTGxQ3.d.ts +0 -11
- package/dist/chunks/vm.jEFQDlX_.js +0 -852
|
@@ -14,60 +14,75 @@ import ve from 'node:module';
|
|
|
14
14
|
import require$$0 from 'fs';
|
|
15
15
|
|
|
16
16
|
function hasFailedSnapshot(suite) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
);
|
|
21
|
-
});
|
|
17
|
+
return getTests(suite).some((s) => {
|
|
18
|
+
return s.result?.errors?.some((e) => typeof e?.message === "string" && e.message.match(/Snapshot .* mismatched/));
|
|
19
|
+
});
|
|
22
20
|
}
|
|
23
21
|
function convertTasksToEvents(file, onTask) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
+
packs.push([
|
|
38
|
+
task.id,
|
|
39
|
+
task.result,
|
|
40
|
+
task.meta
|
|
41
|
+
]);
|
|
42
|
+
if (task.mode !== "skip" && task.mode !== "todo") {
|
|
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
|
+
};
|
|
45
54
|
}
|
|
46
55
|
|
|
47
56
|
const REGEXP_WRAP_PREFIX = "$$vitest:";
|
|
48
57
|
function getOutputFile(config, reporter) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
if (!config?.outputFile) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (typeof config.outputFile === "string") {
|
|
62
|
+
return config.outputFile;
|
|
63
|
+
}
|
|
64
|
+
return config.outputFile[reporter];
|
|
56
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Prepares `SerializedConfig` for serialization, e.g. `node:v8.serialize`
|
|
68
|
+
*/
|
|
57
69
|
function wrapSerializableConfig(config) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
+
};
|
|
71
86
|
}
|
|
72
87
|
|
|
73
88
|
// AST walker module for ESTree compatible trees
|
|
@@ -347,170 +362,169 @@ base.MethodDefinition = base.PropertyDefinition = base.Property = function (node
|
|
|
347
362
|
};
|
|
348
363
|
|
|
349
364
|
async function collectTests(ctx, filepath) {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
};
|
|
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
|
+
};
|
|
514
528
|
}
|
|
515
529
|
|
|
516
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};
|
|
@@ -527,432 +541,416 @@ const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
|
|
|
527
541
|
const newLineRegExp = /\r?\n/;
|
|
528
542
|
const errCodeRegExp = /error TS(?<errCode>\d+)/;
|
|
529
543
|
async function makeTscErrorInfo(errInfo) {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
errMsg: errMsgRaw.slice(`error TS${errCode} `.length)
|
|
562
|
-
}
|
|
563
|
-
];
|
|
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
|
+
}];
|
|
564
575
|
}
|
|
565
576
|
async function getTsconfig(root, config) {
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
} catch (err) {
|
|
592
|
-
throw new Error(`failed to write ${tempTsConfigName}`, { cause: err });
|
|
593
|
-
}
|
|
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
|
+
}
|
|
594
602
|
}
|
|
595
603
|
async function getRawErrsMapFromTsCompile(tscErrorStdout) {
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
}
|
|
619
|
-
});
|
|
620
|
-
return rawErrsMap;
|
|
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;
|
|
621
626
|
}
|
|
622
627
|
|
|
623
628
|
function createIndexMap(source) {
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
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;
|
|
638
643
|
}
|
|
639
644
|
|
|
640
645
|
class TypeCheckError extends Error {
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
646
|
+
name = "TypeCheckError";
|
|
647
|
+
constructor(message, stacks) {
|
|
648
|
+
super(message);
|
|
649
|
+
this.message = message;
|
|
650
|
+
this.stacks = stacks;
|
|
651
|
+
}
|
|
647
652
|
}
|
|
648
653
|
class Typechecker {
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
const events = [];
|
|
923
|
-
for (const { file } of Object.values(this._tests || {})) {
|
|
924
|
-
const result = convertTasksToEvents(file);
|
|
925
|
-
packs.push(...result.packs);
|
|
926
|
-
events.push(...result.events);
|
|
927
|
-
}
|
|
928
|
-
return { packs, events };
|
|
929
|
-
}
|
|
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
|
+
}
|
|
930
927
|
}
|
|
931
928
|
function findGeneratedPosition(traceMap, { line, column, source }) {
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
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
|
+
};
|
|
956
954
|
}
|
|
957
955
|
|
|
958
956
|
export { TypeCheckError as T, Typechecker as a, convertTasksToEvents as c, getOutputFile as g, hasFailedSnapshot as h, wrapSerializableConfig as w };
|