vitest 0.24.5 → 0.25.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.
Files changed (49) hide show
  1. package/LICENSE.md +286 -57
  2. package/dist/browser.d.ts +3 -3
  3. package/dist/browser.js +18 -11
  4. package/dist/{chunk-api-setup.629f8133.js → chunk-api-setup.f40616e2.js} +38 -19
  5. package/dist/{chunk-env-node.700b7e95.js → chunk-env-node.67948209.js} +8 -11
  6. package/dist/{chunk-install-pkg.22707ee4.js → chunk-install-pkg.579a5a27.js} +3 -4
  7. package/dist/{chunk-integrations-coverage.cca09977.js → chunk-integrations-coverage.befed097.js} +57 -1
  8. package/dist/chunk-integrations-globals.796fe181.js +25 -0
  9. package/dist/{chunk-node-git.82174cfe.js → chunk-node-git.5a1b1656.js} +5 -6
  10. package/dist/{chunk-runtime-chain.37ec5d73.js → chunk-runtime-chain.e387e274.js} +36 -25
  11. package/dist/{chunk-runtime-error.17751c39.js → chunk-runtime-error.6287172c.js} +9 -2
  12. package/dist/{chunk-runtime-mocker.41b92ec9.js → chunk-runtime-mocker.503a4f67.js} +4 -4
  13. package/dist/{chunk-runtime-rpc.b418c0ab.js → chunk-runtime-rpc.1e7530d3.js} +2 -2
  14. package/dist/chunk-runtime-setup.5c4e0f49.js +1363 -0
  15. package/dist/{chunk-runtime-hooks.d748b085.js → chunk-runtime-test-state.4ed42543.js} +119 -6
  16. package/dist/{chunk-mock-date.030959d3.js → chunk-typecheck-constants.4891f22f.js} +23 -4
  17. package/dist/{chunk-utils-env.b1281522.js → chunk-utils-env.03f840f2.js} +2 -0
  18. package/dist/chunk-utils-source-map.c6dfbbc1.js +90 -0
  19. package/dist/{chunk-utils-timers.8fca243e.js → chunk-utils-timers.06f993db.js} +86 -79
  20. package/dist/{chunk-vite-node-client.3868b3ba.js → chunk-vite-node-client.b2ab6dcf.js} +25 -5
  21. package/dist/{chunk-vite-node-externalize.d9033432.js → chunk-vite-node-externalize.477f36a4.js} +821 -92
  22. package/dist/chunk-vite-node-utils.8f0b4a12.js +1400 -0
  23. package/dist/cli-wrapper.js +5 -6
  24. package/dist/cli.js +27 -13
  25. package/dist/config.cjs +6 -1
  26. package/dist/config.d.ts +6 -1
  27. package/dist/config.js +6 -1
  28. package/dist/entry.js +15 -13
  29. package/dist/environments.d.ts +1 -1
  30. package/dist/environments.js +1 -1
  31. package/dist/index-2f5b6168.d.ts +256 -0
  32. package/dist/index.d.ts +13 -4
  33. package/dist/index.js +13 -7
  34. package/dist/loader.js +4 -3
  35. package/dist/node.d.ts +2 -2
  36. package/dist/node.js +18 -11
  37. package/dist/suite.js +6 -6
  38. package/dist/{global-58e8e951.d.ts → types-f302dae9.d.ts} +210 -19
  39. package/dist/{vendor-index.cc8d244b.js → vendor-index.737c3cff.js} +1 -2
  40. package/dist/{vendor-index.12d51d29.js → vendor-index.e1d4cf84.js} +279 -7
  41. package/dist/worker.js +9 -8
  42. package/globals.d.ts +2 -0
  43. package/package.json +13 -9
  44. package/dist/chunk-integrations-globals.32ef80c3.js +0 -25
  45. package/dist/chunk-runtime-setup.ab6b6274.js +0 -676
  46. package/dist/chunk-utils-source-map.663e2952.js +0 -3429
  47. package/dist/chunk-vite-node-utils.2144000e.js +0 -6946
  48. package/dist/index-220c1d70.d.ts +0 -117
  49. package/dist/vendor-index.1a291e86.js +0 -275
@@ -1,7 +1,7 @@
1
- import { b as resolve, p as picocolors, j as join, c as basename, d as dirname, e as distDir, f as rootDir, g as isAbsolute, r as relative, i as isNode, h as configFiles, k as defaultPort, n as normalize, t as toNamespacedPath, E as EXIT_CODE_RESTART } from './chunk-utils-env.b1281522.js';
2
- import { p as pLimit, g as getCoverageProvider, C as CoverageProviderMap } from './chunk-integrations-coverage.cca09977.js';
3
- import { g as getEnvPackageName } from './chunk-env-node.700b7e95.js';
4
- import { A as AggregateErrorPonyfill, s as slash$2, k as relativePath, x as getTests, e as getFullName, q as hasFailed, y as hasFailedSnapshot, z as getSuites, j as notNullish, l as shuffle, t as toArray$1, n as noop$1, B as deepMerge, b as getCallLastIndex, C as ensurePackageInstalled, D as stdout } from './chunk-mock-date.030959d3.js';
1
+ import { b as resolve, p as picocolors, j as join, c as basename, d as dirname, r as relative, e as distDir, f as rootDir, g as isAbsolute, i as isNode, h as configFiles, k as defaultPort, n as normalize, t as toNamespacedPath, E as EXIT_CODE_RESTART } from './chunk-utils-env.03f840f2.js';
2
+ import { p as pLimit, s as someTasksAreOnly, i as interpretTaskModes, g as getCoverageProvider, C as CoverageProviderMap } from './chunk-integrations-coverage.befed097.js';
3
+ import { g as getEnvPackageName } from './chunk-env-node.67948209.js';
4
+ import { T as TYPECHECK_SUITE, x as ensurePackageInstalled, A as AggregateErrorPonyfill, s as slash$2, k as relativePath, y as getTests, e as getFullName, q as hasFailed, z as hasFailedSnapshot, B as getTypecheckTests, C as getSuites, D as isTypecheckTest, j as notNullish, l as shuffle, t as toArray$1, n as noop$1, E as deepMerge, b as getCallLastIndex, F as removeUndefinedValues, G as stdout } from './chunk-typecheck-constants.4891f22f.js';
5
5
  import { loadConfigFromFile, normalizePath, createServer, mergeConfig } from 'vite';
6
6
  import path$a from 'path';
7
7
  import url, { fileURLToPath } from 'url';
@@ -12,24 +12,30 @@ import util$2 from 'util';
12
12
  import require$$0$1 from 'stream';
13
13
  import require$$2 from 'events';
14
14
  import { c as commonjsGlobal } from './vendor-_commonjsHelpers.addc3445.js';
15
- import { c as createBirpc, V as ViteNodeRunner } from './chunk-vite-node-client.3868b3ba.js';
15
+ import { c as createBirpc, V as ViteNodeRunner } from './chunk-vite-node-client.b2ab6dcf.js';
16
16
  import { performance } from 'perf_hooks';
17
17
  import createDebug from 'debug';
18
- import { i as isNodeBuiltin, a as isValidNodeImport, s as slash$1, t as toArray, b as toFilePath, w as withInlineSourcemap } from './chunk-vite-node-utils.2144000e.js';
18
+ import { i as isNodeBuiltin, a as isValidNodeImport, s as slash$1, t as toArray, b as toFilePath, w as withInlineSourcemap } from './chunk-vite-node-utils.8f0b4a12.js';
19
+ import { writeFile, rm } from 'fs/promises';
20
+ import { e as execa } from './vendor-index.737c3cff.js';
21
+ import { SourceMapConsumer } from 'source-map';
22
+ import H from 'module';
23
+ import { parse as parse$4 } from 'acorn';
24
+ import { ancestor } from 'acorn-walk';
19
25
  import { MessageChannel } from 'worker_threads';
20
26
  import { Tinypool } from 'tinypool';
21
- import { c as stripAnsi, d as safeSetInterval, e as safeClearInterval, g as cliTruncate, s as safeSetTimeout, h as stringWidth, i as ansiStyles, j as sliceAnsi, a as stringify$5, u as unifiedDiff, b as safeClearTimeout } from './chunk-utils-timers.8fca243e.js';
22
- import { p as parseStacktrace, i as interpretSourcePos, a as posToNumber, l as lineSplitRE } from './chunk-utils-source-map.663e2952.js';
27
+ import { c as stripAnsi, d as safeSetInterval, e as safeClearInterval, g as cliTruncate, s as safeSetTimeout, h as stringWidth, i as ansiStyles, j as sliceAnsi, a as stringify$5, u as unifiedDiff, b as safeClearTimeout } from './chunk-utils-timers.06f993db.js';
28
+ import { p as parseStacktrace, a as posToNumber, l as lineSplitRE } from './chunk-utils-source-map.c6dfbbc1.js';
23
29
  import { resolveModule } from 'local-pkg';
24
30
  import { createHash } from 'crypto';
25
31
  import { o as onetime } from './vendor-index.9c919048.js';
26
- import { s as signalExit } from './vendor-index.1a291e86.js';
32
+ import { s as signalExit } from './vendor-index.e1d4cf84.js';
27
33
  import MagicString from './chunk-magic-string.ffe2b171.js';
28
34
  import { stripLiteral } from 'strip-literal';
29
35
  import require$$0$2 from 'readline';
30
36
  import { p as prompts } from './vendor-index.9f20a9be.js';
31
37
 
32
- var version$1 = "0.24.5";
38
+ var version$1 = "0.25.1";
33
39
 
