vitest 2.0.0-beta.1 → 2.0.0-beta.11
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 +1 -1
- package/dist/browser.d.ts +22 -2
- package/dist/browser.js +5 -3
- package/dist/chunks/{integrations-globals.B5Jl0grA.js → integrations-globals.CC2ed6Py.js} +9 -9
- package/dist/chunks/{node-git.CCI8evVZ.js → node-git.ZtkbKc8u.js} +14 -15
- package/dist/chunks/{runtime-console.CUES-L8X.js → runtime-console.Ckl0vEQr.js} +76 -31
- package/dist/chunks/{runtime-runBaseTests._dXkRAZc.js → runtime-runBaseTests.BXW_BJeO.js} +40 -32
- package/dist/cli.js +3 -3
- package/dist/config.cjs +43 -20
- package/dist/config.d.ts +2 -2
- package/dist/config.js +43 -21
- package/dist/coverage.d.ts +4 -4
- package/dist/coverage.js +125 -37
- package/dist/environments.d.ts +1 -1
- package/dist/environments.js +1 -1
- package/dist/execute.d.ts +2 -2
- package/dist/execute.js +2 -2
- package/dist/index.d.ts +20 -30
- package/dist/index.js +9 -9
- package/dist/node.d.ts +22 -9
- package/dist/node.js +25 -15
- package/dist/path.js +4 -1
- package/dist/{reporters-MGvT5U9f.d.ts → reporters-fiIq_dT9.d.ts} +310 -148
- package/dist/reporters.d.ts +1 -1
- package/dist/reporters.js +8 -8
- package/dist/runners.d.ts +4 -2
- package/dist/runners.js +103 -57
- package/dist/{suite-8WAe-urM.d.ts → suite-D4aoU9rI.d.ts} +1 -1
- package/dist/suite.d.ts +2 -2
- package/dist/suite.js +2 -2
- package/dist/utils.d.ts +1 -5
- package/dist/utils.js +1 -6
- package/dist/vendor/{base.VFkIJ66g.js → base.C2DbLEfT.js} +4 -3
- package/dist/vendor/{base._gnK9Slw.js → base.CTYV4Gnz.js} +24 -17
- package/dist/vendor/{benchmark.BNLebNi5.js → benchmark.CMp8QfyL.js} +13 -14
- package/dist/vendor/{cac.DzKZaJu2.js → cac.BcJW7n2j.js} +127 -51
- package/dist/vendor/{cli-api.DTeni0Qq.js → cli-api.C8t8m4__.js} +2771 -1711
- package/dist/vendor/{constants.5SOfHUj0.js → constants.BWsVtsAj.js} +6 -22
- package/dist/vendor/{coverage.ChSqD-qS.js → coverage.BhYSDdTT.js} +27 -11
- package/dist/vendor/{date.BKM1wewY.js → date.W2xKR2qe.js} +5 -3
- package/dist/vendor/{execute.CLLNVNnK.js → execute.T3gg2ZK6.js} +177 -63
- package/dist/vendor/{index.BfoZyXD1.js → index.-dbR4KUi.js} +17 -9
- package/dist/vendor/{index.CRxYS9H3.js → index.BC5zhX9y.js} +1201 -491
- package/dist/vendor/{index.DP-km6lF.js → index.BMmMjLIQ.js} +64 -51
- package/dist/vendor/{index._7XLd8Kd.js → index.C9Thslzw.js} +2 -1
- package/dist/vendor/{index.CmILuxzC.js → index.CQJ2m700.js} +3 -3
- package/dist/vendor/{index.DeR1hhfY.js → index.D4nqnQWz.js} +71 -74
- package/dist/vendor/{rpc.DRDE9Pu1.js → rpc.BGx7q_k2.js} +30 -19
- package/dist/vendor/{run-once.DLomgGUH.js → run-once.Db8Hgq9X.js} +2 -1
- package/dist/vendor/{setup-common.XeoZAW8t.js → setup-common.uqZOEWuR.js} +30 -15
- package/dist/vendor/spy.Cf_4R5Oe.js +22 -0
- package/dist/vendor/{tasks.WC7M-K-v.js → tasks.DhVtQBtW.js} +3 -1
- package/dist/vendor/{utils.D5gGkwyH.js → utils.DSO2UK15.js} +41 -26
- package/dist/vendor/{utils.CUjzkRH7.js → utils.DkxLWvS1.js} +12 -5
- package/dist/vendor/{vi.ClD3hi7L.js → vi.BPjl8cAZ.js} +350 -166
- package/dist/vendor/{vm.Bi3bljci.js → vm.CycSoHnJ.js} +151 -86
- package/dist/worker.js +31 -15
- package/dist/workers/forks.js +4 -4
- package/dist/workers/runVmTests.js +14 -13
- package/dist/workers/threads.js +4 -4
- package/dist/workers/vmForks.js +6 -6
- package/dist/workers/vmThreads.js +6 -6
- package/dist/workers.d.ts +2 -2
- package/dist/workers.js +9 -9
- package/package.json +22 -22
- package/suppress-warnings.cjs +2 -4
|
@@ -2,20 +2,20 @@ import fs, { existsSync, promises, readFileSync } from 'node:fs';
|
|
|
2
2
|
import c from 'picocolors';
|
|
3
3
|
import * as pathe from 'pathe';
|
|
4
4
|
import { basename, dirname, resolve, join, relative, extname, normalize } from 'pathe';
|
|
5
|
-
import { a as getFullName, h as hasFailedSnapshot } from './tasks.
|
|
5
|
+
import { a as getFullName, h as hasFailedSnapshot } from './tasks.DhVtQBtW.js';
|
|
6
6
|
import { getSafeTimers, notNullish, highlight, shuffle, inspect, positionToOffset, lineSplitRE } from '@vitest/utils';
|
|
7
7
|
import { i as isNode } from './env.bmJgw1qP.js';
|
|
8
|
-
import { g as getStateSymbol, f as formatProjectName, p as pointer, F as F_RIGHT, r as renderSnapshotSummary,
|
|
8
|
+
import { g as getStateSymbol, f as formatProjectName, p as pointer, F as F_RIGHT, a as F_POINTER, r as renderSnapshotSummary, b as getStateString, c as formatTimeString, d as countTestErrors, e as divider, s as stripAnsi, h as getCols, i as getHookStateSymbol } from './utils.DSO2UK15.js';
|
|
9
9
|
import { generateHash, calculateSuiteHash, someTasksAreOnly, interpretTaskModes, getTasks, getTests, hasFailed, getSuites } from '@vitest/runner/utils';
|
|
10
10
|
import { performance } from 'node:perf_hooks';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
11
|
+
import { TraceMap, generatedPositionFor, parseStacktrace, parseErrorStacktrace } from '@vitest/utils/source-map';
|
|
12
|
+
import { r as relativePath } from './index.C9Thslzw.js';
|
|
13
|
+
import { UNKNOWN_TEST_ID } from '../chunks/runtime-console.Ckl0vEQr.js';
|
|
14
|
+
import { t as toArray, b as isPrimitive } from './base.CTYV4Gnz.js';
|
|
14
15
|
import { isCI } from 'std-env';
|
|
15
|
-
import { TraceMap, generatedPositionFor, parseErrorStacktrace } from '@vitest/utils/source-map';
|
|
16
16
|
import nodeos__default, { hostname } from 'node:os';
|
|
17
17
|
import { Writable } from 'node:stream';
|
|
18
|
-
import { writeFile, rm } from 'node:fs/promises';
|
|
18
|
+
import { writeFile, rm, mkdir, readdir, readFile } from 'node:fs/promises';
|
|
19
19
|
import { execa } from 'execa';
|
|
20
20
|
import url from 'node:url';
|
|
21
21
|
import p$1 from 'path';
|
|
@@ -28,24 +28,135 @@ import { g as getDefaultExportFromCjs, c as commonjsGlobal } from './_commonjsHe
|
|
|
28
28
|
import require$$0$2 from 'assert';
|
|
29
29
|
import require$$0$1 from 'events';
|
|
30
30
|
import { createHash } from 'node:crypto';
|
|
31
|
-
import { slash } from 'vite-node/utils';
|
|
31
|
+
import { slash, cleanUrl } from 'vite-node/utils';
|
|
32
32
|
import { createRequire } from 'node:module';
|
|
33
33
|
|
|
34
|
+
/// <reference types="../types/index.d.ts" />
|
|
35
|
+
|
|
36
|
+
// (c) 2020-present Andrea Giammarchi
|
|
37
|
+
|
|
38
|
+
const {parse: $parse, stringify: $stringify} = JSON;
|
|
39
|
+
const {keys} = Object;
|
|
40
|
+
|
|
41
|
+
const Primitive = String; // it could be Number
|
|
42
|
+
const primitive = 'string'; // it could be 'number'
|
|
43
|
+
|
|
44
|
+
const ignore$1 = {};
|
|
45
|
+
const object = 'object';
|
|
46
|
+
|
|
47
|
+
const noop = (_, value) => value;
|
|
48
|
+
|
|
49
|
+
const primitives = value => (
|
|
50
|
+
value instanceof Primitive ? Primitive(value) : value
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const Primitives = (_, value) => (
|
|
54
|
+
typeof value === primitive ? new Primitive(value) : value
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const revive = (input, parsed, output, $) => {
|
|
58
|
+
const lazy = [];
|
|
59
|
+
for (let ke = keys(output), {length} = ke, y = 0; y < length; y++) {
|
|
60
|
+
const k = ke[y];
|
|
61
|
+
const value = output[k];
|
|
62
|
+
if (value instanceof Primitive) {
|
|
63
|
+
const tmp = input[value];
|
|
64
|
+
if (typeof tmp === object && !parsed.has(tmp)) {
|
|
65
|
+
parsed.add(tmp);
|
|
66
|
+
output[k] = ignore$1;
|
|
67
|
+
lazy.push({k, a: [input, parsed, tmp, $]});
|
|
68
|
+
}
|
|
69
|
+
else
|
|
70
|
+
output[k] = $.call(output, k, tmp);
|
|
71
|
+
}
|
|
72
|
+
else if (output[k] !== ignore$1)
|
|
73
|
+
output[k] = $.call(output, k, value);
|
|
74
|
+
}
|
|
75
|
+
for (let {length} = lazy, i = 0; i < length; i++) {
|
|
76
|
+
const {k, a} = lazy[i];
|
|
77
|
+
output[k] = $.call(output, k, revive.apply(null, a));
|
|
78
|
+
}
|
|
79
|
+
return output;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const set = (known, input, value) => {
|
|
83
|
+
const index = Primitive(input.push(value) - 1);
|
|
84
|
+
known.set(value, index);
|
|
85
|
+
return index;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Converts a specialized flatted string into a JS value.
|
|
90
|
+
* @param {string} text
|
|
91
|
+
* @param {(this: any, key: string, value: any) => any} [reviver]
|
|
92
|
+
* @returns {any}
|
|
93
|
+
*/
|
|
94
|
+
const parse = (text, reviver) => {
|
|
95
|
+
const input = $parse(text, Primitives).map(primitives);
|
|
96
|
+
const value = input[0];
|
|
97
|
+
const $ = reviver || noop;
|
|
98
|
+
const tmp = typeof value === object && value ?
|
|
99
|
+
revive(input, new Set, value, $) :
|
|
100
|
+
value;
|
|
101
|
+
return $.call({'': tmp}, '', tmp);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Converts a JS value into a specialized flatted string.
|
|
106
|
+
* @param {any} value
|
|
107
|
+
* @param {((this: any, key: string, value: any) => any) | (string | number)[] | null | undefined} [replacer]
|
|
108
|
+
* @param {string | number | undefined} [space]
|
|
109
|
+
* @returns {string}
|
|
110
|
+
*/
|
|
111
|
+
const stringify = (value, replacer, space) => {
|
|
112
|
+
const $ = replacer && typeof replacer === object ?
|
|
113
|
+
(k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0) :
|
|
114
|
+
(replacer || noop);
|
|
115
|
+
const known = new Map;
|
|
116
|
+
const input = [];
|
|
117
|
+
const output = [];
|
|
118
|
+
let i = +set(known, input, $.call({'': value}, '', value));
|
|
119
|
+
let firstRun = !i;
|
|
120
|
+
while (i < input.length) {
|
|
121
|
+
firstRun = true;
|
|
122
|
+
output[i] = $stringify(input[i++], replace, space);
|
|
123
|
+
}
|
|
124
|
+
return '[' + output.join(',') + ']';
|
|
125
|
+
function replace(key, value) {
|
|
126
|
+
if (firstRun) {
|
|
127
|
+
firstRun = !firstRun;
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
const after = $.call(this, key, value);
|
|
131
|
+
switch (typeof after) {
|
|
132
|
+
case object:
|
|
133
|
+
if (after === null) return after;
|
|
134
|
+
case primitive:
|
|
135
|
+
return known.get(after) || set(known, input, after);
|
|
136
|
+
}
|
|
137
|
+
return after;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
34
141
|
const REGEXP_WRAP_PREFIX = "$$vitest:";
|
|
35
142
|
function getOutputFile(config, reporter) {
|
|
36
|
-
if (!(config == null ? void 0 : config.outputFile))
|
|
143
|
+
if (!(config == null ? void 0 : config.outputFile)) {
|
|
37
144
|
return;
|
|
38
|
-
|
|
145
|
+
}
|
|
146
|
+
if (typeof config.outputFile === "string") {
|
|
39
147
|
return config.outputFile;
|
|
148
|
+
}
|
|
40
149
|
return config.outputFile[reporter];
|
|
41
150
|
}
|
|
42
151
|
function wrapSerializableConfig(config) {
|
|
43
152
|
let testNamePattern = config.testNamePattern;
|
|
44
153
|
let defines = config.defines;
|
|
45
|
-
if (testNamePattern && typeof testNamePattern !== "string")
|
|
154
|
+
if (testNamePattern && typeof testNamePattern !== "string") {
|
|
46
155
|
testNamePattern = `${REGEXP_WRAP_PREFIX}${testNamePattern.toString()}`;
|
|
47
|
-
|
|
156
|
+
}
|
|
157
|
+
if (defines) {
|
|
48
158
|
defines = { keys: Object.keys(defines), original: defines };
|
|
159
|
+
}
|
|
49
160
|
return {
|
|
50
161
|
...config,
|
|
51
162
|
testNamePattern,
|
|
@@ -61,7 +172,7 @@ function B(e){return e.startsWith("\\\\?\\")?e:e.replace(/\\/g,"/")}const W=e=>{
|
|
|
61
172
|
`+" ".repeat(t)),new Array(F).fill(0).map((e,t)=>"\r"+" ".repeat(t)),new Array(F).fill(0).map((e,t)=>`\r
|
|
62
173
|
`+" ".repeat(t)),new Array(F).fill(0).map((e,t)=>`
|
|
63
174
|
`+" ".repeat(t)),new Array(F).fill(0).map((e,t)=>"\r"+" ".repeat(t)),new Array(F).fill(0).map((e,t)=>`\r
|
|
64
|
-
`+" ".repeat(t));var P;(function(e){e.DEFAULT={allowTrailingComma:!1};})(P||(P={}));function we(e,t=[],i=P.DEFAULT){let n=null,l=[];const s=[];function o(u){Array.isArray(l)?l.push(u):n!==null&&(l[n]=u);}return Te(e,{onObjectBegin:()=>{const u={};o(u),s.push(l),l=u,n=null;},onObjectProperty:u=>{n=u;},onObjectEnd:()=>{l=s.pop();},onArrayBegin:()=>{const u=[];o(u),s.push(l),l=u,n=null;},onArrayEnd:()=>{l=s.pop();},onLiteralValue:o,onError:(u,w,v)=>{t.push({error:u,offset:w,length:v});}},i),l[0]}function Te(e,t,i=P.DEFAULT){const n=be(e,!1),l=[];function s(a){return a?()=>a(n.getTokenOffset(),n.getTokenLength(),n.getTokenStartLine(),n.getTokenStartCharacter()):()=>!0}function o(a){return a?()=>a(n.getTokenOffset(),n.getTokenLength(),n.getTokenStartLine(),n.getTokenStartCharacter(),()=>l.slice()):()=>!0}function m(a){return a?O=>a(O,n.getTokenOffset(),n.getTokenLength(),n.getTokenStartLine(),n.getTokenStartCharacter()):()=>!0}function u(a){return a?O=>a(O,n.getTokenOffset(),n.getTokenLength(),n.getTokenStartLine(),n.getTokenStartCharacter(),()=>l.slice()):()=>!0}const w=o(t.onObjectBegin),v=u(t.onObjectProperty),f=s(t.onObjectEnd),E=o(t.onArrayBegin),b=s(t.onArrayEnd),T=u(t.onLiteralValue),k=m(t.onSeparator),j=s(t.onComment),L=m(t.onError),U=i&&i.disallowComments,r=i&&i.allowTrailingComma;function g(){for(;;){const a=n.scan();switch(n.getTokenError()){case 4:c(14);break;case 5:c(15);break;case 3:c(13);break;case 1:U||c(11);break;case 2:c(12);break;case 6:c(16);break}switch(a){case 12:case 13:U?c(10):j();break;case 16:c(1);break;case 15:case 14:break;default:return a}}}function c(a,O=[],Z=[]){if(L(a),O.length+Z.length>0){let x=n.getToken();for(;x!==17;){if(O.indexOf(x)!==-1){g();break}else if(Z.indexOf(x)!==-1)break;x=g();}}}function $(a){const O=n.getTokenValue();return a?T(O):(v(O),l.push(O)),g(),!0}function A(){switch(n.getToken()){case 11:const a=n.getTokenValue();let O=Number(a);isNaN(O)&&(c(2),O=0),T(O);break;case 7:T(null);break;case 8:T(!0);break;case 9:T(!1);break;default:return !1}return g(),!0}function ce(){return n.getToken()!==10?(c(3,[],[2,5]),!1):($(!1),n.getToken()===6?(k(":"),g(),S()||c(4,[],[2,5])):c(5,[],[2,5]),l.pop(),!0)}function pe(){w(),g();let a=!1;for(;n.getToken()!==2&&n.getToken()!==17;){if(n.getToken()===5){if(a||c(4,[],[]),k(","),g(),n.getToken()===2&&r)break}else a&&c(6,[],[]);ce()||c(4,[],[2,5]),a=!0;}return f(),n.getToken()!==2?c(7,[2],[]):g(),!0}function me(){E(),g();let a=!0,O=!1;for(;n.getToken()!==4&&n.getToken()!==17;){if(n.getToken()===5){if(O||c(4,[],[]),k(","),g(),n.getToken()===4&&r)break}else O&&c(6,[],[]);a?(l.push(0),a=!1):l[l.length-1]++,S()||c(4,[],[4,5]),O=!0;}return b(),a||l.pop(),n.getToken()!==4?c(8,[4],[]):g(),!0}function S(){switch(n.getToken()){case 3:return me();case 1:return pe();case 10:return $(!0);default:return A()}}return g(),n.getToken()===17?i.allowEmptyContent?!0:(c(4,[],[]),!1):S()?(n.getToken()!==17&&c(9,[],[]),!0):(c(4,[],[]),!1)}var C;(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";})(C||(C={}));var ee;(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";})(ee||(ee={}));const ve=we;var ne;(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";})(ne||(ne={}));const te=(e,t)=>ve(ke(t,e,"utf8")),R=Symbol("implicitBaseUrl"),Ae=()=>{const{findPnpApi:e}=ge;return e&&e(process.cwd())},G=(e,t,i,n)=>{const l=`resolveFromPackageJsonPath:${e}:${t}:${i}`;if(n!=null&&n.has(l))return n.get(l);const s=te(e,n);if(!s)return;let o=t||"tsconfig.json";if(!i&&s.exports)try{const[m]=v(s.exports,t,["require","types"]);o=m;}catch{return !1}else !t&&s.tsconfig&&(o=s.tsconfig);return o=p$1.join(e,"..",o),n==null||n.set(l,o),o},z="package.json",Q="tsconfig.json",Oe=(e,t,i)=>{let n=e;if(e===".."&&(n=p$1.join(n,Q)),e[0]==="."&&(n=p$1.resolve(t,n)),p$1.isAbsolute(n)){if(_(i,n)){if(I(i,n).isFile())return n}else if(!n.endsWith(".json")){const b=`${n}.json`;if(_(i,b))return b}return}const[l,...s]=e.split("/"),o=l[0]==="@"?`${l}/${s.shift()}`:l,m=s.join("/"),u=Ae();if(u){const{resolveRequest:b}=u;try{if(o===e){const T=b(p$1.join(o,z),t);if(T){const k=G(T,m,!1,i);if(k&&_(i,k))return k}}else {let T;try{T=b(e,t,{extensions:[".json"]});}catch{T=b(p$1.join(e,Q),t);}if(T)return T}}catch{}}const w=q(t,p$1.join("node_modules",o),i);if(!w||!I(i,w).isDirectory())return;const v=p$1.join(w,z);if(_(i,v)){const b=G(v,m,!1,i);if(b===!1)return;if(b&&_(i,b)&&I(i,b).isFile())return b}const f=p$1.join(w,m),E=f.endsWith(".json");if(!E){const b=`${f}.json`;if(_(i,b))return b}if(_(i,f)){if(I(i,f).isDirectory()){const b=p$1.join(f,z);if(_(i,b)){const k=G(b,"",!0,i);if(k&&_(i,k))return k}const T=p$1.join(f,Q);if(_(i,T))return T}else if(E)return f}},je=(e,t,i,n)=>{const l=Oe(e,t,n);if(!l)throw new Error(`File '${e}' not found.`);if(i.has(l))throw new Error(`Circularity detected while resolving configuration: ${l}`);i.add(l);const s=p$1.dirname(l),o=ie(l,n,i);delete o.references;const{compilerOptions:m}=o;if(m){const u=["baseUrl","outDir"];for(const w of u){const v=m[w];v&&(m[w]=B(p$1.relative(t,p$1.join(s,v)))||"./");}}return o.files&&(o.files=o.files.map(u=>B(p$1.relative(t,p$1.join(s,u))))),o.include&&(o.include=o.include.map(u=>B(p$1.relative(t,p$1.join(s,u))))),o.exclude&&(o.exclude=o.exclude.map(u=>B(p$1.relative(t,p$1.join(s,u))))),o},ie=(e,t,i=new Set)=>{let n;try{n=te(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:s}=n;s.paths&&!s.baseUrl&&(s[R]=l);}if(n.extends){const s=Array.isArray(n.extends)?n.extends:[n.extends];delete n.extends;for(const o of s.reverse()){const m=je(o,l,new Set(i),t),u={...m,...n,compilerOptions:{...m.compilerOptions,...n.compilerOptions}};m.watchOptions&&(u.watchOptions={...m.watchOptions,...n.watchOptions}),n=u;}}if(n.compilerOptions){const{compilerOptions:s}=n,o=["baseUrl","rootDir"];for(const u of o){const w=s[u];if(w){const v=p$1.resolve(l,w),f=J(p$1.relative(l,v));s[u]=f;}}const{outDir:m}=s;m&&(Array.isArray(n.exclude)||(n.exclude=[]),n.exclude.includes(m)||n.exclude.push(m),s.outDir=J(m));}else n.compilerOptions={};if(n.files&&(n.files=n.files.map(J)),n.include&&(n.include=n.include.map(B)),n.watchOptions){const{watchOptions:s}=n;s.excludeDirectories&&(s.excludeDirectories=s.excludeDirectories.map(o=>B(p$1.resolve(l,o))));}return n},le=(e,t=new Map)=>ie(e,t),$e=(e=process.cwd(),t="tsconfig.json",i=new Map)=>{const n=q(B(e),t,i);if(!n)return null;const l=le(n,i);return {path:n,config:l}};p$1.posix;process.platform==="win32";
|
|
175
|
+
`+" ".repeat(t));var P;(function(e){e.DEFAULT={allowTrailingComma:!1};})(P||(P={}));function we(e,t=[],i=P.DEFAULT){let n=null,l=[];const s=[];function o(u){Array.isArray(l)?l.push(u):n!==null&&(l[n]=u);}return Te(e,{onObjectBegin:()=>{const u={};o(u),s.push(l),l=u,n=null;},onObjectProperty:u=>{n=u;},onObjectEnd:()=>{l=s.pop();},onArrayBegin:()=>{const u=[];o(u),s.push(l),l=u,n=null;},onArrayEnd:()=>{l=s.pop();},onLiteralValue:o,onError:(u,w,v)=>{t.push({error:u,offset:w,length:v});}},i),l[0]}function Te(e,t,i=P.DEFAULT){const n=be(e,!1),l=[];function s(a){return a?()=>a(n.getTokenOffset(),n.getTokenLength(),n.getTokenStartLine(),n.getTokenStartCharacter()):()=>!0}function o(a){return a?()=>a(n.getTokenOffset(),n.getTokenLength(),n.getTokenStartLine(),n.getTokenStartCharacter(),()=>l.slice()):()=>!0}function m(a){return a?O=>a(O,n.getTokenOffset(),n.getTokenLength(),n.getTokenStartLine(),n.getTokenStartCharacter()):()=>!0}function u(a){return a?O=>a(O,n.getTokenOffset(),n.getTokenLength(),n.getTokenStartLine(),n.getTokenStartCharacter(),()=>l.slice()):()=>!0}const w=o(t.onObjectBegin),v=u(t.onObjectProperty),f=s(t.onObjectEnd),E=o(t.onArrayBegin),b=s(t.onArrayEnd),T=u(t.onLiteralValue),k=m(t.onSeparator),j=s(t.onComment),L=m(t.onError),U=i&&i.disallowComments,r=i&&i.allowTrailingComma;function g(){for(;;){const a=n.scan();switch(n.getTokenError()){case 4:c(14);break;case 5:c(15);break;case 3:c(13);break;case 1:U||c(11);break;case 2:c(12);break;case 6:c(16);break}switch(a){case 12:case 13:U?c(10):j();break;case 16:c(1);break;case 15:case 14:break;default:return a}}}function c(a,O=[],Z=[]){if(L(a),O.length+Z.length>0){let x=n.getToken();for(;x!==17;){if(O.indexOf(x)!==-1){g();break}else if(Z.indexOf(x)!==-1)break;x=g();}}}function $(a){const O=n.getTokenValue();return a?T(O):(v(O),l.push(O)),g(),!0}function A(){switch(n.getToken()){case 11:const a=n.getTokenValue();let O=Number(a);isNaN(O)&&(c(2),O=0),T(O);break;case 7:T(null);break;case 8:T(!0);break;case 9:T(!1);break;default:return !1}return g(),!0}function ce(){return n.getToken()!==10?(c(3,[],[2,5]),!1):($(!1),n.getToken()===6?(k(":"),g(),S()||c(4,[],[2,5])):c(5,[],[2,5]),l.pop(),!0)}function pe(){w(),g();let a=!1;for(;n.getToken()!==2&&n.getToken()!==17;){if(n.getToken()===5){if(a||c(4,[],[]),k(","),g(),n.getToken()===2&&r)break}else a&&c(6,[],[]);ce()||c(4,[],[2,5]),a=!0;}return f(),n.getToken()!==2?c(7,[2],[]):g(),!0}function me(){E(),g();let a=!0,O=!1;for(;n.getToken()!==4&&n.getToken()!==17;){if(n.getToken()===5){if(O||c(4,[],[]),k(","),g(),n.getToken()===4&&r)break}else O&&c(6,[],[]);a?(l.push(0),a=!1):l[l.length-1]++,S()||c(4,[],[4,5]),O=!0;}return b(),a||l.pop(),n.getToken()!==4?c(8,[4],[]):g(),!0}function S(){switch(n.getToken()){case 3:return me();case 1:return pe();case 10:return $(!0);default:return A()}}return g(),n.getToken()===17?i.allowEmptyContent?!0:(c(4,[],[]),!1):S()?(n.getToken()!==17&&c(9,[],[]),!0):(c(4,[],[]),!1)}var C;(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";})(C||(C={}));var ee;(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";})(ee||(ee={}));const ve=we;var ne;(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";})(ne||(ne={}));const te=(e,t)=>ve(ke(t,e,"utf8")),R=Symbol("implicitBaseUrl"),Ae=()=>{const{findPnpApi:e}=ge;return e&&e(process.cwd())},G=(e,t,i,n)=>{const l=`resolveFromPackageJsonPath:${e}:${t}:${i}`;if(n!=null&&n.has(l))return n.get(l);const s=te(e,n);if(!s)return;let o=t||"tsconfig.json";if(!i&&s.exports)try{const[m]=v(s.exports,t,["require","types"]);o=m;}catch{return !1}else !t&&s.tsconfig&&(o=s.tsconfig);return o=p$1.join(e,"..",o),n==null||n.set(l,o),o},z="package.json",Q="tsconfig.json",Oe=(e,t,i)=>{let n=e;if(e===".."&&(n=p$1.join(n,Q)),e[0]==="."&&(n=p$1.resolve(t,n)),p$1.isAbsolute(n)){if(_(i,n)){if(I(i,n).isFile())return n}else if(!n.endsWith(".json")){const b=`${n}.json`;if(_(i,b))return b}return}const[l,...s]=e.split("/"),o=l[0]==="@"?`${l}/${s.shift()}`:l,m=s.join("/"),u=Ae();if(u){const{resolveRequest:b}=u;try{if(o===e){const T=b(p$1.join(o,z),t);if(T){const k=G(T,m,!1,i);if(k&&_(i,k))return k}}else {let T;try{T=b(e,t,{extensions:[".json"]});}catch{T=b(p$1.join(e,Q),t);}if(T)return T}}catch{}}const w=q(p$1.resolve(t),p$1.join("node_modules",o),i);if(!w||!I(i,w).isDirectory())return;const v=p$1.join(w,z);if(_(i,v)){const b=G(v,m,!1,i);if(b===!1)return;if(b&&_(i,b)&&I(i,b).isFile())return b}const f=p$1.join(w,m),E=f.endsWith(".json");if(!E){const b=`${f}.json`;if(_(i,b))return b}if(_(i,f)){if(I(i,f).isDirectory()){const b=p$1.join(f,z);if(_(i,b)){const k=G(b,"",!0,i);if(k&&_(i,k))return k}const T=p$1.join(f,Q);if(_(i,T))return T}else if(E)return f}},je=(e,t,i,n)=>{const l=Oe(e,t,n);if(!l)throw new Error(`File '${e}' not found.`);if(i.has(l))throw new Error(`Circularity detected while resolving configuration: ${l}`);i.add(l);const s=p$1.dirname(l),o=ie(l,n,i);delete o.references;const{compilerOptions:m}=o;if(m){const u=["baseUrl","outDir"];for(const w of u){const v=m[w];v&&(m[w]=B(p$1.relative(t,p$1.join(s,v)))||"./");}}return o.files&&(o.files=o.files.map(u=>B(p$1.relative(t,p$1.join(s,u))))),o.include&&(o.include=o.include.map(u=>B(p$1.relative(t,p$1.join(s,u))))),o.exclude&&(o.exclude=o.exclude.map(u=>B(p$1.relative(t,p$1.join(s,u))))),o},ie=(e,t,i=new Set)=>{let n;try{n=te(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:s}=n;s.paths&&!s.baseUrl&&(s[R]=l);}if(n.extends){const s=Array.isArray(n.extends)?n.extends:[n.extends];delete n.extends;for(const o of s.reverse()){const m=je(o,l,new Set(i),t),u={...m,...n,compilerOptions:{...m.compilerOptions,...n.compilerOptions}};m.watchOptions&&(u.watchOptions={...m.watchOptions,...n.watchOptions}),n=u;}}if(n.compilerOptions){const{compilerOptions:s}=n,o=["baseUrl","rootDir"];for(const u of o){const w=s[u];if(w){const v=p$1.resolve(l,w),f=J(p$1.relative(l,v));s[u]=f;}}const{outDir:m}=s;m&&(Array.isArray(n.exclude)||(n.exclude=[]),n.exclude.includes(m)||n.exclude.push(m),s.outDir=J(m));}else n.compilerOptions={};if(n.files&&(n.files=n.files.map(J)),n.include&&(n.include=n.include.map(B)),n.watchOptions){const{watchOptions:s}=n;s.excludeDirectories&&(s.excludeDirectories=s.excludeDirectories.map(o=>B(p$1.resolve(l,o))));}return n},le=(e,t=new Map)=>ie(e,t),$e=(e=process.cwd(),t="tsconfig.json",i=new Map)=>{const n=q(B(e),t,i);if(!n)return null;const l=le(n,i);return {path:n,config:l}};p$1.posix;process.platform==="win32";
|
|
65
176
|
|
|
66
177
|
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
|
|
67
178
|
const newLineRegExp = /\r?\n/;
|
|
@@ -69,21 +180,26 @@ const errCodeRegExp = /error TS(?<errCode>\d+)/;
|
|
|
69
180
|
async function makeTscErrorInfo(errInfo) {
|
|
70
181
|
var _a;
|
|
71
182
|
const [errFilePathPos = "", ...errMsgRawArr] = errInfo.split(":");
|
|
72
|
-
if (!errFilePathPos || errMsgRawArr.length === 0 || errMsgRawArr.join("").length === 0)
|
|
183
|
+
if (!errFilePathPos || errMsgRawArr.length === 0 || errMsgRawArr.join("").length === 0) {
|
|
73
184
|
return ["unknown filepath", null];
|
|
185
|
+
}
|
|
74
186
|
const errMsgRaw = errMsgRawArr.join("").trim();
|
|
75
187
|
const [errFilePath, errPos] = errFilePathPos.slice(0, -1).split("(");
|
|
76
|
-
if (!errFilePath || !errPos)
|
|
188
|
+
if (!errFilePath || !errPos) {
|
|
77
189
|
return ["unknown filepath", null];
|
|
190
|
+
}
|
|
78
191
|
const [errLine, errCol] = errPos.split(",");
|
|
79
|
-
if (!errLine || !errCol)
|
|
192
|
+
if (!errLine || !errCol) {
|
|
80
193
|
return [errFilePath, null];
|
|
194
|
+
}
|
|
81
195
|
const execArr = errCodeRegExp.exec(errMsgRaw);
|
|
82
|
-
if (!execArr)
|
|
196
|
+
if (!execArr) {
|
|
83
197
|
return [errFilePath, null];
|
|
198
|
+
}
|
|
84
199
|
const errCodeStr = ((_a = execArr.groups) == null ? void 0 : _a.errCode) ?? "";
|
|
85
|
-
if (!errCodeStr)
|
|
200
|
+
if (!errCodeStr) {
|
|
86
201
|
return [errFilePath, null];
|
|
202
|
+
}
|
|
87
203
|
const line = Number(errLine);
|
|
88
204
|
const col = Number(errCol);
|
|
89
205
|
const errCode = Number(errCodeStr);
|
|
@@ -102,9 +218,13 @@ async function getTsconfig(root, config) {
|
|
|
102
218
|
const configName = config.tsconfig ? basename(config.tsconfig) : void 0;
|
|
103
219
|
const configSearchPath = config.tsconfig ? dirname(resolve(root, config.tsconfig)) : root;
|
|
104
220
|
const tsconfig = $e(configSearchPath, configName);
|
|
105
|
-
if (!tsconfig)
|
|
221
|
+
if (!tsconfig) {
|
|
106
222
|
throw new Error("no tsconfig.json found");
|
|
107
|
-
|
|
223
|
+
}
|
|
224
|
+
const tempConfigPath = join(
|
|
225
|
+
dirname(tsconfig.path),
|
|
226
|
+
"tsconfig.vitest-temp.json"
|
|
227
|
+
);
|
|
108
228
|
try {
|
|
109
229
|
const tmpTsConfig = { ...tsconfig.config };
|
|
110
230
|
tmpTsConfig.compilerOptions = tmpTsConfig.compilerOptions || {};
|
|
@@ -125,24 +245,27 @@ async function getRawErrsMapFromTsCompile(tscErrorStdout) {
|
|
|
125
245
|
const rawErrsMap = /* @__PURE__ */ new Map();
|
|
126
246
|
const infos = await Promise.all(
|
|
127
247
|
tscErrorStdout.split(newLineRegExp).reduce((prev, next) => {
|
|
128
|
-
if (!next)
|
|
248
|
+
if (!next) {
|
|
129
249
|
return prev;
|
|
130
|
-
else if (!next.startsWith(" "))
|
|
250
|
+
} else if (!next.startsWith(" ")) {
|
|
131
251
|
prev.push(next);
|
|
132
|
-
else
|
|
252
|
+
} else {
|
|
133
253
|
prev[prev.length - 1] += `
|
|
134
254
|
${next}`;
|
|
255
|
+
}
|
|
135
256
|
return prev;
|
|
136
257
|
}, []).map((errInfoLine) => makeTscErrorInfo(errInfoLine))
|
|
137
258
|
);
|
|
138
259
|
infos.forEach(([errFilePath, errInfo]) => {
|
|
139
260
|
var _a;
|
|
140
|
-
if (!errInfo)
|
|
261
|
+
if (!errInfo) {
|
|
141
262
|
return;
|
|
142
|
-
|
|
263
|
+
}
|
|
264
|
+
if (!rawErrsMap.has(errFilePath)) {
|
|
143
265
|
rawErrsMap.set(errFilePath, [errInfo]);
|
|
144
|
-
else
|
|
266
|
+
} else {
|
|
145
267
|
(_a = rawErrsMap.get(errFilePath)) == null ? void 0 : _a.push(errInfo);
|
|
268
|
+
}
|
|
146
269
|
});
|
|
147
270
|
return rawErrsMap;
|
|
148
271
|
}
|
|
@@ -477,8 +600,9 @@ base.MethodDefinition = base.PropertyDefinition = base.Property = function (node
|
|
|
477
600
|
|
|
478
601
|
async function collectTests(ctx, filepath) {
|
|
479
602
|
const request = await ctx.vitenode.transformRequest(filepath, filepath);
|
|
480
|
-
if (!request)
|
|
603
|
+
if (!request) {
|
|
481
604
|
return null;
|
|
605
|
+
}
|
|
482
606
|
const ast = await parseAstAsync(request.code);
|
|
483
607
|
const testFilepath = relative(ctx.config.root, filepath);
|
|
484
608
|
const file = {
|
|
@@ -498,13 +622,16 @@ async function collectTests(ctx, filepath) {
|
|
|
498
622
|
const definitions = [];
|
|
499
623
|
const getName = (callee) => {
|
|
500
624
|
var _a, _b, _c;
|
|
501
|
-
if (!callee)
|
|
625
|
+
if (!callee) {
|
|
502
626
|
return null;
|
|
503
|
-
|
|
627
|
+
}
|
|
628
|
+
if (callee.type === "Identifier") {
|
|
504
629
|
return callee.name;
|
|
630
|
+
}
|
|
505
631
|
if (callee.type === "MemberExpression") {
|
|
506
|
-
if ((_b = (_a = callee.object) == null ? void 0 : _a.name) == null ? void 0 : _b.startsWith("__vite_ssr_"))
|
|
632
|
+
if ((_b = (_a = callee.object) == null ? void 0 : _a.name) == null ? void 0 : _b.startsWith("__vite_ssr_")) {
|
|
507
633
|
return getName(callee.property);
|
|
634
|
+
}
|
|
508
635
|
return getName((_c = callee.object) == null ? void 0 : _c.property);
|
|
509
636
|
}
|
|
510
637
|
return null;
|
|
@@ -514,17 +641,25 @@ async function collectTests(ctx, filepath) {
|
|
|
514
641
|
var _a;
|
|
515
642
|
const { callee } = node;
|
|
516
643
|
const name = getName(callee);
|
|
517
|
-
if (!name)
|
|
644
|
+
if (!name) {
|
|
518
645
|
return;
|
|
519
|
-
|
|
646
|
+
}
|
|
647
|
+
if (!["it", "test", "describe", "suite"].includes(name)) {
|
|
520
648
|
return;
|
|
521
|
-
|
|
649
|
+
}
|
|
650
|
+
const {
|
|
651
|
+
arguments: [{ value: message }]
|
|
652
|
+
} = node;
|
|
522
653
|
const property = (_a = callee == null ? void 0 : callee.property) == null ? void 0 : _a.name;
|
|
523
654
|
let mode = !property || property === name ? "run" : property;
|
|
524
|
-
if (!["run", "skip", "todo", "only", "skipIf", "runIf"].includes(mode))
|
|
525
|
-
throw new Error(
|
|
526
|
-
|
|
655
|
+
if (!["run", "skip", "todo", "only", "skipIf", "runIf"].includes(mode)) {
|
|
656
|
+
throw new Error(
|
|
657
|
+
`${name}.${mode} syntax is not supported when testing types`
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
if (mode === "skipIf" || mode === "runIf") {
|
|
527
661
|
mode = "skip";
|
|
662
|
+
}
|
|
528
663
|
definitions.push({
|
|
529
664
|
start: node.start,
|
|
530
665
|
end: node.end,
|
|
@@ -536,15 +671,17 @@ async function collectTests(ctx, filepath) {
|
|
|
536
671
|
});
|
|
537
672
|
let lastSuite = file;
|
|
538
673
|
const updateLatestSuite = (index) => {
|
|
539
|
-
while (lastSuite.suite && lastSuite.end < index)
|
|
674
|
+
while (lastSuite.suite && lastSuite.end < index) {
|
|
540
675
|
lastSuite = lastSuite.suite;
|
|
676
|
+
}
|
|
541
677
|
return lastSuite;
|
|
542
678
|
};
|
|
543
679
|
definitions.sort((a, b) => a.start - b.start).forEach((definition) => {
|
|
544
680
|
const latestSuite = updateLatestSuite(definition.start);
|
|
545
681
|
let mode = definition.mode;
|
|
546
|
-
if (latestSuite.mode !== "run")
|
|
682
|
+
if (latestSuite.mode !== "run") {
|
|
547
683
|
mode = latestSuite.mode;
|
|
684
|
+
}
|
|
548
685
|
if (definition.type === "suite") {
|
|
549
686
|
const task2 = {
|
|
550
687
|
type: definition.type,
|
|
@@ -585,7 +722,13 @@ async function collectTests(ctx, filepath) {
|
|
|
585
722
|
});
|
|
586
723
|
calculateSuiteHash(file);
|
|
587
724
|
const hasOnly = someTasksAreOnly(file);
|
|
588
|
-
interpretTaskModes(
|
|
725
|
+
interpretTaskModes(
|
|
726
|
+
file,
|
|
727
|
+
ctx.config.testNamePattern,
|
|
728
|
+
hasOnly,
|
|
729
|
+
false,
|
|
730
|
+
ctx.config.allowOnly
|
|
731
|
+
);
|
|
589
732
|
return {
|
|
590
733
|
file,
|
|
591
734
|
parsed: request.code,
|
|
@@ -647,8 +790,9 @@ class Typechecker {
|
|
|
647
790
|
const tests = (await Promise.all(
|
|
648
791
|
this.getFiles().map((filepath) => this.collectFileTests(filepath))
|
|
649
792
|
)).reduce((acc, data) => {
|
|
650
|
-
if (!data)
|
|
793
|
+
if (!data) {
|
|
651
794
|
return acc;
|
|
795
|
+
}
|
|
652
796
|
acc[data.filepath] = data;
|
|
653
797
|
return acc;
|
|
654
798
|
}, {});
|
|
@@ -665,8 +809,9 @@ class Typechecker {
|
|
|
665
809
|
const markTasks = (tasks) => {
|
|
666
810
|
var _a2;
|
|
667
811
|
for (const task of tasks) {
|
|
668
|
-
if ("tasks" in task)
|
|
812
|
+
if ("tasks" in task) {
|
|
669
813
|
markTasks(task.tasks);
|
|
814
|
+
}
|
|
670
815
|
if (!((_a2 = task.result) == null ? void 0 : _a2.state) && task.mode === "run") {
|
|
671
816
|
task.result = {
|
|
672
817
|
state: "pass"
|
|
@@ -679,8 +824,9 @@ class Typechecker {
|
|
|
679
824
|
async prepareResults(output) {
|
|
680
825
|
const typeErrors = await this.parseTscLikeOutput(output);
|
|
681
826
|
const testFiles = new Set(this.getFiles());
|
|
682
|
-
if (!this._tests)
|
|
827
|
+
if (!this._tests) {
|
|
683
828
|
this._tests = await this.collectTests();
|
|
829
|
+
}
|
|
684
830
|
const sourceErrors = [];
|
|
685
831
|
const files = [];
|
|
686
832
|
testFiles.forEach((path) => {
|
|
@@ -691,17 +837,20 @@ class Typechecker {
|
|
|
691
837
|
this.markPassed(file);
|
|
692
838
|
return;
|
|
693
839
|
}
|
|
694
|
-
const sortedDefinitions = [
|
|
840
|
+
const sortedDefinitions = [
|
|
841
|
+
...definitions.sort((a, b) => b.start - a.start)
|
|
842
|
+
];
|
|
695
843
|
const traceMap = map && new TraceMap(map);
|
|
696
844
|
const indexMap = createIndexMap(parsed);
|
|
697
845
|
const markState = (task, state) => {
|
|
698
846
|
task.result = {
|
|
699
847
|
state: task.mode === "run" || task.mode === "only" ? state : task.mode
|
|
700
848
|
};
|
|
701
|
-
if (task.suite)
|
|
849
|
+
if (task.suite) {
|
|
702
850
|
markState(task.suite, state);
|
|
703
|
-
else if (task.file && task !== task.file)
|
|
851
|
+
} else if (task.file && task !== task.file) {
|
|
704
852
|
markState(task.file, state);
|
|
853
|
+
}
|
|
705
854
|
};
|
|
706
855
|
errors.forEach(({ error, originalError }) => {
|
|
707
856
|
var _a;
|
|
@@ -713,7 +862,9 @@ class Typechecker {
|
|
|
713
862
|
const line = processedPos.line ?? originalError.line;
|
|
714
863
|
const column = processedPos.column ?? originalError.column;
|
|
715
864
|
const index = indexMap.get(`${line}:${column}`);
|
|
716
|
-
const definition = index != null && sortedDefinitions.find(
|
|
865
|
+
const definition = index != null && sortedDefinitions.find(
|
|
866
|
+
(def) => def.start <= index && def.end >= index
|
|
867
|
+
);
|
|
717
868
|
const suite = definition ? definition.task : file;
|
|
718
869
|
const state = suite.mode === "run" || suite.mode === "only" ? "fail" : suite.mode;
|
|
719
870
|
const errors2 = ((_a = suite.result) == null ? void 0 : _a.errors) || [];
|
|
@@ -723,17 +874,19 @@ class Typechecker {
|
|
|
723
874
|
};
|
|
724
875
|
errors2.push(error);
|
|
725
876
|
if (state === "fail") {
|
|
726
|
-
if (suite.suite)
|
|
877
|
+
if (suite.suite) {
|
|
727
878
|
markState(suite.suite, "fail");
|
|
728
|
-
else if (suite.file && suite !== suite.file)
|
|
879
|
+
} else if (suite.file && suite !== suite.file) {
|
|
729
880
|
markState(suite.file, "fail");
|
|
881
|
+
}
|
|
730
882
|
}
|
|
731
883
|
});
|
|
732
884
|
this.markPassed(file);
|
|
733
885
|
});
|
|
734
886
|
typeErrors.forEach((errors, path) => {
|
|
735
|
-
if (!testFiles.has(path))
|
|
887
|
+
if (!testFiles.has(path)) {
|
|
736
888
|
sourceErrors.push(...errors.map(({ error }) => error));
|
|
889
|
+
}
|
|
737
890
|
});
|
|
738
891
|
return {
|
|
739
892
|
files,
|
|
@@ -749,7 +902,10 @@ class Typechecker {
|
|
|
749
902
|
const suiteErrors = errors.map((info) => {
|
|
750
903
|
const limit = Error.stackTraceLimit;
|
|
751
904
|
Error.stackTraceLimit = 0;
|
|
752
|
-
const errMsg = info.errMsg.replace(
|
|
905
|
+
const errMsg = info.errMsg.replace(
|
|
906
|
+
/\r?\n\s*(Type .* has no call signatures)/g,
|
|
907
|
+
" $1"
|
|
908
|
+
);
|
|
753
909
|
const error = new TypeCheckError(errMsg, [
|
|
754
910
|
{
|
|
755
911
|
file: filepath,
|
|
@@ -776,8 +932,9 @@ class Typechecker {
|
|
|
776
932
|
return typesErrors;
|
|
777
933
|
}
|
|
778
934
|
async clear() {
|
|
779
|
-
if (this.tempConfigPath)
|
|
935
|
+
if (this.tempConfigPath) {
|
|
780
936
|
await rm(this.tempConfigPath, { force: true });
|
|
937
|
+
}
|
|
781
938
|
}
|
|
782
939
|
async stop() {
|
|
783
940
|
var _a;
|
|
@@ -785,8 +942,9 @@ class Typechecker {
|
|
|
785
942
|
(_a = this.process) == null ? void 0 : _a.kill();
|
|
786
943
|
}
|
|
787
944
|
async ensurePackageInstalled(ctx, checker) {
|
|
788
|
-
if (checker !== "tsc" && checker !== "vue-tsc")
|
|
945
|
+
if (checker !== "tsc" && checker !== "vue-tsc") {
|
|
789
946
|
return;
|
|
947
|
+
}
|
|
790
948
|
const packageName = checker === "tsc" ? "typescript" : "vue-tsc";
|
|
791
949
|
await ctx.packageInstaller.ensureInstalled(packageName, ctx.config.root);
|
|
792
950
|
}
|
|
@@ -805,14 +963,17 @@ class Typechecker {
|
|
|
805
963
|
}
|
|
806
964
|
async start() {
|
|
807
965
|
var _a, _b, _c;
|
|
808
|
-
if (!this.tempConfigPath)
|
|
966
|
+
if (!this.tempConfigPath) {
|
|
809
967
|
throw new Error("tsconfig was not initialized");
|
|
968
|
+
}
|
|
810
969
|
const { root, watch, typecheck } = this.ctx.config;
|
|
811
970
|
const args = ["--noEmit", "--pretty", "false", "-p", this.tempConfigPath];
|
|
812
|
-
if (watch)
|
|
971
|
+
if (watch) {
|
|
813
972
|
args.push("--watch");
|
|
814
|
-
|
|
973
|
+
}
|
|
974
|
+
if (typecheck.allowJs) {
|
|
815
975
|
args.push("--allowJs", "--checkJs");
|
|
976
|
+
}
|
|
816
977
|
this._output = "";
|
|
817
978
|
this._startTime = performance.now();
|
|
818
979
|
const child = execa(typecheck.checker, args, {
|
|
@@ -826,8 +987,9 @@ class Typechecker {
|
|
|
826
987
|
(_b = child.stdout) == null ? void 0 : _b.on("data", (chunk) => {
|
|
827
988
|
var _a2;
|
|
828
989
|
this._output += chunk;
|
|
829
|
-
if (!watch)
|
|
990
|
+
if (!watch) {
|
|
830
991
|
return;
|
|
992
|
+
}
|
|
831
993
|
if (this._output.includes("File change detected") && !rerunTriggered) {
|
|
832
994
|
(_a2 = this._onWatcherRerun) == null ? void 0 : _a2.call(this);
|
|
833
995
|
this._startTime = performance.now();
|
|
@@ -863,31 +1025,39 @@ class Typechecker {
|
|
|
863
1025
|
}
|
|
864
1026
|
}
|
|
865
1027
|
|
|
866
|
-
var _a;
|
|
867
1028
|
const BADGE_PADDING = " ";
|
|
868
1029
|
const HELP_HINT = `${c.dim("press ")}${c.bold("h")}${c.dim(" to show help")}`;
|
|
869
1030
|
const HELP_UPDATE_SNAP = c.dim("press ") + c.bold(c.yellow("u")) + c.dim(" to update snapshot");
|
|
870
1031
|
const HELP_QUITE = `${c.dim("press ")}${c.bold("q")}${c.dim(" to quit")}`;
|
|
871
1032
|
const WAIT_FOR_CHANGE_PASS = `
|
|
872
|
-
${c.bold(
|
|
1033
|
+
${c.bold(
|
|
1034
|
+
c.inverse(c.green(" PASS "))
|
|
1035
|
+
)}${c.green(" Waiting for file changes...")}`;
|
|
873
1036
|
const WAIT_FOR_CHANGE_FAIL = `
|
|
874
|
-
${c.bold(c.inverse(c.red(" FAIL ")))}${c.red(
|
|
1037
|
+
${c.bold(c.inverse(c.red(" FAIL ")))}${c.red(
|
|
1038
|
+
" Tests failed. Watching for file changes..."
|
|
1039
|
+
)}`;
|
|
875
1040
|
const WAIT_FOR_CHANGE_CANCELLED = `
|
|
876
|
-
${c.bold(
|
|
1041
|
+
${c.bold(
|
|
1042
|
+
c.inverse(c.red(" CANCELLED "))
|
|
1043
|
+
)}${c.red(" Test run cancelled. Watching for file changes...")}`;
|
|
877
1044
|
const LAST_RUN_LOG_TIMEOUT = 1500;
|
|
878
1045
|
class BaseReporter {
|
|
879
1046
|
start = 0;
|
|
880
1047
|
end = 0;
|
|
881
1048
|
watchFilters;
|
|
882
|
-
isTTY
|
|
1049
|
+
isTTY;
|
|
883
1050
|
ctx = void 0;
|
|
1051
|
+
verbose = false;
|
|
884
1052
|
_filesInWatchMode = /* @__PURE__ */ new Map();
|
|
885
1053
|
_lastRunTimeout = 0;
|
|
886
1054
|
_lastRunTimer;
|
|
887
1055
|
_lastRunCount = 0;
|
|
888
1056
|
_timeStart = /* @__PURE__ */ new Date();
|
|
889
1057
|
_offUnhandledRejection;
|
|
890
|
-
constructor() {
|
|
1058
|
+
constructor(options = {}) {
|
|
1059
|
+
var _a;
|
|
1060
|
+
this.isTTY = options.isTTY ?? (isNode && ((_a = process.stdout) == null ? void 0 : _a.isTTY) && !isCI);
|
|
891
1061
|
this.registerUnhandledRejection();
|
|
892
1062
|
}
|
|
893
1063
|
get mode() {
|
|
@@ -896,8 +1066,8 @@ class BaseReporter {
|
|
|
896
1066
|
onInit(ctx) {
|
|
897
1067
|
this.ctx = ctx;
|
|
898
1068
|
ctx.onClose(() => {
|
|
899
|
-
var
|
|
900
|
-
(
|
|
1069
|
+
var _a;
|
|
1070
|
+
(_a = this._offUnhandledRejection) == null ? void 0 : _a.call(this);
|
|
901
1071
|
});
|
|
902
1072
|
ctx.logger.printBanner();
|
|
903
1073
|
this.start = performance.now();
|
|
@@ -909,39 +1079,49 @@ class BaseReporter {
|
|
|
909
1079
|
this.end = performance.now();
|
|
910
1080
|
this.reportSummary(files, errors);
|
|
911
1081
|
if (errors.length) {
|
|
912
|
-
if (!this.ctx.config.dangerouslyIgnoreUnhandledErrors)
|
|
1082
|
+
if (!this.ctx.config.dangerouslyIgnoreUnhandledErrors) {
|
|
913
1083
|
process.exitCode = 1;
|
|
1084
|
+
}
|
|
914
1085
|
}
|
|
915
1086
|
}
|
|
916
1087
|
onTaskUpdate(packs) {
|
|
917
|
-
var
|
|
918
|
-
if (this.isTTY)
|
|
1088
|
+
var _a, _b, _c, _d;
|
|
1089
|
+
if (this.isTTY) {
|
|
919
1090
|
return;
|
|
1091
|
+
}
|
|
920
1092
|
const logger = this.ctx.logger;
|
|
921
1093
|
for (const pack of packs) {
|
|
922
1094
|
const task = this.ctx.state.idMap.get(pack[0]);
|
|
923
|
-
if (task && "filepath" in task && ((
|
|
1095
|
+
if (task && "filepath" in task && ((_a = task.result) == null ? void 0 : _a.state) && ((_b = task.result) == null ? void 0 : _b.state) !== "run") {
|
|
924
1096
|
const tests = getTests(task);
|
|
925
1097
|
const failed = tests.filter((t) => {
|
|
926
|
-
var
|
|
927
|
-
return ((
|
|
1098
|
+
var _a2;
|
|
1099
|
+
return ((_a2 = t.result) == null ? void 0 : _a2.state) === "fail";
|
|
928
1100
|
});
|
|
929
|
-
const skipped = tests.filter(
|
|
1101
|
+
const skipped = tests.filter(
|
|
1102
|
+
(t) => t.mode === "skip" || t.mode === "todo"
|
|
1103
|
+
);
|
|
930
1104
|
let state = c.dim(`${tests.length} test${tests.length > 1 ? "s" : ""}`);
|
|
931
|
-
if (failed.length)
|
|
1105
|
+
if (failed.length) {
|
|
932
1106
|
state += ` ${c.dim("|")} ${c.red(`${failed.length} failed`)}`;
|
|
933
|
-
|
|
1107
|
+
}
|
|
1108
|
+
if (skipped.length) {
|
|
934
1109
|
state += ` ${c.dim("|")} ${c.yellow(`${skipped.length} skipped`)}`;
|
|
1110
|
+
}
|
|
935
1111
|
let suffix = c.dim(" (") + state + c.dim(")");
|
|
936
1112
|
if (task.result.duration) {
|
|
937
1113
|
const color = task.result.duration > this.ctx.config.slowTestThreshold ? c.yellow : c.gray;
|
|
938
1114
|
suffix += color(` ${Math.round(task.result.duration)}${c.dim("ms")}`);
|
|
939
1115
|
}
|
|
940
|
-
if (this.ctx.config.logHeapUsage && task.result.heap != null)
|
|
941
|
-
suffix += c.magenta(
|
|
1116
|
+
if (this.ctx.config.logHeapUsage && task.result.heap != null) {
|
|
1117
|
+
suffix += c.magenta(
|
|
1118
|
+
` ${Math.floor(task.result.heap / 1024 / 1024)} MB heap used`
|
|
1119
|
+
);
|
|
1120
|
+
}
|
|
942
1121
|
let title = ` ${getStateSymbol(task)} `;
|
|
943
|
-
if (task.projectName)
|
|
1122
|
+
if (task.projectName) {
|
|
944
1123
|
title += formatProjectName(task.projectName);
|
|
1124
|
+
}
|
|
945
1125
|
title += `${task.name} ${suffix}`;
|
|
946
1126
|
logger.log(title);
|
|
947
1127
|
for (const test of failed) {
|
|
@@ -958,18 +1138,20 @@ class BaseReporter {
|
|
|
958
1138
|
const failed = errors.length > 0 || hasFailed(files);
|
|
959
1139
|
const failedSnap = hasFailedSnapshot(files);
|
|
960
1140
|
const cancelled = this.ctx.isCancelling;
|
|
961
|
-
if (failed)
|
|
1141
|
+
if (failed) {
|
|
962
1142
|
this.ctx.logger.log(WAIT_FOR_CHANGE_FAIL);
|
|
963
|
-
else if (cancelled)
|
|
1143
|
+
} else if (cancelled) {
|
|
964
1144
|
this.ctx.logger.log(WAIT_FOR_CHANGE_CANCELLED);
|
|
965
|
-
else
|
|
1145
|
+
} else {
|
|
966
1146
|
this.ctx.logger.log(WAIT_FOR_CHANGE_PASS);
|
|
1147
|
+
}
|
|
967
1148
|
const hints = [];
|
|
968
1149
|
hints.push(HELP_HINT);
|
|
969
|
-
if (failedSnap)
|
|
1150
|
+
if (failedSnap) {
|
|
970
1151
|
hints.unshift(HELP_UPDATE_SNAP);
|
|
971
|
-
else
|
|
1152
|
+
} else {
|
|
972
1153
|
hints.push(HELP_QUITE);
|
|
1154
|
+
}
|
|
973
1155
|
this.ctx.logger.log(BADGE_PADDING + hints.join(c.dim(", ")));
|
|
974
1156
|
if (this._lastRunCount) {
|
|
975
1157
|
const LAST_RUN_TEXT = `rerun x${this._lastRunCount}`;
|
|
@@ -981,16 +1163,16 @@ class BaseReporter {
|
|
|
981
1163
|
this.ctx.logger.logUpdate(BADGE_PADDING + LAST_RUN_TEXTS[0]);
|
|
982
1164
|
this._lastRunTimeout = 0;
|
|
983
1165
|
const { setInterval } = getSafeTimers();
|
|
984
|
-
this._lastRunTimer = setInterval(
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
);
|
|
1166
|
+
this._lastRunTimer = setInterval(() => {
|
|
1167
|
+
this._lastRunTimeout += 1;
|
|
1168
|
+
if (this._lastRunTimeout >= LAST_RUN_TEXTS.length) {
|
|
1169
|
+
this.resetLastRunLog();
|
|
1170
|
+
} else {
|
|
1171
|
+
this.ctx.logger.logUpdate(
|
|
1172
|
+
BADGE_PADDING + LAST_RUN_TEXTS[this._lastRunTimeout]
|
|
1173
|
+
);
|
|
1174
|
+
}
|
|
1175
|
+
}, LAST_RUN_LOG_TIMEOUT / LAST_RUN_TEXTS.length);
|
|
994
1176
|
}
|
|
995
1177
|
}
|
|
996
1178
|
resetLastRunLog() {
|
|
@@ -1008,109 +1190,200 @@ class BaseReporter {
|
|
|
1008
1190
|
});
|
|
1009
1191
|
const BADGE = c.inverse(c.bold(c.blue(" RERUN ")));
|
|
1010
1192
|
const TRIGGER = trigger ? c.dim(` ${this.relative(trigger)}`) : "";
|
|
1011
|
-
const FILENAME_PATTERN = this.ctx.filenamePattern ? `${BADGE_PADDING} ${c.dim("Filename pattern: ")}${c.blue(
|
|
1193
|
+
const FILENAME_PATTERN = this.ctx.filenamePattern ? `${BADGE_PADDING} ${c.dim("Filename pattern: ")}${c.blue(
|
|
1194
|
+
this.ctx.filenamePattern
|
|
1195
|
+
)}
|
|
1012
1196
|
` : "";
|
|
1013
|
-
const TESTNAME_PATTERN = this.ctx.configOverride.testNamePattern ? `${BADGE_PADDING} ${c.dim("Test name pattern: ")}${c.blue(
|
|
1197
|
+
const TESTNAME_PATTERN = this.ctx.configOverride.testNamePattern ? `${BADGE_PADDING} ${c.dim("Test name pattern: ")}${c.blue(
|
|
1198
|
+
String(this.ctx.configOverride.testNamePattern)
|
|
1199
|
+
)}
|
|
1014
1200
|
` : "";
|
|
1015
|
-
const PROJECT_FILTER = this.ctx.configOverride.project ? `${BADGE_PADDING} ${c.dim("Project name: ")}${c.blue(
|
|
1201
|
+
const PROJECT_FILTER = this.ctx.configOverride.project ? `${BADGE_PADDING} ${c.dim("Project name: ")}${c.blue(
|
|
1202
|
+
toArray(this.ctx.configOverride.project).join(", ")
|
|
1203
|
+
)}
|
|
1016
1204
|
` : "";
|
|
1017
1205
|
if (files.length > 1 || !files.length) {
|
|
1018
|
-
this.ctx.logger.clearFullScreen(
|
|
1206
|
+
this.ctx.logger.clearFullScreen(
|
|
1207
|
+
`
|
|
1019
1208
|
${BADGE}${TRIGGER}
|
|
1020
|
-
${PROJECT_FILTER}${FILENAME_PATTERN}${TESTNAME_PATTERN}`
|
|
1209
|
+
${PROJECT_FILTER}${FILENAME_PATTERN}${TESTNAME_PATTERN}`
|
|
1210
|
+
);
|
|
1021
1211
|
this._lastRunCount = 0;
|
|
1022
1212
|
} else if (files.length === 1) {
|
|
1023
1213
|
const rerun = this._filesInWatchMode.get(files[0]) ?? 1;
|
|
1024
1214
|
this._lastRunCount = rerun;
|
|
1025
|
-
this.ctx.logger.clearFullScreen(
|
|
1026
|
-
|
|
1027
|
-
${
|
|
1215
|
+
this.ctx.logger.clearFullScreen(
|
|
1216
|
+
`
|
|
1217
|
+
${BADGE}${TRIGGER} ${c.blue(
|
|
1218
|
+
`x${rerun}`
|
|
1219
|
+
)}
|
|
1220
|
+
${PROJECT_FILTER}${FILENAME_PATTERN}${TESTNAME_PATTERN}`
|
|
1221
|
+
);
|
|
1028
1222
|
}
|
|
1029
1223
|
this._timeStart = /* @__PURE__ */ new Date();
|
|
1030
1224
|
this.start = performance.now();
|
|
1031
1225
|
}
|
|
1032
1226
|
onUserConsoleLog(log) {
|
|
1033
|
-
if (!this.shouldLog(log))
|
|
1227
|
+
if (!this.shouldLog(log)) {
|
|
1034
1228
|
return;
|
|
1229
|
+
}
|
|
1035
1230
|
const task = log.taskId ? this.ctx.state.idMap.get(log.taskId) : void 0;
|
|
1036
|
-
const header = c.gray(
|
|
1231
|
+
const header = c.gray(
|
|
1232
|
+
log.type + c.dim(
|
|
1233
|
+
` | ${task ? getFullName(task, c.dim(" > ")) : log.taskId !== UNKNOWN_TEST_ID ? log.taskId : "unknown test"}`
|
|
1234
|
+
)
|
|
1235
|
+
);
|
|
1037
1236
|
const output = log.type === "stdout" ? this.ctx.logger.outputStream : this.ctx.logger.errorStream;
|
|
1038
|
-
output.write(
|
|
1039
|
-
|
|
1040
|
-
`);
|
|
1237
|
+
const write = (msg) => output.write(msg);
|
|
1238
|
+
write(`${header}
|
|
1239
|
+
${log.content}`);
|
|
1240
|
+
if (log.origin) {
|
|
1241
|
+
if (log.browser) {
|
|
1242
|
+
write("\n");
|
|
1243
|
+
}
|
|
1244
|
+
const project = log.taskId ? this.ctx.getProjectByTaskId(log.taskId) : this.ctx.getCoreWorkspaceProject();
|
|
1245
|
+
const stack = parseStacktrace(log.origin, {
|
|
1246
|
+
getSourceMap: (file) => project.getBrowserSourceMapModuleById(file),
|
|
1247
|
+
frameFilter: project.config.onStackTrace
|
|
1248
|
+
});
|
|
1249
|
+
const highlight = task ? stack.find((i) => i.file === task.file.filepath) : null;
|
|
1250
|
+
for (const frame of stack) {
|
|
1251
|
+
const color = frame === highlight ? c.cyan : c.gray;
|
|
1252
|
+
const path = relative(project.config.root, frame.file);
|
|
1253
|
+
write(
|
|
1254
|
+
color(
|
|
1255
|
+
` ${c.dim(F_POINTER)} ${[
|
|
1256
|
+
frame.method,
|
|
1257
|
+
`${path}:${c.dim(`${frame.line}:${frame.column}`)}`
|
|
1258
|
+
].filter(Boolean).join(" ")}
|
|
1259
|
+
`
|
|
1260
|
+
)
|
|
1261
|
+
);
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
write("\n");
|
|
1041
1265
|
}
|
|
1042
1266
|
shouldLog(log) {
|
|
1043
|
-
var
|
|
1044
|
-
if (this.ctx.config.silent)
|
|
1267
|
+
var _a, _b;
|
|
1268
|
+
if (this.ctx.config.silent) {
|
|
1045
1269
|
return false;
|
|
1046
|
-
|
|
1047
|
-
|
|
1270
|
+
}
|
|
1271
|
+
const shouldLog = (_b = (_a = this.ctx.config).onConsoleLog) == null ? void 0 : _b.call(_a, log.content, log.type);
|
|
1272
|
+
if (shouldLog === false) {
|
|
1048
1273
|
return shouldLog;
|
|
1274
|
+
}
|
|
1049
1275
|
return true;
|
|
1050
1276
|
}
|
|
1051
1277
|
onServerRestart(reason) {
|
|
1052
|
-
this.ctx.logger.log(
|
|
1053
|
-
|
|
1054
|
-
|
|
1278
|
+
this.ctx.logger.log(
|
|
1279
|
+
c.bold(
|
|
1280
|
+
c.magenta(
|
|
1281
|
+
reason === "config" ? "\nRestarting due to config changes..." : "\nRestarting Vitest..."
|
|
1282
|
+
)
|
|
1283
|
+
)
|
|
1284
|
+
);
|
|
1055
1285
|
}
|
|
1056
1286
|
reportSummary(files, errors) {
|
|
1057
1287
|
this.printErrorsSummary(files, errors);
|
|
1058
|
-
if (this.mode === "benchmark")
|
|
1288
|
+
if (this.mode === "benchmark") {
|
|
1059
1289
|
this.reportBenchmarkSummary(files);
|
|
1060
|
-
else
|
|
1290
|
+
} else {
|
|
1061
1291
|
this.reportTestSummary(files, errors);
|
|
1292
|
+
}
|
|
1062
1293
|
}
|
|
1063
1294
|
reportTestSummary(files, errors) {
|
|
1064
1295
|
const tests = getTests(files);
|
|
1065
1296
|
const logger = this.ctx.logger;
|
|
1066
1297
|
const executionTime = this.end - this.start;
|
|
1067
|
-
const collectTime = files.reduce(
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1298
|
+
const collectTime = files.reduce(
|
|
1299
|
+
(acc, test) => acc + Math.max(0, test.collectDuration || 0),
|
|
1300
|
+
0
|
|
1301
|
+
);
|
|
1302
|
+
const setupTime = files.reduce(
|
|
1303
|
+
(acc, test) => acc + Math.max(0, test.setupDuration || 0),
|
|
1304
|
+
0
|
|
1305
|
+
);
|
|
1306
|
+
const testsTime = files.reduce(
|
|
1307
|
+
(acc, test) => {
|
|
1308
|
+
var _a;
|
|
1309
|
+
return acc + Math.max(0, ((_a = test.result) == null ? void 0 : _a.duration) || 0);
|
|
1310
|
+
},
|
|
1311
|
+
0
|
|
1312
|
+
);
|
|
1073
1313
|
const transformTime = this.ctx.projects.flatMap((w) => w.vitenode.getTotalDuration()).reduce((a, b) => a + b, 0);
|
|
1074
|
-
const environmentTime = files.reduce(
|
|
1075
|
-
|
|
1314
|
+
const environmentTime = files.reduce(
|
|
1315
|
+
(acc, file) => acc + Math.max(0, file.environmentLoad || 0),
|
|
1316
|
+
0
|
|
1317
|
+
);
|
|
1318
|
+
const prepareTime = files.reduce(
|
|
1319
|
+
(acc, file) => acc + Math.max(0, file.prepareDuration || 0),
|
|
1320
|
+
0
|
|
1321
|
+
);
|
|
1076
1322
|
const threadTime = collectTime + testsTime + setupTime;
|
|
1077
1323
|
const padTitle = (str) => c.dim(`${str.padStart(11)} `);
|
|
1078
1324
|
const time = (time2) => {
|
|
1079
|
-
if (time2 > 1e3)
|
|
1325
|
+
if (time2 > 1e3) {
|
|
1080
1326
|
return `${(time2 / 1e3).toFixed(2)}s`;
|
|
1327
|
+
}
|
|
1081
1328
|
return `${Math.round(time2)}ms`;
|
|
1082
1329
|
};
|
|
1083
|
-
const snapshotOutput = renderSnapshotSummary(
|
|
1330
|
+
const snapshotOutput = renderSnapshotSummary(
|
|
1331
|
+
this.ctx.config.root,
|
|
1332
|
+
this.ctx.snapshot.summary
|
|
1333
|
+
);
|
|
1084
1334
|
if (snapshotOutput.length) {
|
|
1085
|
-
logger.log(
|
|
1086
|
-
(
|
|
1087
|
-
|
|
1088
|
-
|
|
1335
|
+
logger.log(
|
|
1336
|
+
snapshotOutput.map(
|
|
1337
|
+
(t, i) => i === 0 ? `${padTitle("Snapshots")} ${t}` : `${padTitle("")} ${t}`
|
|
1338
|
+
).join("\n")
|
|
1339
|
+
);
|
|
1340
|
+
if (snapshotOutput.length > 1) {
|
|
1089
1341
|
logger.log();
|
|
1342
|
+
}
|
|
1090
1343
|
}
|
|
1091
1344
|
logger.log(padTitle("Test Files"), getStateString(files));
|
|
1092
1345
|
logger.log(padTitle("Tests"), getStateString(tests));
|
|
1093
1346
|
if (this.ctx.projects.some((c2) => c2.config.typecheck.enabled)) {
|
|
1094
|
-
const failed = tests.filter(
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1347
|
+
const failed = tests.filter(
|
|
1348
|
+
(t) => {
|
|
1349
|
+
var _a, _b, _c;
|
|
1350
|
+
return ((_a = t.meta) == null ? void 0 : _a.typecheck) && ((_c = (_b = t.result) == null ? void 0 : _b.errors) == null ? void 0 : _c.length);
|
|
1351
|
+
}
|
|
1352
|
+
);
|
|
1353
|
+
logger.log(
|
|
1354
|
+
padTitle("Type Errors"),
|
|
1355
|
+
failed.length ? c.bold(c.red(`${failed.length} failed`)) : c.dim("no errors")
|
|
1356
|
+
);
|
|
1357
|
+
}
|
|
1358
|
+
if (errors.length) {
|
|
1359
|
+
logger.log(
|
|
1360
|
+
padTitle("Errors"),
|
|
1361
|
+
c.bold(c.red(`${errors.length} error${errors.length > 1 ? "s" : ""}`))
|
|
1362
|
+
);
|
|
1099
1363
|
}
|
|
1100
|
-
if (errors.length)
|
|
1101
|
-
logger.log(padTitle("Errors"), c.bold(c.red(`${errors.length} error${errors.length > 1 ? "s" : ""}`)));
|
|
1102
1364
|
logger.log(padTitle("Start at"), formatTimeString(this._timeStart));
|
|
1103
1365
|
if (this.watchFilters) {
|
|
1104
1366
|
logger.log(padTitle("Duration"), time(threadTime));
|
|
1105
1367
|
} else {
|
|
1106
|
-
let timers = `transform ${time(transformTime)}, setup ${time(
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
},
|
|
1111
|
-
|
|
1368
|
+
let timers = `transform ${time(transformTime)}, setup ${time(
|
|
1369
|
+
setupTime
|
|
1370
|
+
)}, collect ${time(collectTime)}, tests ${time(
|
|
1371
|
+
testsTime
|
|
1372
|
+
)}, environment ${time(environmentTime)}, prepare ${time(prepareTime)}`;
|
|
1373
|
+
const typecheck = this.ctx.projects.reduce(
|
|
1374
|
+
(acc, c2) => {
|
|
1375
|
+
var _a;
|
|
1376
|
+
return acc + (((_a = c2.typechecker) == null ? void 0 : _a.getResult().time) || 0);
|
|
1377
|
+
},
|
|
1378
|
+
0
|
|
1379
|
+
);
|
|
1380
|
+
if (typecheck) {
|
|
1112
1381
|
timers += `, typecheck ${time(typecheck)}`;
|
|
1113
|
-
|
|
1382
|
+
}
|
|
1383
|
+
logger.log(
|
|
1384
|
+
padTitle("Duration"),
|
|
1385
|
+
time(executionTime) + c.dim(` (${timers})`)
|
|
1386
|
+
);
|
|
1114
1387
|
}
|
|
1115
1388
|
logger.log();
|
|
1116
1389
|
}
|
|
@@ -1119,24 +1392,36 @@ ${log.content}
|
|
|
1119
1392
|
const suites = getSuites(files);
|
|
1120
1393
|
const tests = getTests(files);
|
|
1121
1394
|
const failedSuites = suites.filter((i) => {
|
|
1122
|
-
var
|
|
1123
|
-
return (
|
|
1395
|
+
var _a;
|
|
1396
|
+
return (_a = i.result) == null ? void 0 : _a.errors;
|
|
1124
1397
|
});
|
|
1125
1398
|
const failedTests = tests.filter((i) => {
|
|
1126
|
-
var
|
|
1127
|
-
return ((
|
|
1399
|
+
var _a;
|
|
1400
|
+
return ((_a = i.result) == null ? void 0 : _a.state) === "fail";
|
|
1128
1401
|
});
|
|
1129
1402
|
const failedTotal = countTestErrors(failedSuites) + countTestErrors(failedTests);
|
|
1130
1403
|
let current = 1;
|
|
1131
|
-
const errorDivider = () => logger.error(
|
|
1132
|
-
|
|
1404
|
+
const errorDivider = () => logger.error(
|
|
1405
|
+
`${c.red(
|
|
1406
|
+
c.dim(divider(`[${current++}/${failedTotal}]`, void 0, 1))
|
|
1407
|
+
)}
|
|
1408
|
+
`
|
|
1409
|
+
);
|
|
1133
1410
|
if (failedSuites.length) {
|
|
1134
|
-
logger.error(
|
|
1411
|
+
logger.error(
|
|
1412
|
+
c.red(
|
|
1413
|
+
divider(c.bold(c.inverse(` Failed Suites ${failedSuites.length} `)))
|
|
1414
|
+
)
|
|
1415
|
+
);
|
|
1135
1416
|
logger.error();
|
|
1136
1417
|
this.printTaskErrors(failedSuites, errorDivider);
|
|
1137
1418
|
}
|
|
1138
1419
|
if (failedTests.length) {
|
|
1139
|
-
logger.error(
|
|
1420
|
+
logger.error(
|
|
1421
|
+
c.red(
|
|
1422
|
+
divider(c.bold(c.inverse(` Failed Tests ${failedTests.length} `)))
|
|
1423
|
+
)
|
|
1424
|
+
);
|
|
1140
1425
|
logger.error();
|
|
1141
1426
|
this.printTaskErrors(failedTests, errorDivider);
|
|
1142
1427
|
}
|
|
@@ -1150,21 +1435,24 @@ ${log.content}
|
|
|
1150
1435
|
const logger = this.ctx.logger;
|
|
1151
1436
|
const benches = getTests(files);
|
|
1152
1437
|
const topBenches = benches.filter((i) => {
|
|
1153
|
-
var
|
|
1154
|
-
return ((_b = (
|
|
1438
|
+
var _a, _b;
|
|
1439
|
+
return ((_b = (_a = i.result) == null ? void 0 : _a.benchmark) == null ? void 0 : _b.rank) === 1;
|
|
1155
1440
|
});
|
|
1156
|
-
logger.log(
|
|
1441
|
+
logger.log(
|
|
1442
|
+
`
|
|
1157
1443
|
${c.cyan(c.inverse(c.bold(" BENCH ")))} ${c.cyan("Summary")}
|
|
1158
|
-
`
|
|
1444
|
+
`
|
|
1445
|
+
);
|
|
1159
1446
|
for (const bench of topBenches) {
|
|
1160
1447
|
const group = bench.suite || bench.file;
|
|
1161
|
-
if (!group)
|
|
1448
|
+
if (!group) {
|
|
1162
1449
|
continue;
|
|
1450
|
+
}
|
|
1163
1451
|
const groupName = getFullName(group, c.dim(" > "));
|
|
1164
1452
|
logger.log(` ${bench.name}${c.dim(` - ${groupName}`)}`);
|
|
1165
1453
|
const siblings = group.tasks.filter((i) => {
|
|
1166
|
-
var
|
|
1167
|
-
return i.meta.benchmark && ((
|
|
1454
|
+
var _a;
|
|
1455
|
+
return i.meta.benchmark && ((_a = i.result) == null ? void 0 : _a.benchmark) && i !== bench;
|
|
1168
1456
|
}).sort((a, b) => a.result.benchmark.rank - b.result.benchmark.rank);
|
|
1169
1457
|
if (siblings.length === 0) {
|
|
1170
1458
|
logger.log("");
|
|
@@ -1172,49 +1460,61 @@ ${c.cyan(c.inverse(c.bold(" BENCH ")))} ${c.cyan("Summary")}
|
|
|
1172
1460
|
}
|
|
1173
1461
|
for (const sibling of siblings) {
|
|
1174
1462
|
const number = `${(sibling.result.benchmark.mean / bench.result.benchmark.mean).toFixed(2)}x`;
|
|
1175
|
-
logger.log(
|
|
1463
|
+
logger.log(
|
|
1464
|
+
` ${c.green(number)} ${c.gray("faster than")} ${sibling.name}`
|
|
1465
|
+
);
|
|
1176
1466
|
}
|
|
1177
1467
|
logger.log("");
|
|
1178
1468
|
}
|
|
1179
1469
|
}
|
|
1180
1470
|
printTaskErrors(tasks, errorDivider) {
|
|
1181
|
-
var
|
|
1471
|
+
var _a, _b, _c;
|
|
1182
1472
|
const errorsQueue = [];
|
|
1183
1473
|
for (const task of tasks) {
|
|
1184
|
-
(_b = (
|
|
1474
|
+
(_b = (_a = task.result) == null ? void 0 : _a.errors) == null ? void 0 : _b.forEach((error) => {
|
|
1185
1475
|
const errorItem = (error == null ? void 0 : error.stackStr) && errorsQueue.find((i) => {
|
|
1186
|
-
var
|
|
1187
|
-
const hasStr = ((
|
|
1188
|
-
if (!hasStr)
|
|
1476
|
+
var _a2, _b2, _c2, _d;
|
|
1477
|
+
const hasStr = ((_a2 = i[0]) == null ? void 0 : _a2.stackStr) === error.stackStr;
|
|
1478
|
+
if (!hasStr) {
|
|
1189
1479
|
return false;
|
|
1190
|
-
|
|
1191
|
-
const
|
|
1480
|
+
}
|
|
1481
|
+
const currentProjectName = (task == null ? void 0 : task.projectName) || ((_b2 = task.file) == null ? void 0 : _b2.projectName) || "";
|
|
1482
|
+
const projectName = ((_c2 = i[1][0]) == null ? void 0 : _c2.projectName) || ((_d = i[1][0].file) == null ? void 0 : _d.projectName) || "";
|
|
1192
1483
|
return projectName === currentProjectName;
|
|
1193
1484
|
});
|
|
1194
|
-
if (errorItem)
|
|
1485
|
+
if (errorItem) {
|
|
1195
1486
|
errorItem[1].push(task);
|
|
1196
|
-
else
|
|
1487
|
+
} else {
|
|
1197
1488
|
errorsQueue.push([error, [task]]);
|
|
1489
|
+
}
|
|
1198
1490
|
});
|
|
1199
1491
|
}
|
|
1200
1492
|
for (const [error, tasks2] of errorsQueue) {
|
|
1201
1493
|
for (const task of tasks2) {
|
|
1202
1494
|
const filepath = (task == null ? void 0 : task.filepath) || "";
|
|
1203
|
-
const projectName = (task == null ? void 0 : task.projectName) || ((_c = task.file) == null ? void 0 : _c.projectName);
|
|
1495
|
+
const projectName = (task == null ? void 0 : task.projectName) || ((_c = task.file) == null ? void 0 : _c.projectName) || "";
|
|
1204
1496
|
let name = getFullName(task, c.dim(" > "));
|
|
1205
|
-
if (filepath)
|
|
1497
|
+
if (filepath) {
|
|
1206
1498
|
name = `${name} ${c.dim(`[ ${this.relative(filepath)} ]`)}`;
|
|
1207
|
-
|
|
1499
|
+
}
|
|
1500
|
+
this.ctx.logger.error(
|
|
1501
|
+
`${c.red(c.bold(c.inverse(" FAIL ")))} ${formatProjectName(
|
|
1502
|
+
projectName
|
|
1503
|
+
)}${name}`
|
|
1504
|
+
);
|
|
1208
1505
|
}
|
|
1209
1506
|
const project = this.ctx.getProjectByTaskId(tasks2[0].id);
|
|
1210
|
-
this.ctx.logger.printError(error, { project });
|
|
1507
|
+
this.ctx.logger.printError(error, { project, verbose: this.verbose });
|
|
1211
1508
|
errorDivider();
|
|
1212
1509
|
}
|
|
1213
1510
|
}
|
|
1214
1511
|
registerUnhandledRejection() {
|
|
1215
1512
|
const onUnhandledRejection = async (err) => {
|
|
1216
1513
|
process.exitCode = 1;
|
|
1217
|
-
this.ctx.logger.printError(err, {
|
|
1514
|
+
this.ctx.logger.printError(err, {
|
|
1515
|
+
fullStack: true,
|
|
1516
|
+
type: "Unhandled Rejection"
|
|
1517
|
+
});
|
|
1218
1518
|
this.ctx.logger.error("\n\n");
|
|
1219
1519
|
process.exit(1);
|
|
1220
1520
|
};
|
|
@@ -2133,20 +2433,24 @@ function formatFilepath$1(path) {
|
|
|
2133
2433
|
const lastSlash = Math.max(path.lastIndexOf("/") + 1, 0);
|
|
2134
2434
|
const basename = path.slice(lastSlash);
|
|
2135
2435
|
let firstDot = basename.indexOf(".");
|
|
2136
|
-
if (firstDot < 0)
|
|
2436
|
+
if (firstDot < 0) {
|
|
2137
2437
|
firstDot = basename.length;
|
|
2438
|
+
}
|
|
2138
2439
|
firstDot += lastSlash;
|
|
2139
2440
|
return c.dim(path.slice(0, lastSlash)) + path.slice(lastSlash, firstDot) + c.dim(path.slice(firstDot));
|
|
2140
2441
|
}
|
|
2141
2442
|
function formatNumber$1(number) {
|
|
2142
2443
|
const res = String(number.toFixed(number < 100 ? 4 : 2)).split(".");
|
|
2143
|
-
return res[0].replace(/(?=(?:\d{3})+$)
|
|
2444
|
+
return res[0].replace(/(?=(?:\d{3})+$)\B/g, ",") + (res[1] ? `.${res[1]}` : "");
|
|
2144
2445
|
}
|
|
2145
2446
|
function renderHookState(task, hookName, level = 0) {
|
|
2146
2447
|
var _a, _b;
|
|
2147
2448
|
const state = (_b = (_a = task.result) == null ? void 0 : _a.hooks) == null ? void 0 : _b[hookName];
|
|
2148
|
-
if (state && state === "run")
|
|
2149
|
-
return `${" ".repeat(level)} ${getHookStateSymbol(task, hookName)} ${c.dim(
|
|
2449
|
+
if (state && state === "run") {
|
|
2450
|
+
return `${" ".repeat(level)} ${getHookStateSymbol(task, hookName)} ${c.dim(
|
|
2451
|
+
`[ ${hookName} ]`
|
|
2452
|
+
)}`;
|
|
2453
|
+
}
|
|
2150
2454
|
return "";
|
|
2151
2455
|
}
|
|
2152
2456
|
function renderBenchmarkItems$1(result) {
|
|
@@ -2161,8 +2465,9 @@ function renderBenchmarkItems$1(result) {
|
|
|
2161
2465
|
function renderBenchmark$1(task, tasks) {
|
|
2162
2466
|
var _a;
|
|
2163
2467
|
const result = (_a = task.result) == null ? void 0 : _a.benchmark;
|
|
2164
|
-
if (!result)
|
|
2468
|
+
if (!result) {
|
|
2165
2469
|
return task.name;
|
|
2470
|
+
}
|
|
2166
2471
|
const benches = tasks.map((i) => {
|
|
2167
2472
|
var _a2, _b;
|
|
2168
2473
|
return ((_a2 = i.meta) == null ? void 0 : _a2.benchmark) ? (_b = i.result) == null ? void 0 : _b.benchmark : void 0;
|
|
@@ -2192,27 +2497,38 @@ function renderTree$1(tasks, options, level = 0, maxRows) {
|
|
|
2192
2497
|
const taskOutput = [];
|
|
2193
2498
|
let suffix = "";
|
|
2194
2499
|
let prefix = ` ${getStateSymbol(task)} `;
|
|
2195
|
-
if (level === 0 && task.type === "suite" && "projectName" in task)
|
|
2500
|
+
if (level === 0 && task.type === "suite" && "projectName" in task) {
|
|
2196
2501
|
prefix += formatProjectName(task.projectName);
|
|
2197
|
-
|
|
2502
|
+
}
|
|
2503
|
+
if (task.type === "test" && ((_a = task.result) == null ? void 0 : _a.retryCount) && task.result.retryCount > 0) {
|
|
2198
2504
|
suffix += c.yellow(` (retry x${task.result.retryCount})`);
|
|
2505
|
+
}
|
|
2199
2506
|
if (task.type === "suite") {
|
|
2200
2507
|
const tests = getTests(task);
|
|
2201
2508
|
suffix += c.dim(` (${tests.length})`);
|
|
2202
2509
|
}
|
|
2203
|
-
if (task.mode === "skip" || task.mode === "todo")
|
|
2510
|
+
if (task.mode === "skip" || task.mode === "todo") {
|
|
2204
2511
|
suffix += ` ${c.dim(c.gray("[skipped]"))}`;
|
|
2205
|
-
|
|
2512
|
+
}
|
|
2513
|
+
if (task.type === "test" && ((_b = task.result) == null ? void 0 : _b.repeatCount) && task.result.repeatCount > 0) {
|
|
2206
2514
|
suffix += c.yellow(` (repeat x${task.result.repeatCount})`);
|
|
2515
|
+
}
|
|
2207
2516
|
if (((_c = task.result) == null ? void 0 : _c.duration) != null) {
|
|
2208
|
-
if (task.result.duration > options.slowTestThreshold)
|
|
2209
|
-
suffix += c.yellow(
|
|
2517
|
+
if (task.result.duration > options.slowTestThreshold) {
|
|
2518
|
+
suffix += c.yellow(
|
|
2519
|
+
` ${Math.round(task.result.duration)}${c.dim("ms")}`
|
|
2520
|
+
);
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
if (options.showHeap && ((_d = task.result) == null ? void 0 : _d.heap) != null) {
|
|
2524
|
+
suffix += c.magenta(
|
|
2525
|
+
` ${Math.floor(task.result.heap / 1024 / 1024)} MB heap used`
|
|
2526
|
+
);
|
|
2210
2527
|
}
|
|
2211
|
-
if (options.showHeap && ((_d = task.result) == null ? void 0 : _d.heap) != null)
|
|
2212
|
-
suffix += c.magenta(` ${Math.floor(task.result.heap / 1024 / 1024)} MB heap used`);
|
|
2213
2528
|
let name = task.name;
|
|
2214
|
-
if (level === 0)
|
|
2529
|
+
if (level === 0) {
|
|
2215
2530
|
name = formatFilepath$1(name);
|
|
2531
|
+
}
|
|
2216
2532
|
const padding = " ".repeat(level);
|
|
2217
2533
|
const body = ((_e = task.meta) == null ? void 0 : _e.benchmark) ? renderBenchmark$1(task, tasks) : name;
|
|
2218
2534
|
taskOutput.push(padding + prefix + body + suffix);
|
|
@@ -2220,8 +2536,9 @@ function renderTree$1(tasks, options, level = 0, maxRows) {
|
|
|
2220
2536
|
let data = outputMap$1.get(task);
|
|
2221
2537
|
if (typeof data === "string") {
|
|
2222
2538
|
data = stripAnsi(data.trim().split("\n").filter(Boolean).pop());
|
|
2223
|
-
if (data === "")
|
|
2539
|
+
if (data === "") {
|
|
2224
2540
|
data = void 0;
|
|
2541
|
+
}
|
|
2225
2542
|
}
|
|
2226
2543
|
if (data != null) {
|
|
2227
2544
|
const out = `${" ".repeat(level)}${F_RIGHT} ${data}`;
|
|
@@ -2233,8 +2550,12 @@ function renderTree$1(tasks, options, level = 0, maxRows) {
|
|
|
2233
2550
|
if (task.type === "suite" && task.tasks.length > 0) {
|
|
2234
2551
|
if (((_g = task.result) == null ? void 0 : _g.state) === "fail" || ((_h = task.result) == null ? void 0 : _h.state) === "run" || options.renderSucceed) {
|
|
2235
2552
|
if (options.logger.ctx.config.hideSkippedTests) {
|
|
2236
|
-
const filteredTasks = task.tasks.filter(
|
|
2237
|
-
|
|
2553
|
+
const filteredTasks = task.tasks.filter(
|
|
2554
|
+
(t) => t.mode !== "skip" && t.mode !== "todo"
|
|
2555
|
+
);
|
|
2556
|
+
taskOutput.push(
|
|
2557
|
+
renderTree$1(filteredTasks, options, level + 1, maxRows)
|
|
2558
|
+
);
|
|
2238
2559
|
} else {
|
|
2239
2560
|
taskOutput.push(renderTree$1(task.tasks, options, level + 1, maxRows));
|
|
2240
2561
|
}
|
|
@@ -2245,8 +2566,9 @@ function renderTree$1(tasks, options, level = 0, maxRows) {
|
|
|
2245
2566
|
const rows = taskOutput.filter(Boolean);
|
|
2246
2567
|
output.push(rows.join("\n"));
|
|
2247
2568
|
currentRowCount += rows.length;
|
|
2248
|
-
if (maxRows && currentRowCount >= maxRows)
|
|
2569
|
+
if (maxRows && currentRowCount >= maxRows) {
|
|
2249
2570
|
break;
|
|
2571
|
+
}
|
|
2250
2572
|
}
|
|
2251
2573
|
return output.reverse().join("\n");
|
|
2252
2574
|
}
|
|
@@ -2256,30 +2578,37 @@ function createListRenderer(_tasks, options) {
|
|
|
2256
2578
|
const log = options.logger.logUpdate;
|
|
2257
2579
|
function update() {
|
|
2258
2580
|
if (options.logger.ctx.config.hideSkippedTests) {
|
|
2259
|
-
const filteredTasks = tasks.filter(
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2581
|
+
const filteredTasks = tasks.filter(
|
|
2582
|
+
(t) => t.mode !== "skip" && t.mode !== "todo"
|
|
2583
|
+
);
|
|
2584
|
+
log(
|
|
2585
|
+
renderTree$1(
|
|
2586
|
+
filteredTasks,
|
|
2587
|
+
options,
|
|
2588
|
+
0,
|
|
2589
|
+
// log-update already limits the amount of printed rows to fit the current terminal
|
|
2590
|
+
// but we can optimize performance by doing it ourselves
|
|
2591
|
+
process.stdout.rows
|
|
2592
|
+
)
|
|
2593
|
+
);
|
|
2268
2594
|
} else {
|
|
2269
|
-
log(
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2595
|
+
log(
|
|
2596
|
+
renderTree$1(
|
|
2597
|
+
tasks,
|
|
2598
|
+
options,
|
|
2599
|
+
0,
|
|
2600
|
+
// log-update already limits the amount of printed rows to fit the current terminal
|
|
2601
|
+
// but we can optimize performance by doing it ourselves
|
|
2602
|
+
process.stdout.rows
|
|
2603
|
+
)
|
|
2604
|
+
);
|
|
2277
2605
|
}
|
|
2278
2606
|
}
|
|
2279
2607
|
return {
|
|
2280
2608
|
start() {
|
|
2281
|
-
if (timer)
|
|
2609
|
+
if (timer) {
|
|
2282
2610
|
return this;
|
|
2611
|
+
}
|
|
2283
2612
|
timer = setInterval(update, 16);
|
|
2284
2613
|
return this;
|
|
2285
2614
|
},
|
|
@@ -2294,7 +2623,9 @@ function createListRenderer(_tasks, options) {
|
|
|
2294
2623
|
}
|
|
2295
2624
|
log.clear();
|
|
2296
2625
|
if (options.logger.ctx.config.hideSkippedTests) {
|
|
2297
|
-
const filteredTasks = tasks.filter(
|
|
2626
|
+
const filteredTasks = tasks.filter(
|
|
2627
|
+
(t) => t.mode !== "skip" && t.mode !== "todo"
|
|
2628
|
+
);
|
|
2298
2629
|
options.logger.log(renderTree$1(filteredTasks, options));
|
|
2299
2630
|
} else {
|
|
2300
2631
|
options.logger.log(renderTree$1(tasks, options));
|
|
@@ -2313,16 +2644,21 @@ class DefaultReporter extends BaseReporter {
|
|
|
2313
2644
|
renderSucceedDefault;
|
|
2314
2645
|
onPathsCollected(paths = []) {
|
|
2315
2646
|
if (this.isTTY) {
|
|
2316
|
-
if (this.renderSucceedDefault === void 0)
|
|
2647
|
+
if (this.renderSucceedDefault === void 0) {
|
|
2317
2648
|
this.renderSucceedDefault = !!this.rendererOptions.renderSucceed;
|
|
2318
|
-
|
|
2649
|
+
}
|
|
2650
|
+
if (this.renderSucceedDefault !== true) {
|
|
2319
2651
|
this.rendererOptions.renderSucceed = paths.length <= 1;
|
|
2652
|
+
}
|
|
2320
2653
|
}
|
|
2321
2654
|
}
|
|
2322
2655
|
async onTestRemoved(trigger) {
|
|
2323
2656
|
this.stopListRender();
|
|
2324
|
-
this.ctx.logger.clearScreen(
|
|
2325
|
-
|
|
2657
|
+
this.ctx.logger.clearScreen(
|
|
2658
|
+
c.yellow("Test removed...") + (trigger ? c.dim(` [ ${this.relative(trigger)} ]
|
|
2659
|
+
`) : ""),
|
|
2660
|
+
true
|
|
2661
|
+
);
|
|
2326
2662
|
const files = this.ctx.state.getFiles(this.watchFilters);
|
|
2327
2663
|
createListRenderer(files, this.rendererOptions).stop();
|
|
2328
2664
|
this.ctx.logger.log();
|
|
@@ -2336,10 +2672,11 @@ class DefaultReporter extends BaseReporter {
|
|
|
2336
2672
|
this.rendererOptions.slowTestThreshold = this.ctx.config.slowTestThreshold;
|
|
2337
2673
|
this.rendererOptions.mode = this.mode;
|
|
2338
2674
|
const files = this.ctx.state.getFiles(this.watchFilters);
|
|
2339
|
-
if (!this.renderer)
|
|
2675
|
+
if (!this.renderer) {
|
|
2340
2676
|
this.renderer = createListRenderer(files, this.rendererOptions).start();
|
|
2341
|
-
else
|
|
2677
|
+
} else {
|
|
2342
2678
|
this.renderer.update(files);
|
|
2679
|
+
}
|
|
2343
2680
|
}
|
|
2344
2681
|
}
|
|
2345
2682
|
onFinished(files = this.ctx.state.getFiles(), errors = this.ctx.state.getUnhandledErrors()) {
|
|
@@ -2362,8 +2699,9 @@ class DefaultReporter extends BaseReporter {
|
|
|
2362
2699
|
}
|
|
2363
2700
|
onUserConsoleLog(log) {
|
|
2364
2701
|
var _a;
|
|
2365
|
-
if (!this.shouldLog(log))
|
|
2702
|
+
if (!this.shouldLog(log)) {
|
|
2366
2703
|
return;
|
|
2704
|
+
}
|
|
2367
2705
|
(_a = this.renderer) == null ? void 0 : _a.clear();
|
|
2368
2706
|
super.onUserConsoleLog(log);
|
|
2369
2707
|
}
|
|
@@ -2375,8 +2713,9 @@ const pending = { char: "*", color: c.yellow };
|
|
|
2375
2713
|
const skip = { char: "-", color: (char) => c.dim(c.gray(char)) };
|
|
2376
2714
|
function getIcon(task) {
|
|
2377
2715
|
var _a;
|
|
2378
|
-
if (task.mode === "skip" || task.mode === "todo")
|
|
2716
|
+
if (task.mode === "skip" || task.mode === "todo") {
|
|
2379
2717
|
return skip;
|
|
2718
|
+
}
|
|
2380
2719
|
switch ((_a = task.result) == null ? void 0 : _a.state) {
|
|
2381
2720
|
case "pass":
|
|
2382
2721
|
return check;
|
|
@@ -2438,8 +2777,9 @@ function createDotRenderer(_tasks, options) {
|
|
|
2438
2777
|
}
|
|
2439
2778
|
return {
|
|
2440
2779
|
start() {
|
|
2441
|
-
if (timer)
|
|
2780
|
+
if (timer) {
|
|
2442
2781
|
return this;
|
|
2782
|
+
}
|
|
2443
2783
|
timer = setInterval(update, 16);
|
|
2444
2784
|
return this;
|
|
2445
2785
|
},
|
|
@@ -2467,10 +2807,13 @@ class DotReporter extends BaseReporter {
|
|
|
2467
2807
|
onCollected() {
|
|
2468
2808
|
if (this.isTTY) {
|
|
2469
2809
|
const files = this.ctx.state.getFiles(this.watchFilters);
|
|
2470
|
-
if (!this.renderer)
|
|
2471
|
-
this.renderer = createDotRenderer(files, {
|
|
2472
|
-
|
|
2810
|
+
if (!this.renderer) {
|
|
2811
|
+
this.renderer = createDotRenderer(files, {
|
|
2812
|
+
logger: this.ctx.logger
|
|
2813
|
+
}).start();
|
|
2814
|
+
} else {
|
|
2473
2815
|
this.renderer.update(files);
|
|
2816
|
+
}
|
|
2474
2817
|
}
|
|
2475
2818
|
}
|
|
2476
2819
|
async onFinished(files = this.ctx.state.getFiles(), errors = this.ctx.state.getUnhandledErrors()) {
|
|
@@ -2529,34 +2872,50 @@ class JsonReporter {
|
|
|
2529
2872
|
return (_a2 = s.result) == null ? void 0 : _a2.errors;
|
|
2530
2873
|
}).length;
|
|
2531
2874
|
const numPassedTestSuites = numTotalTestSuites - numFailedTestSuites;
|
|
2532
|
-
const numPendingTestSuites = suites.filter(
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2875
|
+
const numPendingTestSuites = suites.filter(
|
|
2876
|
+
(s) => {
|
|
2877
|
+
var _a2;
|
|
2878
|
+
return ((_a2 = s.result) == null ? void 0 : _a2.state) === "run";
|
|
2879
|
+
}
|
|
2880
|
+
).length;
|
|
2881
|
+
const numFailedTests = tests.filter(
|
|
2882
|
+
(t) => {
|
|
2883
|
+
var _a2;
|
|
2884
|
+
return ((_a2 = t.result) == null ? void 0 : _a2.state) === "fail";
|
|
2885
|
+
}
|
|
2886
|
+
).length;
|
|
2540
2887
|
const numPassedTests = numTotalTests - numFailedTests;
|
|
2541
|
-
const numPendingTests = tests.filter(
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2888
|
+
const numPendingTests = tests.filter(
|
|
2889
|
+
(t) => {
|
|
2890
|
+
var _a2;
|
|
2891
|
+
return ((_a2 = t.result) == null ? void 0 : _a2.state) === "run";
|
|
2892
|
+
}
|
|
2893
|
+
).length;
|
|
2545
2894
|
const numTodoTests = tests.filter((t) => t.mode === "todo").length;
|
|
2546
2895
|
const testResults = [];
|
|
2547
2896
|
const success = numFailedTestSuites === 0 && numFailedTests === 0;
|
|
2548
2897
|
for (const file of files) {
|
|
2549
2898
|
const tests2 = getTests([file]);
|
|
2550
|
-
let startTime = tests2.reduce(
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2899
|
+
let startTime = tests2.reduce(
|
|
2900
|
+
(prev, next) => {
|
|
2901
|
+
var _a2;
|
|
2902
|
+
return Math.min(prev, ((_a2 = next.result) == null ? void 0 : _a2.startTime) ?? Number.POSITIVE_INFINITY);
|
|
2903
|
+
},
|
|
2904
|
+
Number.POSITIVE_INFINITY
|
|
2905
|
+
);
|
|
2906
|
+
if (startTime === Number.POSITIVE_INFINITY) {
|
|
2555
2907
|
startTime = this.start;
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2908
|
+
}
|
|
2909
|
+
const endTime = tests2.reduce(
|
|
2910
|
+
(prev, next) => {
|
|
2911
|
+
var _a2, _b2;
|
|
2912
|
+
return Math.max(
|
|
2913
|
+
prev,
|
|
2914
|
+
(((_a2 = next.result) == null ? void 0 : _a2.startTime) ?? 0) + (((_b2 = next.result) == null ? void 0 : _b2.duration) ?? 0)
|
|
2915
|
+
);
|
|
2916
|
+
},
|
|
2917
|
+
startTime
|
|
2918
|
+
);
|
|
2560
2919
|
const assertionResults = tests2.map((t) => {
|
|
2561
2920
|
var _a2, _b2, _c2, _d2;
|
|
2562
2921
|
const ancestorTitles = [];
|
|
@@ -2573,14 +2932,17 @@ class JsonReporter {
|
|
|
2573
2932
|
title: t.name,
|
|
2574
2933
|
duration: (_b2 = t.result) == null ? void 0 : _b2.duration,
|
|
2575
2934
|
failureMessages: ((_d2 = (_c2 = t.result) == null ? void 0 : _c2.errors) == null ? void 0 : _d2.map((e) => e.stack || e.message)) || [],
|
|
2576
|
-
location: t.location
|
|
2935
|
+
location: t.location,
|
|
2936
|
+
meta: t.meta
|
|
2577
2937
|
};
|
|
2578
2938
|
});
|
|
2579
2939
|
if (tests2.some((t) => {
|
|
2580
2940
|
var _a2;
|
|
2581
2941
|
return ((_a2 = t.result) == null ? void 0 : _a2.state) === "run";
|
|
2582
2942
|
})) {
|
|
2583
|
-
this.ctx.logger.warn(
|
|
2943
|
+
this.ctx.logger.warn(
|
|
2944
|
+
"WARNING: Some tests are still running when generating the JSON report.This is likely an internal bug in Vitest.Please report it to https://github.com/vitest-dev/vitest/issues"
|
|
2945
|
+
);
|
|
2584
2946
|
}
|
|
2585
2947
|
const hasFailedTests = tests2.some((t) => {
|
|
2586
2948
|
var _a2;
|
|
@@ -2625,8 +2987,9 @@ class JsonReporter {
|
|
|
2625
2987
|
if (outputFile) {
|
|
2626
2988
|
const reportFile = resolve(this.ctx.config.root, outputFile);
|
|
2627
2989
|
const outputDirectory = dirname(reportFile);
|
|
2628
|
-
if (!existsSync(outputDirectory))
|
|
2990
|
+
if (!existsSync(outputDirectory)) {
|
|
2629
2991
|
await promises.mkdir(outputDirectory, { recursive: true });
|
|
2992
|
+
}
|
|
2630
2993
|
await promises.writeFile(reportFile, report, "utf-8");
|
|
2631
2994
|
this.ctx.logger.log(`JSON report written to ${reportFile}`);
|
|
2632
2995
|
} else {
|
|
@@ -2636,25 +2999,34 @@ class JsonReporter {
|
|
|
2636
2999
|
}
|
|
2637
3000
|
|
|
2638
3001
|
class VerboseReporter extends DefaultReporter {
|
|
3002
|
+
verbose = true;
|
|
2639
3003
|
constructor() {
|
|
2640
3004
|
super();
|
|
2641
3005
|
this.rendererOptions.renderSucceed = true;
|
|
2642
3006
|
}
|
|
2643
3007
|
onTaskUpdate(packs) {
|
|
2644
3008
|
var _a, _b, _c;
|
|
2645
|
-
if (this.isTTY)
|
|
3009
|
+
if (this.isTTY) {
|
|
2646
3010
|
return;
|
|
3011
|
+
}
|
|
2647
3012
|
for (const pack of packs) {
|
|
2648
3013
|
const task = this.ctx.state.idMap.get(pack[0]);
|
|
2649
3014
|
if (task && task.type === "test" && ((_a = task.result) == null ? void 0 : _a.state) && ((_b = task.result) == null ? void 0 : _b.state) !== "run") {
|
|
2650
3015
|
let title = ` ${getStateSymbol(task)} `;
|
|
2651
|
-
if (task.file.projectName)
|
|
3016
|
+
if (task.file.projectName) {
|
|
2652
3017
|
title += formatProjectName(task.file.projectName);
|
|
3018
|
+
}
|
|
2653
3019
|
title += getFullName(task, c.dim(" > "));
|
|
2654
|
-
if (task.result.duration != null && task.result.duration > this.ctx.config.slowTestThreshold)
|
|
2655
|
-
title += c.yellow(
|
|
2656
|
-
|
|
2657
|
-
|
|
3020
|
+
if (task.result.duration != null && task.result.duration > this.ctx.config.slowTestThreshold) {
|
|
3021
|
+
title += c.yellow(
|
|
3022
|
+
` ${Math.round(task.result.duration)}${c.dim("ms")}`
|
|
3023
|
+
);
|
|
3024
|
+
}
|
|
3025
|
+
if (this.ctx.config.logHeapUsage && task.result.heap != null) {
|
|
3026
|
+
title += c.magenta(
|
|
3027
|
+
` ${Math.floor(task.result.heap / 1024 / 1024)} MB heap used`
|
|
3028
|
+
);
|
|
3029
|
+
}
|
|
2658
3030
|
this.ctx.logger.log(title);
|
|
2659
3031
|
if (task.result.state === "fail") {
|
|
2660
3032
|
(_c = task.result.errors) == null ? void 0 : _c.forEach((error) => {
|
|
@@ -2675,7 +3047,10 @@ class IndentedLogger {
|
|
|
2675
3047
|
this.currentIndent += " ";
|
|
2676
3048
|
}
|
|
2677
3049
|
unindent() {
|
|
2678
|
-
this.currentIndent = this.currentIndent.substring(
|
|
3050
|
+
this.currentIndent = this.currentIndent.substring(
|
|
3051
|
+
0,
|
|
3052
|
+
this.currentIndent.length - 4
|
|
3053
|
+
);
|
|
2679
3054
|
}
|
|
2680
3055
|
log(text) {
|
|
2681
3056
|
return this.baseLog(this.currentIndent + text);
|
|
@@ -2697,21 +3072,24 @@ class TapReporter {
|
|
|
2697
3072
|
}
|
|
2698
3073
|
static getComment(task) {
|
|
2699
3074
|
var _a;
|
|
2700
|
-
if (task.mode === "skip")
|
|
3075
|
+
if (task.mode === "skip") {
|
|
2701
3076
|
return " # SKIP";
|
|
2702
|
-
else if (task.mode === "todo")
|
|
3077
|
+
} else if (task.mode === "todo") {
|
|
2703
3078
|
return " # TODO";
|
|
2704
|
-
else if (((_a = task.result) == null ? void 0 : _a.duration) != null)
|
|
3079
|
+
} else if (((_a = task.result) == null ? void 0 : _a.duration) != null) {
|
|
2705
3080
|
return ` # time=${task.result.duration.toFixed(2)}ms`;
|
|
2706
|
-
else
|
|
3081
|
+
} else {
|
|
2707
3082
|
return "";
|
|
3083
|
+
}
|
|
2708
3084
|
}
|
|
2709
3085
|
logErrorDetails(error, stack) {
|
|
2710
3086
|
const errorName = error.name || error.nameStr || "Unknown Error";
|
|
2711
3087
|
this.logger.log(`name: ${yamlString(String(errorName))}`);
|
|
2712
3088
|
this.logger.log(`message: ${yamlString(String(error.message))}`);
|
|
2713
3089
|
if (stack) {
|
|
2714
|
-
this.logger.log(
|
|
3090
|
+
this.logger.log(
|
|
3091
|
+
`stack: ${yamlString(`${stack.file}:${stack.line}:${stack.column}`)}`
|
|
3092
|
+
);
|
|
2715
3093
|
}
|
|
2716
3094
|
}
|
|
2717
3095
|
logTasks(tasks) {
|
|
@@ -2743,8 +3121,13 @@ class TapReporter {
|
|
|
2743
3121
|
this.logger.indent();
|
|
2744
3122
|
this.logErrorDetails(error);
|
|
2745
3123
|
this.logger.unindent();
|
|
2746
|
-
if (stack)
|
|
2747
|
-
this.logger.log(
|
|
3124
|
+
if (stack) {
|
|
3125
|
+
this.logger.log(
|
|
3126
|
+
`at: ${yamlString(
|
|
3127
|
+
`${stack.file}:${stack.line}:${stack.column}`
|
|
3128
|
+
)}`
|
|
3129
|
+
);
|
|
3130
|
+
}
|
|
2748
3131
|
if (error.showDiff) {
|
|
2749
3132
|
this.logger.log(`actual: ${yamlString(error.actual)}`);
|
|
2750
3133
|
this.logger.log(`expected: ${yamlString(error.expected)}`);
|
|
@@ -3961,18 +4344,21 @@ createLogUpdate(process$2.stdout);
|
|
|
3961
4344
|
|
|
3962
4345
|
createLogUpdate(process$2.stderr);
|
|
3963
4346
|
|
|
3964
|
-
const HIGHLIGHT_SUPPORTED_EXTS = new Set(
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
4347
|
+
const HIGHLIGHT_SUPPORTED_EXTS = new Set(
|
|
4348
|
+
["js", "ts"].flatMap((lang) => [
|
|
4349
|
+
`.${lang}`,
|
|
4350
|
+
`.m${lang}`,
|
|
4351
|
+
`.c${lang}`,
|
|
4352
|
+
`.${lang}x`,
|
|
4353
|
+
`.m${lang}x`,
|
|
4354
|
+
`.c${lang}x`
|
|
4355
|
+
])
|
|
4356
|
+
);
|
|
3972
4357
|
function highlightCode(id, source, colors) {
|
|
3973
4358
|
const ext = extname(id);
|
|
3974
|
-
if (!HIGHLIGHT_SUPPORTED_EXTS.has(ext))
|
|
4359
|
+
if (!HIGHLIGHT_SUPPORTED_EXTS.has(ext)) {
|
|
3975
4360
|
return source;
|
|
4361
|
+
}
|
|
3976
4362
|
const isJsx = ext.endsWith("x");
|
|
3977
4363
|
return highlight(source, { jsx: isJsx, colors: c });
|
|
3978
4364
|
}
|
|
@@ -4009,14 +4395,17 @@ class BaseSequencer {
|
|
|
4009
4395
|
if (!aState || !bState) {
|
|
4010
4396
|
const statsA = cache.getFileStats(keyA);
|
|
4011
4397
|
const statsB = cache.getFileStats(keyB);
|
|
4012
|
-
if (!statsA || !statsB)
|
|
4398
|
+
if (!statsA || !statsB) {
|
|
4013
4399
|
return !statsA && statsB ? -1 : !statsB && statsA ? 1 : 0;
|
|
4400
|
+
}
|
|
4014
4401
|
return statsB.size - statsA.size;
|
|
4015
4402
|
}
|
|
4016
|
-
if (aState.failed && !bState.failed)
|
|
4403
|
+
if (aState.failed && !bState.failed) {
|
|
4017
4404
|
return -1;
|
|
4018
|
-
|
|
4405
|
+
}
|
|
4406
|
+
if (!aState.failed && bState.failed) {
|
|
4019
4407
|
return 1;
|
|
4408
|
+
}
|
|
4020
4409
|
return bState.duration - aState.duration;
|
|
4021
4410
|
});
|
|
4022
4411
|
}
|
|
@@ -4072,12 +4461,14 @@ class Logger {
|
|
|
4072
4461
|
return;
|
|
4073
4462
|
}
|
|
4074
4463
|
this._clearScreenPending = message;
|
|
4075
|
-
if (force)
|
|
4464
|
+
if (force) {
|
|
4076
4465
|
this._clearScreen();
|
|
4466
|
+
}
|
|
4077
4467
|
}
|
|
4078
4468
|
_clearScreen() {
|
|
4079
|
-
if (this._clearScreenPending == null)
|
|
4469
|
+
if (this._clearScreenPending == null) {
|
|
4080
4470
|
return;
|
|
4471
|
+
}
|
|
4081
4472
|
const log = this._clearScreenPending;
|
|
4082
4473
|
this._clearScreenPending = void 0;
|
|
4083
4474
|
this.console.log(`${CURSOR_TO_START}${ERASE_DOWN}${log}`);
|
|
@@ -4089,18 +4480,21 @@ class Logger {
|
|
|
4089
4480
|
fullStack,
|
|
4090
4481
|
type,
|
|
4091
4482
|
showCodeFrame: true,
|
|
4092
|
-
logger: this
|
|
4483
|
+
logger: this,
|
|
4484
|
+
printProperties: options.verbose
|
|
4093
4485
|
});
|
|
4094
4486
|
}
|
|
4095
4487
|
clearHighlightCache(filename) {
|
|
4096
|
-
if (filename)
|
|
4488
|
+
if (filename) {
|
|
4097
4489
|
this._highlights.delete(filename);
|
|
4098
|
-
else
|
|
4490
|
+
} else {
|
|
4099
4491
|
this._highlights.clear();
|
|
4492
|
+
}
|
|
4100
4493
|
}
|
|
4101
4494
|
highlight(filename, source) {
|
|
4102
|
-
if (this._highlights.has(filename))
|
|
4495
|
+
if (this._highlights.has(filename)) {
|
|
4103
4496
|
return this._highlights.get(filename);
|
|
4497
|
+
}
|
|
4104
4498
|
const code = highlightCode(filename, source);
|
|
4105
4499
|
this._highlights.set(filename, code);
|
|
4106
4500
|
return code;
|
|
@@ -4109,36 +4503,54 @@ class Logger {
|
|
|
4109
4503
|
var _a;
|
|
4110
4504
|
const config = this.ctx.config;
|
|
4111
4505
|
const comma = c.dim(", ");
|
|
4112
|
-
if (filters == null ? void 0 : filters.length)
|
|
4506
|
+
if (filters == null ? void 0 : filters.length) {
|
|
4113
4507
|
this.console.error(c.dim("filter: ") + c.yellow(filters.join(comma)));
|
|
4508
|
+
}
|
|
4114
4509
|
const projectsFilter = toArray(config.project);
|
|
4115
|
-
if (projectsFilter.length)
|
|
4116
|
-
this.console.error(
|
|
4510
|
+
if (projectsFilter.length) {
|
|
4511
|
+
this.console.error(
|
|
4512
|
+
c.dim("projects: ") + c.yellow(projectsFilter.join(comma))
|
|
4513
|
+
);
|
|
4514
|
+
}
|
|
4117
4515
|
this.ctx.projects.forEach((project) => {
|
|
4118
4516
|
const config2 = project.config;
|
|
4119
4517
|
const name = project.getName();
|
|
4120
4518
|
const output = project.isCore() || !name ? "" : `[${name}]`;
|
|
4121
|
-
if (output)
|
|
4519
|
+
if (output) {
|
|
4122
4520
|
this.console.error(c.bgCyan(`${output} Config`));
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4521
|
+
}
|
|
4522
|
+
if (config2.include) {
|
|
4523
|
+
this.console.error(
|
|
4524
|
+
c.dim("include: ") + c.yellow(config2.include.join(comma))
|
|
4525
|
+
);
|
|
4526
|
+
}
|
|
4527
|
+
if (config2.exclude) {
|
|
4528
|
+
this.console.error(
|
|
4529
|
+
c.dim("exclude: ") + c.yellow(config2.exclude.join(comma))
|
|
4530
|
+
);
|
|
4531
|
+
}
|
|
4127
4532
|
if (config2.typecheck.enabled) {
|
|
4128
|
-
this.console.error(
|
|
4129
|
-
|
|
4533
|
+
this.console.error(
|
|
4534
|
+
c.dim("typecheck include: ") + c.yellow(config2.typecheck.include.join(comma))
|
|
4535
|
+
);
|
|
4536
|
+
this.console.error(
|
|
4537
|
+
c.dim("typecheck exclude: ") + c.yellow(config2.typecheck.exclude.join(comma))
|
|
4538
|
+
);
|
|
4130
4539
|
}
|
|
4131
4540
|
});
|
|
4132
4541
|
if (config.watch && (config.changed || ((_a = config.related) == null ? void 0 : _a.length))) {
|
|
4133
4542
|
this.log(`No affected ${config.mode} files found
|
|
4134
4543
|
`);
|
|
4135
4544
|
} else {
|
|
4136
|
-
if (config.passWithNoTests)
|
|
4545
|
+
if (config.passWithNoTests) {
|
|
4137
4546
|
this.log(`No ${config.mode} files found, exiting with code 0
|
|
4138
4547
|
`);
|
|
4139
|
-
else
|
|
4140
|
-
this.error(
|
|
4141
|
-
|
|
4548
|
+
} else {
|
|
4549
|
+
this.error(
|
|
4550
|
+
c.red(`
|
|
4551
|
+
No ${config.mode} files found, exiting with code 1`)
|
|
4552
|
+
);
|
|
4553
|
+
}
|
|
4142
4554
|
}
|
|
4143
4555
|
}
|
|
4144
4556
|
printBanner() {
|
|
@@ -4146,52 +4558,89 @@ No ${config.mode} files found, exiting with code 1`));
|
|
|
4146
4558
|
this.log();
|
|
4147
4559
|
const versionTest = this.ctx.config.watch ? c.blue(`v${this.ctx.version}`) : c.cyan(`v${this.ctx.version}`);
|
|
4148
4560
|
const mode = this.ctx.config.watch ? c.blue(" DEV ") : c.cyan(" RUN ");
|
|
4149
|
-
this.log(
|
|
4150
|
-
|
|
4151
|
-
|
|
4561
|
+
this.log(
|
|
4562
|
+
`${c.inverse(c.bold(mode))} ${versionTest} ${c.gray(
|
|
4563
|
+
this.ctx.config.root
|
|
4564
|
+
)}`
|
|
4565
|
+
);
|
|
4566
|
+
if (this.ctx.config.sequence.sequencer === RandomSequencer) {
|
|
4567
|
+
this.log(
|
|
4568
|
+
c.gray(
|
|
4569
|
+
` Running tests with seed "${this.ctx.config.sequence.seed}"`
|
|
4570
|
+
)
|
|
4571
|
+
);
|
|
4572
|
+
}
|
|
4152
4573
|
this.ctx.projects.forEach((project) => {
|
|
4153
|
-
if (!project.browser)
|
|
4574
|
+
if (!project.browser) {
|
|
4154
4575
|
return;
|
|
4576
|
+
}
|
|
4155
4577
|
const name = project.getName();
|
|
4156
4578
|
const output = project.isCore() ? "" : ` [${name}]`;
|
|
4157
|
-
const resolvedUrls = project.browser.resolvedUrls;
|
|
4579
|
+
const resolvedUrls = project.browser.vite.resolvedUrls;
|
|
4158
4580
|
const origin = (resolvedUrls == null ? void 0 : resolvedUrls.local[0]) ?? (resolvedUrls == null ? void 0 : resolvedUrls.network[0]);
|
|
4159
|
-
this.log(
|
|
4581
|
+
this.log(
|
|
4582
|
+
c.dim(
|
|
4583
|
+
c.green(
|
|
4584
|
+
` ${output} Browser runner started at ${new URL("/", origin)}`
|
|
4585
|
+
)
|
|
4586
|
+
)
|
|
4587
|
+
);
|
|
4160
4588
|
});
|
|
4161
4589
|
if (this.ctx.config.ui) {
|
|
4162
|
-
this.log(
|
|
4590
|
+
this.log(
|
|
4591
|
+
c.dim(
|
|
4592
|
+
c.green(
|
|
4593
|
+
` UI started at http://${((_a = this.ctx.config.api) == null ? void 0 : _a.host) || "localhost"}:${c.bold(`${this.ctx.server.config.server.port}`)}${this.ctx.config.uiBase}`
|
|
4594
|
+
)
|
|
4595
|
+
)
|
|
4596
|
+
);
|
|
4163
4597
|
} else if ((_b = this.ctx.config.api) == null ? void 0 : _b.port) {
|
|
4164
4598
|
const resolvedUrls = this.ctx.server.resolvedUrls;
|
|
4165
4599
|
const fallbackUrl = `http://${this.ctx.config.api.host || "localhost"}:${this.ctx.config.api.port}`;
|
|
4166
4600
|
const origin = (resolvedUrls == null ? void 0 : resolvedUrls.local[0]) ?? (resolvedUrls == null ? void 0 : resolvedUrls.network[0]) ?? fallbackUrl;
|
|
4167
4601
|
this.log(c.dim(c.green(` API started at ${new URL("/", origin)}`)));
|
|
4168
4602
|
}
|
|
4169
|
-
if (this.ctx.coverageProvider)
|
|
4170
|
-
this.log(
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4603
|
+
if (this.ctx.coverageProvider) {
|
|
4604
|
+
this.log(
|
|
4605
|
+
c.dim(" Coverage enabled with ") + c.yellow(this.ctx.coverageProvider.name)
|
|
4606
|
+
);
|
|
4607
|
+
}
|
|
4608
|
+
if (this.ctx.config.standalone) {
|
|
4609
|
+
this.log(
|
|
4610
|
+
c.yellow(
|
|
4611
|
+
`
|
|
4612
|
+
Vitest is running in standalone mode. Edit a test file to rerun tests.`
|
|
4613
|
+
)
|
|
4614
|
+
);
|
|
4615
|
+
} else {
|
|
4175
4616
|
this.log();
|
|
4617
|
+
}
|
|
4176
4618
|
}
|
|
4177
4619
|
printUnhandledErrors(errors) {
|
|
4178
|
-
const errorMessage = c.red(
|
|
4179
|
-
|
|
4620
|
+
const errorMessage = c.red(
|
|
4621
|
+
c.bold(
|
|
4622
|
+
`
|
|
4180
4623
|
Vitest caught ${errors.length} unhandled error${errors.length > 1 ? "s" : ""} during the test run.
|
|
4181
4624
|
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.`
|
|
4182
|
-
|
|
4625
|
+
)
|
|
4626
|
+
);
|
|
4183
4627
|
this.log(c.red(divider(c.bold(c.inverse(" Unhandled Errors ")))));
|
|
4184
4628
|
this.log(errorMessage);
|
|
4185
4629
|
errors.forEach((err) => {
|
|
4186
|
-
this.printError(err, {
|
|
4630
|
+
this.printError(err, {
|
|
4631
|
+
fullStack: true,
|
|
4632
|
+
type: err.type || "Unhandled Error"
|
|
4633
|
+
});
|
|
4187
4634
|
});
|
|
4188
4635
|
this.log(c.red(divider()));
|
|
4189
4636
|
}
|
|
4190
4637
|
printSourceTypeErrors(errors) {
|
|
4191
|
-
const errorMessage = c.red(
|
|
4192
|
-
|
|
4638
|
+
const errorMessage = c.red(
|
|
4639
|
+
c.bold(
|
|
4640
|
+
`
|
|
4193
4641
|
Vitest found ${errors.length} error${errors.length > 1 ? "s" : ""} not related to your test files.`
|
|
4194
|
-
|
|
4642
|
+
)
|
|
4643
|
+
);
|
|
4195
4644
|
this.log(c.red(divider(c.bold(c.inverse(" Source Errors ")))));
|
|
4196
4645
|
this.log(errorMessage);
|
|
4197
4646
|
errors.forEach((err) => {
|
|
@@ -4216,7 +4665,7 @@ function capturePrintError(error, ctx, project) {
|
|
|
4216
4665
|
return { nearest: result == null ? void 0 : result.nearest, output };
|
|
4217
4666
|
}
|
|
4218
4667
|
function printError(error, project, options) {
|
|
4219
|
-
const { showCodeFrame = true, fullStack = false, type } = options;
|
|
4668
|
+
const { showCodeFrame = true, fullStack = false, type, printProperties = true } = options;
|
|
4220
4669
|
const logger = options.logger;
|
|
4221
4670
|
let e = error;
|
|
4222
4671
|
if (isPrimitive(e)) {
|
|
@@ -4241,53 +4690,82 @@ function printError(error, project, options) {
|
|
|
4241
4690
|
getSourceMap: (file) => project.getBrowserSourceMapModuleById(file),
|
|
4242
4691
|
frameFilter: project.config.onStackTrace
|
|
4243
4692
|
};
|
|
4244
|
-
if (fullStack)
|
|
4693
|
+
if (fullStack) {
|
|
4245
4694
|
parserOptions.ignoreStackEntries = [];
|
|
4695
|
+
}
|
|
4246
4696
|
const stacks = parseErrorStacktrace(e, parserOptions);
|
|
4247
|
-
const nearest = error instanceof TypeCheckError ? error.stacks[0] : stacks.find(
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
return false;
|
|
4253
|
-
}
|
|
4697
|
+
const nearest = error instanceof TypeCheckError ? error.stacks[0] : stacks.find((stack) => {
|
|
4698
|
+
try {
|
|
4699
|
+
return project.server && project.getModuleById(stack.file) && existsSync(stack.file);
|
|
4700
|
+
} catch {
|
|
4701
|
+
return false;
|
|
4254
4702
|
}
|
|
4255
|
-
);
|
|
4256
|
-
const errorProperties = getErrorProperties(e);
|
|
4257
|
-
if (type)
|
|
4703
|
+
});
|
|
4704
|
+
const errorProperties = printProperties ? getErrorProperties(e) : {};
|
|
4705
|
+
if (type) {
|
|
4258
4706
|
printErrorType(type, project.ctx);
|
|
4707
|
+
}
|
|
4259
4708
|
printErrorMessage(e, logger);
|
|
4260
|
-
if (e.codeFrame)
|
|
4709
|
+
if (e.codeFrame) {
|
|
4261
4710
|
logger.error(`${e.codeFrame}
|
|
4262
4711
|
`);
|
|
4263
|
-
|
|
4712
|
+
}
|
|
4713
|
+
if (e.diff) {
|
|
4264
4714
|
displayDiff(e.diff, logger.console);
|
|
4715
|
+
}
|
|
4265
4716
|
if (e.frame) {
|
|
4266
4717
|
logger.error(c.yellow(e.frame));
|
|
4267
4718
|
} else {
|
|
4268
4719
|
printStack(logger, project, stacks, nearest, errorProperties, (s) => {
|
|
4269
4720
|
if (showCodeFrame && s === nearest && nearest) {
|
|
4270
4721
|
const sourceCode = readFileSync(nearest.file, "utf-8");
|
|
4271
|
-
logger.error(
|
|
4722
|
+
logger.error(
|
|
4723
|
+
generateCodeFrame(
|
|
4724
|
+
sourceCode.length > 1e5 ? sourceCode : logger.highlight(nearest.file, sourceCode),
|
|
4725
|
+
4,
|
|
4726
|
+
s
|
|
4727
|
+
)
|
|
4728
|
+
);
|
|
4272
4729
|
}
|
|
4273
4730
|
});
|
|
4274
4731
|
}
|
|
4275
4732
|
const testPath = e.VITEST_TEST_PATH;
|
|
4276
4733
|
const testName = e.VITEST_TEST_NAME;
|
|
4277
4734
|
const afterEnvTeardown = e.VITEST_AFTER_ENV_TEARDOWN;
|
|
4278
|
-
if (testPath)
|
|
4279
|
-
logger.error(
|
|
4735
|
+
if (testPath) {
|
|
4736
|
+
logger.error(
|
|
4737
|
+
c.red(
|
|
4738
|
+
`This error originated in "${c.bold(
|
|
4739
|
+
testPath
|
|
4740
|
+
)}" test file. It doesn't mean the error was thrown inside the file itself, but while it was running.`
|
|
4741
|
+
)
|
|
4742
|
+
);
|
|
4743
|
+
}
|
|
4280
4744
|
if (testName) {
|
|
4281
|
-
logger.error(
|
|
4745
|
+
logger.error(
|
|
4746
|
+
c.red(
|
|
4747
|
+
`The latest test that might've caused the error is "${c.bold(
|
|
4748
|
+
testName
|
|
4749
|
+
)}". It might mean one of the following:
|
|
4282
4750
|
- The error was thrown, while Vitest was running this test.
|
|
4283
|
-
- If the error occurred after the test had been completed, this was the last documented test before it was thrown.`
|
|
4751
|
+
- If the error occurred after the test had been completed, this was the last documented test before it was thrown.`
|
|
4752
|
+
)
|
|
4753
|
+
);
|
|
4284
4754
|
}
|
|
4285
4755
|
if (afterEnvTeardown) {
|
|
4286
|
-
logger.error(
|
|
4756
|
+
logger.error(
|
|
4757
|
+
c.red(
|
|
4758
|
+
"This error was caught after test environment was torn down. Make sure to cancel any running tasks before test finishes:\n- cancel timeouts using clearTimeout and clearInterval\n- wait for promises to resolve using the await keyword"
|
|
4759
|
+
)
|
|
4760
|
+
);
|
|
4287
4761
|
}
|
|
4288
4762
|
if (typeof e.cause === "object" && e.cause && "name" in e.cause) {
|
|
4289
4763
|
e.cause.name = `Caused by: ${e.cause.name}`;
|
|
4290
|
-
printError(e.cause, project, {
|
|
4764
|
+
printError(e.cause, project, {
|
|
4765
|
+
fullStack,
|
|
4766
|
+
showCodeFrame: false,
|
|
4767
|
+
logger: options.logger
|
|
4768
|
+
});
|
|
4291
4769
|
}
|
|
4292
4770
|
handleImportOutsideModuleError(e.stack || e.stackStr || "", logger);
|
|
4293
4771
|
return { nearest };
|
|
@@ -4304,6 +4782,8 @@ const skipErrorProperties = /* @__PURE__ */ new Set([
|
|
|
4304
4782
|
"stackStr",
|
|
4305
4783
|
"type",
|
|
4306
4784
|
"showDiff",
|
|
4785
|
+
"ok",
|
|
4786
|
+
"operator",
|
|
4307
4787
|
"diff",
|
|
4308
4788
|
"codeFrame",
|
|
4309
4789
|
"actual",
|
|
@@ -4317,11 +4797,13 @@ const skipErrorProperties = /* @__PURE__ */ new Set([
|
|
|
4317
4797
|
]);
|
|
4318
4798
|
function getErrorProperties(e) {
|
|
4319
4799
|
const errorObject = /* @__PURE__ */ Object.create(null);
|
|
4320
|
-
if (e.name === "AssertionError")
|
|
4800
|
+
if (e.name === "AssertionError") {
|
|
4321
4801
|
return errorObject;
|
|
4802
|
+
}
|
|
4322
4803
|
for (const key of Object.getOwnPropertyNames(e)) {
|
|
4323
|
-
if (!skipErrorProperties.has(key))
|
|
4804
|
+
if (!skipErrorProperties.has(key)) {
|
|
4324
4805
|
errorObject[key] = e[key];
|
|
4806
|
+
}
|
|
4325
4807
|
}
|
|
4326
4808
|
return errorObject;
|
|
4327
4809
|
}
|
|
@@ -4330,22 +4812,28 @@ const esmErrors = [
|
|
|
4330
4812
|
"Unexpected token 'export'"
|
|
4331
4813
|
];
|
|
4332
4814
|
function handleImportOutsideModuleError(stack, logger) {
|
|
4333
|
-
if (!esmErrors.some((e) => stack.includes(e)))
|
|
4815
|
+
if (!esmErrors.some((e) => stack.includes(e))) {
|
|
4334
4816
|
return;
|
|
4817
|
+
}
|
|
4335
4818
|
const path = normalize(stack.split("\n")[0].trim());
|
|
4336
4819
|
let name = path.split("/node_modules/").pop() || "";
|
|
4337
|
-
if (name == null ? void 0 : name.startsWith("@"))
|
|
4820
|
+
if (name == null ? void 0 : name.startsWith("@")) {
|
|
4338
4821
|
name = name.split("/").slice(0, 2).join("/");
|
|
4339
|
-
else
|
|
4822
|
+
} else {
|
|
4340
4823
|
name = name.split("/")[0];
|
|
4341
|
-
|
|
4824
|
+
}
|
|
4825
|
+
if (name) {
|
|
4342
4826
|
printModuleWarningForPackage(logger, path, name);
|
|
4343
|
-
else
|
|
4827
|
+
} else {
|
|
4344
4828
|
printModuleWarningForSourceCode(logger, path);
|
|
4829
|
+
}
|
|
4345
4830
|
}
|
|
4346
4831
|
function printModuleWarningForPackage(logger, path, name) {
|
|
4347
|
-
logger.error(
|
|
4348
|
-
|
|
4832
|
+
logger.error(
|
|
4833
|
+
c.yellow(
|
|
4834
|
+
`Module ${path} seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue to the package ${c.bold(
|
|
4835
|
+
`"${name}"`
|
|
4836
|
+
)} asking them to ship the file in .mjs extension or add "type": "module" in their package.json.
|
|
4349
4837
|
|
|
4350
4838
|
As a temporary workaround you can try to inline the package by updating your config:
|
|
4351
4839
|
|
|
@@ -4361,18 +4849,22 @@ As a temporary workaround you can try to inline the package by updating your con
|
|
|
4361
4849
|
}
|
|
4362
4850
|
}
|
|
4363
4851
|
`)
|
|
4364
|
-
|
|
4852
|
+
)
|
|
4853
|
+
);
|
|
4365
4854
|
}
|
|
4366
4855
|
function printModuleWarningForSourceCode(logger, path) {
|
|
4367
|
-
logger.error(
|
|
4368
|
-
|
|
4369
|
-
|
|
4856
|
+
logger.error(
|
|
4857
|
+
c.yellow(
|
|
4858
|
+
`Module ${path} seems to be an ES Module but shipped in a CommonJS package. To fix this issue, change the file extension to .mjs or add "type": "module" in your package.json.`
|
|
4859
|
+
)
|
|
4860
|
+
);
|
|
4370
4861
|
}
|
|
4371
4862
|
function displayDiff(diff, console) {
|
|
4372
|
-
if (diff)
|
|
4863
|
+
if (diff) {
|
|
4373
4864
|
console.error(`
|
|
4374
4865
|
${diff}
|
|
4375
4866
|
`);
|
|
4867
|
+
}
|
|
4376
4868
|
}
|
|
4377
4869
|
function printErrorMessage(error, logger) {
|
|
4378
4870
|
const errorName = error.name || error.nameStr || "Unknown Error";
|
|
@@ -4390,18 +4882,31 @@ function printStack(logger, project, stack, highlight, errorProperties, onStack)
|
|
|
4390
4882
|
for (const frame of stack) {
|
|
4391
4883
|
const color = frame === highlight ? c.cyan : c.gray;
|
|
4392
4884
|
const path = relative(project.config.root, frame.file);
|
|
4393
|
-
logger.error(
|
|
4885
|
+
logger.error(
|
|
4886
|
+
color(
|
|
4887
|
+
` ${c.dim(F_POINTER)} ${[
|
|
4888
|
+
frame.method,
|
|
4889
|
+
`${path}:${c.dim(`${frame.line}:${frame.column}`)}`
|
|
4890
|
+
].filter(Boolean).join(" ")}`
|
|
4891
|
+
)
|
|
4892
|
+
);
|
|
4394
4893
|
onStack == null ? void 0 : onStack(frame);
|
|
4395
4894
|
}
|
|
4396
|
-
if (stack.length)
|
|
4895
|
+
if (stack.length) {
|
|
4397
4896
|
logger.error();
|
|
4398
|
-
|
|
4399
|
-
if (hasProperties) {
|
|
4897
|
+
}
|
|
4898
|
+
if (hasProperties(errorProperties)) {
|
|
4400
4899
|
logger.error(c.red(c.dim(divider())));
|
|
4401
4900
|
const propertiesString = inspect(errorProperties);
|
|
4402
4901
|
logger.error(c.red(c.bold("Serialized Error:")), c.gray(propertiesString));
|
|
4403
4902
|
}
|
|
4404
4903
|
}
|
|
4904
|
+
function hasProperties(obj) {
|
|
4905
|
+
for (const _key in obj) {
|
|
4906
|
+
return true;
|
|
4907
|
+
}
|
|
4908
|
+
return false;
|
|
4909
|
+
}
|
|
4405
4910
|
function generateCodeFrame(source, indent = 0, loc, range = 2) {
|
|
4406
4911
|
var _a;
|
|
4407
4912
|
const start = typeof loc === "object" ? positionToOffset(source, loc.line, loc.column) : loc;
|
|
@@ -4418,15 +4923,22 @@ function generateCodeFrame(source, indent = 0, loc, range = 2) {
|
|
|
4418
4923
|
count += lines[i].length + nl;
|
|
4419
4924
|
if (count >= start) {
|
|
4420
4925
|
for (let j = i - range; j <= i + range || end > count; j++) {
|
|
4421
|
-
if (j < 0 || j >= lines.length)
|
|
4926
|
+
if (j < 0 || j >= lines.length) {
|
|
4422
4927
|
continue;
|
|
4928
|
+
}
|
|
4423
4929
|
const lineLength = lines[j].length;
|
|
4424
|
-
if (stripAnsi(lines[j]).length > 200)
|
|
4930
|
+
if (stripAnsi(lines[j]).length > 200) {
|
|
4425
4931
|
return "";
|
|
4426
|
-
|
|
4932
|
+
}
|
|
4933
|
+
res.push(
|
|
4934
|
+
lineNo(j + 1) + cliTruncate(lines[j].replace(/\t/g, " "), columns - 5 - indent)
|
|
4935
|
+
);
|
|
4427
4936
|
if (j === i) {
|
|
4428
4937
|
const pad = start - (count - lineLength) + (nl - 1);
|
|
4429
|
-
const length = Math.max(
|
|
4938
|
+
const length = Math.max(
|
|
4939
|
+
1,
|
|
4940
|
+
end > count ? lineLength - pad : end - start
|
|
4941
|
+
);
|
|
4430
4942
|
res.push(lineNo() + " ".repeat(pad) + c.red("^".repeat(length)));
|
|
4431
4943
|
} else if (j > i) {
|
|
4432
4944
|
if (end > count) {
|
|
@@ -4439,29 +4951,36 @@ function generateCodeFrame(source, indent = 0, loc, range = 2) {
|
|
|
4439
4951
|
break;
|
|
4440
4952
|
}
|
|
4441
4953
|
}
|
|
4442
|
-
if (indent)
|
|
4954
|
+
if (indent) {
|
|
4443
4955
|
res = res.map((line) => " ".repeat(indent) + line);
|
|
4956
|
+
}
|
|
4444
4957
|
return res.join("\n");
|
|
4445
4958
|
}
|
|
4446
4959
|
|
|
4447
4960
|
function flattenTasks$1(task, baseName = "") {
|
|
4448
4961
|
const base = baseName ? `${baseName} > ` : "";
|
|
4449
4962
|
if (task.type === "suite") {
|
|
4450
|
-
return task.tasks.flatMap(
|
|
4963
|
+
return task.tasks.flatMap(
|
|
4964
|
+
(child) => flattenTasks$1(child, `${base}${task.name}`)
|
|
4965
|
+
);
|
|
4451
4966
|
} else {
|
|
4452
|
-
return [
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4967
|
+
return [
|
|
4968
|
+
{
|
|
4969
|
+
...task,
|
|
4970
|
+
name: `${base}${task.name}`
|
|
4971
|
+
}
|
|
4972
|
+
];
|
|
4456
4973
|
}
|
|
4457
4974
|
}
|
|
4458
4975
|
function removeInvalidXMLCharacters(value, removeDiscouragedChars) {
|
|
4459
|
-
let regex = /(
|
|
4976
|
+
let regex = /([\0-\x08\v\f\x0E-\x1F\uFFFD\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])/g;
|
|
4460
4977
|
value = String(value || "").replace(regex, "");
|
|
4461
4978
|
{
|
|
4462
4979
|
regex = new RegExp(
|
|
4463
|
-
|
|
4980
|
+
/* eslint-disable regexp/prefer-character-class, regexp/no-obscure-range, regexp/no-useless-non-capturing-group */
|
|
4981
|
+
"([\\x7F-\\x84]|[\\x86-\\x9F]|[\\uFDD0-\\uFDEF]|\\uD83F[\\uDFFE\\uDFFF]|(?:\\uD87F[\\uDFFE\\uDFFF])|\\uD8BF[\\uDFFE\\uDFFF]|\\uD8FF[\\uDFFE\\uDFFF]|(?:\\uD93F[\\uDFFE\\uDFFF])|\\uD97F[\\uDFFE\\uDFFF]|\\uD9BF[\\uDFFE\\uDFFF]|\\uD9FF[\\uDFFE\\uDFFF]|\\uDA3F[\\uDFFE\\uDFFF]|\\uDA7F[\\uDFFE\\uDFFF]|\\uDABF[\\uDFFE\\uDFFF]|(?:\\uDAFF[\\uDFFE\\uDFFF])|\\uDB3F[\\uDFFE\\uDFFF]|\\uDB7F[\\uDFFE\\uDFFF]|(?:\\uDBBF[\\uDFFE\\uDFFF])|\\uDBFF[\\uDFFE\\uDFFF](?:[\\0-\\t\\v\\f\\x0E-\\u2027\\u202A-\\uD7FF\\uE000-\\uFFFF]|[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF]))",
|
|
4464
4982
|
"g"
|
|
4983
|
+
/* eslint-enable */
|
|
4465
4984
|
);
|
|
4466
4985
|
value = value.replace(regex, "");
|
|
4467
4986
|
}
|
|
@@ -4472,7 +4991,10 @@ function escapeXML(value) {
|
|
|
4472
4991
|
String(value).replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">"));
|
|
4473
4992
|
}
|
|
4474
4993
|
function executionTime(durationMS) {
|
|
4475
|
-
return (durationMS / 1e3).toLocaleString("en-US", {
|
|
4994
|
+
return (durationMS / 1e3).toLocaleString("en-US", {
|
|
4995
|
+
useGrouping: false,
|
|
4996
|
+
maximumFractionDigits: 10
|
|
4997
|
+
});
|
|
4476
4998
|
}
|
|
4477
4999
|
function getDuration(task) {
|
|
4478
5000
|
var _a;
|
|
@@ -4498,13 +5020,15 @@ class JUnitReporter {
|
|
|
4498
5020
|
if (outputFile) {
|
|
4499
5021
|
this.reportFile = resolve(this.ctx.config.root, outputFile);
|
|
4500
5022
|
const outputDirectory = dirname(this.reportFile);
|
|
4501
|
-
if (!existsSync(outputDirectory))
|
|
5023
|
+
if (!existsSync(outputDirectory)) {
|
|
4502
5024
|
await promises.mkdir(outputDirectory, { recursive: true });
|
|
5025
|
+
}
|
|
4503
5026
|
const fileFd = await promises.open(this.reportFile, "w+");
|
|
4504
5027
|
this.fileFd = fileFd;
|
|
4505
5028
|
this.baseLog = async (text) => {
|
|
4506
|
-
if (!this.fileFd)
|
|
5029
|
+
if (!this.fileFd) {
|
|
4507
5030
|
this.fileFd = await promises.open(this.reportFile, "w+");
|
|
5031
|
+
}
|
|
4508
5032
|
await promises.writeFile(this.fileFd, `${text}
|
|
4509
5033
|
`);
|
|
4510
5034
|
};
|
|
@@ -4518,63 +5042,80 @@ class JUnitReporter {
|
|
|
4518
5042
|
const pairs = [];
|
|
4519
5043
|
for (const key in attrs) {
|
|
4520
5044
|
const attr = attrs[key];
|
|
4521
|
-
if (attr === void 0)
|
|
5045
|
+
if (attr === void 0) {
|
|
4522
5046
|
continue;
|
|
5047
|
+
}
|
|
4523
5048
|
pairs.push(`${key}="${escapeXML(attr)}"`);
|
|
4524
5049
|
}
|
|
4525
|
-
await this.logger.log(
|
|
5050
|
+
await this.logger.log(
|
|
5051
|
+
`<${name}${pairs.length ? ` ${pairs.join(" ")}` : ""}>`
|
|
5052
|
+
);
|
|
4526
5053
|
this.logger.indent();
|
|
4527
5054
|
await children.call(this);
|
|
4528
5055
|
this.logger.unindent();
|
|
4529
5056
|
await this.logger.log(`</${name}>`);
|
|
4530
5057
|
}
|
|
4531
5058
|
async writeLogs(task, type) {
|
|
4532
|
-
if (task.logs == null || task.logs.length === 0)
|
|
5059
|
+
if (task.logs == null || task.logs.length === 0) {
|
|
4533
5060
|
return;
|
|
5061
|
+
}
|
|
4534
5062
|
const logType = type === "err" ? "stderr" : "stdout";
|
|
4535
5063
|
const logs = task.logs.filter((log) => log.type === logType);
|
|
4536
|
-
if (logs.length === 0)
|
|
5064
|
+
if (logs.length === 0) {
|
|
4537
5065
|
return;
|
|
5066
|
+
}
|
|
4538
5067
|
await this.writeElement(`system-${type}`, {}, async () => {
|
|
4539
|
-
for (const log of logs)
|
|
5068
|
+
for (const log of logs) {
|
|
4540
5069
|
await this.baseLog(escapeXML(log.content));
|
|
5070
|
+
}
|
|
4541
5071
|
});
|
|
4542
5072
|
}
|
|
4543
5073
|
async writeTasks(tasks, filename) {
|
|
4544
5074
|
for (const task of tasks) {
|
|
4545
|
-
await this.writeElement(
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
5075
|
+
await this.writeElement(
|
|
5076
|
+
"testcase",
|
|
5077
|
+
{
|
|
5078
|
+
classname: this.options.classname ?? filename,
|
|
5079
|
+
file: this.options.addFileAttribute ? filename : void 0,
|
|
5080
|
+
name: task.name,
|
|
5081
|
+
time: getDuration(task)
|
|
5082
|
+
},
|
|
5083
|
+
async () => {
|
|
5084
|
+
var _a;
|
|
5085
|
+
if (this.options.includeConsoleOutput) {
|
|
5086
|
+
await this.writeLogs(task, "out");
|
|
5087
|
+
await this.writeLogs(task, "err");
|
|
5088
|
+
}
|
|
5089
|
+
if (task.mode === "skip" || task.mode === "todo") {
|
|
5090
|
+
await this.logger.log("<skipped/>");
|
|
5091
|
+
}
|
|
5092
|
+
if (((_a = task.result) == null ? void 0 : _a.state) === "fail") {
|
|
5093
|
+
const errors = task.result.errors || [];
|
|
5094
|
+
for (const error of errors) {
|
|
5095
|
+
await this.writeElement(
|
|
5096
|
+
"failure",
|
|
5097
|
+
{
|
|
5098
|
+
message: error == null ? void 0 : error.message,
|
|
5099
|
+
type: (error == null ? void 0 : error.name) ?? (error == null ? void 0 : error.nameStr)
|
|
5100
|
+
},
|
|
5101
|
+
async () => {
|
|
5102
|
+
if (!error) {
|
|
5103
|
+
return;
|
|
5104
|
+
}
|
|
5105
|
+
const result = capturePrintError(
|
|
5106
|
+
error,
|
|
5107
|
+
this.ctx,
|
|
5108
|
+
this.ctx.getProjectByTaskId(task.id)
|
|
5109
|
+
);
|
|
5110
|
+
await this.baseLog(
|
|
5111
|
+
escapeXML(stripAnsi(result.output.trim()))
|
|
5112
|
+
);
|
|
5113
|
+
}
|
|
4572
5114
|
);
|
|
4573
|
-
|
|
4574
|
-
});
|
|
5115
|
+
}
|
|
4575
5116
|
}
|
|
4576
5117
|
}
|
|
4577
|
-
|
|
5118
|
+
);
|
|
4578
5119
|
}
|
|
4579
5120
|
}
|
|
4580
5121
|
async onFinished(files = this.ctx.state.getFiles()) {
|
|
@@ -4583,18 +5124,21 @@ class JUnitReporter {
|
|
|
4583
5124
|
const transformed = files.map((file) => {
|
|
4584
5125
|
var _a2, _b;
|
|
4585
5126
|
const tasks = file.tasks.flatMap((task) => flattenTasks$1(task));
|
|
4586
|
-
const stats2 = tasks.reduce(
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
5127
|
+
const stats2 = tasks.reduce(
|
|
5128
|
+
(stats3, task) => {
|
|
5129
|
+
var _a3, _b2;
|
|
5130
|
+
return {
|
|
5131
|
+
passed: stats3.passed + Number(((_a3 = task.result) == null ? void 0 : _a3.state) === "pass"),
|
|
5132
|
+
failures: stats3.failures + Number(((_b2 = task.result) == null ? void 0 : _b2.state) === "fail"),
|
|
5133
|
+
skipped: stats3.skipped + Number(task.mode === "skip" || task.mode === "todo")
|
|
5134
|
+
};
|
|
5135
|
+
},
|
|
5136
|
+
{
|
|
5137
|
+
passed: 0,
|
|
5138
|
+
failures: 0,
|
|
5139
|
+
skipped: 0
|
|
5140
|
+
}
|
|
5141
|
+
);
|
|
4598
5142
|
const suites = getSuites(file);
|
|
4599
5143
|
for (const suite of suites) {
|
|
4600
5144
|
if ((_a2 = suite.result) == null ? void 0 : _a2.errors) {
|
|
@@ -4623,39 +5167,46 @@ class JUnitReporter {
|
|
|
4623
5167
|
stats: stats2
|
|
4624
5168
|
};
|
|
4625
5169
|
});
|
|
4626
|
-
const stats = transformed.reduce(
|
|
4627
|
-
stats2
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
5170
|
+
const stats = transformed.reduce(
|
|
5171
|
+
(stats2, file) => {
|
|
5172
|
+
stats2.tests += file.tasks.length;
|
|
5173
|
+
stats2.failures += file.stats.failures;
|
|
5174
|
+
return stats2;
|
|
5175
|
+
},
|
|
5176
|
+
{
|
|
5177
|
+
name: this.options.suiteName || "vitest tests",
|
|
5178
|
+
tests: 0,
|
|
5179
|
+
failures: 0,
|
|
5180
|
+
errors: 0,
|
|
5181
|
+
// we cannot detect those
|
|
5182
|
+
time: executionTime((/* @__PURE__ */ new Date()).getTime() - this._timeStart.getTime())
|
|
5183
|
+
}
|
|
5184
|
+
);
|
|
4639
5185
|
await this.writeElement("testsuites", stats, async () => {
|
|
4640
5186
|
for (const file of transformed) {
|
|
4641
5187
|
const filename = relative(this.ctx.config.root, file.filepath);
|
|
4642
|
-
await this.writeElement(
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
5188
|
+
await this.writeElement(
|
|
5189
|
+
"testsuite",
|
|
5190
|
+
{
|
|
5191
|
+
name: filename,
|
|
5192
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5193
|
+
hostname: hostname(),
|
|
5194
|
+
tests: file.tasks.length,
|
|
5195
|
+
failures: file.stats.failures,
|
|
5196
|
+
errors: 0,
|
|
5197
|
+
// An errored test is one that had an unanticipated problem. We cannot detect those.
|
|
5198
|
+
skipped: file.stats.skipped,
|
|
5199
|
+
time: getDuration(file)
|
|
5200
|
+
},
|
|
5201
|
+
async () => {
|
|
5202
|
+
await this.writeTasks(file.tasks, filename);
|
|
5203
|
+
}
|
|
5204
|
+
);
|
|
4655
5205
|
}
|
|
4656
5206
|
});
|
|
4657
|
-
if (this.reportFile)
|
|
5207
|
+
if (this.reportFile) {
|
|
4658
5208
|
this.ctx.logger.log(`JUNIT report written to ${this.reportFile}`);
|
|
5209
|
+
}
|
|
4659
5210
|
await ((_a = this.fileFd) == null ? void 0 : _a.close());
|
|
4660
5211
|
this.fileFd = void 0;
|
|
4661
5212
|
}
|
|
@@ -4664,12 +5215,16 @@ class JUnitReporter {
|
|
|
4664
5215
|
function flattenTasks(task, baseName = "") {
|
|
4665
5216
|
const base = baseName ? `${baseName} > ` : "";
|
|
4666
5217
|
if (task.type === "suite" && task.tasks.length > 0) {
|
|
4667
|
-
return task.tasks.flatMap(
|
|
5218
|
+
return task.tasks.flatMap(
|
|
5219
|
+
(child) => flattenTasks(child, `${base}${task.name}`)
|
|
5220
|
+
);
|
|
4668
5221
|
} else {
|
|
4669
|
-
return [
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
5222
|
+
return [
|
|
5223
|
+
{
|
|
5224
|
+
...task,
|
|
5225
|
+
name: `${base}${task.name}`
|
|
5226
|
+
}
|
|
5227
|
+
];
|
|
4673
5228
|
}
|
|
4674
5229
|
}
|
|
4675
5230
|
class TapFlatReporter extends TapReporter {
|
|
@@ -4714,8 +5269,9 @@ class GithubActionsReporter {
|
|
|
4714
5269
|
const tasks = getTasks(file);
|
|
4715
5270
|
const project = this.ctx.getProjectByTaskId(file.id);
|
|
4716
5271
|
for (const task of tasks) {
|
|
4717
|
-
if (((_a = task.result) == null ? void 0 : _a.state) !== "fail")
|
|
5272
|
+
if (((_a = task.result) == null ? void 0 : _a.state) !== "fail") {
|
|
4718
5273
|
continue;
|
|
5274
|
+
}
|
|
4719
5275
|
const title = getFullName(task, " > ");
|
|
4720
5276
|
for (const error of ((_b = task.result) == null ? void 0 : _b.errors) ?? []) {
|
|
4721
5277
|
projectErrors.push({
|
|
@@ -4729,8 +5285,9 @@ class GithubActionsReporter {
|
|
|
4729
5285
|
for (const { project, title, error } of projectErrors) {
|
|
4730
5286
|
const result = capturePrintError(error, this.ctx, project);
|
|
4731
5287
|
const stack = result == null ? void 0 : result.nearest;
|
|
4732
|
-
if (!stack)
|
|
5288
|
+
if (!stack) {
|
|
4733
5289
|
continue;
|
|
5290
|
+
}
|
|
4734
5291
|
const formatted = formatMessage({
|
|
4735
5292
|
command: "error",
|
|
4736
5293
|
properties: {
|
|
@@ -4766,21 +5323,139 @@ function escapeProperty(s) {
|
|
|
4766
5323
|
return s.replace(/%/g, "%25").replace(/\r/g, "%0D").replace(/\n/g, "%0A").replace(/:/g, "%3A").replace(/,/g, "%2C");
|
|
4767
5324
|
}
|
|
4768
5325
|
|
|
5326
|
+
class BlobReporter {
|
|
5327
|
+
ctx;
|
|
5328
|
+
options;
|
|
5329
|
+
constructor(options) {
|
|
5330
|
+
this.options = options;
|
|
5331
|
+
}
|
|
5332
|
+
onInit(ctx) {
|
|
5333
|
+
if (ctx.config.watch) {
|
|
5334
|
+
throw new Error("Blob reporter is not supported in watch mode");
|
|
5335
|
+
}
|
|
5336
|
+
this.ctx = ctx;
|
|
5337
|
+
}
|
|
5338
|
+
async onFinished(files = [], errors = [], coverage) {
|
|
5339
|
+
let outputFile = this.options.outputFile ?? getOutputFile(this.ctx.config, "blob");
|
|
5340
|
+
if (!outputFile) {
|
|
5341
|
+
const shard = this.ctx.config.shard;
|
|
5342
|
+
outputFile = shard ? `.vitest-reports/blob-${shard.index}-${shard.count}.json` : ".vitest-reports/blob.json";
|
|
5343
|
+
}
|
|
5344
|
+
const moduleKeys = this.ctx.projects.map(
|
|
5345
|
+
(project) => {
|
|
5346
|
+
return [
|
|
5347
|
+
project.getName(),
|
|
5348
|
+
[...project.server.moduleGraph.idToModuleMap.keys()]
|
|
5349
|
+
];
|
|
5350
|
+
}
|
|
5351
|
+
);
|
|
5352
|
+
const report = stringify([
|
|
5353
|
+
this.ctx.version,
|
|
5354
|
+
files,
|
|
5355
|
+
errors,
|
|
5356
|
+
moduleKeys,
|
|
5357
|
+
coverage
|
|
5358
|
+
]);
|
|
5359
|
+
const reportFile = resolve(this.ctx.config.root, outputFile);
|
|
5360
|
+
const dir = dirname(reportFile);
|
|
5361
|
+
if (!existsSync(dir)) {
|
|
5362
|
+
await mkdir(dir, { recursive: true });
|
|
5363
|
+
}
|
|
5364
|
+
await writeFile(reportFile, report, "utf-8");
|
|
5365
|
+
this.ctx.logger.log("blob report written to", reportFile);
|
|
5366
|
+
}
|
|
5367
|
+
}
|
|
5368
|
+
async function readBlobs(blobsDirectory, projectsArray) {
|
|
5369
|
+
const resolvedDir = resolve(process.cwd(), blobsDirectory);
|
|
5370
|
+
const blobsFiles = await readdir(resolvedDir);
|
|
5371
|
+
const promises = blobsFiles.map(async (file) => {
|
|
5372
|
+
const content = await readFile(resolve(resolvedDir, file), "utf-8");
|
|
5373
|
+
const [version, files2, errors2, moduleKeys, coverage] = parse(
|
|
5374
|
+
content
|
|
5375
|
+
);
|
|
5376
|
+
return { version, files: files2, errors: errors2, moduleKeys, coverage };
|
|
5377
|
+
});
|
|
5378
|
+
const blobs = await Promise.all(promises);
|
|
5379
|
+
if (!blobs.length) {
|
|
5380
|
+
throw new Error(
|
|
5381
|
+
`vitest.mergeReports() requires at least one blob file paths in the config`
|
|
5382
|
+
);
|
|
5383
|
+
}
|
|
5384
|
+
const projects = Object.fromEntries(
|
|
5385
|
+
projectsArray.map((p) => [p.getName(), p])
|
|
5386
|
+
);
|
|
5387
|
+
blobs.forEach((blob) => {
|
|
5388
|
+
blob.moduleKeys.forEach(([projectName, moduleIds]) => {
|
|
5389
|
+
const project = projects[projectName];
|
|
5390
|
+
if (!project) {
|
|
5391
|
+
return;
|
|
5392
|
+
}
|
|
5393
|
+
moduleIds.forEach((moduleId) => {
|
|
5394
|
+
project.server.moduleGraph.idToModuleMap.set(moduleId, {
|
|
5395
|
+
id: moduleId,
|
|
5396
|
+
url: moduleId,
|
|
5397
|
+
file: cleanUrl(moduleId),
|
|
5398
|
+
ssrTransformResult: null,
|
|
5399
|
+
transformResult: null,
|
|
5400
|
+
importedBindings: null,
|
|
5401
|
+
importedModules: /* @__PURE__ */ new Set(),
|
|
5402
|
+
importers: /* @__PURE__ */ new Set(),
|
|
5403
|
+
type: "js",
|
|
5404
|
+
clientImportedModules: /* @__PURE__ */ new Set(),
|
|
5405
|
+
ssrError: null,
|
|
5406
|
+
ssrImportedModules: /* @__PURE__ */ new Set(),
|
|
5407
|
+
ssrModule: null,
|
|
5408
|
+
acceptedHmrDeps: /* @__PURE__ */ new Set(),
|
|
5409
|
+
acceptedHmrExports: null,
|
|
5410
|
+
lastHMRTimestamp: 0,
|
|
5411
|
+
lastInvalidationTimestamp: 0
|
|
5412
|
+
});
|
|
5413
|
+
});
|
|
5414
|
+
});
|
|
5415
|
+
});
|
|
5416
|
+
const files = blobs.flatMap((blob) => blob.files).sort((f1, f2) => {
|
|
5417
|
+
var _a, _b;
|
|
5418
|
+
const time1 = ((_a = f1.result) == null ? void 0 : _a.startTime) || 0;
|
|
5419
|
+
const time2 = ((_b = f2.result) == null ? void 0 : _b.startTime) || 0;
|
|
5420
|
+
return time1 - time2;
|
|
5421
|
+
});
|
|
5422
|
+
const errors = blobs.flatMap((blob) => blob.errors);
|
|
5423
|
+
const coverages = blobs.map((blob) => blob.coverage);
|
|
5424
|
+
return {
|
|
5425
|
+
files,
|
|
5426
|
+
errors,
|
|
5427
|
+
coverages
|
|
5428
|
+
};
|
|
5429
|
+
}
|
|
5430
|
+
|
|
4769
5431
|
const outputMap = /* @__PURE__ */ new WeakMap();
|
|
4770
5432
|
function formatFilepath(path) {
|
|
4771
5433
|
const lastSlash = Math.max(path.lastIndexOf("/") + 1, 0);
|
|
4772
5434
|
const basename = path.slice(lastSlash);
|
|
4773
5435
|
let firstDot = basename.indexOf(".");
|
|
4774
|
-
if (firstDot < 0)
|
|
5436
|
+
if (firstDot < 0) {
|
|
4775
5437
|
firstDot = basename.length;
|
|
5438
|
+
}
|
|
4776
5439
|
firstDot += lastSlash;
|
|
4777
5440
|
return c.dim(path.slice(0, lastSlash)) + path.slice(lastSlash, firstDot) + c.dim(path.slice(firstDot));
|
|
4778
5441
|
}
|
|
4779
5442
|
function formatNumber(number) {
|
|
4780
5443
|
const res = String(number.toFixed(number < 100 ? 4 : 2)).split(".");
|
|
4781
|
-
return res[0].replace(/(?=(?:\d{3})+$)
|
|
5444
|
+
return res[0].replace(/(?=(?:\d{3})+$)\B/g, ",") + (res[1] ? `.${res[1]}` : "");
|
|
4782
5445
|
}
|
|
4783
|
-
const tableHead = [
|
|
5446
|
+
const tableHead = [
|
|
5447
|
+
"name",
|
|
5448
|
+
"hz",
|
|
5449
|
+
"min",
|
|
5450
|
+
"max",
|
|
5451
|
+
"mean",
|
|
5452
|
+
"p75",
|
|
5453
|
+
"p99",
|
|
5454
|
+
"p995",
|
|
5455
|
+
"p999",
|
|
5456
|
+
"rme",
|
|
5457
|
+
"samples"
|
|
5458
|
+
];
|
|
4784
5459
|
function renderBenchmarkItems(result) {
|
|
4785
5460
|
return [
|
|
4786
5461
|
result.name,
|
|
@@ -4797,14 +5472,8 @@ function renderBenchmarkItems(result) {
|
|
|
4797
5472
|
];
|
|
4798
5473
|
}
|
|
4799
5474
|
function computeColumnWidths(results) {
|
|
4800
|
-
const rows = [
|
|
4801
|
-
|
|
4802
|
-
...results.map((v) => renderBenchmarkItems(v))
|
|
4803
|
-
];
|
|
4804
|
-
return Array.from(
|
|
4805
|
-
tableHead,
|
|
4806
|
-
(_, i) => Math.max(...rows.map((row) => stripAnsi(row[i]).length))
|
|
4807
|
-
);
|
|
5475
|
+
const rows = [tableHead, ...results.map((v) => renderBenchmarkItems(v))];
|
|
5476
|
+
return Array.from(tableHead, (_, i) => Math.max(...rows.map((row) => stripAnsi(row[i]).length)));
|
|
4808
5477
|
}
|
|
4809
5478
|
function padRow(row, widths) {
|
|
4810
5479
|
return row.map(
|
|
@@ -4868,24 +5537,34 @@ function renderTree(tasks, options, level = 0, shallow = false) {
|
|
|
4868
5537
|
for (const task of tasks) {
|
|
4869
5538
|
const padding = " ".repeat(level ? 1 : 0);
|
|
4870
5539
|
let prefix = "";
|
|
4871
|
-
if (idx === 0 && ((_c = task.meta) == null ? void 0 : _c.benchmark))
|
|
5540
|
+
if (idx === 0 && ((_c = task.meta) == null ? void 0 : _c.benchmark)) {
|
|
4872
5541
|
prefix += `${renderTableHead(columnWidths)}
|
|
4873
5542
|
${padding}`;
|
|
5543
|
+
}
|
|
4874
5544
|
prefix += ` ${getStateSymbol(task)} `;
|
|
4875
5545
|
let suffix = "";
|
|
4876
|
-
if (task.type === "suite")
|
|
5546
|
+
if (task.type === "suite") {
|
|
4877
5547
|
suffix += c.dim(` (${getTests(task).length})`);
|
|
4878
|
-
|
|
5548
|
+
}
|
|
5549
|
+
if (task.mode === "skip" || task.mode === "todo") {
|
|
4879
5550
|
suffix += ` ${c.dim(c.gray("[skipped]"))}`;
|
|
5551
|
+
}
|
|
4880
5552
|
if (((_d = task.result) == null ? void 0 : _d.duration) != null) {
|
|
4881
|
-
if (task.result.duration > options.slowTestThreshold)
|
|
4882
|
-
suffix += c.yellow(
|
|
5553
|
+
if (task.result.duration > options.slowTestThreshold) {
|
|
5554
|
+
suffix += c.yellow(
|
|
5555
|
+
` ${Math.round(task.result.duration)}${c.dim("ms")}`
|
|
5556
|
+
);
|
|
5557
|
+
}
|
|
5558
|
+
}
|
|
5559
|
+
if (options.showHeap && ((_e = task.result) == null ? void 0 : _e.heap) != null) {
|
|
5560
|
+
suffix += c.magenta(
|
|
5561
|
+
` ${Math.floor(task.result.heap / 1024 / 1024)} MB heap used`
|
|
5562
|
+
);
|
|
4883
5563
|
}
|
|
4884
|
-
if (options.showHeap && ((_e = task.result) == null ? void 0 : _e.heap) != null)
|
|
4885
|
-
suffix += c.magenta(` ${Math.floor(task.result.heap / 1024 / 1024)} MB heap used`);
|
|
4886
5564
|
let name = task.name;
|
|
4887
|
-
if (level === 0)
|
|
5565
|
+
if (level === 0) {
|
|
4888
5566
|
name = formatFilepath(name);
|
|
5567
|
+
}
|
|
4889
5568
|
const bench = benchMap[task.id];
|
|
4890
5569
|
if (bench) {
|
|
4891
5570
|
let body = renderBenchmark(bench.current, columnWidths);
|
|
@@ -4893,21 +5572,25 @@ ${padding}`;
|
|
|
4893
5572
|
if (bench.current.hz) {
|
|
4894
5573
|
const diff = bench.current.hz / bench.baseline.hz;
|
|
4895
5574
|
const diffFixed = diff.toFixed(2);
|
|
4896
|
-
if (diffFixed === "1.0.0")
|
|
5575
|
+
if (diffFixed === "1.0.0") {
|
|
4897
5576
|
body += ` ${c.gray(`[${diffFixed}x]`)}`;
|
|
4898
|
-
|
|
5577
|
+
}
|
|
5578
|
+
if (diff > 1) {
|
|
4899
5579
|
body += ` ${c.blue(`[${diffFixed}x] \u21D1`)}`;
|
|
4900
|
-
else
|
|
5580
|
+
} else {
|
|
4901
5581
|
body += ` ${c.red(`[${diffFixed}x] \u21D3`)}`;
|
|
5582
|
+
}
|
|
4902
5583
|
}
|
|
4903
5584
|
output.push(padding + prefix + body + suffix);
|
|
4904
5585
|
const bodyBaseline = renderBenchmark(bench.baseline, columnWidths);
|
|
4905
5586
|
output.push(`${padding} ${bodyBaseline} ${c.dim("(baseline)")}`);
|
|
4906
5587
|
} else {
|
|
4907
|
-
if (bench.current.rank === 1 && benchCount > 1)
|
|
5588
|
+
if (bench.current.rank === 1 && benchCount > 1) {
|
|
4908
5589
|
body += ` ${c.bold(c.green(" fastest"))}`;
|
|
4909
|
-
|
|
5590
|
+
}
|
|
5591
|
+
if (bench.current.rank === benchCount && benchCount > 2) {
|
|
4910
5592
|
body += ` ${c.bold(c.gray(" slowest"))}`;
|
|
5593
|
+
}
|
|
4911
5594
|
output.push(padding + prefix + body + suffix);
|
|
4912
5595
|
}
|
|
4913
5596
|
} else {
|
|
@@ -4917,8 +5600,9 @@ ${padding}`;
|
|
|
4917
5600
|
let data = outputMap.get(task);
|
|
4918
5601
|
if (typeof data === "string") {
|
|
4919
5602
|
data = stripAnsi(data.trim().split("\n").filter(Boolean).pop());
|
|
4920
|
-
if (data === "")
|
|
5603
|
+
if (data === "") {
|
|
4921
5604
|
data = void 0;
|
|
5605
|
+
}
|
|
4922
5606
|
}
|
|
4923
5607
|
if (data != null) {
|
|
4924
5608
|
const out = `${" ".repeat(level)}${F_RIGHT} ${data}`;
|
|
@@ -4926,8 +5610,9 @@ ${padding}`;
|
|
|
4926
5610
|
}
|
|
4927
5611
|
}
|
|
4928
5612
|
if (!shallow && task.type === "suite" && task.tasks.length > 0) {
|
|
4929
|
-
if ((_g = task.result) == null ? void 0 : _g.state)
|
|
5613
|
+
if ((_g = task.result) == null ? void 0 : _g.state) {
|
|
4930
5614
|
output.push(renderTree(task.tasks, options, level + 1));
|
|
5615
|
+
}
|
|
4931
5616
|
}
|
|
4932
5617
|
idx++;
|
|
4933
5618
|
}
|
|
@@ -4942,8 +5627,9 @@ function createTableRenderer(_tasks, options) {
|
|
|
4942
5627
|
}
|
|
4943
5628
|
return {
|
|
4944
5629
|
start() {
|
|
4945
|
-
if (timer)
|
|
5630
|
+
if (timer) {
|
|
4946
5631
|
return this;
|
|
5632
|
+
}
|
|
4947
5633
|
timer = setInterval(update, 200);
|
|
4948
5634
|
return this;
|
|
4949
5635
|
},
|
|
@@ -4972,8 +5658,11 @@ class TableReporter extends BaseReporter {
|
|
|
4972
5658
|
rendererOptions = {};
|
|
4973
5659
|
onTestRemoved(trigger) {
|
|
4974
5660
|
this.stopListRender();
|
|
4975
|
-
this.ctx.logger.clearScreen(
|
|
4976
|
-
|
|
5661
|
+
this.ctx.logger.clearScreen(
|
|
5662
|
+
c.yellow("Test removed...") + (trigger ? c.dim(` [ ${this.relative(trigger)} ]
|
|
5663
|
+
`) : ""),
|
|
5664
|
+
true
|
|
5665
|
+
);
|
|
4977
5666
|
const files = this.ctx.state.getFiles(this.watchFilters);
|
|
4978
5667
|
createTableRenderer(files, this.rendererOptions).stop();
|
|
4979
5668
|
this.ctx.logger.log();
|
|
@@ -4986,9 +5675,12 @@ class TableReporter extends BaseReporter {
|
|
|
4986
5675
|
this.rendererOptions.showHeap = this.ctx.config.logHeapUsage;
|
|
4987
5676
|
this.rendererOptions.slowTestThreshold = this.ctx.config.slowTestThreshold;
|
|
4988
5677
|
if ((_a = this.ctx.config.benchmark) == null ? void 0 : _a.compare) {
|
|
4989
|
-
const compareFile = pathe.resolve(
|
|
5678
|
+
const compareFile = pathe.resolve(
|
|
5679
|
+
this.ctx.config.root,
|
|
5680
|
+
(_b = this.ctx.config.benchmark) == null ? void 0 : _b.compare
|
|
5681
|
+
);
|
|
4990
5682
|
try {
|
|
4991
|
-
this.rendererOptions.compare =
|
|
5683
|
+
this.rendererOptions.compare = flattenFormattedBenchmarkReport(
|
|
4992
5684
|
JSON.parse(
|
|
4993
5685
|
await fs.promises.readFile(compareFile, "utf-8")
|
|
4994
5686
|
)
|
|
@@ -4999,16 +5691,21 @@ class TableReporter extends BaseReporter {
|
|
|
4999
5691
|
}
|
|
5000
5692
|
if (this.isTTY) {
|
|
5001
5693
|
const files = this.ctx.state.getFiles(this.watchFilters);
|
|
5002
|
-
if (!this.renderer)
|
|
5003
|
-
this.renderer = createTableRenderer(
|
|
5004
|
-
|
|
5694
|
+
if (!this.renderer) {
|
|
5695
|
+
this.renderer = createTableRenderer(
|
|
5696
|
+
files,
|
|
5697
|
+
this.rendererOptions
|
|
5698
|
+
).start();
|
|
5699
|
+
} else {
|
|
5005
5700
|
this.renderer.update(files);
|
|
5701
|
+
}
|
|
5006
5702
|
}
|
|
5007
5703
|
}
|
|
5008
5704
|
onTaskUpdate(packs) {
|
|
5009
5705
|
var _a, _b;
|
|
5010
|
-
if (this.isTTY)
|
|
5706
|
+
if (this.isTTY) {
|
|
5011
5707
|
return;
|
|
5708
|
+
}
|
|
5012
5709
|
for (const pack of packs) {
|
|
5013
5710
|
const task = this.ctx.state.idMap.get(pack[0]);
|
|
5014
5711
|
if (task && task.type === "suite" && ((_a = task.result) == null ? void 0 : _a.state) && ((_b = task.result) == null ? void 0 : _b.state) !== "run") {
|
|
@@ -5017,11 +5714,19 @@ class TableReporter extends BaseReporter {
|
|
|
5017
5714
|
var _a2;
|
|
5018
5715
|
return ((_a2 = t.result) == null ? void 0 : _a2.state) !== "run";
|
|
5019
5716
|
})) {
|
|
5020
|
-
let title = ` ${getStateSymbol(task)} ${getFullName(
|
|
5021
|
-
|
|
5022
|
-
|
|
5717
|
+
let title = ` ${getStateSymbol(task)} ${getFullName(
|
|
5718
|
+
task,
|
|
5719
|
+
c.dim(" > ")
|
|
5720
|
+
)}`;
|
|
5721
|
+
if (task.result.duration != null && task.result.duration > this.ctx.config.slowTestThreshold) {
|
|
5722
|
+
title += c.yellow(
|
|
5723
|
+
` ${Math.round(task.result.duration)}${c.dim("ms")}`
|
|
5724
|
+
);
|
|
5725
|
+
}
|
|
5023
5726
|
this.ctx.logger.log(title);
|
|
5024
|
-
this.ctx.logger.log(
|
|
5727
|
+
this.ctx.logger.log(
|
|
5728
|
+
renderTree(benches, this.rendererOptions, 1, true)
|
|
5729
|
+
);
|
|
5025
5730
|
}
|
|
5026
5731
|
}
|
|
5027
5732
|
}
|
|
@@ -5035,9 +5740,10 @@ class TableReporter extends BaseReporter {
|
|
|
5035
5740
|
if (outputFile) {
|
|
5036
5741
|
outputFile = pathe.resolve(this.ctx.config.root, outputFile);
|
|
5037
5742
|
const outputDirectory = pathe.dirname(outputFile);
|
|
5038
|
-
if (!fs.existsSync(outputDirectory))
|
|
5743
|
+
if (!fs.existsSync(outputDirectory)) {
|
|
5039
5744
|
await fs.promises.mkdir(outputDirectory, { recursive: true });
|
|
5040
|
-
|
|
5745
|
+
}
|
|
5746
|
+
const output = createFormattedBenchmarkReport(files);
|
|
5041
5747
|
await fs.promises.writeFile(outputFile, JSON.stringify(output, null, 2));
|
|
5042
5748
|
this.ctx.logger.log(`Benchmark report written to ${outputFile}`);
|
|
5043
5749
|
}
|
|
@@ -5057,13 +5763,14 @@ class TableReporter extends BaseReporter {
|
|
|
5057
5763
|
}
|
|
5058
5764
|
onUserConsoleLog(log) {
|
|
5059
5765
|
var _a;
|
|
5060
|
-
if (!this.shouldLog(log))
|
|
5766
|
+
if (!this.shouldLog(log)) {
|
|
5061
5767
|
return;
|
|
5768
|
+
}
|
|
5062
5769
|
(_a = this.renderer) == null ? void 0 : _a.clear();
|
|
5063
5770
|
super.onUserConsoleLog(log);
|
|
5064
5771
|
}
|
|
5065
5772
|
}
|
|
5066
|
-
function
|
|
5773
|
+
function createFormattedBenchmarkReport(files) {
|
|
5067
5774
|
var _a;
|
|
5068
5775
|
const report = { files: [] };
|
|
5069
5776
|
for (const file of files) {
|
|
@@ -5078,6 +5785,7 @@ function createFormattedBenchamrkReport(files) {
|
|
|
5078
5785
|
benchmarks.push({
|
|
5079
5786
|
id: t.id,
|
|
5080
5787
|
sampleCount: samples.length,
|
|
5788
|
+
median: samples.length % 2 ? samples[Math.floor(samples.length / 2)] : (samples[samples.length / 2] + samples[samples.length / 2 - 1]) / 2,
|
|
5081
5789
|
...rest
|
|
5082
5790
|
});
|
|
5083
5791
|
}
|
|
@@ -5097,12 +5805,13 @@ function createFormattedBenchamrkReport(files) {
|
|
|
5097
5805
|
}
|
|
5098
5806
|
return report;
|
|
5099
5807
|
}
|
|
5100
|
-
function
|
|
5808
|
+
function flattenFormattedBenchmarkReport(report) {
|
|
5101
5809
|
const flat = {};
|
|
5102
5810
|
for (const file of report.files) {
|
|
5103
5811
|
for (const group of file.groups) {
|
|
5104
|
-
for (const t of group.benchmarks)
|
|
5812
|
+
for (const t of group.benchmarks) {
|
|
5105
5813
|
flat[t.id] = t;
|
|
5814
|
+
}
|
|
5106
5815
|
}
|
|
5107
5816
|
}
|
|
5108
5817
|
return flat;
|
|
@@ -5116,6 +5825,7 @@ const BenchmarkReportsMap = {
|
|
|
5116
5825
|
const ReportersMap = {
|
|
5117
5826
|
"default": DefaultReporter,
|
|
5118
5827
|
"basic": BasicReporter,
|
|
5828
|
+
"blob": BlobReporter,
|
|
5119
5829
|
"verbose": VerboseReporter,
|
|
5120
5830
|
"dot": DotReporter,
|
|
5121
5831
|
"json": JsonReporter,
|
|
@@ -5126,4 +5836,4 @@ const ReportersMap = {
|
|
|
5126
5836
|
"github-actions": GithubActionsReporter
|
|
5127
5837
|
};
|
|
5128
5838
|
|
|
5129
|
-
export {
|
|
5839
|
+
export { BasicReporter as B, DefaultReporter as D, GithubActionsReporter as G, HangingProcessReporter as H, JsonReporter as J, Logger as L, ReportersMap as R, TapReporter as T, VerboseReporter as V, DotReporter as a, JUnitReporter as b, TapFlatReporter as c, BenchmarkReportsMap as d, BaseSequencer as e, Typechecker as f, RandomSequencer as g, findNodeAround as h, generateCodeFrame as i, highlightCode as j, BlobReporter as k, parse as p, readBlobs as r, stringify as s, wrapSerializableConfig as w };
|