vitest 2.0.4 → 2.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.d.ts +21 -42
- package/dist/browser.js +5 -5
- package/dist/chunks/RandomSequencer.B4M2ux5b.js +952 -0
- package/dist/{vendor/base.DRHPZCCj.js → chunks/base.BH-FAiX7.js} +2 -2
- package/dist/{vendor/base.Csk7BT3h.js → chunks/base.BYvKfYzm.js} +3 -3
- package/dist/{vendor/benchmark.B6pblCp2.js → chunks/benchmark.C8CRJYG4.js} +1 -1
- package/dist/chunks/benchmark.puBFxyfE.d.ts +22 -0
- package/dist/{vendor/cac.DFtWvZc2.js → chunks/cac.CaYKA7Wt.js} +19 -21
- package/dist/{vendor/cli-api.CTkP2Ier.js → chunks/cli-api.B8LE391_.js} +500 -4615
- package/dist/chunks/config.CHuotKvS.d.ts +206 -0
- package/dist/chunks/{runtime-console.C2L2zykk.js → console.DI3gHgtH.js} +11 -14
- package/dist/{vendor/constants.CsnA4eRy.js → chunks/constants.CaAN7icJ.js} +1 -3
- package/dist/{vendor/coverage.BhYSDdTT.js → chunks/coverage.CqfT4xaf.js} +4 -7
- package/dist/chunks/{browser-creator.CyaOd8pl.js → creator.GreKbaUc.js} +10 -11
- package/dist/chunks/env.CmHVDJnw.js +7 -0
- package/dist/chunks/environment.0M5R1SX_.d.ts +173 -0
- package/dist/{vendor/execute.jzOWtys_.js → chunks/execute.DT9BA6zp.js} +28 -20
- package/dist/chunks/globals.DRPLtPOv.js +31 -0
- package/dist/{vendor/index.D6GZqexG.js → chunks/index.CM5UI-4O.js} +2 -2
- package/dist/{vendor/index.DI9daj1Q.js → chunks/index.CNZXZ9PJ.js} +43 -43
- package/dist/{vendor/index.BJmtb_7W.js → chunks/index.CxRxs566.js} +2 -2
- package/dist/{vendor/index.CVqMv71L.js → chunks/index.CxWPpGJz.js} +11 -12
- package/dist/{vendor/index.CuuL9y4g.js → chunks/index.YuPJueCg.js} +505 -1185
- package/dist/{vendor/index.D4nqnQWz.js → chunks/index.lVXYBqEP.js} +1 -18
- package/dist/{vendor/inspector.-FCQUzqR.js → chunks/inspector.70d6emsh.js} +4 -5
- package/dist/chunks/{environments-node.XE5FbRPQ.js → node.Bx4JZjMG.js} +2 -2
- package/dist/{reporters-B7ebVMkT.d.ts → chunks/reporters.DRZ7ndzr.d.ts} +860 -1000
- package/dist/chunks/resolveConfig.CGobt8AB.js +8120 -0
- package/dist/{vendor/rpc.BGx7q_k2.js → chunks/rpc.B7Mfb-Yf.js} +3 -5
- package/dist/{vendor/run-once.Db8Hgq9X.js → chunks/run-once.Sxe67Wng.js} +1 -1
- package/dist/chunks/{runtime-runBaseTests.Dq_sJZq9.js → runBaseTests.BAhL8UH_.js} +21 -23
- package/dist/{vendor/setup-common.symvFZPh.js → chunks/setup-common.KBrCO5LJ.js} +2 -2
- package/dist/{suite-CRLAhsm0.d.ts → chunks/suite.CcK46U-P.d.ts} +1 -1
- package/dist/{vendor/tasks.DhVtQBtW.js → chunks/tasks.BZnCS9aT.js} +2 -3
- package/dist/{vendor/utils.DkxLWvS1.js → chunks/utils.C3_cBsyn.js} +3 -4
- package/dist/{vendor/global.7bFbnyXl.js → chunks/utils.Ck2hJTRs.js} +1 -1
- package/dist/{vendor/utils.BySfPUwy.js → chunks/utils.DO38lwfj.js} +8 -21
- package/dist/{vendor/vi.Elqer9-7.js → chunks/vi.B6QZ938s.js} +13 -18
- package/dist/{vendor/vm.img-AOox.js → chunks/vm.kl9T_5ai.js} +40 -68
- package/dist/chunks/worker.BANO5ak1.d.ts +144 -0
- package/dist/chunks/worker.Cx2xE71X.d.ts +8 -0
- package/dist/cli.js +3 -3
- package/dist/config.cjs +6 -8
- package/dist/config.d.ts +10 -8
- package/dist/config.js +6 -8
- package/dist/coverage.d.ts +10 -8
- package/dist/coverage.js +35 -15
- package/dist/environments.d.ts +3 -19
- package/dist/environments.js +1 -1
- package/dist/execute.d.ts +5 -14
- package/dist/execute.js +2 -2
- package/dist/index.d.ts +267 -34
- package/dist/index.js +12 -12
- package/dist/node.d.ts +15 -9
- package/dist/node.js +26 -28
- package/dist/reporters.d.ts +10 -8
- package/dist/reporters.js +16 -18
- package/dist/runners.d.ts +15 -20
- package/dist/runners.js +12 -13
- package/dist/snapshot.js +3 -3
- package/dist/suite.d.ts +2 -16
- package/dist/suite.js +4 -4
- package/dist/worker.js +7 -8
- package/dist/workers/forks.js +5 -5
- package/dist/workers/runVmTests.js +18 -19
- package/dist/workers/threads.js +5 -5
- package/dist/workers/vmForks.js +8 -8
- package/dist/workers/vmThreads.js +8 -8
- package/dist/workers.d.ts +13 -8
- package/dist/workers.js +13 -13
- package/package.json +16 -17
- package/dist/chunks/integrations-globals.nDMtdOcn.js +0 -31
- package/dist/vendor/env.2ltrQNq0.js +0 -8
- package/dist/vendor/index.BMmMjLIQ.js +0 -3975
- /package/dist/{vendor → chunks}/_commonjsHelpers.BFTU3MAI.js +0 -0
- /package/dist/{vendor → chunks}/date.W2xKR2qe.js +0 -0
- /package/dist/chunks/{node-git.ZtkbKc8u.js → git.ZtkbKc8u.js} +0 -0
- /package/dist/{vendor → chunks}/index.BpSiYbpB.js +0 -0
- /package/dist/chunks/{install-pkg.DNUmWFkO.js → index.DNUmWFkO.js} +0 -0
- /package/dist/{vendor → chunks}/spy.Cf_4R5Oe.js +0 -0
|
@@ -1,35 +1,28 @@
|
|
|
1
|
+
import { g as getTestName, h as hasFailedSnapshot, a as getFullName } from './tasks.BZnCS9aT.js';
|
|
1
2
|
import fs, { existsSync, promises, readFileSync } from 'node:fs';
|
|
2
3
|
import c from 'tinyrainbow';
|
|
3
4
|
import * as pathe from 'pathe';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { generateHash, calculateSuiteHash, someTasksAreOnly, interpretTaskModes, getTasks, getTests, hasFailed, getSuites } from '@vitest/runner/utils';
|
|
5
|
+
import { relative, resolve, dirname, extname, normalize } from 'pathe';
|
|
6
|
+
import { notNullish, highlight, inspect, positionToOffset, lineSplitRE } from '@vitest/utils';
|
|
7
|
+
import { a as isNode, b as isDeno } from './env.CmHVDJnw.js';
|
|
8
|
+
import { g as getStateSymbol, f as formatProjectName, t as taskFail, 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.DO38lwfj.js';
|
|
9
|
+
import { getTests, hasFailed, getSuites, getTasks } from '@vitest/runner/utils';
|
|
10
10
|
import { performance } from 'node:perf_hooks';
|
|
11
|
-
import {
|
|
12
|
-
import { r as relativePath } from './index.
|
|
13
|
-
import {
|
|
14
|
-
import { t as toArray, b as isPrimitive } from './base.DRHPZCCj.js';
|
|
11
|
+
import { parseStacktrace, parseErrorStacktrace } from '@vitest/utils/source-map';
|
|
12
|
+
import { r as relativePath } from './index.CxRxs566.js';
|
|
13
|
+
import { t as toArray, c as isPrimitive } from './base.BH-FAiX7.js';
|
|
15
14
|
import { isCI } from 'std-env';
|
|
16
|
-
import
|
|
15
|
+
import { g as getOutputFile, R as RandomSequencer, a as TypeCheckError } from './RandomSequencer.B4M2ux5b.js';
|
|
16
|
+
import { hostname } from 'node:os';
|
|
17
17
|
import { Writable } from 'node:stream';
|
|
18
|
-
import { writeFile, rm, mkdir, readdir, readFile } from 'node:fs/promises';
|
|
19
|
-
import { execa } from 'execa';
|
|
20
|
-
import url from 'node:url';
|
|
21
|
-
import p$1 from 'path';
|
|
22
|
-
import require$$0 from 'fs';
|
|
23
|
-
import ge from 'module';
|
|
24
|
-
import { parseAstAsync } from 'vite';
|
|
25
18
|
import { Console } from 'node:console';
|
|
26
19
|
import process$2 from 'node:process';
|
|
27
20
|
import { g as getDefaultExportFromCjs, c as commonjsGlobal } from './_commonjsHelpers.BFTU3MAI.js';
|
|
28
|
-
import require$$0$
|
|
29
|
-
import require$$0
|
|
30
|
-
import { createHash } from 'node:crypto';
|
|
31
|
-
import { slash, cleanUrl } from 'vite-node/utils';
|
|
21
|
+
import require$$0$1 from 'assert';
|
|
22
|
+
import require$$0 from 'events';
|
|
32
23
|
import { createRequire } from 'node:module';
|
|
24
|
+
import { mkdir, writeFile, readdir, readFile } from 'node:fs/promises';
|
|
25
|
+
import { cleanUrl } from 'vite-node/utils';
|
|
33
26
|
|
|
34
27
|
/// <reference types="../types/index.d.ts" />
|
|
35
28
|
|
|
@@ -41,7 +34,7 @@ const {keys} = Object;
|
|
|
41
34
|
const Primitive = String; // it could be Number
|
|
42
35
|
const primitive = 'string'; // it could be 'number'
|
|
43
36
|
|
|
44
|
-
const ignore
|
|
37
|
+
const ignore = {};
|
|
45
38
|
const object = 'object';
|
|
46
39
|
|
|
47
40
|
const noop = (_, value) => value;
|
|
@@ -63,13 +56,13 @@ const revive = (input, parsed, output, $) => {
|
|
|
63
56
|
const tmp = input[value];
|
|
64
57
|
if (typeof tmp === object && !parsed.has(tmp)) {
|
|
65
58
|
parsed.add(tmp);
|
|
66
|
-
output[k] = ignore
|
|
59
|
+
output[k] = ignore;
|
|
67
60
|
lazy.push({k, a: [input, parsed, tmp, $]});
|
|
68
61
|
}
|
|
69
62
|
else
|
|
70
63
|
output[k] = $.call(output, k, tmp);
|
|
71
64
|
}
|
|
72
|
-
else if (output[k] !== ignore
|
|
65
|
+
else if (output[k] !== ignore)
|
|
73
66
|
output[k] = $.call(output, k, value);
|
|
74
67
|
}
|
|
75
68
|
for (let {length} = lazy, i = 0; i < length; i++) {
|
|
@@ -138,897 +131,6 @@ const stringify = (value, replacer, space) => {
|
|
|
138
131
|
}
|
|
139
132
|
};
|
|
140
133
|
|
|
141
|
-
const REGEXP_WRAP_PREFIX = "$$vitest:";
|
|
142
|
-
function getOutputFile(config, reporter) {
|
|
143
|
-
if (!(config == null ? void 0 : config.outputFile)) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
if (typeof config.outputFile === "string") {
|
|
147
|
-
return config.outputFile;
|
|
148
|
-
}
|
|
149
|
-
return config.outputFile[reporter];
|
|
150
|
-
}
|
|
151
|
-
function wrapSerializableConfig(config) {
|
|
152
|
-
let testNamePattern = config.testNamePattern;
|
|
153
|
-
let defines = config.defines;
|
|
154
|
-
if (testNamePattern && typeof testNamePattern !== "string") {
|
|
155
|
-
testNamePattern = `${REGEXP_WRAP_PREFIX}${testNamePattern.toString()}`;
|
|
156
|
-
}
|
|
157
|
-
if (defines) {
|
|
158
|
-
defines = { keys: Object.keys(defines), original: defines };
|
|
159
|
-
}
|
|
160
|
-
return {
|
|
161
|
-
...config,
|
|
162
|
-
testNamePattern,
|
|
163
|
-
defines
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const A=r=>r!==null&&typeof r=="object",a=(r,t)=>Object.assign(new Error(`[${r}]: ${t}`),{code:r}),_$1="ERR_INVALID_PACKAGE_CONFIG",E="ERR_INVALID_PACKAGE_TARGET",I$1="ERR_PACKAGE_PATH_NOT_EXPORTED",R$1=/^\d+$/,O=/^(\.{1,2}|node_modules)$/i,w=/\/|\\/;var h$1=(r=>(r.Export="exports",r.Import="imports",r))(h$1||{});const f=(r,t,e,o,c)=>{if(t==null)return [];if(typeof t=="string"){const[n,...i]=t.split(w);if(n===".."||i.some(l=>O.test(l)))throw a(E,`Invalid "${r}" target "${t}" defined in the package config`);return [c?t.replace(/\*/g,c):t]}if(Array.isArray(t))return t.flatMap(n=>f(r,n,e,o,c));if(A(t)){for(const n of Object.keys(t)){if(R$1.test(n))throw a(_$1,"Cannot contain numeric property keys");if(n==="default"||o.includes(n))return f(r,t[n],e,o,c)}return []}throw a(E,`Invalid "${r}" target "${t}"`)},s="*",m=(r,t)=>{const e=r.indexOf(s),o=t.indexOf(s);return e===o?t.length>r.length:o>e};function d(r,t){if(!t.includes(s)&&r.hasOwnProperty(t))return [t];let e,o;for(const c of Object.keys(r))if(c.includes(s)){const[n,i,l]=c.split(s);if(l===void 0&&t.startsWith(n)&&t.endsWith(i)){const g=t.slice(n.length,-i.length||void 0);g&&(!e||m(e,c))&&(e=c,o=g);}}return [e,o]}const p=r=>Object.keys(r).reduce((t,e)=>{const o=e===""||e[0]!==".";if(t===void 0||t===o)return o;throw a(_$1,'"exports" cannot contain some keys starting with "." and some not')},void 0),u=/^\w+:/,v=(r,t,e)=>{if(!r)throw new Error('"exports" is required');t=t===""?".":`./${t}`,(typeof r=="string"||Array.isArray(r)||A(r)&&p(r))&&(r={".":r});const[o,c]=d(r,t),n=f(h$1.Export,r[o],t,e,c);if(n.length===0)throw a(I$1,t==="."?'No "exports" main defined':`Package subpath '${t}' is not defined by "exports"`);for(const i of n)if(!i.startsWith("./")&&!u.test(i))throw a(E,`Invalid "exports" target "${i}" defined in the package config`);return n};
|
|
168
|
-
|
|
169
|
-
function B(e){return e.startsWith("\\\\?\\")?e:e.replace(/\\/g,"/")}const W=e=>{const t=require$$0[e];return (i,...n)=>{const l=`${e}:${n.join(":")}`;let s=i==null?void 0:i.get(l);return s===void 0&&(s=Reflect.apply(t,require$$0,n),i==null||i.set(l,s)),s}},_=W("existsSync"),ke=W("readFileSync"),I=W("statSync"),q=(e,t,i)=>{for(;;){const n=p$1.posix.join(e,t);if(_(i,n))return n;const l=p$1.dirname(e);if(l===e)return;e=l;}},h=/^\.{1,2}(\/.*)?$/,J=e=>{const t=B(e);return h.test(t)?t:`./${t}`};function be(e,t=!1){const i=e.length;let n=0,l="",s=0,o=16,m=0,u=0,w=0,v=0,f=0;function E(r,g){let c=0,$=0;for(;c<r||!g;){let A=e.charCodeAt(n);if(A>=48&&A<=57)$=$*16+A-48;else if(A>=65&&A<=70)$=$*16+A-65+10;else if(A>=97&&A<=102)$=$*16+A-97+10;else break;n++,c++;}return c<r&&($=-1),$}function b(r){n=r,l="",s=0,o=16,f=0;}function T(){let r=n;if(e.charCodeAt(n)===48)n++;else for(n++;n<e.length&&y(e.charCodeAt(n));)n++;if(n<e.length&&e.charCodeAt(n)===46)if(n++,n<e.length&&y(e.charCodeAt(n)))for(n++;n<e.length&&y(e.charCodeAt(n));)n++;else return f=3,e.substring(r,n);let g=n;if(n<e.length&&(e.charCodeAt(n)===69||e.charCodeAt(n)===101))if(n++,(n<e.length&&e.charCodeAt(n)===43||e.charCodeAt(n)===45)&&n++,n<e.length&&y(e.charCodeAt(n))){for(n++;n<e.length&&y(e.charCodeAt(n));)n++;g=n;}else f=3;return e.substring(r,g)}function k(){let r="",g=n;for(;;){if(n>=i){r+=e.substring(g,n),f=2;break}const c=e.charCodeAt(n);if(c===34){r+=e.substring(g,n),n++;break}if(c===92){if(r+=e.substring(g,n),n++,n>=i){f=2;break}switch(e.charCodeAt(n++)){case 34:r+='"';break;case 92:r+="\\";break;case 47:r+="/";break;case 98:r+="\b";break;case 102:r+="\f";break;case 110:r+=`
|
|
170
|
-
`;break;case 114:r+="\r";break;case 116:r+=" ";break;case 117:const A=E(4,!0);A>=0?r+=String.fromCharCode(A):f=4;break;default:f=5;}g=n;continue}if(c>=0&&c<=31)if(N(c)){r+=e.substring(g,n),f=2;break}else f=6;n++;}return r}function j(){if(l="",f=0,s=n,u=m,v=w,n>=i)return s=i,o=17;let r=e.charCodeAt(n);if(M(r)){do n++,l+=String.fromCharCode(r),r=e.charCodeAt(n);while(M(r));return o=15}if(N(r))return n++,l+=String.fromCharCode(r),r===13&&e.charCodeAt(n)===10&&(n++,l+=`
|
|
171
|
-
`),m++,w=n,o=14;switch(r){case 123:return n++,o=1;case 125:return n++,o=2;case 91:return n++,o=3;case 93:return n++,o=4;case 58:return n++,o=6;case 44:return n++,o=5;case 34:return n++,l=k(),o=10;case 47:const g=n-1;if(e.charCodeAt(n+1)===47){for(n+=2;n<i&&!N(e.charCodeAt(n));)n++;return l=e.substring(g,n),o=12}if(e.charCodeAt(n+1)===42){n+=2;const c=i-1;let $=!1;for(;n<c;){const A=e.charCodeAt(n);if(A===42&&e.charCodeAt(n+1)===47){n+=2,$=!0;break}n++,N(A)&&(A===13&&e.charCodeAt(n)===10&&n++,m++,w=n);}return $||(n++,f=1),l=e.substring(g,n),o=13}return l+=String.fromCharCode(r),n++,o=16;case 45:if(l+=String.fromCharCode(r),n++,n===i||!y(e.charCodeAt(n)))return o=16;case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return l+=T(),o=11;default:for(;n<i&&L(r);)n++,r=e.charCodeAt(n);if(s!==n){switch(l=e.substring(s,n),l){case"true":return o=8;case"false":return o=9;case"null":return o=7}return o=16}return l+=String.fromCharCode(r),n++,o=16}}function L(r){if(M(r)||N(r))return !1;switch(r){case 125:case 93:case 123:case 91:case 34:case 58:case 44:case 47:return !1}return !0}function U(){let r;do r=j();while(r>=12&&r<=15);return r}return {setPosition:b,getPosition:()=>n,scan:t?U:j,getToken:()=>o,getTokenValue:()=>l,getTokenOffset:()=>s,getTokenLength:()=>n-s,getTokenStartLine:()=>u,getTokenStartCharacter:()=>s-v,getTokenError:()=>f}}function M(e){return e===32||e===9}function N(e){return e===10||e===13}function y(e){return e>=48&&e<=57}var K;((function(e){e[e.lineFeed=10]="lineFeed",e[e.carriageReturn=13]="carriageReturn",e[e.space=32]="space",e[e._0=48]="_0",e[e._1=49]="_1",e[e._2=50]="_2",e[e._3=51]="_3",e[e._4=52]="_4",e[e._5=53]="_5",e[e._6=54]="_6",e[e._7=55]="_7",e[e._8=56]="_8",e[e._9=57]="_9",e[e.a=97]="a",e[e.b=98]="b",e[e.c=99]="c",e[e.d=100]="d",e[e.e=101]="e",e[e.f=102]="f",e[e.g=103]="g",e[e.h=104]="h",e[e.i=105]="i",e[e.j=106]="j",e[e.k=107]="k",e[e.l=108]="l",e[e.m=109]="m",e[e.n=110]="n",e[e.o=111]="o",e[e.p=112]="p",e[e.q=113]="q",e[e.r=114]="r",e[e.s=115]="s",e[e.t=116]="t",e[e.u=117]="u",e[e.v=118]="v",e[e.w=119]="w",e[e.x=120]="x",e[e.y=121]="y",e[e.z=122]="z",e[e.A=65]="A",e[e.B=66]="B",e[e.C=67]="C",e[e.D=68]="D",e[e.E=69]="E",e[e.F=70]="F",e[e.G=71]="G",e[e.H=72]="H",e[e.I=73]="I",e[e.J=74]="J",e[e.K=75]="K",e[e.L=76]="L",e[e.M=77]="M",e[e.N=78]="N",e[e.O=79]="O",e[e.P=80]="P",e[e.Q=81]="Q",e[e.R=82]="R",e[e.S=83]="S",e[e.T=84]="T",e[e.U=85]="U",e[e.V=86]="V",e[e.W=87]="W",e[e.X=88]="X",e[e.Y=89]="Y",e[e.Z=90]="Z",e[e.asterisk=42]="asterisk",e[e.backslash=92]="backslash",e[e.closeBrace=125]="closeBrace",e[e.closeBracket=93]="closeBracket",e[e.colon=58]="colon",e[e.comma=44]="comma",e[e.dot=46]="dot",e[e.doubleQuote=34]="doubleQuote",e[e.minus=45]="minus",e[e.openBrace=123]="openBrace",e[e.openBracket=91]="openBracket",e[e.plus=43]="plus",e[e.slash=47]="slash",e[e.formFeed=12]="formFeed",e[e.tab=9]="tab";}))(K||(K={})),new Array(20).fill(0).map((e,t)=>" ".repeat(t));const F=200;new Array(F).fill(0).map((e,t)=>`
|
|
172
|
-
`+" ".repeat(t)),new Array(F).fill(0).map((e,t)=>"\r"+" ".repeat(t)),new Array(F).fill(0).map((e,t)=>`\r
|
|
173
|
-
`+" ".repeat(t)),new Array(F).fill(0).map((e,t)=>`
|
|
174
|
-
`+" ".repeat(t)),new Array(F).fill(0).map((e,t)=>"\r"+" ".repeat(t)),new Array(F).fill(0).map((e,t)=>`\r
|
|
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";
|
|
176
|
-
|
|
177
|
-
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
|
|
178
|
-
const newLineRegExp = /\r?\n/;
|
|
179
|
-
const errCodeRegExp = /error TS(?<errCode>\d+)/;
|
|
180
|
-
async function makeTscErrorInfo(errInfo) {
|
|
181
|
-
var _a;
|
|
182
|
-
const [errFilePathPos = "", ...errMsgRawArr] = errInfo.split(":");
|
|
183
|
-
if (!errFilePathPos || errMsgRawArr.length === 0 || errMsgRawArr.join("").length === 0) {
|
|
184
|
-
return ["unknown filepath", null];
|
|
185
|
-
}
|
|
186
|
-
const errMsgRaw = errMsgRawArr.join("").trim();
|
|
187
|
-
const [errFilePath, errPos] = errFilePathPos.slice(0, -1).split("(");
|
|
188
|
-
if (!errFilePath || !errPos) {
|
|
189
|
-
return ["unknown filepath", null];
|
|
190
|
-
}
|
|
191
|
-
const [errLine, errCol] = errPos.split(",");
|
|
192
|
-
if (!errLine || !errCol) {
|
|
193
|
-
return [errFilePath, null];
|
|
194
|
-
}
|
|
195
|
-
const execArr = errCodeRegExp.exec(errMsgRaw);
|
|
196
|
-
if (!execArr) {
|
|
197
|
-
return [errFilePath, null];
|
|
198
|
-
}
|
|
199
|
-
const errCodeStr = ((_a = execArr.groups) == null ? void 0 : _a.errCode) ?? "";
|
|
200
|
-
if (!errCodeStr) {
|
|
201
|
-
return [errFilePath, null];
|
|
202
|
-
}
|
|
203
|
-
const line = Number(errLine);
|
|
204
|
-
const col = Number(errCol);
|
|
205
|
-
const errCode = Number(errCodeStr);
|
|
206
|
-
return [
|
|
207
|
-
errFilePath,
|
|
208
|
-
{
|
|
209
|
-
filePath: errFilePath,
|
|
210
|
-
errCode,
|
|
211
|
-
line,
|
|
212
|
-
column: col,
|
|
213
|
-
errMsg: errMsgRaw.slice(`error TS${errCode} `.length)
|
|
214
|
-
}
|
|
215
|
-
];
|
|
216
|
-
}
|
|
217
|
-
async function getTsconfig(root, config) {
|
|
218
|
-
const configName = config.tsconfig ? basename(config.tsconfig) : void 0;
|
|
219
|
-
const configSearchPath = config.tsconfig ? dirname(resolve(root, config.tsconfig)) : root;
|
|
220
|
-
const tsconfig = $e(configSearchPath, configName);
|
|
221
|
-
if (!tsconfig) {
|
|
222
|
-
throw new Error("no tsconfig.json found");
|
|
223
|
-
}
|
|
224
|
-
const tempConfigPath = join(
|
|
225
|
-
dirname(tsconfig.path),
|
|
226
|
-
"tsconfig.vitest-temp.json"
|
|
227
|
-
);
|
|
228
|
-
try {
|
|
229
|
-
const tmpTsConfig = { ...tsconfig.config };
|
|
230
|
-
tmpTsConfig.compilerOptions = tmpTsConfig.compilerOptions || {};
|
|
231
|
-
tmpTsConfig.compilerOptions.emitDeclarationOnly = false;
|
|
232
|
-
tmpTsConfig.compilerOptions.incremental = true;
|
|
233
|
-
tmpTsConfig.compilerOptions.tsBuildInfoFile = join(
|
|
234
|
-
process.versions.pnp ? join(nodeos__default.tmpdir(), "vitest") : __dirname,
|
|
235
|
-
"tsconfig.tmp.tsbuildinfo"
|
|
236
|
-
);
|
|
237
|
-
const tsconfigFinalContent = JSON.stringify(tmpTsConfig, null, 2);
|
|
238
|
-
await writeFile(tempConfigPath, tsconfigFinalContent);
|
|
239
|
-
return { path: tempConfigPath, config: tmpTsConfig };
|
|
240
|
-
} catch (err) {
|
|
241
|
-
throw new Error("failed to write tsconfig.temp.json", { cause: err });
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
async function getRawErrsMapFromTsCompile(tscErrorStdout) {
|
|
245
|
-
const rawErrsMap = /* @__PURE__ */ new Map();
|
|
246
|
-
const infos = await Promise.all(
|
|
247
|
-
tscErrorStdout.split(newLineRegExp).reduce((prev, next) => {
|
|
248
|
-
if (!next) {
|
|
249
|
-
return prev;
|
|
250
|
-
} else if (!next.startsWith(" ")) {
|
|
251
|
-
prev.push(next);
|
|
252
|
-
} else {
|
|
253
|
-
prev[prev.length - 1] += `
|
|
254
|
-
${next}`;
|
|
255
|
-
}
|
|
256
|
-
return prev;
|
|
257
|
-
}, []).map((errInfoLine) => makeTscErrorInfo(errInfoLine))
|
|
258
|
-
);
|
|
259
|
-
infos.forEach(([errFilePath, errInfo]) => {
|
|
260
|
-
var _a;
|
|
261
|
-
if (!errInfo) {
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
if (!rawErrsMap.has(errFilePath)) {
|
|
265
|
-
rawErrsMap.set(errFilePath, [errInfo]);
|
|
266
|
-
} else {
|
|
267
|
-
(_a = rawErrsMap.get(errFilePath)) == null ? void 0 : _a.push(errInfo);
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
return rawErrsMap;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function createIndexMap(source) {
|
|
274
|
-
const map = /* @__PURE__ */ new Map();
|
|
275
|
-
let index = 0;
|
|
276
|
-
let line = 1;
|
|
277
|
-
let column = 1;
|
|
278
|
-
for (const char of source) {
|
|
279
|
-
map.set(`${line}:${column}`, index++);
|
|
280
|
-
if (char === "\n" || char === "\r\n") {
|
|
281
|
-
line++;
|
|
282
|
-
column = 0;
|
|
283
|
-
} else {
|
|
284
|
-
column++;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
return map;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
// AST walker module for ESTree compatible trees
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
// An ancestor walk keeps an array of ancestor nodes (including the
|
|
294
|
-
// current node) and passes them to the callback as third parameter
|
|
295
|
-
// (and also as state parameter when no other state is present).
|
|
296
|
-
function ancestor(node, visitors, baseVisitor, state, override) {
|
|
297
|
-
var ancestors = [];
|
|
298
|
-
if (!baseVisitor) { baseVisitor = base
|
|
299
|
-
; }(function c(node, st, override) {
|
|
300
|
-
var type = override || node.type;
|
|
301
|
-
var isNew = node !== ancestors[ancestors.length - 1];
|
|
302
|
-
if (isNew) { ancestors.push(node); }
|
|
303
|
-
baseVisitor[type](node, st, c);
|
|
304
|
-
if (visitors[type]) { visitors[type](node, st || ancestors, ancestors); }
|
|
305
|
-
if (isNew) { ancestors.pop(); }
|
|
306
|
-
})(node, state, override);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
function makeTest(test) {
|
|
310
|
-
if (typeof test === "string")
|
|
311
|
-
{ return function (type) { return type === test; } }
|
|
312
|
-
else if (!test)
|
|
313
|
-
{ return function () { return true; } }
|
|
314
|
-
else
|
|
315
|
-
{ return test }
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
var Found = function Found(node, state) { this.node = node; this.state = state; };
|
|
319
|
-
|
|
320
|
-
// Find the innermost node of a given type that contains the given
|
|
321
|
-
// position. Interface similar to findNodeAt.
|
|
322
|
-
function findNodeAround(node, pos, test, baseVisitor, state) {
|
|
323
|
-
test = makeTest(test);
|
|
324
|
-
if (!baseVisitor) { baseVisitor = base; }
|
|
325
|
-
try {
|
|
326
|
-
(function c(node, st, override) {
|
|
327
|
-
var type = override || node.type;
|
|
328
|
-
if (node.start > pos || node.end < pos) { return }
|
|
329
|
-
baseVisitor[type](node, st, c);
|
|
330
|
-
if (test(type, node)) { throw new Found(node, st) }
|
|
331
|
-
})(node, state);
|
|
332
|
-
} catch (e) {
|
|
333
|
-
if (e instanceof Found) { return e }
|
|
334
|
-
throw e
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
function skipThrough(node, st, c) { c(node, st); }
|
|
339
|
-
function ignore(_node, _st, _c) {}
|
|
340
|
-
|
|
341
|
-
// Node walkers.
|
|
342
|
-
|
|
343
|
-
var base = {};
|
|
344
|
-
|
|
345
|
-
base.Program = base.BlockStatement = base.StaticBlock = function (node, st, c) {
|
|
346
|
-
for (var i = 0, list = node.body; i < list.length; i += 1)
|
|
347
|
-
{
|
|
348
|
-
var stmt = list[i];
|
|
349
|
-
|
|
350
|
-
c(stmt, st, "Statement");
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
base.Statement = skipThrough;
|
|
354
|
-
base.EmptyStatement = ignore;
|
|
355
|
-
base.ExpressionStatement = base.ParenthesizedExpression = base.ChainExpression =
|
|
356
|
-
function (node, st, c) { return c(node.expression, st, "Expression"); };
|
|
357
|
-
base.IfStatement = function (node, st, c) {
|
|
358
|
-
c(node.test, st, "Expression");
|
|
359
|
-
c(node.consequent, st, "Statement");
|
|
360
|
-
if (node.alternate) { c(node.alternate, st, "Statement"); }
|
|
361
|
-
};
|
|
362
|
-
base.LabeledStatement = function (node, st, c) { return c(node.body, st, "Statement"); };
|
|
363
|
-
base.BreakStatement = base.ContinueStatement = ignore;
|
|
364
|
-
base.WithStatement = function (node, st, c) {
|
|
365
|
-
c(node.object, st, "Expression");
|
|
366
|
-
c(node.body, st, "Statement");
|
|
367
|
-
};
|
|
368
|
-
base.SwitchStatement = function (node, st, c) {
|
|
369
|
-
c(node.discriminant, st, "Expression");
|
|
370
|
-
for (var i$1 = 0, list$1 = node.cases; i$1 < list$1.length; i$1 += 1) {
|
|
371
|
-
var cs = list$1[i$1];
|
|
372
|
-
|
|
373
|
-
if (cs.test) { c(cs.test, st, "Expression"); }
|
|
374
|
-
for (var i = 0, list = cs.consequent; i < list.length; i += 1)
|
|
375
|
-
{
|
|
376
|
-
var cons = list[i];
|
|
377
|
-
|
|
378
|
-
c(cons, st, "Statement");
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
|
-
base.SwitchCase = function (node, st, c) {
|
|
383
|
-
if (node.test) { c(node.test, st, "Expression"); }
|
|
384
|
-
for (var i = 0, list = node.consequent; i < list.length; i += 1)
|
|
385
|
-
{
|
|
386
|
-
var cons = list[i];
|
|
387
|
-
|
|
388
|
-
c(cons, st, "Statement");
|
|
389
|
-
}
|
|
390
|
-
};
|
|
391
|
-
base.ReturnStatement = base.YieldExpression = base.AwaitExpression = function (node, st, c) {
|
|
392
|
-
if (node.argument) { c(node.argument, st, "Expression"); }
|
|
393
|
-
};
|
|
394
|
-
base.ThrowStatement = base.SpreadElement =
|
|
395
|
-
function (node, st, c) { return c(node.argument, st, "Expression"); };
|
|
396
|
-
base.TryStatement = function (node, st, c) {
|
|
397
|
-
c(node.block, st, "Statement");
|
|
398
|
-
if (node.handler) { c(node.handler, st); }
|
|
399
|
-
if (node.finalizer) { c(node.finalizer, st, "Statement"); }
|
|
400
|
-
};
|
|
401
|
-
base.CatchClause = function (node, st, c) {
|
|
402
|
-
if (node.param) { c(node.param, st, "Pattern"); }
|
|
403
|
-
c(node.body, st, "Statement");
|
|
404
|
-
};
|
|
405
|
-
base.WhileStatement = base.DoWhileStatement = function (node, st, c) {
|
|
406
|
-
c(node.test, st, "Expression");
|
|
407
|
-
c(node.body, st, "Statement");
|
|
408
|
-
};
|
|
409
|
-
base.ForStatement = function (node, st, c) {
|
|
410
|
-
if (node.init) { c(node.init, st, "ForInit"); }
|
|
411
|
-
if (node.test) { c(node.test, st, "Expression"); }
|
|
412
|
-
if (node.update) { c(node.update, st, "Expression"); }
|
|
413
|
-
c(node.body, st, "Statement");
|
|
414
|
-
};
|
|
415
|
-
base.ForInStatement = base.ForOfStatement = function (node, st, c) {
|
|
416
|
-
c(node.left, st, "ForInit");
|
|
417
|
-
c(node.right, st, "Expression");
|
|
418
|
-
c(node.body, st, "Statement");
|
|
419
|
-
};
|
|
420
|
-
base.ForInit = function (node, st, c) {
|
|
421
|
-
if (node.type === "VariableDeclaration") { c(node, st); }
|
|
422
|
-
else { c(node, st, "Expression"); }
|
|
423
|
-
};
|
|
424
|
-
base.DebuggerStatement = ignore;
|
|
425
|
-
|
|
426
|
-
base.FunctionDeclaration = function (node, st, c) { return c(node, st, "Function"); };
|
|
427
|
-
base.VariableDeclaration = function (node, st, c) {
|
|
428
|
-
for (var i = 0, list = node.declarations; i < list.length; i += 1)
|
|
429
|
-
{
|
|
430
|
-
var decl = list[i];
|
|
431
|
-
|
|
432
|
-
c(decl, st);
|
|
433
|
-
}
|
|
434
|
-
};
|
|
435
|
-
base.VariableDeclarator = function (node, st, c) {
|
|
436
|
-
c(node.id, st, "Pattern");
|
|
437
|
-
if (node.init) { c(node.init, st, "Expression"); }
|
|
438
|
-
};
|
|
439
|
-
|
|
440
|
-
base.Function = function (node, st, c) {
|
|
441
|
-
if (node.id) { c(node.id, st, "Pattern"); }
|
|
442
|
-
for (var i = 0, list = node.params; i < list.length; i += 1)
|
|
443
|
-
{
|
|
444
|
-
var param = list[i];
|
|
445
|
-
|
|
446
|
-
c(param, st, "Pattern");
|
|
447
|
-
}
|
|
448
|
-
c(node.body, st, node.expression ? "Expression" : "Statement");
|
|
449
|
-
};
|
|
450
|
-
|
|
451
|
-
base.Pattern = function (node, st, c) {
|
|
452
|
-
if (node.type === "Identifier")
|
|
453
|
-
{ c(node, st, "VariablePattern"); }
|
|
454
|
-
else if (node.type === "MemberExpression")
|
|
455
|
-
{ c(node, st, "MemberPattern"); }
|
|
456
|
-
else
|
|
457
|
-
{ c(node, st); }
|
|
458
|
-
};
|
|
459
|
-
base.VariablePattern = ignore;
|
|
460
|
-
base.MemberPattern = skipThrough;
|
|
461
|
-
base.RestElement = function (node, st, c) { return c(node.argument, st, "Pattern"); };
|
|
462
|
-
base.ArrayPattern = function (node, st, c) {
|
|
463
|
-
for (var i = 0, list = node.elements; i < list.length; i += 1) {
|
|
464
|
-
var elt = list[i];
|
|
465
|
-
|
|
466
|
-
if (elt) { c(elt, st, "Pattern"); }
|
|
467
|
-
}
|
|
468
|
-
};
|
|
469
|
-
base.ObjectPattern = function (node, st, c) {
|
|
470
|
-
for (var i = 0, list = node.properties; i < list.length; i += 1) {
|
|
471
|
-
var prop = list[i];
|
|
472
|
-
|
|
473
|
-
if (prop.type === "Property") {
|
|
474
|
-
if (prop.computed) { c(prop.key, st, "Expression"); }
|
|
475
|
-
c(prop.value, st, "Pattern");
|
|
476
|
-
} else if (prop.type === "RestElement") {
|
|
477
|
-
c(prop.argument, st, "Pattern");
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
|
|
482
|
-
base.Expression = skipThrough;
|
|
483
|
-
base.ThisExpression = base.Super = base.MetaProperty = ignore;
|
|
484
|
-
base.ArrayExpression = function (node, st, c) {
|
|
485
|
-
for (var i = 0, list = node.elements; i < list.length; i += 1) {
|
|
486
|
-
var elt = list[i];
|
|
487
|
-
|
|
488
|
-
if (elt) { c(elt, st, "Expression"); }
|
|
489
|
-
}
|
|
490
|
-
};
|
|
491
|
-
base.ObjectExpression = function (node, st, c) {
|
|
492
|
-
for (var i = 0, list = node.properties; i < list.length; i += 1)
|
|
493
|
-
{
|
|
494
|
-
var prop = list[i];
|
|
495
|
-
|
|
496
|
-
c(prop, st);
|
|
497
|
-
}
|
|
498
|
-
};
|
|
499
|
-
base.FunctionExpression = base.ArrowFunctionExpression = base.FunctionDeclaration;
|
|
500
|
-
base.SequenceExpression = function (node, st, c) {
|
|
501
|
-
for (var i = 0, list = node.expressions; i < list.length; i += 1)
|
|
502
|
-
{
|
|
503
|
-
var expr = list[i];
|
|
504
|
-
|
|
505
|
-
c(expr, st, "Expression");
|
|
506
|
-
}
|
|
507
|
-
};
|
|
508
|
-
base.TemplateLiteral = function (node, st, c) {
|
|
509
|
-
for (var i = 0, list = node.quasis; i < list.length; i += 1)
|
|
510
|
-
{
|
|
511
|
-
var quasi = list[i];
|
|
512
|
-
|
|
513
|
-
c(quasi, st);
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
for (var i$1 = 0, list$1 = node.expressions; i$1 < list$1.length; i$1 += 1)
|
|
517
|
-
{
|
|
518
|
-
var expr = list$1[i$1];
|
|
519
|
-
|
|
520
|
-
c(expr, st, "Expression");
|
|
521
|
-
}
|
|
522
|
-
};
|
|
523
|
-
base.TemplateElement = ignore;
|
|
524
|
-
base.UnaryExpression = base.UpdateExpression = function (node, st, c) {
|
|
525
|
-
c(node.argument, st, "Expression");
|
|
526
|
-
};
|
|
527
|
-
base.BinaryExpression = base.LogicalExpression = function (node, st, c) {
|
|
528
|
-
c(node.left, st, "Expression");
|
|
529
|
-
c(node.right, st, "Expression");
|
|
530
|
-
};
|
|
531
|
-
base.AssignmentExpression = base.AssignmentPattern = function (node, st, c) {
|
|
532
|
-
c(node.left, st, "Pattern");
|
|
533
|
-
c(node.right, st, "Expression");
|
|
534
|
-
};
|
|
535
|
-
base.ConditionalExpression = function (node, st, c) {
|
|
536
|
-
c(node.test, st, "Expression");
|
|
537
|
-
c(node.consequent, st, "Expression");
|
|
538
|
-
c(node.alternate, st, "Expression");
|
|
539
|
-
};
|
|
540
|
-
base.NewExpression = base.CallExpression = function (node, st, c) {
|
|
541
|
-
c(node.callee, st, "Expression");
|
|
542
|
-
if (node.arguments)
|
|
543
|
-
{ for (var i = 0, list = node.arguments; i < list.length; i += 1)
|
|
544
|
-
{
|
|
545
|
-
var arg = list[i];
|
|
546
|
-
|
|
547
|
-
c(arg, st, "Expression");
|
|
548
|
-
} }
|
|
549
|
-
};
|
|
550
|
-
base.MemberExpression = function (node, st, c) {
|
|
551
|
-
c(node.object, st, "Expression");
|
|
552
|
-
if (node.computed) { c(node.property, st, "Expression"); }
|
|
553
|
-
};
|
|
554
|
-
base.ExportNamedDeclaration = base.ExportDefaultDeclaration = function (node, st, c) {
|
|
555
|
-
if (node.declaration)
|
|
556
|
-
{ c(node.declaration, st, node.type === "ExportNamedDeclaration" || node.declaration.id ? "Statement" : "Expression"); }
|
|
557
|
-
if (node.source) { c(node.source, st, "Expression"); }
|
|
558
|
-
};
|
|
559
|
-
base.ExportAllDeclaration = function (node, st, c) {
|
|
560
|
-
if (node.exported)
|
|
561
|
-
{ c(node.exported, st); }
|
|
562
|
-
c(node.source, st, "Expression");
|
|
563
|
-
};
|
|
564
|
-
base.ImportDeclaration = function (node, st, c) {
|
|
565
|
-
for (var i = 0, list = node.specifiers; i < list.length; i += 1)
|
|
566
|
-
{
|
|
567
|
-
var spec = list[i];
|
|
568
|
-
|
|
569
|
-
c(spec, st);
|
|
570
|
-
}
|
|
571
|
-
c(node.source, st, "Expression");
|
|
572
|
-
};
|
|
573
|
-
base.ImportExpression = function (node, st, c) {
|
|
574
|
-
c(node.source, st, "Expression");
|
|
575
|
-
};
|
|
576
|
-
base.ImportSpecifier = base.ImportDefaultSpecifier = base.ImportNamespaceSpecifier = base.Identifier = base.PrivateIdentifier = base.Literal = ignore;
|
|
577
|
-
|
|
578
|
-
base.TaggedTemplateExpression = function (node, st, c) {
|
|
579
|
-
c(node.tag, st, "Expression");
|
|
580
|
-
c(node.quasi, st, "Expression");
|
|
581
|
-
};
|
|
582
|
-
base.ClassDeclaration = base.ClassExpression = function (node, st, c) { return c(node, st, "Class"); };
|
|
583
|
-
base.Class = function (node, st, c) {
|
|
584
|
-
if (node.id) { c(node.id, st, "Pattern"); }
|
|
585
|
-
if (node.superClass) { c(node.superClass, st, "Expression"); }
|
|
586
|
-
c(node.body, st);
|
|
587
|
-
};
|
|
588
|
-
base.ClassBody = function (node, st, c) {
|
|
589
|
-
for (var i = 0, list = node.body; i < list.length; i += 1)
|
|
590
|
-
{
|
|
591
|
-
var elt = list[i];
|
|
592
|
-
|
|
593
|
-
c(elt, st);
|
|
594
|
-
}
|
|
595
|
-
};
|
|
596
|
-
base.MethodDefinition = base.PropertyDefinition = base.Property = function (node, st, c) {
|
|
597
|
-
if (node.computed) { c(node.key, st, "Expression"); }
|
|
598
|
-
if (node.value) { c(node.value, st, "Expression"); }
|
|
599
|
-
};
|
|
600
|
-
|
|
601
|
-
async function collectTests(ctx, filepath) {
|
|
602
|
-
const request = await ctx.vitenode.transformRequest(filepath, filepath);
|
|
603
|
-
if (!request) {
|
|
604
|
-
return null;
|
|
605
|
-
}
|
|
606
|
-
const ast = await parseAstAsync(request.code);
|
|
607
|
-
const testFilepath = relative(ctx.config.root, filepath);
|
|
608
|
-
const file = {
|
|
609
|
-
filepath,
|
|
610
|
-
type: "suite",
|
|
611
|
-
id: generateHash(`${testFilepath}${ctx.config.name || ""}`),
|
|
612
|
-
name: testFilepath,
|
|
613
|
-
mode: "run",
|
|
614
|
-
tasks: [],
|
|
615
|
-
start: ast.start,
|
|
616
|
-
end: ast.end,
|
|
617
|
-
projectName: ctx.getName(),
|
|
618
|
-
meta: { typecheck: true },
|
|
619
|
-
file: null
|
|
620
|
-
};
|
|
621
|
-
file.file = file;
|
|
622
|
-
const definitions = [];
|
|
623
|
-
const getName = (callee) => {
|
|
624
|
-
var _a, _b, _c;
|
|
625
|
-
if (!callee) {
|
|
626
|
-
return null;
|
|
627
|
-
}
|
|
628
|
-
if (callee.type === "Identifier") {
|
|
629
|
-
return callee.name;
|
|
630
|
-
}
|
|
631
|
-
if (callee.type === "MemberExpression") {
|
|
632
|
-
if ((_b = (_a = callee.object) == null ? void 0 : _a.name) == null ? void 0 : _b.startsWith("__vite_ssr_")) {
|
|
633
|
-
return getName(callee.property);
|
|
634
|
-
}
|
|
635
|
-
return getName((_c = callee.object) == null ? void 0 : _c.property);
|
|
636
|
-
}
|
|
637
|
-
return null;
|
|
638
|
-
};
|
|
639
|
-
ancestor(ast, {
|
|
640
|
-
CallExpression(node) {
|
|
641
|
-
var _a;
|
|
642
|
-
const { callee } = node;
|
|
643
|
-
const name = getName(callee);
|
|
644
|
-
if (!name) {
|
|
645
|
-
return;
|
|
646
|
-
}
|
|
647
|
-
if (!["it", "test", "describe", "suite"].includes(name)) {
|
|
648
|
-
return;
|
|
649
|
-
}
|
|
650
|
-
const {
|
|
651
|
-
arguments: [{ value: message }]
|
|
652
|
-
} = node;
|
|
653
|
-
const property = (_a = callee == null ? void 0 : callee.property) == null ? void 0 : _a.name;
|
|
654
|
-
let mode = !property || property === name ? "run" : property;
|
|
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") {
|
|
661
|
-
mode = "skip";
|
|
662
|
-
}
|
|
663
|
-
definitions.push({
|
|
664
|
-
start: node.start,
|
|
665
|
-
end: node.end,
|
|
666
|
-
name: message,
|
|
667
|
-
type: name === "it" || name === "test" ? "test" : "suite",
|
|
668
|
-
mode
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
|
-
});
|
|
672
|
-
let lastSuite = file;
|
|
673
|
-
const updateLatestSuite = (index) => {
|
|
674
|
-
while (lastSuite.suite && lastSuite.end < index) {
|
|
675
|
-
lastSuite = lastSuite.suite;
|
|
676
|
-
}
|
|
677
|
-
return lastSuite;
|
|
678
|
-
};
|
|
679
|
-
definitions.sort((a, b) => a.start - b.start).forEach((definition) => {
|
|
680
|
-
const latestSuite = updateLatestSuite(definition.start);
|
|
681
|
-
let mode = definition.mode;
|
|
682
|
-
if (latestSuite.mode !== "run") {
|
|
683
|
-
mode = latestSuite.mode;
|
|
684
|
-
}
|
|
685
|
-
if (definition.type === "suite") {
|
|
686
|
-
const task2 = {
|
|
687
|
-
type: definition.type,
|
|
688
|
-
id: "",
|
|
689
|
-
suite: latestSuite,
|
|
690
|
-
file,
|
|
691
|
-
tasks: [],
|
|
692
|
-
mode,
|
|
693
|
-
name: definition.name,
|
|
694
|
-
end: definition.end,
|
|
695
|
-
start: definition.start,
|
|
696
|
-
meta: {
|
|
697
|
-
typecheck: true
|
|
698
|
-
}
|
|
699
|
-
};
|
|
700
|
-
definition.task = task2;
|
|
701
|
-
latestSuite.tasks.push(task2);
|
|
702
|
-
lastSuite = task2;
|
|
703
|
-
return;
|
|
704
|
-
}
|
|
705
|
-
const task = {
|
|
706
|
-
type: definition.type,
|
|
707
|
-
id: "",
|
|
708
|
-
suite: latestSuite,
|
|
709
|
-
file,
|
|
710
|
-
mode,
|
|
711
|
-
context: {},
|
|
712
|
-
// not used in typecheck
|
|
713
|
-
name: definition.name,
|
|
714
|
-
end: definition.end,
|
|
715
|
-
start: definition.start,
|
|
716
|
-
meta: {
|
|
717
|
-
typecheck: true
|
|
718
|
-
}
|
|
719
|
-
};
|
|
720
|
-
definition.task = task;
|
|
721
|
-
latestSuite.tasks.push(task);
|
|
722
|
-
});
|
|
723
|
-
calculateSuiteHash(file);
|
|
724
|
-
const hasOnly = someTasksAreOnly(file);
|
|
725
|
-
interpretTaskModes(
|
|
726
|
-
file,
|
|
727
|
-
ctx.config.testNamePattern,
|
|
728
|
-
hasOnly,
|
|
729
|
-
false,
|
|
730
|
-
ctx.config.allowOnly
|
|
731
|
-
);
|
|
732
|
-
return {
|
|
733
|
-
file,
|
|
734
|
-
parsed: request.code,
|
|
735
|
-
filepath,
|
|
736
|
-
map: request.map,
|
|
737
|
-
definitions
|
|
738
|
-
};
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
class TypeCheckError extends Error {
|
|
742
|
-
constructor(message, stacks) {
|
|
743
|
-
super(message);
|
|
744
|
-
this.message = message;
|
|
745
|
-
this.stacks = stacks;
|
|
746
|
-
}
|
|
747
|
-
name = "TypeCheckError";
|
|
748
|
-
}
|
|
749
|
-
class Typechecker {
|
|
750
|
-
constructor(ctx) {
|
|
751
|
-
this.ctx = ctx;
|
|
752
|
-
}
|
|
753
|
-
_onParseStart;
|
|
754
|
-
_onParseEnd;
|
|
755
|
-
_onWatcherRerun;
|
|
756
|
-
_result = {
|
|
757
|
-
files: [],
|
|
758
|
-
sourceErrors: [],
|
|
759
|
-
time: 0
|
|
760
|
-
};
|
|
761
|
-
_startTime = 0;
|
|
762
|
-
_output = "";
|
|
763
|
-
_tests = {};
|
|
764
|
-
tempConfigPath;
|
|
765
|
-
allowJs;
|
|
766
|
-
process;
|
|
767
|
-
files = [];
|
|
768
|
-
setFiles(files) {
|
|
769
|
-
this.files = files;
|
|
770
|
-
}
|
|
771
|
-
onParseStart(fn) {
|
|
772
|
-
this._onParseStart = fn;
|
|
773
|
-
}
|
|
774
|
-
onParseEnd(fn) {
|
|
775
|
-
this._onParseEnd = fn;
|
|
776
|
-
}
|
|
777
|
-
onWatcherRerun(fn) {
|
|
778
|
-
this._onWatcherRerun = fn;
|
|
779
|
-
}
|
|
780
|
-
async collectFileTests(filepath) {
|
|
781
|
-
return collectTests(this.ctx, filepath);
|
|
782
|
-
}
|
|
783
|
-
getFiles() {
|
|
784
|
-
return this.files.filter((filename) => {
|
|
785
|
-
const extension = extname(filename);
|
|
786
|
-
return extension !== ".js" || this.allowJs;
|
|
787
|
-
});
|
|
788
|
-
}
|
|
789
|
-
async collectTests() {
|
|
790
|
-
const tests = (await Promise.all(
|
|
791
|
-
this.getFiles().map((filepath) => this.collectFileTests(filepath))
|
|
792
|
-
)).reduce((acc, data) => {
|
|
793
|
-
if (!data) {
|
|
794
|
-
return acc;
|
|
795
|
-
}
|
|
796
|
-
acc[data.filepath] = data;
|
|
797
|
-
return acc;
|
|
798
|
-
}, {});
|
|
799
|
-
this._tests = tests;
|
|
800
|
-
return tests;
|
|
801
|
-
}
|
|
802
|
-
markPassed(file) {
|
|
803
|
-
var _a;
|
|
804
|
-
if (!((_a = file.result) == null ? void 0 : _a.state)) {
|
|
805
|
-
file.result = {
|
|
806
|
-
state: "pass"
|
|
807
|
-
};
|
|
808
|
-
}
|
|
809
|
-
const markTasks = (tasks) => {
|
|
810
|
-
var _a2;
|
|
811
|
-
for (const task of tasks) {
|
|
812
|
-
if ("tasks" in task) {
|
|
813
|
-
markTasks(task.tasks);
|
|
814
|
-
}
|
|
815
|
-
if (!((_a2 = task.result) == null ? void 0 : _a2.state) && task.mode === "run") {
|
|
816
|
-
task.result = {
|
|
817
|
-
state: "pass"
|
|
818
|
-
};
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
};
|
|
822
|
-
markTasks(file.tasks);
|
|
823
|
-
}
|
|
824
|
-
async prepareResults(output) {
|
|
825
|
-
const typeErrors = await this.parseTscLikeOutput(output);
|
|
826
|
-
const testFiles = new Set(this.getFiles());
|
|
827
|
-
if (!this._tests) {
|
|
828
|
-
this._tests = await this.collectTests();
|
|
829
|
-
}
|
|
830
|
-
const sourceErrors = [];
|
|
831
|
-
const files = [];
|
|
832
|
-
testFiles.forEach((path) => {
|
|
833
|
-
const { file, definitions, map, parsed } = this._tests[path];
|
|
834
|
-
const errors = typeErrors.get(path);
|
|
835
|
-
files.push(file);
|
|
836
|
-
if (!errors) {
|
|
837
|
-
this.markPassed(file);
|
|
838
|
-
return;
|
|
839
|
-
}
|
|
840
|
-
const sortedDefinitions = [
|
|
841
|
-
...definitions.sort((a, b) => b.start - a.start)
|
|
842
|
-
];
|
|
843
|
-
const traceMap = map && new TraceMap(map);
|
|
844
|
-
const indexMap = createIndexMap(parsed);
|
|
845
|
-
const markState = (task, state) => {
|
|
846
|
-
task.result = {
|
|
847
|
-
state: task.mode === "run" || task.mode === "only" ? state : task.mode
|
|
848
|
-
};
|
|
849
|
-
if (task.suite) {
|
|
850
|
-
markState(task.suite, state);
|
|
851
|
-
} else if (task.file && task !== task.file) {
|
|
852
|
-
markState(task.file, state);
|
|
853
|
-
}
|
|
854
|
-
};
|
|
855
|
-
errors.forEach(({ error, originalError }) => {
|
|
856
|
-
var _a;
|
|
857
|
-
const processedPos = traceMap ? generatedPositionFor(traceMap, {
|
|
858
|
-
line: originalError.line,
|
|
859
|
-
column: originalError.column,
|
|
860
|
-
source: basename(path)
|
|
861
|
-
}) : originalError;
|
|
862
|
-
const line = processedPos.line ?? originalError.line;
|
|
863
|
-
const column = processedPos.column ?? originalError.column;
|
|
864
|
-
const index = indexMap.get(`${line}:${column}`);
|
|
865
|
-
const definition = index != null && sortedDefinitions.find(
|
|
866
|
-
(def) => def.start <= index && def.end >= index
|
|
867
|
-
);
|
|
868
|
-
const suite = definition ? definition.task : file;
|
|
869
|
-
const state = suite.mode === "run" || suite.mode === "only" ? "fail" : suite.mode;
|
|
870
|
-
const errors2 = ((_a = suite.result) == null ? void 0 : _a.errors) || [];
|
|
871
|
-
suite.result = {
|
|
872
|
-
state,
|
|
873
|
-
errors: errors2
|
|
874
|
-
};
|
|
875
|
-
errors2.push(error);
|
|
876
|
-
if (state === "fail") {
|
|
877
|
-
if (suite.suite) {
|
|
878
|
-
markState(suite.suite, "fail");
|
|
879
|
-
} else if (suite.file && suite !== suite.file) {
|
|
880
|
-
markState(suite.file, "fail");
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
});
|
|
884
|
-
this.markPassed(file);
|
|
885
|
-
});
|
|
886
|
-
typeErrors.forEach((errors, path) => {
|
|
887
|
-
if (!testFiles.has(path)) {
|
|
888
|
-
sourceErrors.push(...errors.map(({ error }) => error));
|
|
889
|
-
}
|
|
890
|
-
});
|
|
891
|
-
return {
|
|
892
|
-
files,
|
|
893
|
-
sourceErrors,
|
|
894
|
-
time: performance.now() - this._startTime
|
|
895
|
-
};
|
|
896
|
-
}
|
|
897
|
-
async parseTscLikeOutput(output) {
|
|
898
|
-
const errorsMap = await getRawErrsMapFromTsCompile(output);
|
|
899
|
-
const typesErrors = /* @__PURE__ */ new Map();
|
|
900
|
-
errorsMap.forEach((errors, path) => {
|
|
901
|
-
const filepath = resolve(this.ctx.config.root, path);
|
|
902
|
-
const suiteErrors = errors.map((info) => {
|
|
903
|
-
const limit = Error.stackTraceLimit;
|
|
904
|
-
Error.stackTraceLimit = 0;
|
|
905
|
-
const errMsg = info.errMsg.replace(
|
|
906
|
-
/\r?\n\s*(Type .* has no call signatures)/g,
|
|
907
|
-
" $1"
|
|
908
|
-
);
|
|
909
|
-
const error = new TypeCheckError(errMsg, [
|
|
910
|
-
{
|
|
911
|
-
file: filepath,
|
|
912
|
-
line: info.line,
|
|
913
|
-
column: info.column,
|
|
914
|
-
method: ""
|
|
915
|
-
}
|
|
916
|
-
]);
|
|
917
|
-
Error.stackTraceLimit = limit;
|
|
918
|
-
return {
|
|
919
|
-
originalError: info,
|
|
920
|
-
error: {
|
|
921
|
-
name: error.name,
|
|
922
|
-
nameStr: String(error.name),
|
|
923
|
-
message: errMsg,
|
|
924
|
-
stacks: error.stacks,
|
|
925
|
-
stack: "",
|
|
926
|
-
stackStr: ""
|
|
927
|
-
}
|
|
928
|
-
};
|
|
929
|
-
});
|
|
930
|
-
typesErrors.set(filepath, suiteErrors);
|
|
931
|
-
});
|
|
932
|
-
return typesErrors;
|
|
933
|
-
}
|
|
934
|
-
async clear() {
|
|
935
|
-
if (this.tempConfigPath) {
|
|
936
|
-
await rm(this.tempConfigPath, { force: true });
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
async stop() {
|
|
940
|
-
var _a;
|
|
941
|
-
await this.clear();
|
|
942
|
-
(_a = this.process) == null ? void 0 : _a.kill();
|
|
943
|
-
this.process = void 0;
|
|
944
|
-
}
|
|
945
|
-
async ensurePackageInstalled(ctx, checker) {
|
|
946
|
-
if (checker !== "tsc" && checker !== "vue-tsc") {
|
|
947
|
-
return;
|
|
948
|
-
}
|
|
949
|
-
const packageName = checker === "tsc" ? "typescript" : "vue-tsc";
|
|
950
|
-
await ctx.packageInstaller.ensureInstalled(packageName, ctx.config.root);
|
|
951
|
-
}
|
|
952
|
-
async prepare() {
|
|
953
|
-
const { root, typecheck } = this.ctx.config;
|
|
954
|
-
const { config, path } = await getTsconfig(root, typecheck);
|
|
955
|
-
this.tempConfigPath = path;
|
|
956
|
-
this.allowJs = typecheck.allowJs || config.allowJs || false;
|
|
957
|
-
}
|
|
958
|
-
getExitCode() {
|
|
959
|
-
var _a;
|
|
960
|
-
return ((_a = this.process) == null ? void 0 : _a.exitCode) != null && this.process.exitCode;
|
|
961
|
-
}
|
|
962
|
-
getOutput() {
|
|
963
|
-
return this._output;
|
|
964
|
-
}
|
|
965
|
-
async start() {
|
|
966
|
-
var _a, _b, _c;
|
|
967
|
-
if (this.process) {
|
|
968
|
-
return;
|
|
969
|
-
}
|
|
970
|
-
if (!this.tempConfigPath) {
|
|
971
|
-
throw new Error("tsconfig was not initialized");
|
|
972
|
-
}
|
|
973
|
-
const { root, watch, typecheck } = this.ctx.config;
|
|
974
|
-
const args = ["--noEmit", "--pretty", "false", "-p", this.tempConfigPath];
|
|
975
|
-
if (watch) {
|
|
976
|
-
args.push("--watch");
|
|
977
|
-
}
|
|
978
|
-
if (typecheck.allowJs) {
|
|
979
|
-
args.push("--allowJs", "--checkJs");
|
|
980
|
-
}
|
|
981
|
-
this._output = "";
|
|
982
|
-
this._startTime = performance.now();
|
|
983
|
-
const child = execa(typecheck.checker, args, {
|
|
984
|
-
cwd: root,
|
|
985
|
-
stdout: "pipe",
|
|
986
|
-
reject: false
|
|
987
|
-
});
|
|
988
|
-
this.process = child;
|
|
989
|
-
await ((_a = this._onParseStart) == null ? void 0 : _a.call(this));
|
|
990
|
-
let rerunTriggered = false;
|
|
991
|
-
(_b = child.stdout) == null ? void 0 : _b.on("data", (chunk) => {
|
|
992
|
-
var _a2;
|
|
993
|
-
this._output += chunk;
|
|
994
|
-
if (!watch) {
|
|
995
|
-
return;
|
|
996
|
-
}
|
|
997
|
-
if (this._output.includes("File change detected") && !rerunTriggered) {
|
|
998
|
-
(_a2 = this._onWatcherRerun) == null ? void 0 : _a2.call(this);
|
|
999
|
-
this._startTime = performance.now();
|
|
1000
|
-
this._result.sourceErrors = [];
|
|
1001
|
-
this._result.files = [];
|
|
1002
|
-
this._tests = null;
|
|
1003
|
-
rerunTriggered = true;
|
|
1004
|
-
}
|
|
1005
|
-
if (/Found \w+ errors*. Watching for/.test(this._output)) {
|
|
1006
|
-
rerunTriggered = false;
|
|
1007
|
-
this.prepareResults(this._output).then((result) => {
|
|
1008
|
-
var _a3;
|
|
1009
|
-
this._result = result;
|
|
1010
|
-
(_a3 = this._onParseEnd) == null ? void 0 : _a3.call(this, result);
|
|
1011
|
-
});
|
|
1012
|
-
this._output = "";
|
|
1013
|
-
}
|
|
1014
|
-
});
|
|
1015
|
-
if (!watch) {
|
|
1016
|
-
await child;
|
|
1017
|
-
this._result = await this.prepareResults(this._output);
|
|
1018
|
-
await ((_c = this._onParseEnd) == null ? void 0 : _c.call(this, this._result));
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
getResult() {
|
|
1022
|
-
return this._result;
|
|
1023
|
-
}
|
|
1024
|
-
getTestFiles() {
|
|
1025
|
-
return Object.values(this._tests || {}).map((i) => i.file);
|
|
1026
|
-
}
|
|
1027
|
-
getTestPacks() {
|
|
1028
|
-
return Object.values(this._tests || {}).map(({ file }) => getTasks(file)).flat().map((i) => [i.id, i.result, { typecheck: true }]);
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
134
|
const BADGE_PADDING = " ";
|
|
1033
135
|
const HELP_HINT = `${c.dim("press ")}${c.bold("h")}${c.dim(" to show help")}`;
|
|
1034
136
|
const HELP_UPDATE_SNAP = c.dim("press ") + c.bold(c.yellow("u")) + c.dim(" to update snapshot");
|
|
@@ -1061,8 +163,7 @@ class BaseReporter {
|
|
|
1061
163
|
_timeStart = /* @__PURE__ */ new Date();
|
|
1062
164
|
_offUnhandledRejection;
|
|
1063
165
|
constructor(options = {}) {
|
|
1064
|
-
|
|
1065
|
-
this.isTTY = options.isTTY ?? ((isNode || isDeno) && ((_a = process.stdout) == null ? void 0 : _a.isTTY) && !isCI);
|
|
166
|
+
this.isTTY = options.isTTY ?? ((isNode || isDeno) && process.stdout?.isTTY && !isCI);
|
|
1066
167
|
this.registerUnhandledRejection();
|
|
1067
168
|
}
|
|
1068
169
|
get mode() {
|
|
@@ -1071,8 +172,7 @@ class BaseReporter {
|
|
|
1071
172
|
onInit(ctx) {
|
|
1072
173
|
this.ctx = ctx;
|
|
1073
174
|
ctx.onClose(() => {
|
|
1074
|
-
|
|
1075
|
-
(_a = this._offUnhandledRejection) == null ? void 0 : _a.call(this);
|
|
175
|
+
this._offUnhandledRejection?.();
|
|
1076
176
|
});
|
|
1077
177
|
ctx.logger.printBanner();
|
|
1078
178
|
this.start = performance.now();
|
|
@@ -1101,16 +201,12 @@ class BaseReporter {
|
|
|
1101
201
|
}
|
|
1102
202
|
}
|
|
1103
203
|
printTask(task) {
|
|
1104
|
-
|
|
1105
|
-
if (!("filepath" in task) || !((_a = task.result) == null ? void 0 : _a.state) || ((_b = task.result) == null ? void 0 : _b.state) === "run") {
|
|
204
|
+
if (!("filepath" in task) || !task.result?.state || task.result?.state === "run") {
|
|
1106
205
|
return;
|
|
1107
206
|
}
|
|
1108
207
|
const logger = this.ctx.logger;
|
|
1109
208
|
const tests = getTests(task);
|
|
1110
|
-
const failed = tests.filter((t) =>
|
|
1111
|
-
var _a2;
|
|
1112
|
-
return ((_a2 = t.result) == null ? void 0 : _a2.state) === "fail";
|
|
1113
|
-
});
|
|
209
|
+
const failed = tests.filter((t) => t.result?.state === "fail");
|
|
1114
210
|
const skipped = tests.filter(
|
|
1115
211
|
(t) => t.mode === "skip" || t.mode === "todo"
|
|
1116
212
|
);
|
|
@@ -1139,8 +235,8 @@ class BaseReporter {
|
|
|
1139
235
|
logger.log(title);
|
|
1140
236
|
for (const test of failed) {
|
|
1141
237
|
logger.log(c.red(` ${taskFail} ${getTestName(test, c.dim(" > "))}`));
|
|
1142
|
-
|
|
1143
|
-
logger.log(c.red(` ${F_RIGHT} ${e
|
|
238
|
+
test.result?.errors?.forEach((e) => {
|
|
239
|
+
logger.log(c.red(` ${F_RIGHT} ${e?.message}`));
|
|
1144
240
|
});
|
|
1145
241
|
}
|
|
1146
242
|
}
|
|
@@ -1241,14 +337,13 @@ ${PROJECT_FILTER}${FILENAME_PATTERN}${TESTNAME_PATTERN}`
|
|
|
1241
337
|
this.start = performance.now();
|
|
1242
338
|
}
|
|
1243
339
|
onUserConsoleLog(log) {
|
|
1244
|
-
var _a;
|
|
1245
340
|
if (!this.shouldLog(log)) {
|
|
1246
341
|
return;
|
|
1247
342
|
}
|
|
1248
343
|
const task = log.taskId ? this.ctx.state.idMap.get(log.taskId) : void 0;
|
|
1249
344
|
const header = c.gray(
|
|
1250
345
|
log.type + c.dim(
|
|
1251
|
-
` | ${task ? getFullName(task, c.dim(" > ")) : log.taskId !==
|
|
346
|
+
` | ${task ? getFullName(task, c.dim(" > ")) : log.taskId !== "__vitest__unknown_test__" ? log.taskId : "unknown test"}`
|
|
1252
347
|
)
|
|
1253
348
|
);
|
|
1254
349
|
const output = log.type === "stdout" ? this.ctx.logger.outputStream : this.ctx.logger.errorStream;
|
|
@@ -1260,7 +355,7 @@ ${log.content}`);
|
|
|
1260
355
|
write("\n");
|
|
1261
356
|
}
|
|
1262
357
|
const project = log.taskId ? this.ctx.getProjectByTaskId(log.taskId) : this.ctx.getCoreWorkspaceProject();
|
|
1263
|
-
const stack = log.browser ?
|
|
358
|
+
const stack = log.browser ? project.browser?.parseStacktrace(log.origin) || [] : parseStacktrace(log.origin);
|
|
1264
359
|
const highlight = task ? stack.find((i) => i.file === task.file.filepath) : null;
|
|
1265
360
|
for (const frame of stack) {
|
|
1266
361
|
const color = frame === highlight ? c.cyan : c.gray;
|
|
@@ -1279,11 +374,10 @@ ${log.content}`);
|
|
|
1279
374
|
write("\n");
|
|
1280
375
|
}
|
|
1281
376
|
shouldLog(log) {
|
|
1282
|
-
var _a, _b;
|
|
1283
377
|
if (this.ctx.config.silent) {
|
|
1284
378
|
return false;
|
|
1285
379
|
}
|
|
1286
|
-
const shouldLog =
|
|
380
|
+
const shouldLog = this.ctx.config.onConsoleLog?.(log.content, log.type);
|
|
1287
381
|
if (shouldLog === false) {
|
|
1288
382
|
return shouldLog;
|
|
1289
383
|
}
|
|
@@ -1323,10 +417,7 @@ ${log.content}`);
|
|
|
1323
417
|
0
|
|
1324
418
|
);
|
|
1325
419
|
const testsTime = files.reduce(
|
|
1326
|
-
(acc, test) =>
|
|
1327
|
-
var _a;
|
|
1328
|
-
return acc + Math.max(0, ((_a = test.result) == null ? void 0 : _a.duration) || 0);
|
|
1329
|
-
},
|
|
420
|
+
(acc, test) => acc + Math.max(0, test.result?.duration || 0),
|
|
1330
421
|
0
|
|
1331
422
|
);
|
|
1332
423
|
const transformTime = this.ctx.projects.flatMap((w) => w.vitenode.getTotalDuration()).reduce((a, b) => a + b, 0);
|
|
@@ -1364,10 +455,7 @@ ${log.content}`);
|
|
|
1364
455
|
logger.log(padTitle("Tests"), getStateString(tests));
|
|
1365
456
|
if (this.ctx.projects.some((c2) => c2.config.typecheck.enabled)) {
|
|
1366
457
|
const failed = tests.filter(
|
|
1367
|
-
(t) =>
|
|
1368
|
-
var _a, _b, _c;
|
|
1369
|
-
return ((_a = t.meta) == null ? void 0 : _a.typecheck) && ((_c = (_b = t.result) == null ? void 0 : _b.errors) == null ? void 0 : _c.length);
|
|
1370
|
-
}
|
|
458
|
+
(t) => t.meta?.typecheck && t.result?.errors?.length
|
|
1371
459
|
);
|
|
1372
460
|
logger.log(
|
|
1373
461
|
padTitle("Type Errors"),
|
|
@@ -1390,10 +478,7 @@ ${log.content}`);
|
|
|
1390
478
|
testsTime
|
|
1391
479
|
)}, environment ${time(environmentTime)}, prepare ${time(prepareTime)}`;
|
|
1392
480
|
const typecheck = this.ctx.projects.reduce(
|
|
1393
|
-
(acc, c2) =>
|
|
1394
|
-
var _a;
|
|
1395
|
-
return acc + (((_a = c2.typechecker) == null ? void 0 : _a.getResult().time) || 0);
|
|
1396
|
-
},
|
|
481
|
+
(acc, c2) => acc + (c2.typechecker?.getResult().time || 0),
|
|
1397
482
|
0
|
|
1398
483
|
);
|
|
1399
484
|
if (typecheck) {
|
|
@@ -1410,14 +495,8 @@ ${log.content}`);
|
|
|
1410
495
|
const logger = this.ctx.logger;
|
|
1411
496
|
const suites = getSuites(files);
|
|
1412
497
|
const tests = getTests(files);
|
|
1413
|
-
const failedSuites = suites.filter((i) =>
|
|
1414
|
-
|
|
1415
|
-
return (_a = i.result) == null ? void 0 : _a.errors;
|
|
1416
|
-
});
|
|
1417
|
-
const failedTests = tests.filter((i) => {
|
|
1418
|
-
var _a;
|
|
1419
|
-
return ((_a = i.result) == null ? void 0 : _a.state) === "fail";
|
|
1420
|
-
});
|
|
498
|
+
const failedSuites = suites.filter((i) => i.result?.errors);
|
|
499
|
+
const failedTests = tests.filter((i) => i.result?.state === "fail");
|
|
1421
500
|
const failedTotal = countTestErrors(failedSuites) + countTestErrors(failedTests);
|
|
1422
501
|
let current = 1;
|
|
1423
502
|
const errorDivider = () => logger.error(
|
|
@@ -1453,10 +532,7 @@ ${log.content}`);
|
|
|
1453
532
|
reportBenchmarkSummary(files) {
|
|
1454
533
|
const logger = this.ctx.logger;
|
|
1455
534
|
const benches = getTests(files);
|
|
1456
|
-
const topBenches = benches.filter((i) =>
|
|
1457
|
-
var _a, _b;
|
|
1458
|
-
return ((_b = (_a = i.result) == null ? void 0 : _a.benchmark) == null ? void 0 : _b.rank) === 1;
|
|
1459
|
-
});
|
|
535
|
+
const topBenches = benches.filter((i) => i.result?.benchmark?.rank === 1);
|
|
1460
536
|
logger.log(
|
|
1461
537
|
`
|
|
1462
538
|
${c.cyan(c.inverse(c.bold(" BENCH ")))} ${c.cyan("Summary")}
|
|
@@ -1469,10 +545,7 @@ ${c.cyan(c.inverse(c.bold(" BENCH ")))} ${c.cyan("Summary")}
|
|
|
1469
545
|
}
|
|
1470
546
|
const groupName = getFullName(group, c.dim(" > "));
|
|
1471
547
|
logger.log(` ${bench.name}${c.dim(` - ${groupName}`)}`);
|
|
1472
|
-
const siblings = group.tasks.filter((i) =>
|
|
1473
|
-
var _a;
|
|
1474
|
-
return i.meta.benchmark && ((_a = i.result) == null ? void 0 : _a.benchmark) && i !== bench;
|
|
1475
|
-
}).sort((a, b) => a.result.benchmark.rank - b.result.benchmark.rank);
|
|
548
|
+
const siblings = group.tasks.filter((i) => i.meta.benchmark && i.result?.benchmark && i !== bench).sort((a, b) => a.result.benchmark.rank - b.result.benchmark.rank);
|
|
1476
549
|
if (siblings.length === 0) {
|
|
1477
550
|
logger.log("");
|
|
1478
551
|
continue;
|
|
@@ -1487,18 +560,16 @@ ${c.cyan(c.inverse(c.bold(" BENCH ")))} ${c.cyan("Summary")}
|
|
|
1487
560
|
}
|
|
1488
561
|
}
|
|
1489
562
|
printTaskErrors(tasks, errorDivider) {
|
|
1490
|
-
var _a, _b, _c;
|
|
1491
563
|
const errorsQueue = [];
|
|
1492
564
|
for (const task of tasks) {
|
|
1493
|
-
|
|
1494
|
-
const errorItem =
|
|
1495
|
-
|
|
1496
|
-
const hasStr = ((_a2 = i[0]) == null ? void 0 : _a2.stackStr) === error.stackStr;
|
|
565
|
+
task.result?.errors?.forEach((error) => {
|
|
566
|
+
const errorItem = error?.stackStr && errorsQueue.find((i) => {
|
|
567
|
+
const hasStr = i[0]?.stackStr === error.stackStr;
|
|
1497
568
|
if (!hasStr) {
|
|
1498
569
|
return false;
|
|
1499
570
|
}
|
|
1500
|
-
const currentProjectName =
|
|
1501
|
-
const projectName =
|
|
571
|
+
const currentProjectName = task?.projectName || task.file?.projectName || "";
|
|
572
|
+
const projectName = i[1][0]?.projectName || i[1][0].file?.projectName || "";
|
|
1502
573
|
return projectName === currentProjectName;
|
|
1503
574
|
});
|
|
1504
575
|
if (errorItem) {
|
|
@@ -1510,8 +581,8 @@ ${c.cyan(c.inverse(c.bold(" BENCH ")))} ${c.cyan("Summary")}
|
|
|
1510
581
|
}
|
|
1511
582
|
for (const [error, tasks2] of errorsQueue) {
|
|
1512
583
|
for (const task of tasks2) {
|
|
1513
|
-
const filepath =
|
|
1514
|
-
const projectName =
|
|
584
|
+
const filepath = task?.filepath || "";
|
|
585
|
+
const projectName = task?.projectName || task.file?.projectName || "";
|
|
1515
586
|
let name = getFullName(task, c.dim(" > "));
|
|
1516
587
|
if (filepath) {
|
|
1517
588
|
name = `${name} ${c.dim(`[ ${this.relative(filepath)} ]`)}`;
|
|
@@ -1522,13 +593,7 @@ ${c.cyan(c.inverse(c.bold(" BENCH ")))} ${c.cyan("Summary")}
|
|
|
1522
593
|
)}${name}`
|
|
1523
594
|
);
|
|
1524
595
|
}
|
|
1525
|
-
const screenshots = tasks2.filter((t) =>
|
|
1526
|
-
var _a2;
|
|
1527
|
-
return (_a2 = t.meta) == null ? void 0 : _a2.failScreenshotPath;
|
|
1528
|
-
}).map((t) => {
|
|
1529
|
-
var _a2;
|
|
1530
|
-
return (_a2 = t.meta) == null ? void 0 : _a2.failScreenshotPath;
|
|
1531
|
-
});
|
|
596
|
+
const screenshots = tasks2.filter((t) => t.meta?.failScreenshotPath).map((t) => t.meta?.failScreenshotPath);
|
|
1532
597
|
const project = this.ctx.getProjectByTaskId(tasks2[0].id);
|
|
1533
598
|
this.ctx.logger.printError(error, {
|
|
1534
599
|
project,
|
|
@@ -2478,8 +1543,7 @@ function formatNumber$1(number) {
|
|
|
2478
1543
|
return res[0].replace(/(?=(?:\d{3})+$)\B/g, ",") + (res[1] ? `.${res[1]}` : "");
|
|
2479
1544
|
}
|
|
2480
1545
|
function renderHookState(task, hookName, level = 0) {
|
|
2481
|
-
|
|
2482
|
-
const state = (_b = (_a = task.result) == null ? void 0 : _a.hooks) == null ? void 0 : _b[hookName];
|
|
1546
|
+
const state = task.result?.hooks?.[hookName];
|
|
2483
1547
|
if (state && state === "run") {
|
|
2484
1548
|
return `${" ".repeat(level)} ${getHookStateSymbol(task, hookName)} ${c.dim(
|
|
2485
1549
|
`[ ${hookName} ]`
|
|
@@ -2497,15 +1561,11 @@ function renderBenchmarkItems$1(result) {
|
|
|
2497
1561
|
];
|
|
2498
1562
|
}
|
|
2499
1563
|
function renderBenchmark$1(task, tasks) {
|
|
2500
|
-
|
|
2501
|
-
const result = (_a = task.result) == null ? void 0 : _a.benchmark;
|
|
1564
|
+
const result = task.result?.benchmark;
|
|
2502
1565
|
if (!result) {
|
|
2503
1566
|
return task.name;
|
|
2504
1567
|
}
|
|
2505
|
-
const benches = tasks.map((i) =>
|
|
2506
|
-
var _a2, _b;
|
|
2507
|
-
return ((_a2 = i.meta) == null ? void 0 : _a2.benchmark) ? (_b = i.result) == null ? void 0 : _b.benchmark : void 0;
|
|
2508
|
-
}).filter(notNullish);
|
|
1568
|
+
const benches = tasks.map((i) => i.meta?.benchmark ? i.result?.benchmark : void 0).filter(notNullish);
|
|
2509
1569
|
const allItems = benches.map(renderBenchmarkItems$1);
|
|
2510
1570
|
const items = renderBenchmarkItems$1(result);
|
|
2511
1571
|
const padded = items.map((i, idx) => {
|
|
@@ -2524,7 +1584,6 @@ function renderBenchmark$1(task, tasks) {
|
|
|
2524
1584
|
].join("");
|
|
2525
1585
|
}
|
|
2526
1586
|
function renderTree$1(tasks, options, level = 0, maxRows) {
|
|
2527
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2528
1587
|
const output = [];
|
|
2529
1588
|
let currentRowCount = 0;
|
|
2530
1589
|
for (const task of [...tasks].reverse()) {
|
|
@@ -2534,7 +1593,7 @@ function renderTree$1(tasks, options, level = 0, maxRows) {
|
|
|
2534
1593
|
if (level === 0 && task.type === "suite" && "projectName" in task) {
|
|
2535
1594
|
prefix += formatProjectName(task.projectName);
|
|
2536
1595
|
}
|
|
2537
|
-
if (task.type === "test" &&
|
|
1596
|
+
if (task.type === "test" && task.result?.retryCount && task.result.retryCount > 0) {
|
|
2538
1597
|
suffix += c.yellow(` (retry x${task.result.retryCount})`);
|
|
2539
1598
|
}
|
|
2540
1599
|
if (task.type === "suite") {
|
|
@@ -2544,17 +1603,17 @@ function renderTree$1(tasks, options, level = 0, maxRows) {
|
|
|
2544
1603
|
if (task.mode === "skip" || task.mode === "todo") {
|
|
2545
1604
|
suffix += ` ${c.dim(c.gray("[skipped]"))}`;
|
|
2546
1605
|
}
|
|
2547
|
-
if (task.type === "test" &&
|
|
1606
|
+
if (task.type === "test" && task.result?.repeatCount && task.result.repeatCount > 0) {
|
|
2548
1607
|
suffix += c.yellow(` (repeat x${task.result.repeatCount})`);
|
|
2549
1608
|
}
|
|
2550
|
-
if (
|
|
1609
|
+
if (task.result?.duration != null) {
|
|
2551
1610
|
if (task.result.duration > options.slowTestThreshold) {
|
|
2552
1611
|
suffix += c.yellow(
|
|
2553
1612
|
` ${Math.round(task.result.duration)}${c.dim("ms")}`
|
|
2554
1613
|
);
|
|
2555
1614
|
}
|
|
2556
1615
|
}
|
|
2557
|
-
if (options.showHeap &&
|
|
1616
|
+
if (options.showHeap && task.result?.heap != null) {
|
|
2558
1617
|
suffix += c.magenta(
|
|
2559
1618
|
` ${Math.floor(task.result.heap / 1024 / 1024)} MB heap used`
|
|
2560
1619
|
);
|
|
@@ -2564,9 +1623,9 @@ function renderTree$1(tasks, options, level = 0, maxRows) {
|
|
|
2564
1623
|
name = formatFilepath$1(name);
|
|
2565
1624
|
}
|
|
2566
1625
|
const padding = " ".repeat(level);
|
|
2567
|
-
const body =
|
|
1626
|
+
const body = task.meta?.benchmark ? renderBenchmark$1(task, tasks) : name;
|
|
2568
1627
|
taskOutput.push(padding + prefix + body + suffix);
|
|
2569
|
-
if (
|
|
1628
|
+
if (task.result?.state !== "pass" && outputMap$1.get(task) != null) {
|
|
2570
1629
|
let data = outputMap$1.get(task);
|
|
2571
1630
|
if (typeof data === "string") {
|
|
2572
1631
|
data = stripAnsi(data.trim().split("\n").filter(Boolean).pop());
|
|
@@ -2582,7 +1641,7 @@ function renderTree$1(tasks, options, level = 0, maxRows) {
|
|
|
2582
1641
|
taskOutput.push(renderHookState(task, "beforeAll", level + 1));
|
|
2583
1642
|
taskOutput.push(renderHookState(task, "beforeEach", level + 1));
|
|
2584
1643
|
if (task.type === "suite" && task.tasks.length > 0) {
|
|
2585
|
-
if (
|
|
1644
|
+
if (task.result?.state === "fail" || task.result?.state === "run" || options.renderSucceed) {
|
|
2586
1645
|
if (options.logger.ctx.config.hideSkippedTests) {
|
|
2587
1646
|
const filteredTasks = task.tasks.filter(
|
|
2588
1647
|
(t) => t.mode !== "skip" && t.mode !== "todo"
|
|
@@ -2714,8 +1773,7 @@ class DefaultReporter extends BaseReporter {
|
|
|
2714
1773
|
}
|
|
2715
1774
|
}
|
|
2716
1775
|
onFinished(files = this.ctx.state.getFiles(), errors = this.ctx.state.getUnhandledErrors()) {
|
|
2717
|
-
|
|
2718
|
-
(_a = this.renderer) == null ? void 0 : _a.update([
|
|
1776
|
+
this.renderer?.update([
|
|
2719
1777
|
...this.failedUnwatchedFiles,
|
|
2720
1778
|
...files
|
|
2721
1779
|
]);
|
|
@@ -2728,8 +1786,7 @@ class DefaultReporter extends BaseReporter {
|
|
|
2728
1786
|
await super.onWatcherStart(files, errors);
|
|
2729
1787
|
}
|
|
2730
1788
|
stopListRender() {
|
|
2731
|
-
|
|
2732
|
-
(_a = this.renderer) == null ? void 0 : _a.stop();
|
|
1789
|
+
this.renderer?.stop();
|
|
2733
1790
|
this.renderer = void 0;
|
|
2734
1791
|
}
|
|
2735
1792
|
async onWatcherRerun(files, trigger) {
|
|
@@ -2737,11 +1794,10 @@ class DefaultReporter extends BaseReporter {
|
|
|
2737
1794
|
await super.onWatcherRerun(files, trigger);
|
|
2738
1795
|
}
|
|
2739
1796
|
onUserConsoleLog(log) {
|
|
2740
|
-
var _a;
|
|
2741
1797
|
if (!this.shouldLog(log)) {
|
|
2742
1798
|
return;
|
|
2743
1799
|
}
|
|
2744
|
-
|
|
1800
|
+
this.renderer?.clear();
|
|
2745
1801
|
super.onUserConsoleLog(log);
|
|
2746
1802
|
}
|
|
2747
1803
|
}
|
|
@@ -2751,11 +1807,10 @@ const cross = { char: "x", color: c.red };
|
|
|
2751
1807
|
const pending = { char: "*", color: c.yellow };
|
|
2752
1808
|
const skip = { char: "-", color: (char) => c.dim(c.gray(char)) };
|
|
2753
1809
|
function getIcon(task) {
|
|
2754
|
-
var _a;
|
|
2755
1810
|
if (task.mode === "skip" || task.mode === "todo") {
|
|
2756
1811
|
return skip;
|
|
2757
1812
|
}
|
|
2758
|
-
switch (
|
|
1813
|
+
switch (task.result?.state) {
|
|
2759
1814
|
case "pass":
|
|
2760
1815
|
return check;
|
|
2761
1816
|
case "fail":
|
|
@@ -2865,8 +1920,7 @@ class DotReporter extends BaseReporter {
|
|
|
2865
1920
|
super.onWatcherStart();
|
|
2866
1921
|
}
|
|
2867
1922
|
async stopListRender() {
|
|
2868
|
-
|
|
2869
|
-
(_a = this.renderer) == null ? void 0 : _a.stop();
|
|
1923
|
+
this.renderer?.stop();
|
|
2870
1924
|
this.renderer = void 0;
|
|
2871
1925
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
2872
1926
|
}
|
|
@@ -2875,8 +1929,7 @@ class DotReporter extends BaseReporter {
|
|
|
2875
1929
|
super.onWatcherRerun(files, trigger);
|
|
2876
1930
|
}
|
|
2877
1931
|
onUserConsoleLog(log) {
|
|
2878
|
-
|
|
2879
|
-
(_a = this.renderer) == null ? void 0 : _a.clear();
|
|
1932
|
+
this.renderer?.clear();
|
|
2880
1933
|
super.onUserConsoleLog(log);
|
|
2881
1934
|
}
|
|
2882
1935
|
}
|
|
@@ -2901,34 +1954,21 @@ class JsonReporter {
|
|
|
2901
1954
|
this.start = Date.now();
|
|
2902
1955
|
}
|
|
2903
1956
|
async logTasks(files) {
|
|
2904
|
-
var _a, _b, _c, _d;
|
|
2905
1957
|
const suites = getSuites(files);
|
|
2906
1958
|
const numTotalTestSuites = suites.length;
|
|
2907
1959
|
const tests = getTests(files);
|
|
2908
1960
|
const numTotalTests = tests.length;
|
|
2909
|
-
const numFailedTestSuites = suites.filter((s) =>
|
|
2910
|
-
var _a2;
|
|
2911
|
-
return (_a2 = s.result) == null ? void 0 : _a2.errors;
|
|
2912
|
-
}).length;
|
|
2913
|
-
const numPassedTestSuites = numTotalTestSuites - numFailedTestSuites;
|
|
1961
|
+
const numFailedTestSuites = suites.filter((s) => s.result?.state === "fail").length;
|
|
2914
1962
|
const numPendingTestSuites = suites.filter(
|
|
2915
|
-
(s) =>
|
|
2916
|
-
var _a2;
|
|
2917
|
-
return ((_a2 = s.result) == null ? void 0 : _a2.state) === "run";
|
|
2918
|
-
}
|
|
1963
|
+
(s) => s.result?.state === "run" || s.mode === "todo"
|
|
2919
1964
|
).length;
|
|
1965
|
+
const numPassedTestSuites = numTotalTestSuites - numFailedTestSuites - numPendingTestSuites;
|
|
2920
1966
|
const numFailedTests = tests.filter(
|
|
2921
|
-
(t) =>
|
|
2922
|
-
var _a2;
|
|
2923
|
-
return ((_a2 = t.result) == null ? void 0 : _a2.state) === "fail";
|
|
2924
|
-
}
|
|
1967
|
+
(t) => t.result?.state === "fail"
|
|
2925
1968
|
).length;
|
|
2926
|
-
const numPassedTests =
|
|
1969
|
+
const numPassedTests = tests.filter((t) => t.result?.state === "pass").length;
|
|
2927
1970
|
const numPendingTests = tests.filter(
|
|
2928
|
-
(t) =>
|
|
2929
|
-
var _a2;
|
|
2930
|
-
return ((_a2 = t.result) == null ? void 0 : _a2.state) === "run";
|
|
2931
|
-
}
|
|
1971
|
+
(t) => t.result?.state === "run" || t.mode === "skip" || t.result?.state === "skip"
|
|
2932
1972
|
).length;
|
|
2933
1973
|
const numTodoTests = tests.filter((t) => t.mode === "todo").length;
|
|
2934
1974
|
const testResults = [];
|
|
@@ -2936,27 +1976,20 @@ class JsonReporter {
|
|
|
2936
1976
|
for (const file of files) {
|
|
2937
1977
|
const tests2 = getTests([file]);
|
|
2938
1978
|
let startTime = tests2.reduce(
|
|
2939
|
-
(prev, next) =>
|
|
2940
|
-
var _a2;
|
|
2941
|
-
return Math.min(prev, ((_a2 = next.result) == null ? void 0 : _a2.startTime) ?? Number.POSITIVE_INFINITY);
|
|
2942
|
-
},
|
|
1979
|
+
(prev, next) => Math.min(prev, next.result?.startTime ?? Number.POSITIVE_INFINITY),
|
|
2943
1980
|
Number.POSITIVE_INFINITY
|
|
2944
1981
|
);
|
|
2945
1982
|
if (startTime === Number.POSITIVE_INFINITY) {
|
|
2946
1983
|
startTime = this.start;
|
|
2947
1984
|
}
|
|
2948
1985
|
const endTime = tests2.reduce(
|
|
2949
|
-
(prev, next) =>
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
(((_a2 = next.result) == null ? void 0 : _a2.startTime) ?? 0) + (((_b2 = next.result) == null ? void 0 : _b2.duration) ?? 0)
|
|
2954
|
-
);
|
|
2955
|
-
},
|
|
1986
|
+
(prev, next) => Math.max(
|
|
1987
|
+
prev,
|
|
1988
|
+
(next.result?.startTime ?? 0) + (next.result?.duration ?? 0)
|
|
1989
|
+
),
|
|
2956
1990
|
startTime
|
|
2957
1991
|
);
|
|
2958
1992
|
const assertionResults = tests2.map((t) => {
|
|
2959
|
-
var _a2, _b2, _c2, _d2;
|
|
2960
1993
|
const ancestorTitles = [];
|
|
2961
1994
|
let iter = t.suite;
|
|
2962
1995
|
while (iter) {
|
|
@@ -2967,32 +2000,26 @@ class JsonReporter {
|
|
|
2967
2000
|
return {
|
|
2968
2001
|
ancestorTitles,
|
|
2969
2002
|
fullName: t.name ? [...ancestorTitles, t.name].join(" ") : ancestorTitles.join(" "),
|
|
2970
|
-
status: StatusMap[
|
|
2003
|
+
status: StatusMap[t.result?.state || t.mode] || "skipped",
|
|
2971
2004
|
title: t.name,
|
|
2972
|
-
duration:
|
|
2973
|
-
failureMessages:
|
|
2005
|
+
duration: t.result?.duration,
|
|
2006
|
+
failureMessages: t.result?.errors?.map((e) => e.stack || e.message) || [],
|
|
2974
2007
|
location: t.location,
|
|
2975
2008
|
meta: t.meta
|
|
2976
2009
|
};
|
|
2977
2010
|
});
|
|
2978
|
-
if (tests2.some((t) => {
|
|
2979
|
-
var _a2;
|
|
2980
|
-
return ((_a2 = t.result) == null ? void 0 : _a2.state) === "run";
|
|
2981
|
-
})) {
|
|
2011
|
+
if (tests2.some((t) => t.result?.state === "run")) {
|
|
2982
2012
|
this.ctx.logger.warn(
|
|
2983
2013
|
"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"
|
|
2984
2014
|
);
|
|
2985
2015
|
}
|
|
2986
|
-
const hasFailedTests = tests2.some((t) =>
|
|
2987
|
-
var _a2;
|
|
2988
|
-
return ((_a2 = t.result) == null ? void 0 : _a2.state) === "fail";
|
|
2989
|
-
});
|
|
2016
|
+
const hasFailedTests = tests2.some((t) => t.result?.state === "fail");
|
|
2990
2017
|
testResults.push({
|
|
2991
2018
|
assertionResults,
|
|
2992
2019
|
startTime,
|
|
2993
2020
|
endTime,
|
|
2994
|
-
status:
|
|
2995
|
-
message:
|
|
2021
|
+
status: file.result?.state === "fail" || hasFailedTests ? "failed" : "passed",
|
|
2022
|
+
message: file.result?.errors?.[0]?.message ?? "",
|
|
2996
2023
|
name: file.filepath
|
|
2997
2024
|
});
|
|
2998
2025
|
}
|
|
@@ -3044,13 +2071,12 @@ class VerboseReporter extends DefaultReporter {
|
|
|
3044
2071
|
this.rendererOptions.renderSucceed = true;
|
|
3045
2072
|
}
|
|
3046
2073
|
onTaskUpdate(packs) {
|
|
3047
|
-
var _a, _b, _c;
|
|
3048
2074
|
if (this.isTTY) {
|
|
3049
2075
|
return;
|
|
3050
2076
|
}
|
|
3051
2077
|
for (const pack of packs) {
|
|
3052
2078
|
const task = this.ctx.state.idMap.get(pack[0]);
|
|
3053
|
-
if (task && task.type === "test" &&
|
|
2079
|
+
if (task && task.type === "test" && task.result?.state && task.result?.state !== "run") {
|
|
3054
2080
|
let title = ` ${getStateSymbol(task)} `;
|
|
3055
2081
|
if (task.file.projectName) {
|
|
3056
2082
|
title += formatProjectName(task.file.projectName);
|
|
@@ -3068,8 +2094,8 @@ class VerboseReporter extends DefaultReporter {
|
|
|
3068
2094
|
}
|
|
3069
2095
|
this.ctx.logger.log(title);
|
|
3070
2096
|
if (task.result.state === "fail") {
|
|
3071
|
-
|
|
3072
|
-
this.ctx.logger.log(c.red(` ${F_RIGHT} ${error
|
|
2097
|
+
task.result.errors?.forEach((error) => {
|
|
2098
|
+
this.ctx.logger.log(c.red(` ${F_RIGHT} ${error?.message}`));
|
|
3073
2099
|
});
|
|
3074
2100
|
}
|
|
3075
2101
|
}
|
|
@@ -3110,12 +2136,11 @@ class TapReporter {
|
|
|
3110
2136
|
this.logger = new IndentedLogger(ctx.logger.log.bind(ctx.logger));
|
|
3111
2137
|
}
|
|
3112
2138
|
static getComment(task) {
|
|
3113
|
-
var _a;
|
|
3114
2139
|
if (task.mode === "skip") {
|
|
3115
2140
|
return " # SKIP";
|
|
3116
2141
|
} else if (task.mode === "todo") {
|
|
3117
2142
|
return " # TODO";
|
|
3118
|
-
} else if (
|
|
2143
|
+
} else if (task.result?.duration != null) {
|
|
3119
2144
|
return ` # time=${task.result.duration.toFixed(2)}ms`;
|
|
3120
2145
|
} else {
|
|
3121
2146
|
return "";
|
|
@@ -3132,11 +2157,10 @@ class TapReporter {
|
|
|
3132
2157
|
}
|
|
3133
2158
|
}
|
|
3134
2159
|
logTasks(tasks) {
|
|
3135
|
-
var _a, _b;
|
|
3136
2160
|
this.logger.log(`1..${tasks.length}`);
|
|
3137
2161
|
for (const [i, task] of tasks.entries()) {
|
|
3138
2162
|
const id = i + 1;
|
|
3139
|
-
const ok =
|
|
2163
|
+
const ok = task.result?.state === "pass" || task.mode === "skip" || task.mode === "todo" ? "ok" : "not ok";
|
|
3140
2164
|
const comment = TapReporter.getComment(task);
|
|
3141
2165
|
if (task.type === "suite" && task.tasks.length > 0) {
|
|
3142
2166
|
this.logger.log(`${ok} ${id} - ${tapString(task.name)}${comment} {`);
|
|
@@ -3147,11 +2171,10 @@ class TapReporter {
|
|
|
3147
2171
|
} else {
|
|
3148
2172
|
this.logger.log(`${ok} ${id} - ${tapString(task.name)}${comment}`);
|
|
3149
2173
|
const project = this.ctx.getProjectByTaskId(task.id);
|
|
3150
|
-
if (
|
|
2174
|
+
if (task.result?.state === "fail" && task.result.errors) {
|
|
3151
2175
|
this.logger.indent();
|
|
3152
2176
|
task.result.errors.forEach((error) => {
|
|
3153
|
-
|
|
3154
|
-
const stacks = task.file.pool === "browser" ? ((_a2 = project.browser) == null ? void 0 : _a2.parseErrorStacktrace(error)) || [] : parseErrorStacktrace(error, {
|
|
2177
|
+
const stacks = task.file.pool === "browser" ? project.browser?.parseErrorStacktrace(error) || [] : parseErrorStacktrace(error, {
|
|
3155
2178
|
frameFilter: this.ctx.config.onStackTrace
|
|
3156
2179
|
});
|
|
3157
2180
|
const stack = stacks[0];
|
|
@@ -3496,11 +2519,11 @@ if (!processOk(process$1)) {
|
|
|
3496
2519
|
return function () {}
|
|
3497
2520
|
};
|
|
3498
2521
|
} else {
|
|
3499
|
-
var assert = require$$0$
|
|
2522
|
+
var assert = require$$0$1;
|
|
3500
2523
|
var signals = requireSignals();
|
|
3501
2524
|
var isWin = /^win/i.test(process$1.platform);
|
|
3502
2525
|
|
|
3503
|
-
var EE = require$$0
|
|
2526
|
+
var EE = require$$0;
|
|
3504
2527
|
/* istanbul ignore if */
|
|
3505
2528
|
if (typeof EE !== 'function') {
|
|
3506
2529
|
EE = EE.EventEmitter;
|
|
@@ -4402,61 +3425,6 @@ function highlightCode(id, source, colors) {
|
|
|
4402
3425
|
return highlight(source, { jsx: isJsx, colors: c });
|
|
4403
3426
|
}
|
|
4404
3427
|
|
|
4405
|
-
class BaseSequencer {
|
|
4406
|
-
ctx;
|
|
4407
|
-
constructor(ctx) {
|
|
4408
|
-
this.ctx = ctx;
|
|
4409
|
-
}
|
|
4410
|
-
// async so it can be extended by other sequelizers
|
|
4411
|
-
async shard(files) {
|
|
4412
|
-
const { config } = this.ctx;
|
|
4413
|
-
const { index, count } = config.shard;
|
|
4414
|
-
const shardSize = Math.ceil(files.length / count);
|
|
4415
|
-
const shardStart = shardSize * (index - 1);
|
|
4416
|
-
const shardEnd = shardSize * index;
|
|
4417
|
-
return [...files].map((spec) => {
|
|
4418
|
-
const fullPath = resolve(slash(config.root), slash(spec[1]));
|
|
4419
|
-
const specPath = fullPath == null ? void 0 : fullPath.slice(config.root.length);
|
|
4420
|
-
return {
|
|
4421
|
-
spec,
|
|
4422
|
-
hash: createHash("sha1").update(specPath).digest("hex")
|
|
4423
|
-
};
|
|
4424
|
-
}).sort((a, b) => a.hash < b.hash ? -1 : a.hash > b.hash ? 1 : 0).slice(shardStart, shardEnd).map(({ spec }) => spec);
|
|
4425
|
-
}
|
|
4426
|
-
// async so it can be extended by other sequelizers
|
|
4427
|
-
async sort(files) {
|
|
4428
|
-
const cache = this.ctx.cache;
|
|
4429
|
-
return [...files].sort((a, b) => {
|
|
4430
|
-
const keyA = `${a[0].getName()}:${relative(this.ctx.config.root, a[1])}`;
|
|
4431
|
-
const keyB = `${b[0].getName()}:${relative(this.ctx.config.root, b[1])}`;
|
|
4432
|
-
const aState = cache.getFileTestResults(keyA);
|
|
4433
|
-
const bState = cache.getFileTestResults(keyB);
|
|
4434
|
-
if (!aState || !bState) {
|
|
4435
|
-
const statsA = cache.getFileStats(keyA);
|
|
4436
|
-
const statsB = cache.getFileStats(keyB);
|
|
4437
|
-
if (!statsA || !statsB) {
|
|
4438
|
-
return !statsA && statsB ? -1 : !statsB && statsA ? 1 : 0;
|
|
4439
|
-
}
|
|
4440
|
-
return statsB.size - statsA.size;
|
|
4441
|
-
}
|
|
4442
|
-
if (aState.failed && !bState.failed) {
|
|
4443
|
-
return -1;
|
|
4444
|
-
}
|
|
4445
|
-
if (!aState.failed && bState.failed) {
|
|
4446
|
-
return 1;
|
|
4447
|
-
}
|
|
4448
|
-
return bState.duration - aState.duration;
|
|
4449
|
-
});
|
|
4450
|
-
}
|
|
4451
|
-
}
|
|
4452
|
-
|
|
4453
|
-
class RandomSequencer extends BaseSequencer {
|
|
4454
|
-
async sort(files) {
|
|
4455
|
-
const { sequence } = this.ctx.config;
|
|
4456
|
-
return shuffle(files, sequence.seed);
|
|
4457
|
-
}
|
|
4458
|
-
}
|
|
4459
|
-
|
|
4460
3428
|
const ESC = "\x1B[";
|
|
4461
3429
|
const ERASE_DOWN = `${ESC}J`;
|
|
4462
3430
|
const ERASE_SCROLLBACK = `${ESC}3J`;
|
|
@@ -4522,8 +3490,7 @@ class Logger {
|
|
|
4522
3490
|
printProperties: options.verbose,
|
|
4523
3491
|
screenshotPaths: options.screenshotPaths,
|
|
4524
3492
|
parseErrorStacktrace: (error) => {
|
|
4525
|
-
|
|
4526
|
-
if (((_a = options.task) == null ? void 0 : _a.file.pool) === "browser" && project.browser) {
|
|
3493
|
+
if (options.task?.file.pool === "browser" && project.browser) {
|
|
4527
3494
|
return project.browser.parseErrorStacktrace(error, {
|
|
4528
3495
|
ignoreStackEntries: fullStack ? [] : void 0
|
|
4529
3496
|
});
|
|
@@ -4551,10 +3518,9 @@ class Logger {
|
|
|
4551
3518
|
return code;
|
|
4552
3519
|
}
|
|
4553
3520
|
printNoTestFound(filters) {
|
|
4554
|
-
var _a;
|
|
4555
3521
|
const config = this.ctx.config;
|
|
4556
3522
|
const comma = c.dim(", ");
|
|
4557
|
-
if (filters
|
|
3523
|
+
if (filters?.length) {
|
|
4558
3524
|
this.console.error(c.dim("filter: ") + c.yellow(filters.join(comma)));
|
|
4559
3525
|
}
|
|
4560
3526
|
const projectsFilter = toArray(config.project);
|
|
@@ -4589,7 +3555,7 @@ class Logger {
|
|
|
4589
3555
|
);
|
|
4590
3556
|
}
|
|
4591
3557
|
});
|
|
4592
|
-
if (config.watch && (config.changed ||
|
|
3558
|
+
if (config.watch && (config.changed || config.related?.length)) {
|
|
4593
3559
|
this.log(`No affected ${config.mode} files found
|
|
4594
3560
|
`);
|
|
4595
3561
|
} else {
|
|
@@ -4605,7 +3571,6 @@ No ${config.mode} files found, exiting with code 1`)
|
|
|
4605
3571
|
}
|
|
4606
3572
|
}
|
|
4607
3573
|
printBanner() {
|
|
4608
|
-
var _a, _b;
|
|
4609
3574
|
this.log();
|
|
4610
3575
|
const versionTest = this.ctx.config.watch ? c.blue(`v${this.ctx.version}`) : c.cyan(`v${this.ctx.version}`);
|
|
4611
3576
|
const mode = this.ctx.config.watch ? c.blue(" DEV ") : c.cyan(" RUN ");
|
|
@@ -4628,7 +3593,7 @@ No ${config.mode} files found, exiting with code 1`)
|
|
|
4628
3593
|
const name = project.getName();
|
|
4629
3594
|
const output = project.isCore() ? "" : ` [${name}]`;
|
|
4630
3595
|
const resolvedUrls = project.browser.vite.resolvedUrls;
|
|
4631
|
-
const origin =
|
|
3596
|
+
const origin = resolvedUrls?.local[0] ?? resolvedUrls?.network[0];
|
|
4632
3597
|
this.log(
|
|
4633
3598
|
c.dim(
|
|
4634
3599
|
c.green(
|
|
@@ -4641,14 +3606,14 @@ No ${config.mode} files found, exiting with code 1`)
|
|
|
4641
3606
|
this.log(
|
|
4642
3607
|
c.dim(
|
|
4643
3608
|
c.green(
|
|
4644
|
-
` UI started at http://${
|
|
3609
|
+
` UI started at http://${this.ctx.config.api?.host || "localhost"}:${c.bold(`${this.ctx.server.config.server.port}`)}${this.ctx.config.uiBase}`
|
|
4645
3610
|
)
|
|
4646
3611
|
)
|
|
4647
3612
|
);
|
|
4648
|
-
} else if (
|
|
3613
|
+
} else if (this.ctx.config.api?.port) {
|
|
4649
3614
|
const resolvedUrls = this.ctx.server.resolvedUrls;
|
|
4650
3615
|
const fallbackUrl = `http://${this.ctx.config.api.host || "localhost"}:${this.ctx.config.api.port}`;
|
|
4651
|
-
const origin =
|
|
3616
|
+
const origin = resolvedUrls?.local[0] ?? resolvedUrls?.network[0] ?? fallbackUrl;
|
|
4652
3617
|
this.log(c.dim(c.green(` API started at ${new URL("/", origin)}`)));
|
|
4653
3618
|
}
|
|
4654
3619
|
if (this.ctx.coverageProvider) {
|
|
@@ -4714,10 +3679,9 @@ function capturePrintError(error, ctx, options) {
|
|
|
4714
3679
|
showCodeFrame: false,
|
|
4715
3680
|
...options
|
|
4716
3681
|
});
|
|
4717
|
-
return { nearest: result
|
|
3682
|
+
return { nearest: result?.nearest, output };
|
|
4718
3683
|
}
|
|
4719
3684
|
function printError(error, project, options) {
|
|
4720
|
-
var _a;
|
|
4721
3685
|
const { showCodeFrame = true, type, printProperties = true } = options;
|
|
4722
3686
|
const logger = options.logger;
|
|
4723
3687
|
let e = error;
|
|
@@ -4750,7 +3714,7 @@ function printError(error, project, options) {
|
|
|
4750
3714
|
printErrorType(type, project.ctx);
|
|
4751
3715
|
}
|
|
4752
3716
|
printErrorMessage(e, logger);
|
|
4753
|
-
if (
|
|
3717
|
+
if (options.screenshotPaths?.length) {
|
|
4754
3718
|
const length = options.screenshotPaths.length;
|
|
4755
3719
|
logger.error(`
|
|
4756
3720
|
Failure screenshot${length > 1 ? "s" : ""}:`);
|
|
@@ -4871,7 +3835,7 @@ function handleImportOutsideModuleError(stack, logger) {
|
|
|
4871
3835
|
}
|
|
4872
3836
|
const path = normalize(stack.split("\n")[0].trim());
|
|
4873
3837
|
let name = path.split("/node_modules/").pop() || "";
|
|
4874
|
-
if (name
|
|
3838
|
+
if (name?.startsWith("@")) {
|
|
4875
3839
|
name = name.split("/").slice(0, 2).join("/");
|
|
4876
3840
|
} else {
|
|
4877
3841
|
name = name.split("/")[0];
|
|
@@ -4944,7 +3908,7 @@ function printStack(logger, project, stack, highlight, errorProperties, onStack)
|
|
|
4944
3908
|
].filter(Boolean).join(" ")}`
|
|
4945
3909
|
)
|
|
4946
3910
|
);
|
|
4947
|
-
onStack
|
|
3911
|
+
onStack?.(frame);
|
|
4948
3912
|
}
|
|
4949
3913
|
if (stack.length) {
|
|
4950
3914
|
logger.error();
|
|
@@ -4962,14 +3926,13 @@ function hasProperties(obj) {
|
|
|
4962
3926
|
return false;
|
|
4963
3927
|
}
|
|
4964
3928
|
function generateCodeFrame(source, indent = 0, loc, range = 2) {
|
|
4965
|
-
var _a;
|
|
4966
3929
|
const start = typeof loc === "object" ? positionToOffset(source, loc.line, loc.column) : loc;
|
|
4967
3930
|
const end = start;
|
|
4968
3931
|
const lines = source.split(lineSplitRE);
|
|
4969
3932
|
const nl = /\r\n/.test(source) ? 2 : 1;
|
|
4970
3933
|
let count = 0;
|
|
4971
3934
|
let res = [];
|
|
4972
|
-
const columns =
|
|
3935
|
+
const columns = process.stdout?.columns || 80;
|
|
4973
3936
|
function lineNo(no = "") {
|
|
4974
3937
|
return c.gray(`${String(no).padStart(3, " ")}| `);
|
|
4975
3938
|
}
|
|
@@ -5051,8 +4014,7 @@ function executionTime(durationMS) {
|
|
|
5051
4014
|
});
|
|
5052
4015
|
}
|
|
5053
4016
|
function getDuration(task) {
|
|
5054
|
-
|
|
5055
|
-
const duration = ((_a = task.result) == null ? void 0 : _a.duration) ?? 0;
|
|
4017
|
+
const duration = task.result?.duration ?? 0;
|
|
5056
4018
|
return executionTime(duration);
|
|
5057
4019
|
}
|
|
5058
4020
|
class JUnitReporter {
|
|
@@ -5064,9 +4026,8 @@ class JUnitReporter {
|
|
|
5064
4026
|
fileFd;
|
|
5065
4027
|
options;
|
|
5066
4028
|
constructor(options) {
|
|
5067
|
-
var _a;
|
|
5068
4029
|
this.options = { ...options };
|
|
5069
|
-
|
|
4030
|
+
this.options.includeConsoleOutput ??= true;
|
|
5070
4031
|
}
|
|
5071
4032
|
async onInit(ctx) {
|
|
5072
4033
|
this.ctx = ctx;
|
|
@@ -5135,7 +4096,6 @@ class JUnitReporter {
|
|
|
5135
4096
|
time: getDuration(task)
|
|
5136
4097
|
},
|
|
5137
4098
|
async () => {
|
|
5138
|
-
var _a;
|
|
5139
4099
|
if (this.options.includeConsoleOutput) {
|
|
5140
4100
|
await this.writeLogs(task, "out");
|
|
5141
4101
|
await this.writeLogs(task, "err");
|
|
@@ -5143,14 +4103,14 @@ class JUnitReporter {
|
|
|
5143
4103
|
if (task.mode === "skip" || task.mode === "todo") {
|
|
5144
4104
|
await this.logger.log("<skipped/>");
|
|
5145
4105
|
}
|
|
5146
|
-
if (
|
|
4106
|
+
if (task.result?.state === "fail") {
|
|
5147
4107
|
const errors = task.result.errors || [];
|
|
5148
4108
|
for (const error of errors) {
|
|
5149
4109
|
await this.writeElement(
|
|
5150
4110
|
"failure",
|
|
5151
4111
|
{
|
|
5152
|
-
message: error
|
|
5153
|
-
type:
|
|
4112
|
+
message: error?.message,
|
|
4113
|
+
type: error?.name ?? error?.nameStr
|
|
5154
4114
|
},
|
|
5155
4115
|
async () => {
|
|
5156
4116
|
if (!error) {
|
|
@@ -5173,17 +4133,14 @@ class JUnitReporter {
|
|
|
5173
4133
|
}
|
|
5174
4134
|
}
|
|
5175
4135
|
async onFinished(files = this.ctx.state.getFiles()) {
|
|
5176
|
-
var _a;
|
|
5177
4136
|
await this.logger.log('<?xml version="1.0" encoding="UTF-8" ?>');
|
|
5178
4137
|
const transformed = files.map((file) => {
|
|
5179
|
-
var _a2, _b;
|
|
5180
4138
|
const tasks = file.tasks.flatMap((task) => flattenTasks$1(task));
|
|
5181
4139
|
const stats2 = tasks.reduce(
|
|
5182
4140
|
(stats3, task) => {
|
|
5183
|
-
var _a3, _b2;
|
|
5184
4141
|
return {
|
|
5185
|
-
passed: stats3.passed + Number(
|
|
5186
|
-
failures: stats3.failures + Number(
|
|
4142
|
+
passed: stats3.passed + Number(task.result?.state === "pass"),
|
|
4143
|
+
failures: stats3.failures + Number(task.result?.state === "fail"),
|
|
5187
4144
|
skipped: stats3.skipped + Number(task.mode === "skip" || task.mode === "todo")
|
|
5188
4145
|
};
|
|
5189
4146
|
},
|
|
@@ -5195,12 +4152,12 @@ class JUnitReporter {
|
|
|
5195
4152
|
);
|
|
5196
4153
|
const suites = getSuites(file);
|
|
5197
4154
|
for (const suite of suites) {
|
|
5198
|
-
if (
|
|
4155
|
+
if (suite.result?.errors) {
|
|
5199
4156
|
tasks.push(suite);
|
|
5200
4157
|
stats2.failures += 1;
|
|
5201
4158
|
}
|
|
5202
4159
|
}
|
|
5203
|
-
if (tasks.length === 0 &&
|
|
4160
|
+
if (tasks.length === 0 && file.result?.state === "fail") {
|
|
5204
4161
|
stats2.failures = 1;
|
|
5205
4162
|
tasks.push({
|
|
5206
4163
|
id: file.id,
|
|
@@ -5261,7 +4218,7 @@ class JUnitReporter {
|
|
|
5261
4218
|
if (this.reportFile) {
|
|
5262
4219
|
this.ctx.logger.log(`JUNIT report written to ${this.reportFile}`);
|
|
5263
4220
|
}
|
|
5264
|
-
await
|
|
4221
|
+
await this.fileFd?.close();
|
|
5265
4222
|
this.fileFd = void 0;
|
|
5266
4223
|
}
|
|
5267
4224
|
}
|
|
@@ -5299,8 +4256,7 @@ class HangingProcessReporter {
|
|
|
5299
4256
|
this.whyRunning = _require("why-is-node-running");
|
|
5300
4257
|
}
|
|
5301
4258
|
onProcessTimeout() {
|
|
5302
|
-
|
|
5303
|
-
(_a = this.whyRunning) == null ? void 0 : _a.call(this);
|
|
4259
|
+
this.whyRunning?.();
|
|
5304
4260
|
}
|
|
5305
4261
|
}
|
|
5306
4262
|
|
|
@@ -5310,7 +4266,6 @@ class GithubActionsReporter {
|
|
|
5310
4266
|
this.ctx = ctx;
|
|
5311
4267
|
}
|
|
5312
4268
|
onFinished(files = [], errors = []) {
|
|
5313
|
-
var _a, _b;
|
|
5314
4269
|
const projectErrors = new Array();
|
|
5315
4270
|
for (const error of errors) {
|
|
5316
4271
|
projectErrors.push({
|
|
@@ -5323,11 +4278,11 @@ class GithubActionsReporter {
|
|
|
5323
4278
|
const tasks = getTasks(file);
|
|
5324
4279
|
const project = this.ctx.getProjectByTaskId(file.id);
|
|
5325
4280
|
for (const task of tasks) {
|
|
5326
|
-
if (
|
|
4281
|
+
if (task.result?.state !== "fail") {
|
|
5327
4282
|
continue;
|
|
5328
4283
|
}
|
|
5329
4284
|
const title = getFullName(task, " > ");
|
|
5330
|
-
for (const error of
|
|
4285
|
+
for (const error of task.result?.errors ?? []) {
|
|
5331
4286
|
projectErrors.push({
|
|
5332
4287
|
project,
|
|
5333
4288
|
title,
|
|
@@ -5339,7 +4294,7 @@ class GithubActionsReporter {
|
|
|
5339
4294
|
}
|
|
5340
4295
|
for (const { project, title, error, file } of projectErrors) {
|
|
5341
4296
|
const result = capturePrintError(error, this.ctx, { project, task: file });
|
|
5342
|
-
const stack = result
|
|
4297
|
+
const stack = result?.nearest;
|
|
5343
4298
|
if (!stack) {
|
|
5344
4299
|
continue;
|
|
5345
4300
|
}
|
|
@@ -5469,9 +4424,8 @@ async function readBlobs(blobsDirectory, projectsArray) {
|
|
|
5469
4424
|
});
|
|
5470
4425
|
});
|
|
5471
4426
|
const files = blobs.flatMap((blob) => blob.files).sort((f1, f2) => {
|
|
5472
|
-
|
|
5473
|
-
const
|
|
5474
|
-
const time2 = ((_b = f2.result) == null ? void 0 : _b.startTime) || 0;
|
|
4427
|
+
const time1 = f1.result?.startTime || 0;
|
|
4428
|
+
const time2 = f2.result?.startTime || 0;
|
|
5475
4429
|
return time1 - time2;
|
|
5476
4430
|
});
|
|
5477
4431
|
const errors = blobs.flatMap((blob) => blob.errors);
|
|
@@ -5483,6 +4437,382 @@ async function readBlobs(blobsDirectory, projectsArray) {
|
|
|
5483
4437
|
};
|
|
5484
4438
|
}
|
|
5485
4439
|
|
|
4440
|
+
class TestProject {
|
|
4441
|
+
/**
|
|
4442
|
+
* The global vitest instance.
|
|
4443
|
+
* @experimental The public Vitest API is experimental and does not follow semver.
|
|
4444
|
+
*/
|
|
4445
|
+
vitest;
|
|
4446
|
+
/**
|
|
4447
|
+
* The workspace project this test project is associated with.
|
|
4448
|
+
* @experimental The public Vitest API is experimental and does not follow semver.
|
|
4449
|
+
*/
|
|
4450
|
+
workspaceProject;
|
|
4451
|
+
/**
|
|
4452
|
+
* Resolved project configuration.
|
|
4453
|
+
*/
|
|
4454
|
+
config;
|
|
4455
|
+
/**
|
|
4456
|
+
* Resolved global configuration. If there are no workspace projects, this will be the same as `config`.
|
|
4457
|
+
*/
|
|
4458
|
+
globalConfig;
|
|
4459
|
+
/**
|
|
4460
|
+
* The name of the project or an empty string if not set.
|
|
4461
|
+
*/
|
|
4462
|
+
name;
|
|
4463
|
+
constructor(workspaceProject) {
|
|
4464
|
+
this.workspaceProject = workspaceProject;
|
|
4465
|
+
this.vitest = workspaceProject.ctx;
|
|
4466
|
+
this.globalConfig = workspaceProject.ctx.config;
|
|
4467
|
+
this.config = workspaceProject.config;
|
|
4468
|
+
this.name = workspaceProject.getName();
|
|
4469
|
+
}
|
|
4470
|
+
/**
|
|
4471
|
+
* Serialized project configuration. This is the config that tests receive.
|
|
4472
|
+
*/
|
|
4473
|
+
get serializedConfig() {
|
|
4474
|
+
return this.workspaceProject.getSerializableConfig();
|
|
4475
|
+
}
|
|
4476
|
+
/**
|
|
4477
|
+
* Custom context provided to the project.
|
|
4478
|
+
*/
|
|
4479
|
+
context() {
|
|
4480
|
+
return this.workspaceProject.getProvidedContext();
|
|
4481
|
+
}
|
|
4482
|
+
/**
|
|
4483
|
+
* Provide a custom serializable context to the project. This context will be available for tests once they run.
|
|
4484
|
+
*/
|
|
4485
|
+
provide(key, value) {
|
|
4486
|
+
this.workspaceProject.provide(key, value);
|
|
4487
|
+
}
|
|
4488
|
+
toJSON() {
|
|
4489
|
+
return {
|
|
4490
|
+
name: this.name,
|
|
4491
|
+
serializedConfig: this.serializedConfig,
|
|
4492
|
+
context: this.context()
|
|
4493
|
+
};
|
|
4494
|
+
}
|
|
4495
|
+
}
|
|
4496
|
+
|
|
4497
|
+
class ReportedTaskImplementation {
|
|
4498
|
+
/**
|
|
4499
|
+
* Task instance.
|
|
4500
|
+
* @experimental Public runner task API is experimental and does not follow semver.
|
|
4501
|
+
*/
|
|
4502
|
+
task;
|
|
4503
|
+
/**
|
|
4504
|
+
* The project assosiacted with the test or suite.
|
|
4505
|
+
*/
|
|
4506
|
+
project;
|
|
4507
|
+
/**
|
|
4508
|
+
* Unique identifier.
|
|
4509
|
+
* This ID is deterministic and will be the same for the same test across multiple runs.
|
|
4510
|
+
* The ID is based on the project name, file path and test position.
|
|
4511
|
+
*/
|
|
4512
|
+
id;
|
|
4513
|
+
/**
|
|
4514
|
+
* Location in the file where the test or suite is defined.
|
|
4515
|
+
*/
|
|
4516
|
+
location;
|
|
4517
|
+
constructor(task, project) {
|
|
4518
|
+
this.task = task;
|
|
4519
|
+
this.project = project.testProject || (project.testProject = new TestProject(project));
|
|
4520
|
+
this.id = task.id;
|
|
4521
|
+
this.location = task.location;
|
|
4522
|
+
}
|
|
4523
|
+
/**
|
|
4524
|
+
* Creates a new reported task instance and stores it in the project's state for future use.
|
|
4525
|
+
*/
|
|
4526
|
+
static register(task, project) {
|
|
4527
|
+
const state = new this(task, project);
|
|
4528
|
+
storeTask(project, task, state);
|
|
4529
|
+
return state;
|
|
4530
|
+
}
|
|
4531
|
+
}
|
|
4532
|
+
class TestCase extends ReportedTaskImplementation {
|
|
4533
|
+
#fullName;
|
|
4534
|
+
type = "test";
|
|
4535
|
+
/**
|
|
4536
|
+
* Direct reference to the test file where the test or suite is defined.
|
|
4537
|
+
*/
|
|
4538
|
+
file;
|
|
4539
|
+
/**
|
|
4540
|
+
* Name of the test.
|
|
4541
|
+
*/
|
|
4542
|
+
name;
|
|
4543
|
+
/**
|
|
4544
|
+
* Options that the test was initiated with.
|
|
4545
|
+
*/
|
|
4546
|
+
options;
|
|
4547
|
+
/**
|
|
4548
|
+
* Parent suite. If the test was called directly inside the file, the parent will be the file.
|
|
4549
|
+
*/
|
|
4550
|
+
parent;
|
|
4551
|
+
constructor(task, project) {
|
|
4552
|
+
super(task, project);
|
|
4553
|
+
this.name = task.name;
|
|
4554
|
+
this.file = getReportedTask(project, task.file);
|
|
4555
|
+
const suite = this.task.suite;
|
|
4556
|
+
if (suite) {
|
|
4557
|
+
this.parent = getReportedTask(project, suite);
|
|
4558
|
+
} else {
|
|
4559
|
+
this.parent = this.file;
|
|
4560
|
+
}
|
|
4561
|
+
this.options = buildOptions(task);
|
|
4562
|
+
}
|
|
4563
|
+
/**
|
|
4564
|
+
* Full name of the test including all parent suites separated with `>`.
|
|
4565
|
+
*/
|
|
4566
|
+
get fullName() {
|
|
4567
|
+
if (this.#fullName === void 0) {
|
|
4568
|
+
this.#fullName = getTestName(this.task, " > ");
|
|
4569
|
+
}
|
|
4570
|
+
return this.#fullName;
|
|
4571
|
+
}
|
|
4572
|
+
/**
|
|
4573
|
+
* Test results. Will be `undefined` if test is not finished yet or was just collected.
|
|
4574
|
+
*/
|
|
4575
|
+
result() {
|
|
4576
|
+
const result = this.task.result;
|
|
4577
|
+
if (!result || result.state === "run") {
|
|
4578
|
+
return void 0;
|
|
4579
|
+
}
|
|
4580
|
+
const state = result.state === "fail" ? "failed" : result.state === "pass" ? "passed" : "skipped";
|
|
4581
|
+
return {
|
|
4582
|
+
state,
|
|
4583
|
+
errors: result.errors
|
|
4584
|
+
};
|
|
4585
|
+
}
|
|
4586
|
+
/**
|
|
4587
|
+
* Checks if the test did not fail the suite.
|
|
4588
|
+
* If the test is not finished yet or was skipped, it will return `true`.
|
|
4589
|
+
*/
|
|
4590
|
+
ok() {
|
|
4591
|
+
const result = this.result();
|
|
4592
|
+
return !result || result.state !== "failed";
|
|
4593
|
+
}
|
|
4594
|
+
/**
|
|
4595
|
+
* Custom metadata that was attached to the test during its execution.
|
|
4596
|
+
*/
|
|
4597
|
+
meta() {
|
|
4598
|
+
return this.task.meta;
|
|
4599
|
+
}
|
|
4600
|
+
/**
|
|
4601
|
+
* Useful information about the test like duration, memory usage, etc.
|
|
4602
|
+
* Diagnostic is only available after the test has finished.
|
|
4603
|
+
*/
|
|
4604
|
+
diagnostic() {
|
|
4605
|
+
const result = this.task.result;
|
|
4606
|
+
if (!result || result.state === "run" || !result.startTime) {
|
|
4607
|
+
return void 0;
|
|
4608
|
+
}
|
|
4609
|
+
return {
|
|
4610
|
+
heap: result.heap,
|
|
4611
|
+
duration: result.duration,
|
|
4612
|
+
startTime: result.startTime,
|
|
4613
|
+
retryCount: result.retryCount ?? 0,
|
|
4614
|
+
repeatCount: result.repeatCount ?? 0,
|
|
4615
|
+
flaky: !!result.retryCount && result.state === "pass" && result.retryCount > 0
|
|
4616
|
+
};
|
|
4617
|
+
}
|
|
4618
|
+
}
|
|
4619
|
+
class TestCollection {
|
|
4620
|
+
#task;
|
|
4621
|
+
#project;
|
|
4622
|
+
constructor(task, project) {
|
|
4623
|
+
this.#task = task;
|
|
4624
|
+
this.#project = project;
|
|
4625
|
+
}
|
|
4626
|
+
/**
|
|
4627
|
+
* Returns the test or suite at a specific index in the array.
|
|
4628
|
+
*/
|
|
4629
|
+
at(index) {
|
|
4630
|
+
if (index < 0) {
|
|
4631
|
+
index = this.size + index;
|
|
4632
|
+
}
|
|
4633
|
+
return getReportedTask(this.#project, this.#task.tasks[index]);
|
|
4634
|
+
}
|
|
4635
|
+
/**
|
|
4636
|
+
* The number of tests and suites in the collection.
|
|
4637
|
+
*/
|
|
4638
|
+
get size() {
|
|
4639
|
+
return this.#task.tasks.length;
|
|
4640
|
+
}
|
|
4641
|
+
/**
|
|
4642
|
+
* Returns the collection in array form for easier manipulation.
|
|
4643
|
+
*/
|
|
4644
|
+
array() {
|
|
4645
|
+
return Array.from(this);
|
|
4646
|
+
}
|
|
4647
|
+
/**
|
|
4648
|
+
* Filters all tests that are part of this collection and its children.
|
|
4649
|
+
*/
|
|
4650
|
+
*allTests(state) {
|
|
4651
|
+
for (const child of this) {
|
|
4652
|
+
if (child.type === "suite") {
|
|
4653
|
+
yield* child.children.allTests(state);
|
|
4654
|
+
} else if (state) {
|
|
4655
|
+
const testState = getTestState(child);
|
|
4656
|
+
if (state === testState) {
|
|
4657
|
+
yield child;
|
|
4658
|
+
}
|
|
4659
|
+
} else {
|
|
4660
|
+
yield child;
|
|
4661
|
+
}
|
|
4662
|
+
}
|
|
4663
|
+
}
|
|
4664
|
+
/**
|
|
4665
|
+
* Filters only the tests that are part of this collection.
|
|
4666
|
+
*/
|
|
4667
|
+
*tests(state) {
|
|
4668
|
+
for (const child of this) {
|
|
4669
|
+
if (child.type !== "test") {
|
|
4670
|
+
continue;
|
|
4671
|
+
}
|
|
4672
|
+
if (state) {
|
|
4673
|
+
const testState = getTestState(child);
|
|
4674
|
+
if (state === testState) {
|
|
4675
|
+
yield child;
|
|
4676
|
+
}
|
|
4677
|
+
} else {
|
|
4678
|
+
yield child;
|
|
4679
|
+
}
|
|
4680
|
+
}
|
|
4681
|
+
}
|
|
4682
|
+
/**
|
|
4683
|
+
* Filters only the suites that are part of this collection.
|
|
4684
|
+
*/
|
|
4685
|
+
*suites() {
|
|
4686
|
+
for (const child of this) {
|
|
4687
|
+
if (child.type === "suite") {
|
|
4688
|
+
yield child;
|
|
4689
|
+
}
|
|
4690
|
+
}
|
|
4691
|
+
}
|
|
4692
|
+
/**
|
|
4693
|
+
* Filters all suites that are part of this collection and its children.
|
|
4694
|
+
*/
|
|
4695
|
+
*allSuites() {
|
|
4696
|
+
for (const child of this) {
|
|
4697
|
+
if (child.type === "suite") {
|
|
4698
|
+
yield child;
|
|
4699
|
+
yield* child.children.allSuites();
|
|
4700
|
+
}
|
|
4701
|
+
}
|
|
4702
|
+
}
|
|
4703
|
+
*[Symbol.iterator]() {
|
|
4704
|
+
for (const task of this.#task.tasks) {
|
|
4705
|
+
yield getReportedTask(this.#project, task);
|
|
4706
|
+
}
|
|
4707
|
+
}
|
|
4708
|
+
}
|
|
4709
|
+
class SuiteImplementation extends ReportedTaskImplementation {
|
|
4710
|
+
/**
|
|
4711
|
+
* Collection of suites and tests that are part of this suite.
|
|
4712
|
+
*/
|
|
4713
|
+
children;
|
|
4714
|
+
constructor(task, project) {
|
|
4715
|
+
super(task, project);
|
|
4716
|
+
this.children = new TestCollection(task, project);
|
|
4717
|
+
}
|
|
4718
|
+
}
|
|
4719
|
+
class TestSuite extends SuiteImplementation {
|
|
4720
|
+
#fullName;
|
|
4721
|
+
type = "suite";
|
|
4722
|
+
/**
|
|
4723
|
+
* Name of the test or the suite.
|
|
4724
|
+
*/
|
|
4725
|
+
name;
|
|
4726
|
+
/**
|
|
4727
|
+
* Direct reference to the test file where the test or suite is defined.
|
|
4728
|
+
*/
|
|
4729
|
+
file;
|
|
4730
|
+
/**
|
|
4731
|
+
* Parent suite. If suite was called directly inside the file, the parent will be the file.
|
|
4732
|
+
*/
|
|
4733
|
+
parent;
|
|
4734
|
+
/**
|
|
4735
|
+
* Options that suite was initiated with.
|
|
4736
|
+
*/
|
|
4737
|
+
options;
|
|
4738
|
+
constructor(task, project) {
|
|
4739
|
+
super(task, project);
|
|
4740
|
+
this.name = task.name;
|
|
4741
|
+
this.file = getReportedTask(project, task.file);
|
|
4742
|
+
const suite = this.task.suite;
|
|
4743
|
+
if (suite) {
|
|
4744
|
+
this.parent = getReportedTask(project, suite);
|
|
4745
|
+
} else {
|
|
4746
|
+
this.parent = this.file;
|
|
4747
|
+
}
|
|
4748
|
+
this.options = buildOptions(task);
|
|
4749
|
+
}
|
|
4750
|
+
/**
|
|
4751
|
+
* Full name of the suite including all parent suites separated with `>`.
|
|
4752
|
+
*/
|
|
4753
|
+
get fullName() {
|
|
4754
|
+
if (this.#fullName === void 0) {
|
|
4755
|
+
this.#fullName = getTestName(this.task, " > ");
|
|
4756
|
+
}
|
|
4757
|
+
return this.#fullName;
|
|
4758
|
+
}
|
|
4759
|
+
}
|
|
4760
|
+
class TestFile extends SuiteImplementation {
|
|
4761
|
+
type = "file";
|
|
4762
|
+
/**
|
|
4763
|
+
* This is usually an absolute UNIX file path.
|
|
4764
|
+
* It can be a virtual id if the file is not on the disk.
|
|
4765
|
+
* This value corresponds to Vite's `ModuleGraph` id.
|
|
4766
|
+
*/
|
|
4767
|
+
moduleId;
|
|
4768
|
+
constructor(task, project) {
|
|
4769
|
+
super(task, project);
|
|
4770
|
+
this.moduleId = task.filepath;
|
|
4771
|
+
}
|
|
4772
|
+
/**
|
|
4773
|
+
* Useful information about the file like duration, memory usage, etc.
|
|
4774
|
+
* If the file was not executed yet, all diagnostic values will return `0`.
|
|
4775
|
+
*/
|
|
4776
|
+
diagnostic() {
|
|
4777
|
+
const setupDuration = this.task.setupDuration || 0;
|
|
4778
|
+
const collectDuration = this.task.collectDuration || 0;
|
|
4779
|
+
const prepareDuration = this.task.prepareDuration || 0;
|
|
4780
|
+
const environmentSetupDuration = this.task.environmentLoad || 0;
|
|
4781
|
+
const duration = this.task.result?.duration || 0;
|
|
4782
|
+
return {
|
|
4783
|
+
environmentSetupDuration,
|
|
4784
|
+
prepareDuration,
|
|
4785
|
+
collectDuration,
|
|
4786
|
+
setupDuration,
|
|
4787
|
+
duration
|
|
4788
|
+
};
|
|
4789
|
+
}
|
|
4790
|
+
}
|
|
4791
|
+
function buildOptions(task) {
|
|
4792
|
+
return {
|
|
4793
|
+
each: task.each,
|
|
4794
|
+
concurrent: task.concurrent,
|
|
4795
|
+
shuffle: task.shuffle,
|
|
4796
|
+
retry: task.retry,
|
|
4797
|
+
repeats: task.repeats,
|
|
4798
|
+
mode: task.mode
|
|
4799
|
+
};
|
|
4800
|
+
}
|
|
4801
|
+
function getTestState(test) {
|
|
4802
|
+
const result = test.result();
|
|
4803
|
+
return result ? result.state : "running";
|
|
4804
|
+
}
|
|
4805
|
+
function storeTask(project, runnerTask, reportedTask) {
|
|
4806
|
+
project.ctx.state.reportedTasksMap.set(runnerTask, reportedTask);
|
|
4807
|
+
}
|
|
4808
|
+
function getReportedTask(project, runnerTask) {
|
|
4809
|
+
const reportedTask = project.ctx.state.getReportedEntity(runnerTask);
|
|
4810
|
+
if (!reportedTask) {
|
|
4811
|
+
throw new Error(`Task instance was not found for ${runnerTask.type} "${runnerTask.name}"`);
|
|
4812
|
+
}
|
|
4813
|
+
return reportedTask;
|
|
4814
|
+
}
|
|
4815
|
+
|
|
5486
4816
|
const outputMap = /* @__PURE__ */ new WeakMap();
|
|
5487
4817
|
function formatFilepath(path) {
|
|
5488
4818
|
const lastSlash = Math.max(path.lastIndexOf("/") + 1, 0);
|
|
@@ -5567,15 +4897,14 @@ function renderBenchmark(result, widths) {
|
|
|
5567
4897
|
].join(" ");
|
|
5568
4898
|
}
|
|
5569
4899
|
function renderTree(tasks, options, level = 0, shallow = false) {
|
|
5570
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
5571
4900
|
const output = [];
|
|
5572
4901
|
const benchMap = {};
|
|
5573
4902
|
for (const t of tasks) {
|
|
5574
|
-
if (t.meta.benchmark &&
|
|
4903
|
+
if (t.meta.benchmark && t.result?.benchmark) {
|
|
5575
4904
|
benchMap[t.id] = {
|
|
5576
4905
|
current: t.result.benchmark
|
|
5577
4906
|
};
|
|
5578
|
-
const baseline =
|
|
4907
|
+
const baseline = options.compare?.[t.id];
|
|
5579
4908
|
if (baseline) {
|
|
5580
4909
|
benchMap[t.id].baseline = {
|
|
5581
4910
|
...baseline,
|
|
@@ -5592,7 +4921,7 @@ function renderTree(tasks, options, level = 0, shallow = false) {
|
|
|
5592
4921
|
for (const task of tasks) {
|
|
5593
4922
|
const padding = " ".repeat(level ? 1 : 0);
|
|
5594
4923
|
let prefix = "";
|
|
5595
|
-
if (idx === 0 &&
|
|
4924
|
+
if (idx === 0 && task.meta?.benchmark) {
|
|
5596
4925
|
prefix += `${renderTableHead(columnWidths)}
|
|
5597
4926
|
${padding}`;
|
|
5598
4927
|
}
|
|
@@ -5604,14 +4933,14 @@ ${padding}`;
|
|
|
5604
4933
|
if (task.mode === "skip" || task.mode === "todo") {
|
|
5605
4934
|
suffix += ` ${c.dim(c.gray("[skipped]"))}`;
|
|
5606
4935
|
}
|
|
5607
|
-
if (
|
|
4936
|
+
if (task.result?.duration != null) {
|
|
5608
4937
|
if (task.result.duration > options.slowTestThreshold) {
|
|
5609
4938
|
suffix += c.yellow(
|
|
5610
4939
|
` ${Math.round(task.result.duration)}${c.dim("ms")}`
|
|
5611
4940
|
);
|
|
5612
4941
|
}
|
|
5613
4942
|
}
|
|
5614
|
-
if (options.showHeap &&
|
|
4943
|
+
if (options.showHeap && task.result?.heap != null) {
|
|
5615
4944
|
suffix += c.magenta(
|
|
5616
4945
|
` ${Math.floor(task.result.heap / 1024 / 1024)} MB heap used`
|
|
5617
4946
|
);
|
|
@@ -5651,7 +4980,7 @@ ${padding}`;
|
|
|
5651
4980
|
} else {
|
|
5652
4981
|
output.push(padding + prefix + name + suffix);
|
|
5653
4982
|
}
|
|
5654
|
-
if (
|
|
4983
|
+
if (task.result?.state !== "pass" && outputMap.get(task) != null) {
|
|
5655
4984
|
let data = outputMap.get(task);
|
|
5656
4985
|
if (typeof data === "string") {
|
|
5657
4986
|
data = stripAnsi(data.trim().split("\n").filter(Boolean).pop());
|
|
@@ -5665,7 +4994,7 @@ ${padding}`;
|
|
|
5665
4994
|
}
|
|
5666
4995
|
}
|
|
5667
4996
|
if (!shallow && task.type === "suite" && task.tasks.length > 0) {
|
|
5668
|
-
if (
|
|
4997
|
+
if (task.result?.state) {
|
|
5669
4998
|
output.push(renderTree(task.tasks, options, level + 1));
|
|
5670
4999
|
}
|
|
5671
5000
|
}
|
|
@@ -5725,14 +5054,13 @@ class TableReporter extends BaseReporter {
|
|
|
5725
5054
|
super.onWatcherStart();
|
|
5726
5055
|
}
|
|
5727
5056
|
async onCollected() {
|
|
5728
|
-
var _a, _b;
|
|
5729
5057
|
this.rendererOptions.logger = this.ctx.logger;
|
|
5730
5058
|
this.rendererOptions.showHeap = this.ctx.config.logHeapUsage;
|
|
5731
5059
|
this.rendererOptions.slowTestThreshold = this.ctx.config.slowTestThreshold;
|
|
5732
|
-
if (
|
|
5060
|
+
if (this.ctx.config.benchmark?.compare) {
|
|
5733
5061
|
const compareFile = pathe.resolve(
|
|
5734
5062
|
this.ctx.config.root,
|
|
5735
|
-
|
|
5063
|
+
this.ctx.config.benchmark?.compare
|
|
5736
5064
|
);
|
|
5737
5065
|
try {
|
|
5738
5066
|
this.rendererOptions.compare = flattenFormattedBenchmarkReport(
|
|
@@ -5757,18 +5085,14 @@ class TableReporter extends BaseReporter {
|
|
|
5757
5085
|
}
|
|
5758
5086
|
}
|
|
5759
5087
|
onTaskUpdate(packs) {
|
|
5760
|
-
var _a, _b;
|
|
5761
5088
|
if (this.isTTY) {
|
|
5762
5089
|
return;
|
|
5763
5090
|
}
|
|
5764
5091
|
for (const pack of packs) {
|
|
5765
5092
|
const task = this.ctx.state.idMap.get(pack[0]);
|
|
5766
|
-
if (task && task.type === "suite" &&
|
|
5093
|
+
if (task && task.type === "suite" && task.result?.state && task.result?.state !== "run") {
|
|
5767
5094
|
const benches = task.tasks.filter((t) => t.meta.benchmark);
|
|
5768
|
-
if (benches.length > 0 && benches.every((t) => {
|
|
5769
|
-
var _a2;
|
|
5770
|
-
return ((_a2 = t.result) == null ? void 0 : _a2.state) !== "run";
|
|
5771
|
-
})) {
|
|
5095
|
+
if (benches.length > 0 && benches.every((t) => t.result?.state !== "run")) {
|
|
5772
5096
|
let title = ` ${getStateSymbol(task)} ${getFullName(
|
|
5773
5097
|
task,
|
|
5774
5098
|
c.dim(" > ")
|
|
@@ -5787,11 +5111,10 @@ class TableReporter extends BaseReporter {
|
|
|
5787
5111
|
}
|
|
5788
5112
|
}
|
|
5789
5113
|
async onFinished(files = this.ctx.state.getFiles(), errors = this.ctx.state.getUnhandledErrors()) {
|
|
5790
|
-
var _a;
|
|
5791
5114
|
this.stopListRender();
|
|
5792
5115
|
this.ctx.logger.log();
|
|
5793
5116
|
super.onFinished(files, errors);
|
|
5794
|
-
let outputFile =
|
|
5117
|
+
let outputFile = this.ctx.config.benchmark?.outputJson;
|
|
5795
5118
|
if (outputFile) {
|
|
5796
5119
|
outputFile = pathe.resolve(this.ctx.config.root, outputFile);
|
|
5797
5120
|
const outputDirectory = pathe.dirname(outputFile);
|
|
@@ -5808,8 +5131,7 @@ class TableReporter extends BaseReporter {
|
|
|
5808
5131
|
await super.onWatcherStart();
|
|
5809
5132
|
}
|
|
5810
5133
|
stopListRender() {
|
|
5811
|
-
|
|
5812
|
-
(_a = this.renderer) == null ? void 0 : _a.stop();
|
|
5134
|
+
this.renderer?.stop();
|
|
5813
5135
|
this.renderer = void 0;
|
|
5814
5136
|
}
|
|
5815
5137
|
async onWatcherRerun(files, trigger) {
|
|
@@ -5817,16 +5139,14 @@ class TableReporter extends BaseReporter {
|
|
|
5817
5139
|
await super.onWatcherRerun(files, trigger);
|
|
5818
5140
|
}
|
|
5819
5141
|
onUserConsoleLog(log) {
|
|
5820
|
-
var _a;
|
|
5821
5142
|
if (!this.shouldLog(log)) {
|
|
5822
5143
|
return;
|
|
5823
5144
|
}
|
|
5824
|
-
|
|
5145
|
+
this.renderer?.clear();
|
|
5825
5146
|
super.onUserConsoleLog(log);
|
|
5826
5147
|
}
|
|
5827
5148
|
}
|
|
5828
5149
|
function createFormattedBenchmarkReport(files) {
|
|
5829
|
-
var _a;
|
|
5830
5150
|
const report = { files: [] };
|
|
5831
5151
|
for (const file of files) {
|
|
5832
5152
|
const groups = [];
|
|
@@ -5834,7 +5154,7 @@ function createFormattedBenchmarkReport(files) {
|
|
|
5834
5154
|
if (task && task.type === "suite") {
|
|
5835
5155
|
const benchmarks = [];
|
|
5836
5156
|
for (const t of task.tasks) {
|
|
5837
|
-
const benchmark = t.meta.benchmark &&
|
|
5157
|
+
const benchmark = t.meta.benchmark && t.result?.benchmark;
|
|
5838
5158
|
if (benchmark) {
|
|
5839
5159
|
const { samples, ...rest } = benchmark;
|
|
5840
5160
|
benchmarks.push({
|
|
@@ -5891,4 +5211,4 @@ const ReportersMap = {
|
|
|
5891
5211
|
"github-actions": GithubActionsReporter
|
|
5892
5212
|
};
|
|
5893
5213
|
|
|
5894
|
-
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,
|
|
5214
|
+
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, TestCase as d, TestFile as e, TestSuite as f, BenchmarkReportsMap as g, TestProject as h, generateCodeFrame as i, highlightCode as j, BlobReporter as k, parse as p, readBlobs as r, stringify as s };
|