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