34
40
  class EndError extends Error {
35
41
  constructor(value) {
@@ -6969,6 +6975,14 @@ class ViteNodeServer {
6969
6975
  const mode = importer && this.getTransformMode(importer) || "ssr";
6970
6976
  return this.server.pluginContainer.resolveId(id, importer, { ssr: mode === "ssr" });
6971
6977
  }
6978
+ getSourceMap(source) {
6979
+ var _a, _b;
6980
+ const fetchResult = (_a = this.fetchCache.get(source)) == null ? void 0 : _a.result;
6981
+ if (fetchResult == null ? void 0 : fetchResult.map)
6982
+ return fetchResult.map;
6983
+ const ssrTransformResult = (_b = this.server.moduleGraph.getModuleById(source)) == null ? void 0 : _b.ssrTransformResult;
6984
+ return (ssrTransformResult == null ? void 0 : ssrTransformResult.map) || null;
6985
+ }
6972
6986
  async fetchModule(id) {
6973
6987
  if (!this.fetchPromiseMap.has(id)) {
6974
6988
  this.fetchPromiseMap.set(
@@ -7124,6 +7138,416 @@ function addSnapshotResult(summary, result) {
7124
7138
  summary.total += result.added + result.matched + result.unmatched + result.updated;
7125
7139
  }
7126
7140
 
7141
+ function T(r){const t=/^\\\\\?\\/.test(r),n=/[^\u0000-\u0080]+/.test(r);return t||n?r:r.replace(/\\/g,"/")}function B(r,t){for(;;){const n=path$a.join(r,t);if(fs$8.existsSync(n))return T(n);const e=path$a.dirname(r);if(e===r)return;r=e;}}function G(r,t){t===void 0&&(t=!1);var n=r.length,e=0,i="",a=0,o=16,u=0,f=0,d=0,C=0,c=0;function y(s,m){for(var v=0,b=0;v<s||!m;){var h=r.charCodeAt(e);if(h>=48&&h<=57)b=b*16+h-48;else if(h>=65&&h<=70)b=b*16+h-65+10;else if(h>=97&&h<=102)b=b*16+h-97+10;else break;e++,v++;}return v<s&&(b=-1),b}function V(s){e=s,i="",a=0,o=16,c=0;}function $(){var s=e;if(r.charCodeAt(e)===48)e++;else for(e++;e<r.length&&j(r.charCodeAt(e));)e++;if(e<r.length&&r.charCodeAt(e)===46)if(e++,e<r.length&&j(r.charCodeAt(e)))for(e++;e<r.length&&j(r.charCodeAt(e));)e++;else return c=3,r.substring(s,e);var m=e;if(e<r.length&&(r.charCodeAt(e)===69||r.charCodeAt(e)===101))if(e++,(e<r.length&&r.charCodeAt(e)===43||r.charCodeAt(e)===45)&&e++,e<r.length&&j(r.charCodeAt(e))){for(e++;e<r.length&&j(r.charCodeAt(e));)e++;m=e;}else c=3;return r.substring(s,m)}function _(){for(var s="",m=e;;){if(e>=n){s+=r.substring(m,e),c=2;break}var v=r.charCodeAt(e);if(v===34){s+=r.substring(m,e),e++;break}if(v===92){if(s+=r.substring(m,e),e++,e>=n){c=2;break}var b=r.charCodeAt(e++);switch(b){case 34:s+='"';break;case 92:s+="\\";break;case 47:s+="/";break;case 98:s+="\b";break;case 102:s+="\f";break;case 110:s+=`
7142
+ `;break;case 114:s+="\r";break;case 116:s+=" ";break;case 117:var h=y(4,!0);h>=0?s+=String.fromCharCode(h):c=4;break;default:c=5;}m=e;continue}if(v>=0&&v<=31)if(P(v)){s+=r.substring(m,e),c=2;break}else c=6;e++;}return s}function S(){if(i="",c=0,a=e,f=u,C=d,e>=n)return a=n,o=17;var s=r.charCodeAt(e);if(U(s)){do e++,i+=String.fromCharCode(s),s=r.charCodeAt(e);while(U(s));return o=15}if(P(s))return e++,i+=String.fromCharCode(s),s===13&&r.charCodeAt(e)===10&&(e++,i+=`
7143
+ `),u++,d=e,o=14;switch(s){case 123:return e++,o=1;case 125:return e++,o=2;case 91:return e++,o=3;case 93:return e++,o=4;case 58:return e++,o=6;case 44:return e++,o=5;case 34:return e++,i=_(),o=10;case 47:var m=e-1;if(r.charCodeAt(e+1)===47){for(e+=2;e<n&&!P(r.charCodeAt(e));)e++;return i=r.substring(m,e),o=12}if(r.charCodeAt(e+1)===42){e+=2;for(var v=n-1,b=!1;e<v;){var h=r.charCodeAt(e);if(h===42&&r.charCodeAt(e+1)===47){e+=2,b=!0;break}e++,P(h)&&(h===13&&r.charCodeAt(e)===10&&e++,u++,d=e);}return b||(e++,c=1),i=r.substring(m,e),o=13}return i+=String.fromCharCode(s),e++,o=16;case 45:if(i+=String.fromCharCode(s),e++,e===n||!j(r.charCodeAt(e)))return o=16;case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return i+=$(),o=11;default:for(;e<n&&k(s);)e++,s=r.charCodeAt(e);if(a!==e){switch(i=r.substring(a,e),i){case"true":return o=8;case"false":return o=9;case"null":return o=7}return o=16}return i+=String.fromCharCode(s),e++,o=16}}function k(s){if(U(s)||P(s))return !1;switch(s){case 125:case 93:case 123:case 91:case 34:case 58:case 44:case 47:return !1}return !0}function l(){var s;do s=S();while(s>=12&&s<=15);return s}return {setPosition:V,getPosition:function(){return e},scan:t?l:S,getToken:function(){return o},getTokenValue:function(){return i},getTokenOffset:function(){return a},getTokenLength:function(){return e-a},getTokenStartLine:function(){return f},getTokenStartCharacter:function(){return a-C},getTokenError:function(){return c}}}function U(r){return r===32||r===9||r===11||r===12||r===160||r===5760||r>=8192&&r<=8203||r===8239||r===8287||r===12288||r===65279}function P(r){return r===10||r===13||r===8232||r===8233}function j(r){return r>=48&&r<=57}var N;(function(r){r.DEFAULT={allowTrailingComma:!1};})(N||(N={}));function K(r,t,n){t===void 0&&(t=[]),n===void 0&&(n=N.DEFAULT);var e=null,i=[],a=[];function o(f){Array.isArray(i)?i.push(f):e!==null&&(i[e]=f);}var u={onObjectBegin:function(){var f={};o(f),a.push(i),i=f,e=null;},onObjectProperty:function(f){e=f;},onObjectEnd:function(){i=a.pop();},onArrayBegin:function(){var f=[];o(f),a.push(i),i=f,e=null;},onArrayEnd:function(){i=a.pop();},onLiteralValue:o,onError:function(f,d,C){t.push({error:f,offset:d,length:C});}};return Q(r,u,n),i[0]}function Q(r,t,n){n===void 0&&(n=N.DEFAULT);var e=G(r,!1);function i(p){return p?function(){return p(e.getTokenOffset(),e.getTokenLength(),e.getTokenStartLine(),e.getTokenStartCharacter())}:function(){return !0}}function a(p){return p?function(w){return p(w,e.getTokenOffset(),e.getTokenLength(),e.getTokenStartLine(),e.getTokenStartCharacter())}:function(){return !0}}var o=i(t.onObjectBegin),u=a(t.onObjectProperty),f=i(t.onObjectEnd),d=i(t.onArrayBegin),C=i(t.onArrayEnd),c=a(t.onLiteralValue),y=a(t.onSeparator),V=i(t.onComment),$=a(t.onError),_=n&&n.disallowComments,S=n&&n.allowTrailingComma;function k(){for(;;){var p=e.scan();switch(e.getTokenError()){case 4:l(14);break;case 5:l(15);break;case 3:l(13);break;case 1:_||l(11);break;case 2:l(12);break;case 6:l(16);break}switch(p){case 12:case 13:_?l(10):V();break;case 16:l(1);break;case 15:case 14:break;default:return p}}}function l(p,w,L){if(w===void 0&&(w=[]),L===void 0&&(L=[]),$(p),w.length+L.length>0)for(var D=e.getToken();D!==17;){if(w.indexOf(D)!==-1){k();break}else if(L.indexOf(D)!==-1)break;D=k();}}function s(p){var w=e.getTokenValue();return p?c(w):u(w),k(),!0}function m(){switch(e.getToken()){case 11:var p=e.getTokenValue(),w=Number(p);isNaN(w)&&(l(2),w=0),c(w);break;case 7:c(null);break;case 8:c(!0);break;case 9:c(!1);break;default:return !1}return k(),!0}function v(){return e.getToken()!==10?(l(3,[],[2,5]),!1):(s(!1),e.getToken()===6?(y(":"),k(),F()||l(4,[],[2,5])):l(5,[],[2,5]),!0)}function b(){o(),k();for(var p=!1;e.getToken()!==2&&e.getToken()!==17;){if(e.getToken()===5){if(p||l(4,[],[]),y(","),k(),e.getToken()===2&&S)break}else p&&l(6,[],[]);v()||l(4,[],[2,5]),p=!0;}return f(),e.getToken()!==2?l(7,[2],[]):k(),!0}function h(){d(),k();for(var p=!1;e.getToken()!==4&&e.getToken()!==17;){if(e.getToken()===5){if(p||l(4,[],[]),y(","),k(),e.getToken()===4&&S)break}else p&&l(6,[],[]);F()||l(4,[],[4,5]),p=!0;}return C(),e.getToken()!==4?l(8,[4],[]):k(),!0}function F(){switch(e.getToken()){case 3:return h();case 1:return b();case 10:return s(!0);default:return m()}}return k(),e.getToken()===17?n.allowEmptyContent?!0:(l(4,[],[]),!1):F()?(e.getToken()!==17&&l(9,[],[]),!0):(l(4,[],[]),!1)}var X=K;const W=/^\.{1,2}(\/.*)?$/,J=r=>T(W.test(r)?r:`./${r}`),{existsSync:E}=fs$8,Y=r=>{try{return JSON.parse(r)}catch{}},Z=()=>{const{findPnpApi:r}=H;return r&&r(process.cwd())};function I(r){const t=Y(fs$8.readFileSync(r,"utf8"));return path$a.join(r,"..",t&&"tsconfig"in t?t.tsconfig:"tsconfig.json")}function x(r,t){let n=r;if(n===".."&&(n+="/tsconfig.json"),n.startsWith(".")){let a=path$a.resolve(t,n);if(E(a)&&fs$8.statSync(a).isFile()||!a.endsWith(".json")&&(a+=".json",E(a)))return a;throw new Error(`File '${r}' not found.`)}const e=Z();if(e){const{resolveRequest:a}=e,[o,u]=r.split("/"),f=o.startsWith("@")?`${o}/${u}`:o;try{if(f===r){const d=a(path$a.join(f,"package.json"),t);if(d){const C=I(d);if(E(C))return C}}else try{return a(r,t,{extensions:[".json"]})}catch{return a(path$a.join(r,"tsconfig.json"),t)}}catch{}}let i=B(t,path$a.join("node_modules",n));if(i){if(fs$8.statSync(i).isDirectory()){const a=path$a.join(i,"package.json");if(E(a)?i=I(a):i=path$a.join(i,"tsconfig.json"),E(i))return i}else if(i.endsWith(".json"))return i}if(!n.endsWith(".json")&&(n+=".json",i=B(t,path$a.join("node_modules",n)),i))return i;throw new Error(`File '${r}' not found.`)}var ee=Object.defineProperty,re=Object.defineProperties,ne=Object.getOwnPropertyDescriptors,R=Object.getOwnPropertySymbols,te=Object.prototype.hasOwnProperty,ae=Object.prototype.propertyIsEnumerable,q=(r,t,n)=>t in r?ee(r,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[t]=n,A=(r,t)=>{for(var n in t||(t={}))te.call(t,n)&&q(r,n,t[n]);if(R)for(var n of R(t))ae.call(t,n)&&q(r,n,t[n]);return r},oe=(r,t)=>re(r,ne(t));function M(r){var t;let n;try{n=fs$8.realpathSync(r);}catch{throw new Error(`Cannot resolve tsconfig at path: ${r}`)}const e=path$a.dirname(n),i=fs$8.readFileSync(n,"utf8").trim();let a={};if(i&&(a=X(i),!a||typeof a!="object"))throw new SyntaxError(`Failed to parse tsconfig at: ${r}`);if(a.extends){const o=x(a.extends,e),u=M(o);if(delete u.references,(t=u.compilerOptions)!=null&&t.baseUrl){const{compilerOptions:d}=u;d.baseUrl=path$a.relative(e,path$a.join(path$a.dirname(o),d.baseUrl))||"./";}u.files&&(u.files=u.files.map(d=>path$a.relative(e,path$a.join(path$a.dirname(o),d)))),u.include&&(u.include=u.include.map(d=>path$a.relative(e,path$a.join(path$a.dirname(o),d)))),delete a.extends;const f=oe(A(A({},u),a),{compilerOptions:A(A({},u.compilerOptions),a.compilerOptions)});u.watchOptions&&(f.watchOptions=A(A({},u.watchOptions),a.watchOptions)),a=f;}if(a.compilerOptions){const{compilerOptions:o}=a;o.baseUrl&&(o.baseUrl=J(o.baseUrl)),o.outDir&&(Array.isArray(a.exclude)||(a.exclude=[]),a.exclude.push(o.outDir),o.outDir=J(o.outDir));}if(a.files&&(a.files=a.files.map(J)),a.include&&(a.include=a.include.map(T)),a.watchOptions){const{watchOptions:o}=a;o.excludeDirectories&&(o.excludeDirectories=o.excludeDirectories.map(u=>T(path$a.resolve(e,u))));}return a}function ie(r=process.cwd(),t="tsconfig.json"){const n=B(r,t);if(!n)return null;const e=M(n);return {path:n,config:e}}
7144
+
7145
+ const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
7146
+ const newLineRegExp = /\r?\n/;
7147
+ const errCodeRegExp = /error TS(?<errCode>\d+)/;
7148
+ async function makeTscErrorInfo(errInfo) {
7149
+ var _a;
7150
+ const [errFilePathPos = "", ...errMsgRawArr] = errInfo.split(":");
7151
+ if (!errFilePathPos || errMsgRawArr.length === 0 || errMsgRawArr.join("").length === 0)
7152
+ return ["unknown filepath", null];
7153
+ const errMsgRaw = errMsgRawArr.join("").trim();
7154
+ const [errFilePath, errPos] = errFilePathPos.slice(0, -1).split("(");
7155
+ if (!errFilePath || !errPos)
7156
+ return ["unknown filepath", null];
7157
+ const [errLine, errCol] = errPos.split(",");
7158
+ if (!errLine || !errCol)
7159
+ return [errFilePath, null];
7160
+ const execArr = errCodeRegExp.exec(errMsgRaw);
7161
+ if (!execArr)
7162
+ return [errFilePath, null];
7163
+ const errCodeStr = ((_a = execArr.groups) == null ? void 0 : _a.errCode) ?? "";
7164
+ if (!errCodeStr)
7165
+ return [errFilePath, null];
7166
+ const line = Number(errLine);
7167
+ const col = Number(errCol);
7168
+ const errCode = Number(errCodeStr);
7169
+ return [
7170
+ errFilePath,
7171
+ {
7172
+ filePath: errFilePath,
7173
+ errCode,
7174
+ line,
7175
+ column: col,
7176
+ errMsg: errMsgRaw.slice(`error TS${errCode} `.length)
7177
+ }
7178
+ ];
7179
+ }
7180
+ async function getTsconfigPath(root, config) {
7181
+ var _a;
7182
+ const tempConfigPath = path$a.join(root, "tsconfig.temp.json");
7183
+ const configName = ((_a = config.tsconfig) == null ? void 0 : _a.includes("jsconfig.json")) ? "jsconfig.json" : void 0;
7184
+ const tsconfig = ie(config.tsconfig || root, configName);
7185
+ if (!tsconfig)
7186
+ throw new Error("no tsconfig.json found");
7187
+ try {
7188
+ const tmpTsConfig = { ...tsconfig.config };
7189
+ tmpTsConfig.compilerOptions ?? (tmpTsConfig.compilerOptions = {});
7190
+ tmpTsConfig.compilerOptions.emitDeclarationOnly = false;
7191
+ tmpTsConfig.compilerOptions.incremental = true;
7192
+ tmpTsConfig.compilerOptions.tsBuildInfoFile = path$a.join(
7193
+ __dirname,
7194
+ "tsconfig.tmp.tsbuildinfo"
7195
+ );
7196
+ const tsconfigFinalContent = JSON.stringify(tmpTsConfig, null, 2);
7197
+ await writeFile(tempConfigPath, tsconfigFinalContent);
7198
+ return tempConfigPath;
7199
+ } catch (err) {
7200
+ throw new Error("failed to write tsconfig.temp.json", { cause: err });
7201
+ }
7202
+ }
7203
+ async function getRawErrsMapFromTsCompile(tscErrorStdout) {
7204
+ const rawErrsMap = /* @__PURE__ */ new Map();
7205
+ const infos = await Promise.all(
7206
+ tscErrorStdout.split(newLineRegExp).reduce((prev, next) => {
7207
+ if (!next)
7208
+ return prev;
7209
+ else if (!next.startsWith(" "))
7210
+ prev.push(next);
7211
+ else
7212
+ prev[prev.length - 1] += `
7213
+ ${next}`;
7214
+ return prev;
7215
+ }, []).map((errInfoLine) => makeTscErrorInfo(errInfoLine))
7216
+ );
7217
+ infos.forEach(([errFilePath, errInfo]) => {
7218
+ var _a;
7219
+ if (!errInfo)
7220
+ return;
7221
+ if (!rawErrsMap.has(errFilePath))
7222
+ rawErrsMap.set(errFilePath, [errInfo]);
7223
+ else
7224
+ (_a = rawErrsMap.get(errFilePath)) == null ? void 0 : _a.push(errInfo);
7225
+ });
7226
+ return rawErrsMap;
7227
+ }
7228
+
7229
+ const createIndexMap = (source) => {
7230
+ const map = /* @__PURE__ */ new Map();
7231
+ let index = 0;
7232
+ let line = 1;
7233
+ let column = 1;
7234
+ for (const char of source) {
7235
+ map.set(`${line}:${column}`, index++);
7236
+ if (char === "\n" || char === "\r\n") {
7237
+ line++;
7238
+ column = 0;
7239
+ } else {
7240
+ column++;
7241
+ }
7242
+ }
7243
+ return map;
7244
+ };
7245
+
7246
+ async function collectTests(ctx, filepath) {
7247
+ const request = await ctx.vitenode.transformRequest(filepath);
7248
+ if (!request)
7249
+ return null;
7250
+ const ast = parse$4(request.code, {
7251
+ ecmaVersion: "latest",
7252
+ allowAwaitOutsideFunction: true
7253
+ });
7254
+ const file = {
7255
+ filepath,
7256
+ type: "suite",
7257
+ id: "-1",
7258
+ name: relative(ctx.config.root, filepath),
7259
+ mode: "run",
7260
+ tasks: [],
7261
+ start: ast.start,
7262
+ end: ast.end,
7263
+ result: {
7264
+ state: "pass"
7265
+ }
7266
+ };
7267
+ const definitions = [];
7268
+ const getName = (callee) => {
7269
+ var _a, _b, _c;
7270
+ if (!callee)
7271
+ return null;
7272
+ if (callee.type === "Identifier")
7273
+ return callee.name;
7274
+ if (callee.type === "MemberExpression") {
7275
+ if ((_b = (_a = callee.object) == null ? void 0 : _a.name) == null ? void 0 : _b.startsWith("__vite_ssr_"))
7276
+ return getName(callee.property);
7277
+ return getName((_c = callee.object) == null ? void 0 : _c.property);
7278
+ }
7279
+ return null;
7280
+ };
7281
+ ancestor(ast, {
7282
+ CallExpression(node) {
7283
+ var _a;
7284
+ const { callee } = node;
7285
+ const name = getName(callee);
7286
+ if (!name)
7287
+ return;
7288
+ if (!["it", "test", "describe", "suite"].includes(name))
7289
+ return;
7290
+ const { arguments: [{ value: message }] } = node;
7291
+ const property = (_a = callee == null ? void 0 : callee.property) == null ? void 0 : _a.name;
7292
+ const mode = !property || property === name ? "run" : property;
7293
+ if (!["run", "skip", "todo", "only"].includes(mode))
7294
+ throw new Error(`${name}.${mode} syntax is not supported when testing types`);
7295
+ definitions.push({
7296
+ start: node.start,
7297
+ end: node.end,
7298
+ name: message,
7299
+ type: name,
7300
+ mode
7301
+ });
7302
+ }
7303
+ });
7304
+ let lastSuite = file;
7305
+ const updateLatestSuite = (index) => {
7306
+ const suite = lastSuite;
7307
+ while (lastSuite !== file && lastSuite.end < index)
7308
+ lastSuite = suite.suite;
7309
+ return lastSuite;
7310
+ };
7311
+ definitions.sort((a, b) => a.start - b.start).forEach((definition, idx) => {
7312
+ const latestSuite = updateLatestSuite(definition.start);
7313
+ let mode = definition.mode;
7314
+ if (latestSuite.mode !== "run")
7315
+ mode = latestSuite.mode;
7316
+ const state = mode === "run" ? "pass" : mode;
7317
+ const task = {
7318
+ type: "suite",
7319
+ id: idx.toString(),
7320
+ suite: latestSuite,
7321
+ file,
7322
+ tasks: [],
7323
+ mode,
7324
+ name: definition.name,
7325
+ end: definition.end,
7326
+ start: definition.start,
7327
+ result: {
7328
+ state
7329
+ }
7330
+ };
7331
+ definition.task = task;
7332
+ latestSuite.tasks.push(task);
7333
+ if (definition.type === "describe" || definition.type === "suite")
7334
+ lastSuite = task;
7335
+ else
7336
+ Object.defineProperty(task, TYPECHECK_SUITE, { value: true });
7337
+ });
7338
+ const hasOnly = someTasksAreOnly(file);
7339
+ interpretTaskModes(file, ctx.config.testNamePattern, hasOnly, false, ctx.config.allowOnly);
7340
+ return {
7341
+ file,
7342
+ parsed: request.code,
7343
+ filepath,
7344
+ map: request.map,
7345
+ definitions
7346
+ };
7347
+ }
7348
+
7349
+ class TypeCheckError extends Error {
7350
+ constructor(message, stacks) {
7351
+ super(message);
7352
+ this.message = message;
7353
+ this.stacks = stacks;
7354
+ this.name = "TypeCheckError";
7355
+ }
7356
+ }
7357
+ class Typechecker {
7358
+ constructor(ctx, files) {
7359
+ this.ctx = ctx;
7360
+ this.files = files;
7361
+ this._result = {
7362
+ files: [],
7363
+ sourceErrors: []
7364
+ };
7365
+ this._tests = {};
7366
+ }
7367
+ onParseStart(fn) {
7368
+ this._onParseStart = fn;
7369
+ }
7370
+ onParseEnd(fn) {
7371
+ this._onParseEnd = fn;
7372
+ }
7373
+ onWatcherRerun(fn) {
7374
+ this._onWatcherRerun = fn;
7375
+ }
7376
+ async collectFileTests(filepath) {
7377
+ return collectTests(this.ctx, filepath);
7378
+ }
7379
+ async collectTests() {
7380
+ const tests = (await Promise.all(
7381
+ this.files.map((filepath) => this.collectFileTests(filepath))
7382
+ )).reduce((acc, data) => {
7383
+ if (!data)
7384
+ return acc;
7385
+ acc[data.filepath] = data;
7386
+ return acc;
7387
+ }, {});
7388
+ this._tests = tests;
7389
+ return tests;
7390
+ }
7391
+ async prepareResults(output) {
7392
+ const typeErrors = await this.parseTscLikeOutput(output);
7393
+ const testFiles = new Set(this.files);
7394
+ if (!this._tests)
7395
+ this._tests = await this.collectTests();
7396
+ const sourceErrors = [];
7397
+ const files = [];
7398
+ testFiles.forEach((path) => {
7399
+ const { file, definitions, map, parsed } = this._tests[path];
7400
+ const errors = typeErrors.get(path);
7401
+ files.push(file);
7402
+ if (!errors)
7403
+ return;
7404
+ const sortedDefinitions = [...definitions.sort((a, b) => b.start - a.start)];
7405
+ const mapConsumer = map && new SourceMapConsumer(map);
7406
+ const indexMap = createIndexMap(parsed);
7407
+ const markFailed = (task) => {
7408
+ task.result = {
7409
+ state: task.mode === "run" || task.mode === "only" ? "fail" : task.mode
7410
+ };
7411
+ if (task.suite)
7412
+ markFailed(task.suite);
7413
+ };
7414
+ errors.forEach(({ error, originalError }, idx) => {
7415
+ const originalPos = (mapConsumer == null ? void 0 : mapConsumer.generatedPositionFor({
7416
+ line: originalError.line,
7417
+ column: originalError.column,
7418
+ source: path
7419
+ })) || originalError;
7420
+ const index = indexMap.get(`${originalPos.line}:${originalPos.column}`);
7421
+ const definition = index != null && sortedDefinitions.find((def) => def.start <= index && def.end >= index) || file;
7422
+ const suite = "task" in definition ? definition.task : definition;
7423
+ const state = suite.mode === "run" || suite.mode === "only" ? "fail" : suite.mode;
7424
+ const task = {
7425
+ type: "typecheck",
7426
+ id: idx.toString(),
7427
+ name: `error expect ${idx + 1}`,
7428
+ mode: suite.mode,
7429
+ file,
7430
+ suite,
7431
+ result: {
7432
+ state,
7433
+ error: state === "fail" ? error : void 0
7434
+ }
7435
+ };
7436
+ if (state === "fail")
7437
+ markFailed(suite);
7438
+ suite.tasks.push(task);
7439
+ });
7440
+ });
7441
+ typeErrors.forEach((errors, path) => {
7442
+ if (!testFiles.has(path))
7443
+ sourceErrors.push(...errors.map(({ error }) => error));
7444
+ });
7445
+ return {
7446
+ files,
7447
+ sourceErrors
7448
+ };
7449
+ }
7450
+ async parseTscLikeOutput(output) {
7451
+ const errorsMap = await getRawErrsMapFromTsCompile(output);
7452
+ const typesErrors = /* @__PURE__ */ new Map();
7453
+ errorsMap.forEach((errors, path) => {
7454
+ const filepath = resolve(this.ctx.config.root, path);
7455
+ const suiteErrors = errors.map((info) => {
7456
+ const limit = Error.stackTraceLimit;
7457
+ Error.stackTraceLimit = 0;
7458
+ const error = new TypeCheckError(info.errMsg, [
7459
+ {
7460
+ file: filepath,
7461
+ line: info.line,
7462
+ column: info.column,
7463
+ method: "",
7464
+ sourcePos: {
7465
+ line: info.line,
7466
+ column: info.column
7467
+ }
7468
+ }
7469
+ ]);
7470
+ Error.stackTraceLimit = limit;
7471
+ return {
7472
+ originalError: info,
7473
+ error
7474
+ };
7475
+ });
7476
+ typesErrors.set(filepath, suiteErrors);
7477
+ });
7478
+ return typesErrors;
7479
+ }
7480
+ async clear() {
7481
+ if (this.tempConfigPath)
7482
+ await rm(this.tempConfigPath, { force: true });
7483
+ }
7484
+ async stop() {
7485
+ var _a;
7486
+ await this.clear();
7487
+ (_a = this.process) == null ? void 0 : _a.kill();
7488
+ }
7489
+ async ensurePackageInstalled(root, checker) {
7490
+ if (checker !== "tsc" && checker !== "vue-tsc")
7491
+ return;
7492
+ const packageName = checker === "tsc" ? "typescript" : "vue-tsc";
7493
+ await ensurePackageInstalled(packageName, root);
7494
+ }
7495
+ async start() {
7496
+ var _a, _b, _c;
7497
+ const { root, watch, typecheck } = this.ctx.config;
7498
+ await this.ensurePackageInstalled(root, typecheck.checker);
7499
+ this.tempConfigPath = await getTsconfigPath(root, typecheck);
7500
+ const args = ["--noEmit", "--pretty", "false", "-p", this.tempConfigPath];
7501
+ if (watch)
7502
+ args.push("--watch");
7503
+ if (typecheck.allowJs)
7504
+ args.push("--allowJs", "--checkJs");
7505
+ let output = "";
7506
+ const child = execa(typecheck.checker, args, {
7507
+ cwd: root,
7508
+ stdout: "pipe",
7509
+ reject: false
7510
+ });
7511
+ this.process = child;
7512
+ await ((_a = this._onParseStart) == null ? void 0 : _a.call(this));
7513
+ let rerunTriggered = false;
7514
+ (_b = child.stdout) == null ? void 0 : _b.on("data", (chunk) => {
7515
+ var _a2;
7516
+ output += chunk;
7517
+ if (!watch)
7518
+ return;
7519
+ if (output.includes("File change detected") && !rerunTriggered) {
7520
+ (_a2 = this._onWatcherRerun) == null ? void 0 : _a2.call(this);
7521
+ this._result.sourceErrors = [];
7522
+ this._result.files = [];
7523
+ this._tests = null;
7524
+ rerunTriggered = true;
7525
+ }
7526
+ if (/Found \w+ errors*. Watching for/.test(output)) {
7527
+ rerunTriggered = false;
7528
+ this.prepareResults(output).then((result) => {
7529
+ var _a3;
7530
+ this._result = result;
7531
+ (_a3 = this._onParseEnd) == null ? void 0 : _a3.call(this, result);
7532
+ });
7533
+ output = "";
7534
+ }
7535
+ });
7536
+ if (!watch) {
7537
+ await child;
7538
+ this._result = await this.prepareResults(output);
7539
+ await ((_c = this._onParseEnd) == null ? void 0 : _c.call(this, this._result));
7540
+ await this.clear();
7541
+ }
7542
+ }
7543
+ getResult() {
7544
+ return this._result;
7545
+ }
7546
+ getTestFiles() {
7547
+ return Object.values(this._tests || {}).map((i) => i.file);
7548
+ }
7549
+ }
7550
+
7127
7551
  const workerPath = url.pathToFileURL(resolve(distDir, "./worker.js")).href;
7128
7552
  const loaderPath = url.pathToFileURL(resolve(distDir, "./loader.js")).href;
7129
7553
  const suppressLoaderWarningsPath = resolve(rootDir, "./suppress-warnings.cjs");
@@ -7132,7 +7556,7 @@ function createPool(ctx) {
7132
7556
  const threadsCount = ctx.config.watch ? Math.max(Math.floor(cpus().length / 2), 1) : Math.max(cpus().length - 1, 1);
7133
7557
  const maxThreads = ctx.config.maxThreads ?? threadsCount;
7134
7558
  const minThreads = ctx.config.minThreads ?? threadsCount;
7135
- const conditions = ((_a = ctx.server.config.resolve.conditions) == null ? void 0 : _a.flatMap((c) => ["-C", c])) || [];
7559
+ const conditions = ((_a = ctx.server.config.resolve.conditions) == null ? void 0 : _a.flatMap((c) => ["--conditions", c])) || [];
7136
7560
  const options = {
7137
7561
  filename: workerPath,
7138
7562
  useAtomics: false,
@@ -7355,7 +7779,7 @@ function renderSnapshotSummary(rootDir, snapshots) {
7355
7779
  }
7356
7780
  return summary;
7357
7781
  }
7358
- function getStateString(tasks, name = "tests") {
7782
+ function getStateString(tasks, name = "tests", showTotal = true) {
7359
7783
  if (tasks.length === 0)
7360
7784
  return picocolors.exports.dim(`no ${name}`);
7361
7785
  const passed = tasks.filter((i) => {
@@ -7373,7 +7797,7 @@ function getStateString(tasks, name = "tests") {
7373
7797
  passed.length ? picocolors.exports.bold(picocolors.exports.green(`${passed.length} passed`)) : null,
7374
7798
  skipped2.length ? picocolors.exports.yellow(`${skipped2.length} skipped`) : null,
7375
7799
  todo.length ? picocolors.exports.gray(`${todo.length} todo`) : null
7376
- ].filter(Boolean).join(picocolors.exports.dim(" | ")) + picocolors.exports.gray(` (${tasks.length})`);
7800
+ ].filter(Boolean).join(picocolors.exports.dim(" | ")) + (showTotal ? picocolors.exports.gray(` (${tasks.length})`) : "");
7377
7801
  }
7378
7802
  function getStateSymbol(task) {
7379
7803
  if (task.mode === "skip" || task.mode === "todo")
@@ -7436,7 +7860,7 @@ const WAIT_FOR_CHANGE_PASS = `
7436
7860
  ${picocolors.exports.bold(picocolors.exports.inverse(picocolors.exports.green(" PASS ")))}${picocolors.exports.green(" Waiting for file changes...")}`;
7437
7861
  const WAIT_FOR_CHANGE_FAIL = `
7438
7862
  ${picocolors.exports.bold(picocolors.exports.inverse(picocolors.exports.red(" FAIL ")))}${picocolors.exports.red(" Tests failed. Watching for file changes...")}`;
7439
- const DURATION_LONG$1 = 300;
7863
+ const DURATION_LONG$2 = 300;
7440
7864
  const LAST_RUN_LOG_TIMEOUT = 1500;
7441
7865
  class BaseReporter {
7442
7866
  constructor() {
@@ -7467,7 +7891,7 @@ class BaseReporter {
7467
7891
  if (errors.length) {
7468
7892
  if (!this.ctx.config.dangerouslyIgnoreUnhandledErrors)
7469
7893
  process.exitCode = 1;
7470
- this.ctx.logger.printUnhandledErrors(errors);
7894
+ await this.ctx.logger.printUnhandledErrors(errors);
7471
7895
  }
7472
7896
  }
7473
7897
  onTaskUpdate(packs) {
@@ -7491,7 +7915,7 @@ class BaseReporter {
7491
7915
  state += ` ${picocolors.exports.dim("|")} ${picocolors.exports.yellow(`${skipped.length} skipped`)}`;
7492
7916
  let suffix = picocolors.exports.dim(" (") + state + picocolors.exports.dim(")");
7493
7917
  if (task.result.duration) {
7494
- const color = task.result.duration > DURATION_LONG$1 ? picocolors.exports.yellow : picocolors.exports.gray;
7918
+ const color = task.result.duration > DURATION_LONG$2 ? picocolors.exports.yellow : picocolors.exports.gray;
7495
7919
  suffix += color(` ${Math.round(task.result.duration)}${picocolors.exports.dim("ms")}`);
7496
7920
  }
7497
7921
  if (this.ctx.config.logHeapUsage && task.result.heap != null)
@@ -7504,17 +7928,17 @@ class BaseReporter {
7504
7928
  }
7505
7929
  }
7506
7930
  }
7507
- async onWatcherStart() {
7931
+ async onWatcherStart(files = this.ctx.state.getFiles(), errors = this.ctx.state.getUnhandledErrors()) {
7508
7932
  this.resetLastRunLog();
7509
- const files = this.ctx.state.getFiles();
7510
- const errors = this.ctx.state.getUnhandledErrors();
7511
7933
  const failed = errors.length > 0 || hasFailed(files);
7512
7934
  const failedSnap = hasFailedSnapshot(files);
7513
7935
  if (failed)
7514
7936
  this.ctx.logger.log(WAIT_FOR_CHANGE_FAIL);
7515
7937
  else
7516
7938
  this.ctx.logger.log(WAIT_FOR_CHANGE_PASS);
7517
- const hints = [HELP_HINT];
7939
+ const hints = [];
7940
+ if (this.mode !== "typecheck")
7941
+ hints.push(HELP_HINT);
7518
7942
  if (failedSnap)
7519
7943
  hints.unshift(HELP_UPDATE_SNAP);
7520
7944
  else
@@ -7556,14 +7980,14 @@ class BaseReporter {
7556
7980
  const BADGE = picocolors.exports.inverse(picocolors.exports.bold(picocolors.exports.blue(" RERUN ")));
7557
7981
  const TRIGGER = trigger ? picocolors.exports.dim(` ${this.relative(trigger)}`) : "";
7558
7982
  if (files.length > 1) {
7559
- this.ctx.logger.clearScreen(`
7983
+ this.ctx.logger.clearFullScreen(`
7560
7984
  ${BADGE}${TRIGGER}
7561
- `, true);
7985
+ `);
7562
7986
  this._lastRunCount = 0;
7563
7987
  } else if (files.length === 1) {
7564
7988
  const rerun = this._filesInWatchMode.get(files[0]) ?? 1;
7565
7989
  this._lastRunCount = rerun;
7566
- this.ctx.logger.clearScreen(`
7990
+ this.ctx.logger.clearFullScreen(`
7567
7991
  ${BADGE}${TRIGGER} ${picocolors.exports.blue(`x${rerun}`)}
7568
7992
  `);
7569
7993
  }
@@ -7600,7 +8024,7 @@ ${BADGE}${TRIGGER} ${picocolors.exports.blue(`x${rerun}`)}
7600
8024
  await this.reportTestSummary(files);
7601
8025
  }
7602
8026
  async reportTestSummary(files) {
7603
- const tests = getTests(files);
8027
+ const tests = this.mode === "typecheck" ? getTypecheckTests(files) : getTests(files);
7604
8028
  const logger = this.ctx.logger;
7605
8029
  const executionTime = this.end - this.start;
7606
8030
  const collectTime = files.reduce((acc, test) => acc + Math.max(0, test.collectDuration || 0), 0);
@@ -7611,7 +8035,7 @@ ${BADGE}${TRIGGER} ${picocolors.exports.blue(`x${rerun}`)}
7611
8035
  }, 0);
7612
8036
  const transformTime = Array.from(this.ctx.vitenode.fetchCache.values()).reduce((a, b) => a + ((b == null ? void 0 : b.duration) || 0), 0);
7613
8037
  const threadTime = collectTime + testsTime + setupTime;
7614
- const padTitle = (str) => picocolors.exports.dim(`${str.padStart(10)} `);
8038
+ const padTitle = (str) => picocolors.exports.dim(`${str.padStart(11)} `);
7615
8039
  const time = (time2) => {
7616
8040
  if (time2 > 1e3)
7617
8041
  return `${(time2 / 1e3).toFixed(2)}s`;
@@ -7627,9 +8051,15 @@ ${BADGE}${TRIGGER} ${picocolors.exports.blue(`x${rerun}`)}
7627
8051
  }
7628
8052
  logger.log(padTitle("Test Files"), getStateString(files));
7629
8053
  logger.log(padTitle("Tests"), getStateString(tests));
8054
+ if (this.mode === "typecheck") {
8055
+ const typechecks = getTests(files).filter((t) => t.type === "typecheck");
8056
+ logger.log(padTitle("Type Errors"), getStateString(typechecks, "errors", false));
8057
+ }
7630
8058
  logger.log(padTitle("Start at"), formatTimeString(this._timeStart));
7631
8059
  if (this.watchFilters)
7632
8060
  logger.log(padTitle("Duration"), time(threadTime));
8061
+ else if (this.mode === "typecheck")
8062
+ logger.log(padTitle("Duration"), time(executionTime));
7633
8063
  else
7634
8064
  logger.log(padTitle("Duration"), time(executionTime) + picocolors.exports.dim(` (transform ${time(transformTime)}, setup ${time(setupTime)}, collect ${time(collectTime)}, tests ${time(testsTime)})`));
7635
8065
  logger.log();
@@ -7656,7 +8086,8 @@ ${BADGE}${TRIGGER} ${picocolors.exports.blue(`x${rerun}`)}
7656
8086
  await this.printTaskErrors(failedSuites, errorDivider);
7657
8087
  }
7658
8088
  if (failedTests.length) {
7659
- logger.error(picocolors.exports.red(divider(picocolors.exports.bold(picocolors.exports.inverse(` Failed Tests ${failedTests.length} `)))));
8089
+ const message = this.mode === "typecheck" ? "Type Errors" : "Failed Tests";
8090
+ logger.error(picocolors.exports.red(divider(picocolors.exports.bold(picocolors.exports.inverse(` ${message} ${failedTests.length} `)))));
7660
8091
  logger.error();
7661
8092
  await this.printTaskErrors(failedTests, errorDivider);
7662
8093
  }
@@ -7674,6 +8105,8 @@ ${picocolors.exports.cyan(picocolors.exports.inverse(picocolors.exports.bold(" B
7674
8105
  `);
7675
8106
  for (const bench of topBenchs) {
7676
8107
  const group = bench.suite;
8108
+ if (!group)
8109
+ continue;
7677
8110
  const groupName = getFullName(group);
7678
8111
  logger.log(` ${bench.name}${picocolors.exports.dim(` - ${groupName}`)}`);
7679
8112
  const siblings = group.tasks.filter((i) => {
@@ -7724,9 +8157,9 @@ ${picocolors.exports.cyan(picocolors.exports.inverse(picocolors.exports.bold(" B
7724
8157
  }
7725
8158
  }
7726
8159
 
7727
- const DURATION_LONG = 300;
7728
- const outputMap = /* @__PURE__ */ new WeakMap();
7729
- function formatFilepath(path) {
8160
+ const DURATION_LONG$1 = 300;
8161
+ const outputMap$1 = /* @__PURE__ */ new WeakMap();
8162
+ function formatFilepath$1(path) {
7730
8163
  const lastSlash = Math.max(path.lastIndexOf("/") + 1, 0);
7731
8164
  const basename = path.slice(lastSlash);
7732
8165
  let firstDot = basename.indexOf(".");
@@ -7735,7 +8168,7 @@ function formatFilepath(path) {
7735
8168
  firstDot += lastSlash;
7736
8169
  return picocolors.exports.dim(path.slice(0, lastSlash)) + path.slice(lastSlash, firstDot) + picocolors.exports.dim(path.slice(firstDot));
7737
8170
  }
7738
- function formatNumber(number) {
8171
+ function formatNumber$1(number) {
7739
8172
  const res = String(number.toFixed(number < 100 ? 4 : 2)).split(".");
7740
8173
  return res[0].replace(/(?=(?:\d{3})+$)(?!\b)/g, ",") + (res[1] ? `.${res[1]}` : "");
7741
8174
  }
@@ -7746,16 +8179,16 @@ function renderHookState(task, hookName, level = 0) {
7746
8179
  return `${" ".repeat(level)} ${getHookStateSymbol(task, hookName)} ${picocolors.exports.dim(`[ ${hookName} ]`)}`;
7747
8180
  return "";
7748
8181
  }
7749
- function renderBenchmarkItems(result) {
8182
+ function renderBenchmarkItems$1(result) {
7750
8183
  return [
7751
8184
  result.name,
7752
- formatNumber(result.hz || 0),
7753
- formatNumber(result.p99 || 0),
8185
+ formatNumber$1(result.hz || 0),
8186
+ formatNumber$1(result.p99 || 0),
7754
8187
  `\xB1${result.rme.toFixed(2)}%`,
7755
8188
  result.samples.length.toString()
7756
8189
  ];
7757
8190
  }
7758
- function renderBenchmark(task, tasks) {
8191
+ function renderBenchmark$1(task, tasks) {
7759
8192
  var _a;
7760
8193
  const result = (_a = task.result) == null ? void 0 : _a.benchmark;
7761
8194
  if (!result)
@@ -7764,8 +8197,8 @@ function renderBenchmark(task, tasks) {
7764
8197
  var _a2;
7765
8198
  return i.type === "benchmark" ? (_a2 = i.result) == null ? void 0 : _a2.benchmark : void 0;
7766
8199
  }).filter(notNullish);
7767
- const allItems = benchs.map(renderBenchmarkItems);
7768
- const items = renderBenchmarkItems(result);
8200
+ const allItems = benchs.map(renderBenchmarkItems$1);
8201
+ const items = renderBenchmarkItems$1(result);
7769
8202
  const padded = items.map((i, idx) => {
7770
8203
  const width = Math.max(...allItems.map((i2) => i2[idx].length));
7771
8204
  return idx ? i.padStart(width, " ") : i.padEnd(width, " ");
@@ -7780,7 +8213,7 @@ function renderBenchmark(task, tasks) {
7780
8213
  result.rank === 1 ? picocolors.exports.bold(picocolors.exports.green(" fastest")) : result.rank === benchs.length && benchs.length > 2 ? picocolors.exports.bold(picocolors.exports.gray(" slowest")) : ""
7781
8214
  ].join("");
7782
8215
  }
7783
- function renderTree(tasks, options, level = 0) {
8216
+ function renderTree$1(tasks, options, level = 0) {
7784
8217
  var _a, _b, _c, _d, _e, _f;
7785
8218
  let output = [];
7786
8219
  for (const task of tasks) {
@@ -7788,24 +8221,26 @@ function renderTree(tasks, options, level = 0) {
7788
8221
  const prefix = ` ${getStateSymbol(task)} `;
7789
8222
  if (task.type === "test" && ((_a = task.result) == null ? void 0 : _a.retryCount) && task.result.retryCount > 1)
7790
8223
  suffix += picocolors.exports.yellow(` (retry x${task.result.retryCount})`);
7791
- if (task.type === "suite")
7792
- suffix += picocolors.exports.dim(` (${getTests(task).length})`);
8224
+ if (task.type === "suite" && !isTypecheckTest(task)) {
8225
+ const tests = options.mode === "typecheck" ? getTypecheckTests(task) : getTests(task);
8226
+ suffix += picocolors.exports.dim(` (${tests.length})`);
8227
+ }
7793
8228
  if (task.mode === "skip" || task.mode === "todo")
7794
8229
  suffix += ` ${picocolors.exports.dim(picocolors.exports.gray("[skipped]"))}`;
7795
8230
  if (((_b = task.result) == null ? void 0 : _b.duration) != null) {
7796
- if (task.result.duration > DURATION_LONG)
8231
+ if (task.result.duration > DURATION_LONG$1)
7797
8232
  suffix += picocolors.exports.yellow(` ${Math.round(task.result.duration)}${picocolors.exports.dim("ms")}`);
7798
8233
  }
7799
8234
  if (options.showHeap && ((_c = task.result) == null ? void 0 : _c.heap) != null)
7800
8235
  suffix += picocolors.exports.magenta(` ${Math.floor(task.result.heap / 1024 / 1024)} MB heap used`);
7801
8236
  let name = task.name;
7802
8237
  if (level === 0)
7803
- name = formatFilepath(name);
8238
+ name = formatFilepath$1(name);
7804
8239
  const padding = " ".repeat(level);
7805
- const body = task.type === "benchmark" ? renderBenchmark(task, tasks) : name;
8240
+ const body = task.type === "benchmark" ? renderBenchmark$1(task, tasks) : name;
7806
8241
  output.push(padding + prefix + body + suffix);
7807
- if (((_d = task.result) == null ? void 0 : _d.state) !== "pass" && outputMap.get(task) != null) {
7808
- let data = outputMap.get(task);
8242
+ if (((_d = task.result) == null ? void 0 : _d.state) !== "pass" && outputMap$1.get(task) != null) {
8243
+ let data = outputMap$1.get(task);
7809
8244
  if (typeof data === "string") {
7810
8245
  data = stripAnsi(data.trim().split("\n").filter(Boolean).pop());
7811
8246
  if (data === "")
@@ -7820,7 +8255,7 @@ function renderTree(tasks, options, level = 0) {
7820
8255
  output = output.concat(renderHookState(task, "beforeEach", level + 1));
7821
8256
  if (task.type === "suite" && task.tasks.length > 0) {
7822
8257
  if (((_e = task.result) == null ? void 0 : _e.state) === "fail" || ((_f = task.result) == null ? void 0 : _f.state) === "run" || options.renderSucceed)
7823
- output = output.concat(renderTree(task.tasks, options, level + 1));
8258
+ output = output.concat(renderTree$1(task.tasks, options, level + 1));
7824
8259
  }
7825
8260
  output = output.concat(renderHookState(task, "afterAll", level + 1));
7826
8261
  output = output.concat(renderHookState(task, "afterEach", level + 1));
@@ -7832,7 +8267,7 @@ const createListRenderer = (_tasks, options) => {
7832
8267
  let timer;
7833
8268
  const log = options.logger.logUpdate;
7834
8269
  function update() {
7835
- log(renderTree(tasks, options));
8270
+ log(renderTree$1(tasks, options));
7836
8271
  }
7837
8272
  return {
7838
8273
  start() {
@@ -7852,7 +8287,7 @@ const createListRenderer = (_tasks, options) => {
7852
8287
  timer = void 0;
7853
8288
  }
7854
8289
  log.clear();
7855
- options.logger.log(renderTree(tasks, options));
8290
+ options.logger.log(renderTree$1(tasks, options));
7856
8291
  return this;
7857
8292
  },
7858
8293
  clear() {
@@ -7880,6 +8315,7 @@ class DefaultReporter extends BaseReporter {
7880
8315
  if (this.isTTY) {
7881
8316
  this.rendererOptions.logger = this.ctx.logger;
7882
8317
  this.rendererOptions.showHeap = this.ctx.config.logHeapUsage;
8318
+ this.rendererOptions.mode = this.mode;
7883
8319
  const files = this.ctx.state.getFiles(this.watchFilters);
7884
8320
  if (!this.renderer)
7885
8321
  this.renderer = createListRenderer(files, this.rendererOptions).start();
@@ -7892,9 +8328,9 @@ class DefaultReporter extends BaseReporter {
7892
8328
  this.ctx.logger.log();
7893
8329
  await super.onFinished(files, errors);
7894
8330
  }
7895
- async onWatcherStart() {
8331
+ async onWatcherStart(files = this.ctx.state.getFiles(), errors = this.ctx.state.getUnhandledErrors()) {
7896
8332
  await this.stopListRender();
7897
- await super.onWatcherStart();
8333
+ await super.onWatcherStart(files, errors);
7898
8334
  }
7899
8335
  async stopListRender() {
7900
8336
  var _a;
@@ -8142,7 +8578,6 @@ class JsonReporter$1 {
8142
8578
  if (!error)
8143
8579
  return;
8144
8580
  const stack = parseStacktrace(error);
8145
- await interpretSourcePos(stack, this.ctx);
8146
8581
  const frame = stack[stack.length - 1];
8147
8582
  if (!frame)
8148
8583
  return;
@@ -8503,8 +8938,215 @@ class JsonReporter {
8503
8938
  }
8504
8939
  }
8505
8940
 
8941
+ const DURATION_LONG = 300;
8942
+ const outputMap = /* @__PURE__ */ new WeakMap();
8943
+ function formatFilepath(path) {
8944
+ const lastSlash = Math.max(path.lastIndexOf("/") + 1, 0);
8945
+ const basename = path.slice(lastSlash);
8946
+ let firstDot = basename.indexOf(".");
8947
+ if (firstDot < 0)
8948
+ firstDot = basename.length;
8949
+ firstDot += lastSlash;
8950
+ return picocolors.exports.dim(path.slice(0, lastSlash)) + path.slice(lastSlash, firstDot) + picocolors.exports.dim(path.slice(firstDot));
8951
+ }
8952
+ function formatNumber(number) {
8953
+ const res = String(number.toFixed(number < 100 ? 4 : 2)).split(".");
8954
+ return res[0].replace(/(?=(?:\d{3})+$)(?!\b)/g, ",") + (res[1] ? `.${res[1]}` : "");
8955
+ }
8956
+ const tableHead = ["name", "hz", "min", "max", "mean", "p75", "p99", "p995", "p999", "rme", "samples"];
8957
+ function renderTableHead(tasks) {
8958
+ const benchs = tasks.map((i) => {
8959
+ var _a;
8960
+ return i.type === "benchmark" ? (_a = i.result) == null ? void 0 : _a.benchmark : void 0;
8961
+ }).filter(notNullish);
8962
+ const allItems = benchs.map(renderBenchmarkItems).concat([tableHead]);
8963
+ return `${" ".repeat(3)}${tableHead.map((i, idx) => {
8964
+ const width = Math.max(...allItems.map((i2) => i2[idx].length));
8965
+ return idx ? i.padStart(width, " ") : i.padEnd(width, " ");
8966
+ }).map(picocolors.exports.bold).join(" ")}`;
8967
+ }
8968
+ function renderBenchmarkItems(result) {
8969
+ return [
8970
+ result.name,
8971
+ formatNumber(result.hz || 0),
8972
+ formatNumber(result.min || 0),
8973
+ formatNumber(result.max || 0),
8974
+ formatNumber(result.mean || 0),
8975
+ formatNumber(result.p75 || 0),
8976
+ formatNumber(result.p99 || 0),
8977
+ formatNumber(result.p995 || 0),
8978
+ formatNumber(result.p999 || 0),
8979
+ `\xB1${(result.rme || 0).toFixed(2)}%`,
8980
+ result.samples.length.toString()
8981
+ ];
8982
+ }
8983
+ function renderBenchmark(task, tasks) {
8984
+ var _a;
8985
+ const result = (_a = task.result) == null ? void 0 : _a.benchmark;
8986
+ if (!result)
8987
+ return task.name;
8988
+ const benchs = tasks.map((i) => {
8989
+ var _a2;
8990
+ return i.type === "benchmark" ? (_a2 = i.result) == null ? void 0 : _a2.benchmark : void 0;
8991
+ }).filter(notNullish);
8992
+ const allItems = benchs.map(renderBenchmarkItems).concat([tableHead]);
8993
+ const items = renderBenchmarkItems(result);
8994
+ const padded = items.map((i, idx) => {
8995
+ const width = Math.max(...allItems.map((i2) => i2[idx].length));
8996
+ return idx ? i.padStart(width, " ") : i.padEnd(width, " ");
8997
+ });
8998
+ return [
8999
+ padded[0],
9000
+ picocolors.exports.blue(padded[1]),
9001
+ picocolors.exports.cyan(padded[2]),
9002
+ picocolors.exports.cyan(padded[3]),
9003
+ picocolors.exports.cyan(padded[4]),
9004
+ picocolors.exports.cyan(padded[5]),
9005
+ picocolors.exports.cyan(padded[6]),
9006
+ picocolors.exports.cyan(padded[7]),
9007
+ picocolors.exports.cyan(padded[8]),
9008
+ picocolors.exports.dim(padded[9]),
9009
+ picocolors.exports.dim(padded[10]),
9010
+ result.rank === 1 ? picocolors.exports.bold(picocolors.exports.green(" fastest")) : result.rank === benchs.length && benchs.length > 2 ? picocolors.exports.bold(picocolors.exports.gray(" slowest")) : ""
9011
+ ].join(" ");
9012
+ }
9013
+ function renderTree(tasks, options, level = 0) {
9014
+ var _a, _b, _c, _d;
9015
+ let output = [];
9016
+ let idx = 0;
9017
+ for (const task of tasks) {
9018
+ const padding = " ".repeat(level ? 1 : 0);
9019
+ let prefix = "";
9020
+ if (idx === 0 && task.type === "benchmark")
9021
+ prefix += `${renderTableHead(tasks)}
9022
+ ${padding}`;
9023
+ prefix += ` ${getStateSymbol(task)} `;
9024
+ let suffix = "";
9025
+ if (task.type === "suite")
9026
+ suffix += picocolors.exports.dim(` (${getTests(task).length})`);
9027
+ if (task.mode === "skip" || task.mode === "todo")
9028
+ suffix += ` ${picocolors.exports.dim(picocolors.exports.gray("[skipped]"))}`;
9029
+ if (((_a = task.result) == null ? void 0 : _a.duration) != null) {
9030
+ if (task.result.duration > DURATION_LONG)
9031
+ suffix += picocolors.exports.yellow(` ${Math.round(task.result.duration)}${picocolors.exports.dim("ms")}`);
9032
+ }
9033
+ if (options.showHeap && ((_b = task.result) == null ? void 0 : _b.heap) != null)
9034
+ suffix += picocolors.exports.magenta(` ${Math.floor(task.result.heap / 1024 / 1024)} MB heap used`);
9035
+ let name = task.name;
9036
+ if (level === 0)
9037
+ name = formatFilepath(name);
9038
+ const body = task.type === "benchmark" ? renderBenchmark(task, tasks) : name;
9039
+ output.push(padding + prefix + body + suffix);
9040
+ if (((_c = task.result) == null ? void 0 : _c.state) !== "pass" && outputMap.get(task) != null) {
9041
+ let data = outputMap.get(task);
9042
+ if (typeof data === "string") {
9043
+ data = stripAnsi(data.trim().split("\n").filter(Boolean).pop());
9044
+ if (data === "")
9045
+ data = void 0;
9046
+ }
9047
+ if (data != null) {
9048
+ const out = `${" ".repeat(level)}${F_RIGHT} ${data}`;
9049
+ output.push(` ${picocolors.exports.gray(cliTruncate(out, getCols(-3)))}`);
9050
+ }
9051
+ }
9052
+ if (task.type === "suite" && task.tasks.length > 0) {
9053
+ if ((_d = task.result) == null ? void 0 : _d.state)
9054
+ output = output.concat(renderTree(task.tasks, options, level + 1));
9055
+ }
9056
+ idx++;
9057
+ }
9058
+ return output.filter(Boolean).join("\n");
9059
+ }
9060
+ const createTableRenderer = (_tasks, options) => {
9061
+ let tasks = _tasks;
9062
+ let timer;
9063
+ const log = options.logger.logUpdate;
9064
+ function update() {
9065
+ log(renderTree(tasks, options));
9066
+ }
9067
+ return {
9068
+ start() {
9069
+ if (timer)
9070
+ return this;
9071
+ timer = safeSetInterval(update, 200);
9072
+ return this;
9073
+ },
9074
+ update(_tasks2) {
9075
+ tasks = _tasks2;
9076
+ update();
9077
+ return this;
9078
+ },
9079
+ async stop() {
9080
+ if (timer) {
9081
+ safeClearInterval(timer);
9082
+ timer = void 0;
9083
+ }
9084
+ log.clear();
9085
+ options.logger.log(renderTree(tasks, options));
9086
+ return this;
9087
+ },
9088
+ clear() {
9089
+ log.clear();
9090
+ }
9091
+ };
9092
+ };
9093
+
9094
+ class TableReporter extends BaseReporter {
9095
+ constructor() {
9096
+ super(...arguments);
9097
+ this.rendererOptions = {};
9098
+ }
9099
+ async onTestRemoved(trigger) {
9100
+ await this.stopListRender();
9101
+ this.ctx.logger.clearScreen(picocolors.exports.yellow("Test removed...") + (trigger ? picocolors.exports.dim(` [ ${this.relative(trigger)} ]
9102
+ `) : ""), true);
9103
+ const files = this.ctx.state.getFiles(this.watchFilters);
9104
+ createTableRenderer(files, this.rendererOptions).stop();
9105
+ this.ctx.logger.log();
9106
+ await super.reportSummary(files);
9107
+ super.onWatcherStart();
9108
+ }
9109
+ onCollected() {
9110
+ if (this.isTTY) {
9111
+ this.rendererOptions.logger = this.ctx.logger;
9112
+ this.rendererOptions.showHeap = this.ctx.config.logHeapUsage;
9113
+ const files = this.ctx.state.getFiles(this.watchFilters);
9114
+ if (!this.renderer)
9115
+ this.renderer = createTableRenderer(files, this.rendererOptions).start();
9116
+ else
9117
+ this.renderer.update(files);
9118
+ }
9119
+ }
9120
+ async onFinished(files = this.ctx.state.getFiles(), errors = this.ctx.state.getUnhandledErrors()) {
9121
+ await this.stopListRender();
9122
+ this.ctx.logger.log();
9123
+ await super.onFinished(files, errors);
9124
+ }
9125
+ async onWatcherStart() {
9126
+ await this.stopListRender();
9127
+ await super.onWatcherStart();
9128
+ }
9129
+ async stopListRender() {
9130
+ var _a;
9131
+ await ((_a = this.renderer) == null ? void 0 : _a.stop());
9132
+ this.renderer = void 0;
9133
+ }
9134
+ async onWatcherRerun(files, trigger) {
9135
+ await this.stopListRender();
9136
+ await super.onWatcherRerun(files, trigger);
9137
+ }
9138
+ onUserConsoleLog(log) {
9139
+ var _a;
9140
+ if (!this.shouldLog(log))
9141
+ return;
9142
+ (_a = this.renderer) == null ? void 0 : _a.clear();
9143
+ super.onUserConsoleLog(log);
9144
+ }
9145
+ }
9146
+
8506
9147
  const BenchmarkReportsMap = {
8507
- default: VerboseReporter,
9148
+ default: TableReporter,
9149
+ verbose: VerboseReporter,
8508
9150
  json: JsonReporter
8509
9151
  };
8510
9152
 
@@ -8739,7 +9381,12 @@ const config = {
8739
9381
  coverage: coverageConfigDefaults,
8740
9382
  fakeTimers: fakeTimersDefaults,
8741
9383
  maxConcurrency: 5,
8742
- dangerouslyIgnoreUnhandledErrors: false
9384
+ dangerouslyIgnoreUnhandledErrors: false,
9385
+ typecheck: {
9386
+ checker: "tsc",
9387
+ include: ["**/*.{test,spec}-d.{ts,js}"],
9388
+ exclude: defaultExclude
9389
+ }
8743
9390
  };
8744
9391
  const configDefaults = Object.freeze(config);
8745
9392
 
@@ -8937,7 +9584,7 @@ function resolveApiConfig(options) {
8937
9584
  return api;
8938
9585
  }
8939
9586
  function resolveConfig(mode, options, viteConfig) {
8940
- var _a, _b, _c, _d, _e, _f;
9587
+ var _a, _b, _c, _d, _e, _f, _g;
8941
9588
  if (options.dom) {
8942
9589
  if (((_a = viteConfig.test) == null ? void 0 : _a.environment) != null && viteConfig.test.environment !== "happy-dom") {
8943
9590
  console.warn(
@@ -9039,10 +9686,19 @@ function resolveConfig(mode, options, viteConfig) {
9039
9686
  resolved.cache ?? (resolved.cache = { dir: "" });
9040
9687
  if (resolved.cache)
9041
9688
  resolved.cache.dir = VitestCache.resolveCacheDir(resolved.root, resolved.cache.dir);
9689
+ resolved.sequence ?? (resolved.sequence = {});
9042
9690
  if (!((_f = resolved.sequence) == null ? void 0 : _f.sequencer)) {
9043
- resolved.sequence ?? (resolved.sequence = {});
9044
9691
  resolved.sequence.sequencer = resolved.sequence.shuffle ? RandomSequencer : BaseSequencer;
9045
9692
  }
9693
+ (_g = resolved.sequence).hooks ?? (_g.hooks = "parallel");
9694
+ resolved.typecheck = {
9695
+ ...configDefaults.typecheck,
9696
+ ...resolved.typecheck
9697
+ };
9698
+ if (mode === "typecheck") {
9699
+ resolved.include = resolved.typecheck.include;
9700
+ resolved.exclude = resolved.typecheck.exclude;
9701
+ }
9046
9702
  return resolved;
9047
9703
  }
9048
9704
 
@@ -9532,7 +10188,7 @@ createLogUpdate(process$1.stdout);
9532
10188
 
9533
10189
  createLogUpdate(process$1.stderr);
9534
10190
 
9535
- var version = "0.24.5";
10191
+ var version = "0.25.1";
9536
10192
 
9537
10193
  function fileFromParsedStack(stack) {
9538
10194
  var _a, _b;
@@ -9557,23 +10213,26 @@ async function printError(error, ctx, options = {}) {
9557
10213
  };
9558
10214
  }
9559
10215
  const stacks = parseStacktrace(e, fullStack);
9560
- await interpretSourcePos(stacks, ctx);
9561
- const nearest = stacks.find(
10216
+ const nearest = error instanceof TypeCheckError ? error.stacks[0] : stacks.find(
9562
10217
  (stack) => ctx.server.moduleGraph.getModuleById(stack.file) && existsSync(stack.file)
9563
10218
  );
9564
10219
  const errorProperties = getErrorProperties(e);
9565
10220
  if (type)
9566
10221
  printErrorType(type, ctx);
9567
10222
  printErrorMessage(e, ctx.logger);
9568
- printStack(ctx, stacks, nearest, errorProperties, (s, pos) => {
9569
- if (showCodeFrame && s === nearest && nearest) {
9570
- const file = fileFromParsedStack(nearest);
9571
- if (existsSync(file)) {
9572
- const sourceCode = readFileSync(file, "utf-8");
9573
- ctx.logger.log(picocolors.exports.yellow(generateCodeFrame(sourceCode, 4, pos)));
10223
+ if (e.frame) {
10224
+ ctx.logger.error(picocolors.exports.yellow(e.frame));
10225
+ } else {
10226
+ printStack(ctx, stacks, nearest, errorProperties, (s, pos) => {
10227
+ if (showCodeFrame && s === nearest && nearest) {
10228
+ const file = fileFromParsedStack(nearest);
10229
+ if (nearest.file === file || existsSync(file)) {
10230
+ const sourceCode = readFileSync(file, "utf-8");
10231
+ ctx.logger.error(picocolors.exports.yellow(generateCodeFrame(sourceCode, 4, pos)));
10232
+ }
9574
10233
  }
9575
- }
9576
- });
10234
+ });
10235
+ }
9577
10236
  if (e.cause && "name" in e.cause) {
9578
10237
  e.cause.name = `Caused by: ${e.cause.name}`;
9579
10238
  await printError(e.cause, ctx, { fullStack, showCodeFrame: false });
@@ -9590,7 +10249,7 @@ function printErrorType(type, ctx) {
9590
10249
  ctx.logger.error(`
9591
10250
  ${picocolors.exports.red(divider(picocolors.exports.bold(picocolors.exports.inverse(` ${type} `))))}`);
9592
10251
  }
9593
- const skipErrorProperties = [
10252
+ const skipErrorProperties = /* @__PURE__ */ new Set([
9594
10253
  "nameStr",
9595
10254
  "stack",
9596
10255
  "cause",
@@ -9602,13 +10261,13 @@ const skipErrorProperties = [
9602
10261
  "expected",
9603
10262
  ...Object.getOwnPropertyNames(Error.prototype),
9604
10263
  ...Object.getOwnPropertyNames(Object.prototype)
9605
- ];
10264
+ ]);
9606
10265
  function getErrorProperties(e) {
9607
10266
  const errorObject = /* @__PURE__ */ Object.create(null);
9608
10267
  if (e.name === "AssertionError")
9609
10268
  return errorObject;
9610
10269
  for (const key of Object.getOwnPropertyNames(e)) {
9611
- if (!skipErrorProperties.includes(key))
10270
+ if (!skipErrorProperties.has(key))
9612
10271
  errorObject[key] = e[key];
9613
10272
  }
9614
10273
  return errorObject;
@@ -9659,17 +10318,17 @@ function printStack(ctx, stack, highlight, errorProperties, onStack) {
9659
10318
  const color = frame === highlight ? picocolors.exports.yellow : picocolors.exports.gray;
9660
10319
  const file = fileFromParsedStack(frame);
9661
10320
  const path = relative(ctx.config.root, file);
9662
- logger.log(color(` ${picocolors.exports.dim(F_POINTER)} ${[frame.method, picocolors.exports.dim(`${path}:${pos.line}:${pos.column}`)].filter(Boolean).join(" ")}`));
10321
+ logger.error(color(` ${picocolors.exports.dim(F_POINTER)} ${[frame.method, picocolors.exports.dim(`${path}:${pos.line}:${pos.column}`)].filter(Boolean).join(" ")}`));
9663
10322
  onStack == null ? void 0 : onStack(frame, pos);
9664
10323
  if (frame.file in ctx.state.filesMap)
9665
10324
  break;
9666
10325
  }
9667
- logger.log();
10326
+ logger.error();
9668
10327
  const hasProperties = Object.keys(errorProperties).length > 0;
9669
10328
  if (hasProperties) {
9670
- logger.log(picocolors.exports.red(picocolors.exports.dim(divider())));
10329
+ logger.error(picocolors.exports.red(picocolors.exports.dim(divider())));
9671
10330
  const propertiesString = stringify$5(errorProperties, 10, { printBasicPrototype: false });
9672
- logger.log(picocolors.exports.red(picocolors.exports.bold("Serialized Error:")), picocolors.exports.gray(propertiesString));
10331
+ logger.error(picocolors.exports.red(picocolors.exports.bold("Serialized Error:")), picocolors.exports.gray(propertiesString));
9673
10332
  }
9674
10333
  }
9675
10334
  function generateCodeFrame(source, indent = 0, start = 0, end, range = 2) {
@@ -9733,6 +10392,13 @@ class Logger {
9733
10392
  this._clearScreen();
9734
10393
  this.console.warn(...args);
9735
10394
  }
10395
+ clearFullScreen(message) {
10396
+ if (this.ctx.server.config.clearScreen === false) {
10397
+ this.console.log(message);
10398
+ return;
10399
+ }
10400
+ this.console.log(`\x1Bc${message}`);
10401
+ }
9736
10402
  clearScreen(message, force = false) {
9737
10403
  if (this.ctx.server.config.clearScreen === false) {
9738
10404
  this.console.log(message);
@@ -9747,7 +10413,7 @@ class Logger {
9747
10413
  return;
9748
10414
  const log = this._clearScreenPending;
9749
10415
  this._clearScreenPending = void 0;
9750
- this.console.log(`\x1Bc${log}`);
10416
+ this.console.log(`\x1B[1;1H\x1B[J${log}`);
9751
10417
  }
9752
10418
  printError(err, fullStack = false, type) {
9753
10419
  return printError(err, this.ctx, {
@@ -9776,7 +10442,7 @@ No ${config.mode} files found, exiting with code 1`));
9776
10442
  }
9777
10443
  printBanner() {
9778
10444
  var _a, _b, _c;
9779
- this.clearScreen("", true);
10445
+ this.log();
9780
10446
  const versionTest = this.ctx.config.watch ? picocolors.exports.blue(`v${version}`) : picocolors.exports.cyan(`v${version}`);
9781
10447
  const mode = this.ctx.config.watch ? picocolors.exports.blue(" DEV ") : picocolors.exports.cyan(" RUN ");
9782
10448
  this.log(`${picocolors.exports.inverse(picocolors.exports.bold(mode))} ${versionTest} ${picocolors.exports.gray(this.ctx.config.root)}`);
@@ -9803,6 +10469,18 @@ This might cause false positive tests. Resolve unhandled errors to make sure you
9803
10469
  }));
9804
10470
  this.log(picocolors.exports.red(divider()));
9805
10471
  }
10472
+ async printSourceTypeErrors(errors) {
10473
+ const errorMessage = picocolors.exports.red(picocolors.exports.bold(
10474
+ `
10475
+ Vitest found ${errors.length} error${errors.length > 1 ? "s" : ""} not related to your test files.`
10476
+ ));
10477
+ this.log(picocolors.exports.red(divider(picocolors.exports.bold(picocolors.exports.inverse(" Source Errors ")))));
10478
+ this.log(errorMessage);
10479
+ await Promise.all(errors.map(async (err) => {
10480
+ await this.printError(err, true);
10481
+ }));
10482
+ this.log(picocolors.exports.red(divider()));
10483
+ }
9806
10484
  }
9807
10485
 
9808
10486
  const WATCHER_DEBOUNCE = 100;
@@ -9908,8 +10586,52 @@ class Vitest {
9908
10586
  this.configOverride || {}
9909
10587
  );
9910
10588
  }
10589
+ async typecheck(filters) {
10590
+ const testsFilesList = await this.globTestFiles(filters);
10591
+ const checker = new Typechecker(this, testsFilesList);
10592
+ this.typechecker = checker;
10593
+ checker.onParseEnd(async ({ files, sourceErrors }) => {
10594
+ this.state.collectFiles(checker.getTestFiles());
10595
+ await this.report("onCollected");
10596
+ if (!files.length)
10597
+ this.logger.printNoTestFound();
10598
+ else
10599
+ await this.report("onFinished", files);
10600
+ if (sourceErrors.length && !this.config.typecheck.ignoreSourceErrors) {
10601
+ process.exitCode = 1;
10602
+ await this.logger.printSourceTypeErrors(sourceErrors);
10603
+ }
10604
+ if (!files.length) {
10605
+ const exitCode = this.config.passWithNoTests ? process.exitCode ?? 0 : 1;
10606
+ process.exit(exitCode);
10607
+ }
10608
+ if (this.config.watch) {
10609
+ await this.report("onWatcherStart", files, [
10610
+ ...sourceErrors,
10611
+ ...this.state.getUnhandledErrors()
10612
+ ]);
10613
+ }
10614
+ });
10615
+ checker.onParseStart(async () => {
10616
+ await this.report("onInit", this);
10617
+ this.state.collectFiles(checker.getTestFiles());
10618
+ await this.report("onCollected");
10619
+ });
10620
+ checker.onWatcherRerun(async () => {
10621
+ await this.report("onWatcherRerun", testsFilesList, "File change detected. Triggering rerun.");
10622
+ await checker.collectTests();
10623
+ this.state.collectFiles(checker.getTestFiles());
10624
+ await this.report("onCollected");
10625
+ });
10626
+ await checker.collectTests();
10627
+ await checker.start();
10628
+ }
9911
10629
  async start(filters) {
9912
10630
  var _a;
10631
+ if (this.mode === "typecheck") {
10632
+ await this.typecheck(filters);
10633
+ return;
10634
+ }
9913
10635
  try {
9914
10636
  await this.initCoverageProvider();
9915
10637
  await ((_a = this.coverageProvider) == null ? void 0 : _a.clean(this.config.coverage.clean));
@@ -9956,7 +10678,7 @@ class Vitest {
9956
10678
  }
9957
10679
  async filterTestsBySource(tests) {
9958
10680
  if (this.config.changed && !this.config.related) {
9959
- const { VitestGit } = await import('./chunk-node-git.82174cfe.js');
10681
+ const { VitestGit } = await import('./chunk-node-git.5a1b1656.js');
9960
10682
  const vitestGit = new VitestGit(this.config.root);
9961
10683
  const related2 = await vitestGit.findChangedFiles({
9962
10684
  changedSince: this.config.changed
@@ -10146,11 +10868,12 @@ class Vitest {
10146
10868
  return rerun;
10147
10869
  }
10148
10870
  async close() {
10149
- var _a;
10871
+ var _a, _b;
10150
10872
  if (!this.closingPromise) {
10151
10873
  this.closingPromise = Promise.allSettled([
10152
10874
  (_a = this.pool) == null ? void 0 : _a.close(),
10153
- this.server.close()
10875
+ this.server.close(),
10876
+ (_b = this.typechecker) == null ? void 0 : _b.stop()
10154
10877
  ].filter(Boolean)).then((results) => {
10155
10878
  results.filter((r) => r.status === "rejected").forEach((err) => {
10156
10879
  this.logger.error("error during close", err.reason);
@@ -10432,7 +11155,7 @@ function getIndexStatus(code, from) {
10432
11155
  inString = char;
10433
11156
  }
10434
11157
  }
10435
- beforeChar = code[index];
11158
+ beforeChar = char;
10436
11159
  index++;
10437
11160
  }
10438
11161
  return {
@@ -10533,7 +11256,12 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
10533
11256
  },
10534
11257
  config(viteConfig) {
10535
11258
  var _a, _b, _c;
10536
- const preOptions = deepMerge({}, configDefaults, options, viteConfig.test ?? {});
11259
+ const preOptions = deepMerge(
11260
+ {},
11261
+ configDefaults,
11262
+ options,
11263
+ removeUndefinedValues(viteConfig.test ?? {})
11264
+ );
10537
11265
  preOptions.api = resolveApiConfig(preOptions);
10538
11266
  if (viteConfig.define) {
10539
11267
  delete viteConfig.define["import.meta.vitest"];
@@ -10629,7 +11357,7 @@ async function VitestPlugin(options = {}, ctx = new Vitest("test")) {
10629
11357
  try {
10630
11358
  await ctx.setServer(options, server);
10631
11359
  if (options.api && options.watch)
10632
- (await import('./chunk-api-setup.629f8133.js')).setup(ctx);
11360
+ (await import('./chunk-api-setup.f40616e2.js')).setup(ctx);
10633
11361
  } catch (err) {
10634
11362
  ctx.logger.printError(err, true);
10635
11363
  process.exit(1);
@@ -10691,6 +11419,10 @@ function registerConsoleShortcuts(ctx) {
10691
11419
  if (ctx.runningPromise)
10692
11420
  return;
10693
11421
  const name = key == null ? void 0 : key.name;
11422
+ if (name === "q")
11423
+ return ctx.exit(true);
11424
+ if (ctx.mode === "typecheck")
11425
+ return;
10694
11426
  if (name === "h")
10695
11427
  return printShortcutsHelp();
10696
11428
  if (name === "u")
@@ -10703,8 +11435,6 @@ function registerConsoleShortcuts(ctx) {
10703
11435
  return inputNamePattern();
10704
11436
  if (name === "p")
10705
11437
  return inputFilePattern();
10706
- if (name === "q")
10707
- return ctx.exit(true);
10708
11438
  }
10709
11439
  async function keypressHandler(str, key) {
10710
11440
  await _keypressHandler(str, key);
@@ -10764,25 +11494,25 @@ async function startVitest(mode, cliFilters, options, viteOverrides) {
10764
11494
  const root = resolve(options.root || process.cwd());
10765
11495
  if (!await ensurePackageInstalled("vite", root)) {
10766
11496
  process.exitCode = 1;
10767
- return false;
11497
+ return;
10768
11498
  }
10769
11499
  if (typeof options.coverage === "boolean")
10770
11500
  options.coverage = { enabled: options.coverage };
10771
11501
  const ctx = await createVitest(mode, options, viteOverrides);
10772
- if (mode !== "benchmark" && ctx.config.coverage.enabled) {
11502
+ if (mode === "test" && ctx.config.coverage.enabled) {
10773
11503
  const provider = ctx.config.coverage.provider || "c8";
10774
11504
  if (typeof provider === "string") {
10775
11505
  const requiredPackages = CoverageProviderMap[provider];
10776
11506
  if (!await ensurePackageInstalled(requiredPackages, root)) {
10777
11507
  process.exitCode = 1;
10778
- return false;
11508
+ return ctx;
10779
11509
  }
10780
11510
  }
10781
11511
  }
10782
11512
  const environmentPackage = getEnvPackageName(ctx.config.environment);
10783
11513
  if (environmentPackage && !await ensurePackageInstalled(environmentPackage, root)) {
10784
11514
  process.exitCode = 1;
10785
- return false;
11515
+ return ctx;
10786
11516
  }
10787
11517
  if (process.stdin.isTTY && ctx.config.watch)
10788
11518
  registerConsoleShortcuts(ctx);
@@ -10799,13 +11529,12 @@ async function startVitest(mode, cliFilters, options, viteOverrides) {
10799
11529
  process.exitCode = 1;
10800
11530
  await ctx.logger.printError(e, true, "Unhandled Error");
10801
11531
  ctx.logger.error("\n\n");
10802
- return false;
10803
- }
10804
- if (!ctx.config.watch) {
10805
- await ctx.exit();
10806
- return !process.exitCode;
11532
+ return ctx;
10807
11533
  }
10808
- return true;
11534
+ if (ctx.config.watch)
11535
+ return ctx;
11536
+ await ctx.close();
11537
+ return ctx;
10809
11538
  }
10810
11539
 
10811
11540
  export { BaseSequencer as B, VitestPlugin as V, createVitest as c, divider as d, startVitest as s, version$1 as v };