@cldmv/vitest-runner 1.4.3 → 1.5.0
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/README.md +16 -5
- package/bin/vitest-runner.mjs +46 -43
- package/dist/index.mjs +40 -41
- package/package.json +2 -2
- package/types/src/cli/args.d.mts +4 -0
- package/types/src/core/discover.d.mts +26 -2
- package/types/src/core/report.d.mts +16 -5
- package/types/src/runner.d.mts +4 -0
- package/types/src/utils/ansi.d.mts +29 -3
package/README.md
CHANGED
|
@@ -17,18 +17,18 @@ Sequential Vitest runner that spawns each test file in its own child process to
|
|
|
17
17
|
|
|
18
18
|
## ✨ What's New
|
|
19
19
|
|
|
20
|
-
### Latest: v1.4.
|
|
20
|
+
### Latest: v1.4.4 (September 2026)
|
|
21
21
|
|
|
22
|
-
- **
|
|
23
|
-
-
|
|
24
|
-
- [View full v1.4.
|
|
22
|
+
- **Dropped the `prepack` workaround** — the underlying gap (CI's publish job invoking lifecycle scripts against a bare, already-built artifact directory) is now fixed upstream in `CLDMV/.github`, so `prepack` goes back to a plain `npm run build`.
|
|
23
|
+
- **Fixed a release-automation gap** — the release-merge gate now re-evaluates after every check-producing workflow finishes, not just CI, so an approval landing before a slower check (CodeQL and similar) can't leave a release PR stuck approved and green with nothing re-triggering the merge.
|
|
24
|
+
- [View full v1.4.4 Changelog](https://github.com/CLDMV/vitest-runner/blob/master/docs/changelog/v1/v1.4.4.md)
|
|
25
25
|
|
|
26
26
|
### Recent Releases
|
|
27
27
|
|
|
28
|
+
- **v1.4.3** (September 2026) — The published build is actually minified now, and `dist/index.cjs` is a thin shim instead of a duplicate bundle ([Changelog](https://github.com/CLDMV/vitest-runner/blob/master/docs/changelog/v1/v1.4.3.md))
|
|
28
29
|
- **v1.4.2** (September 2026) — Fixed npm publish rejecting every release over missing `repository`/`bugs`/`homepage` fields ([Changelog](https://github.com/CLDMV/vitest-runner/blob/master/docs/changelog/v1/v1.4.2.md))
|
|
29
30
|
- **v1.4.1** (September 2026) — Completed the vitest 5 upgrade, fixed the README npm badges, and fixed a `prepack` bug crashing every publish job ([Changelog](https://github.com/CLDMV/vitest-runner/blob/master/docs/changelog/v1/v1.4.1.md))
|
|
30
31
|
- **v1.4.0** (September 2026) — Real bundled `dist/`/`bin/` build, a working CLI, and a runner-owned scratch-directory lifecycle ([Changelog](https://github.com/CLDMV/vitest-runner/blob/master/docs/changelog/v1/v1.4.0.md))
|
|
31
|
-
- **v1.3.3** (September 2026) — Dependency bump (`brace-expansion`, `postcss`) via Dependabot.
|
|
32
32
|
|
|
33
33
|
---
|
|
34
34
|
|
|
@@ -68,6 +68,7 @@ vitest-runner [OPTIONS] [PATTERNS...]
|
|
|
68
68
|
| `--file-pattern <regex>` | Override the file discovery regex (default: `\.test\.vitest\.(?:js\|mjs\|cjs)$`) |
|
|
69
69
|
| `--workers <n>` | Number of parallel workers (default: `4` or `VITEST_WORKERS`) |
|
|
70
70
|
| `--solo-pattern <pat>` | Run files matching this path substring solo (one at a time) before the worker pool; repeatable |
|
|
71
|
+
| `--exclude <glob>` | Directory / file glob, relative to `cwd`, that discovery never enters (e.g. `tmp/**`); repeatable |
|
|
71
72
|
| `--no-error-details` | Hide inline error blocks — show only counts in the summary |
|
|
72
73
|
| `--coverage-quiet` | Implies `--coverage`; suppress per-file output and show only a live progress bar and final summaries |
|
|
73
74
|
| `--log-file <path>` | Write a clean (ANSI-stripped) copy of all output to this file. Defaults to `coverage/coverage-run.log` when `--coverage-quiet` is active |
|
|
@@ -148,6 +149,9 @@ vitest-runner --file-pattern '\.spec\.ts$'
|
|
|
148
149
|
# Run 2 workers, with certain files running solo first
|
|
149
150
|
vitest-runner --workers 2 --solo-pattern heavy/ --solo-pattern listener-cleanup/
|
|
150
151
|
|
|
152
|
+
# Skip scratch worktrees / build output when discovery walks the repo root
|
|
153
|
+
vitest-runner --exclude 'tmp/**' --exclude 'dist/**'
|
|
154
|
+
|
|
151
155
|
# Custom heap and worker count
|
|
152
156
|
VITEST_HEAP_MB=8192 vitest-runner --workers 2 src/tests/heavy
|
|
153
157
|
|
|
@@ -196,6 +200,7 @@ process.exit(code);
|
|
|
196
200
|
| `testPatterns` | `string[]` | `[]` | File / folder patterns to filter — empty means all files in `testDir` |
|
|
197
201
|
| `testListFile` | `string` | `undefined` | Path to a JSON array of test file paths; when set, scanning is skipped entirely |
|
|
198
202
|
| `testFilePattern` | `RegExp` | `DEFAULT_TEST_FILE_PATTERN` | Regex matched against file names during discovery (`*.test.vitest.{js,mjs,cjs}` by default) |
|
|
203
|
+
| `exclude` | `string[]` | `[]` | Directory / file globs, relative to `cwd`, that discovery never enters (e.g. `['tmp/**']`). Applies to both the default scan and partial-path pattern resolution |
|
|
199
204
|
| `vitestArgs` | `string[]` | `[]` | Extra CLI args forwarded verbatim to every vitest invocation |
|
|
200
205
|
| `showErrorDetails` | `boolean` | `true` | Print inline error blocks under each failed file in the summary |
|
|
201
206
|
| `coverageQuiet` | `boolean` | `false` | Suppress per-file output; show only the progress bar and final summaries |
|
|
@@ -299,6 +304,12 @@ This avoids the OOM crash that occurs when a single vitest process holds coverag
|
|
|
299
304
|
|
|
300
305
|
The log file path can be overridden with `--log-file <path>`. Passing `--log-file` by itself only enables log mirroring (it does not enable coverage mode).
|
|
301
306
|
|
|
307
|
+
### When no files are measured
|
|
308
|
+
|
|
309
|
+
If the coverage `include` matches no files (for example, a scaffold repo with a test but no source yet), istanbul reports every percentage as `Unknown` rather than a number. The runner prints those metrics as `Unknown` — `Coverage Unknown% lines | Unknown% statements | …` — adds a note that no files were measured, and exits `0` if the tests passed. The same applies to any individual non-numeric percentage in the worst-coverage table.
|
|
310
|
+
|
|
311
|
+
Coverage thresholds are skipped in this case, because there is nothing to measure: vitest's own threshold check does not fail on an `Unknown` percentage, and the runner does not add a check of its own. Thresholds apply again as soon as at least one file is measured. The JSON report's `coverageSummary.noFilesMeasured` is `true` for such a run.
|
|
312
|
+
|
|
302
313
|
### Producing blobs for an external merge
|
|
303
314
|
|
|
304
315
|
Set `mergeReports: false` (CLI: `--no-merge-reports`) to stop the run after the per-file blobs are written. The internal `vitest --mergeReports` call and the coverage summary are skipped, and `blobsDir` is left intact instead of being deleted. The blobs directory is still cleared at the **start** of each run, so it only ever contains the current run's output.
|
package/bin/vitest-runner.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{createWriteStream as
|
|
2
|
+
import{createWriteStream as zt,mkdirSync as qt}from"fs";import be from"path";var Ot=new Set(["--test-list","--no-error-details","--coverage-quiet","--log-file","--suppress-file-output","--suppress-passing-files","--no-top-summary","--json","--blobs-dir","--no-merge-reports","--workers","--solo-pattern","--exclude","--file-pattern","--keep-tmp","--scratch-dir","--help","-h"]);function rt(e){let t=[],s=[],r=[],o=[],n,l=!0,u=!1,c,a=!1,p=!1,f=!0,h=!1,b,v=!0,y,S=!1,d,T=!1,P;for(let w=0;w<e.length;w++){let g=e[w];g==="--test-list"?n=e[++w]:g.startsWith("--test-list=")?n=g.slice(12):g==="--no-error-details"?l=!1:g==="--coverage-quiet"?u=!0:g==="--log-file"?c=e[++w]:g.startsWith("--log-file=")?c=g.slice(11):g==="--suppress-file-output"?a=!0:g==="--suppress-passing-files"?p=!0:g==="--no-top-summary"?f=!1:g==="--json"?h=!0:g==="--blobs-dir"?b=e[++w]:g.startsWith("--blobs-dir=")?b=g.slice(12):g==="--no-merge-reports"?v=!1:g==="--workers"?y=parseInt(e[++w],10):g.startsWith("--workers=")?y=parseInt(g.slice(10),10):g==="--solo-pattern"?r.push(e[++w]):g.startsWith("--solo-pattern=")?r.push(g.slice(15)):g==="--exclude"?o.push(e[++w]):g.startsWith("--exclude=")?o.push(g.slice(10)):g==="--file-pattern"?d=new RegExp(e[++w],"i"):g.startsWith("--file-pattern=")?d=new RegExp(g.slice(15),"i"):g==="--keep-tmp"?T=!0:g==="--scratch-dir"?P=e[++w]:g.startsWith("--scratch-dir=")?P=g.slice(14):g==="--help"||g==="-h"?S=!0:(g.startsWith("--")||g.startsWith("-"))&&!Ot.has(g)?(t.push(g),w+1<e.length&&!e[w+1].startsWith("-")&&t.push(e[++w])):s.push(g)}return{testListFile:n,showErrorDetails:l,coverageQuiet:u,logFile:c,suppressFileOutput:a,suppressPassingFiles:p,topSummary:f,json:h,blobsDir:b,mergeReports:v,help:S,workers:y,soloPatterns:r,exclude:o,testFilePattern:d,vitestPassthroughArgs:t,testPatterns:s,keepTmp:T,scratchDir:P}}import Z from"chalk";function nt(){console.log(`
|
|
3
3
|
${Z.bold("Vitest Sequential Runner")}
|
|
4
4
|
Runs each test file in its own Vitest process to avoid OOM issues.
|
|
5
5
|
|
|
@@ -11,6 +11,7 @@ ${Z.bold("SPECIAL FLAGS:")}
|
|
|
11
11
|
--file-pattern <regex> Override the file discovery regex (default: \\.test\\.vitest\\.(?:js|mjs|cjs)$)
|
|
12
12
|
--workers <n> Number of parallel workers (default: 4 or VITEST_WORKERS)
|
|
13
13
|
--solo-pattern <pat> Run files matching this path substring solo first (repeatable)
|
|
14
|
+
--exclude <glob> Directory / file glob discovery never enters, relative to cwd (repeatable)
|
|
14
15
|
--no-error-details Hide detailed error output (show only counts)
|
|
15
16
|
--coverage-quiet Implies --coverage; show progress bar + final summaries only
|
|
16
17
|
--log-file <path> Path for mirrored runner output (default: coverage/coverage-run.log with --coverage-quiet)
|
|
@@ -66,6 +67,9 @@ ${Z.bold("ENVIRONMENT VARIABLES:")}
|
|
|
66
67
|
# Run files matching a pattern solo first, then the rest in parallel
|
|
67
68
|
vitest-runner --solo-pattern listener-cleanup/ --solo-pattern heavy/
|
|
68
69
|
|
|
70
|
+
# Skip scratch worktrees when discovery walks the repo root
|
|
71
|
+
vitest-runner --exclude 'tmp/**' --exclude 'dist/**'
|
|
72
|
+
|
|
69
73
|
# Hide detailed errors
|
|
70
74
|
vitest-runner --no-error-details
|
|
71
75
|
|
|
@@ -74,51 +78,50 @@ ${Z.bold("ENVIRONMENT VARIABLES:")}
|
|
|
74
78
|
|
|
75
79
|
# Custom heap and workers
|
|
76
80
|
VITEST_HEAP_MB=8192 vitest-runner --workers 2 src/tests/heavy
|
|
77
|
-
`)}import G from"fs/promises";import
|
|
78
|
-
Test Files`,
|
|
79
|
-
`,
|
|
80
|
-
`,
|
|
81
|
+
`)}import G from"fs/promises";import ve from"path";import $ from"chalk";import{createRequire as kt}from"module";import X from"path";import Dt from"fs/promises";import{pathToFileURL as At}from"url";function ke(e,t,s=t){let r=kt(At(X.join(e,"package.json"))),o=r.resolve(`${t}/package.json`),n=r(o),l=n.bin?.[s]??n.bin;if(!l)throw new Error(`No bin "${s}" found in ${t}/package.json`);return X.join(X.dirname(o),l)}var It=Object.freeze(["vitest.config.ts","vitest.config.mts","vitest.config.cts","vitest.config.mjs","vitest.config.js","vitest.config.cjs","vite.config.ts","vite.config.mts","vite.config.mjs","vite.config.js"]);async function De(e,t){if(t)return X.isAbsolute(t)?t:X.resolve(e,t);for(let s of It){let r=X.join(e,s);try{return await Dt.access(r),r}catch{}}}import Ie from"fs/promises";import j from"path";var it=/\.test\.vitest\.(?:js|mjs|cjs)$/i;function jt(e){let t=e.replace(/\\/g,"/"),s="";for(let r=0;r<t.length;r++){let o=t[r];o==="*"&&t[r+1]==="*"?(s+=".*",r++):o==="*"?s+="[^/]*":o==="?"?s+="[^/]":s+=o.replace(/[.+^${}()|[\]\\]/g,"\\$&")}return new RegExp(`^${s}$`)}function Ae(e,t){return!t||t.length===0?!1:t.some(s=>jt(s).test(e))}async function de(e,t,s=it,r=[]){let o=[e],n=[];for(;o.length;){let l=o.pop(),u;try{u=await Ie.readdir(l,{withFileTypes:!0})}catch{continue}for(let c of u){let a=j.relative(t,j.join(l,c.name)).replace(/\\/g,"/");if(c.isDirectory()){if(c.name==="node_modules"||c.name.startsWith(".")||Ae(a,r)||Ae(`${a}/`,r))continue;o.push(j.join(l,c.name));continue}if(c.isFile()&&s.test(c.name)){if(Ae(a,r))continue;n.push(j.relative(t,j.join(l,c.name)))}}}return n}function ge(e,t=[]){let s=[],r=[];for(let o of e){let n=o.replace(/\\/g,"/"),l=t.findIndex(u=>n.includes(u));l!==-1?s.push({file:o,priorityIndex:l}):r.push(o)}return s.sort((o,n)=>o.priorityIndex-n.priorityIndex||o.file.localeCompare(n.file)),r.sort((o,n)=>o.localeCompare(n)),[...s.map(o=>o.file),...r]}function je(e){let t=e.map(r=>r.replace(/\\/g,"/")),s=new Map;for(let r=0;r<e.length;r++){let o=[];for(let n=0;n<e.length;n++)r!==n&&t[n].includes(t[r])&&o.push(e[n]);s.set(e[r],o)}return s}async function me(e){let{cwd:t,testDir:s,testPatterns:r=[],testListFile:o,testFilePattern:n=it,earlyRunPatterns:l=[],exclude:u=[]}=e,c=s?j.isAbsolute(s)?s:j.resolve(t,s):t;if(o){let p=j.isAbsolute(o)?o:j.resolve(t,o),f;try{let h=await Ie.readFile(p,"utf8");f=JSON.parse(h)}catch(h){throw new Error(`Failed to read test list file "${p}": ${h.message}`,{cause:h})}if(!Array.isArray(f))throw new Error(`Test list file "${p}" must contain a JSON array of test file paths`);return console.log(`\u{1F4CB} Loading test list from: ${j.relative(t,p)}`),ge(f,l)}if(r.length===0){let p=await de(c,t,n,u);return ge(p,l)}let a=[];for(let p of r){let f=j.isAbsolute(p)?p:j.resolve(t,p),h=null;try{h=await Ie.stat(f)}catch{}if(h?.isFile())n.test(f)&&a.push(j.relative(t,f));else if(h?.isDirectory())a.push(...await de(f,t,n,u));else{let v=(await de(c,t,n,u)).filter(y=>y.replace(/\\/g,"/").includes(p.replace(/\\/g,"/")));v.length>0?a.push(...v):console.warn(`\u26A0\uFE0F No matches found for: ${p}`)}}return ge([...new Set(a)],l)}import{spawn as lt}from"child_process";function L(e){return e.replace(/\x1B\[[0-9;]*[a-zA-Z]/g,"")}function ee(e){return typeof e=="number"&&Number.isFinite(e)}function te(e,t){return ee(e)?e.toFixed(t):"Unknown"}function z(e,t){if(!ee(t))return e.dim(te(t,2).padStart(6));let s=t.toFixed(2).padStart(6);return t>=80?e.green(s):t>=50?e.yellow(s):e.red(s)}function Ce(e){let t=L(e),s={testFilesPass:0,testFilesFail:0,testsPass:0,testsFail:0,testsSkip:0,duration:0,heapMb:null,errors:[]},r=t.match(/Test Files\s+(.+)/);if(r){let c=r[1],a=c.match(/(\d+)\s+passed/),p=c.match(/(\d+)\s+failed/);a&&(s.testFilesPass=parseInt(a[1],10)),p&&(s.testFilesFail=parseInt(p[1],10))}let o=t.match(/^\s*Tests\s+(.+)$/m);if(o){let c=o[1],a=c.match(/(\d+)\s+passed/),p=c.match(/(\d+)\s+failed/),f=c.match(/(\d+)\s+skipped/);a&&(s.testsPass=parseInt(a[1],10)),p&&(s.testsFail=parseInt(p[1],10)),f&&(s.testsSkip=parseInt(f[1],10))}let n=t.match(/Duration\s+([\d.]+)s/);n&&(s.duration=parseFloat(n[1])*1e3);let l=t.match(/(\d+)\s*MB\s+heap\s+used/i);l&&(s.heapMb=parseInt(l[1],10));let u=e.indexOf("Failed Tests");if(u!==-1){let c=e.indexOf(`
|
|
82
|
+
Test Files`,u),a=c!==-1?e.substring(u,c):e.substring(u),p=/FAIL\s*(?:\x1B\[[0-9;]*[a-zA-Z]|\s)*tests\//g,f=[...a.matchAll(p)];for(let h=0;h<f.length;h++){let b=f[h].index,v=a.lastIndexOf(`
|
|
83
|
+
`,b),y=v===-1?0:v,S=h<f.length-1?f[h+1].index:a.length,d=a.lastIndexOf(`
|
|
84
|
+
`,S),T=d===-1?S:d,P=a.substring(y,T).trim();P&&s.errors.push(P)}}return s}function Ne(e){let s=e.join(`
|
|
81
85
|
`).split(`
|
|
82
|
-
`),r=new Map,
|
|
83
|
-
`)}function
|
|
84
|
-
${
|
|
85
|
-
${
|
|
86
|
-
`)}}}var
|
|
87
|
-
${"=".repeat(80)}`),console.log(
|
|
88
|
-
${
|
|
89
|
-
${"=".repeat(80)}`)}}function
|
|
90
|
-
`),
|
|
91
|
-
`).trimEnd()){let
|
|
86
|
+
`),r=new Map,o=new Map;s.forEach((l,u)=>{if(l.includes("FAIL")&&l.includes("Config:")){o.set(l,u);let a=L(l).match(/^(.+Config:\s+)'*([^'>]+)'*(.+)$/);if(a){let[,p,f,h]=a,b=`${p.trim()}|||${h.trim()}`;r.has(b)||r.set(b,{lines:[],configs:[]}),r.get(b).lines.push(l),r.get(b).configs.push(f.replace(/'/g,""))}}});let n=new Set;for(let[,l]of r.entries())if(l.configs.length>1){for(let f=1;f<l.lines.length;f++){let h=o.get(l.lines[f]);n.add(h)}let u=l.lines[0],c=`[${l.configs.map(f=>`'${f}'`).join(",")}]`,a=L(u).replace(/(Config:\s+)'*[^'>]+'*/,`$1${c}`),p=o.get(u);s[p]=a}return s.filter((l,u)=>!n.has(u)).join(`
|
|
87
|
+
`)}function Le({maxOldSpaceMb:e,conditions:t=[],base:s=process.env.NODE_OPTIONS??""}){let r=s;for(let o of t){let n=`--conditions=${o}`;r.includes(n)||(r=r?`${r} ${n}`:n)}if(e&&!r.includes("--max-old-space-size")){let o=`--max-old-space-size=${e}`;r=r?`${r} ${o}`:o}return r.trim()}function at({maxOldSpaceMb:e,conditions:t=[],nodeEnv:s="development",extraEnv:r={}}){let o={...process.env};o.NODE_ENV||(o.NODE_ENV=s);let n=Le({maxOldSpaceMb:e,conditions:t,base:o.NODE_OPTIONS??""});return n&&(o.NODE_OPTIONS=n),Object.assign(o,r),o}function Ct(e,t){return[e,...t?["--config",t]:[],"run"]}function he(e,t){let{cwd:s,vitestBin:r,vitestConfig:o,maxOldSpaceMb:n,conditions:l=[],nodeEnv:u="development",vitestArgs:c=[],streamOutput:a=!0,excludePaths:p=[],extraEnv:f={}}=t;return new Promise(h=>{let b=Date.now(),v=p.flatMap(w=>["--exclude",w]),y=[...Ct(r,o),...c,...v,e],S=at({maxOldSpaceMb:n,conditions:l,nodeEnv:u,extraEnv:f}),d=lt(process.execPath,y,{cwd:s,stdio:["ignore","pipe","pipe"],env:S}),T="",P="";d.stdout?.on("data",w=>{T+=w.toString(),a&&process.stdout.write(w)}),d.stderr?.on("data",w=>{P+=w.toString(),a&&process.stderr.write(w)}),d.on("close",w=>{let g=Date.now()-b,V=`${T}
|
|
88
|
+
${P}`,M=Ce(V);h({file:e,code:w??1,duration:M.duration>0?M.duration:g,testFilesPass:M.testFilesPass,testFilesFail:M.testFilesFail,testsPass:M.testsPass,testsFail:M.testsFail,testsSkip:M.testsSkip,heapMb:M.heapMb,errors:M.errors,rawOutput:V})}),d.on("error",w=>{h({file:e,code:1,duration:Date.now()-b,testFilesPass:0,testFilesFail:1,testsPass:0,testsFail:0,testsSkip:0,heapMb:null,errors:[w.message],rawOutput:w.toString()})})})}function _e(e,t){let{cwd:s,vitestBin:r,vitestConfig:o,maxOldSpaceMb:n,conditions:l=[],nodeEnv:u="development",extraCoverageArgs:c=[],quietOutput:a=!1}=t;return new Promise(p=>{let f=o?["--config",o]:[],h=a?["--color"]:[],b=[r,...f,"--mergeReports",e,"--run","--coverage",...h,...c],v=at({maxOldSpaceMb:n,conditions:l,nodeEnv:u}),y=lt(process.execPath,b,{cwd:s,stdio:a?["ignore","pipe","pipe"]:"inherit",env:v}),S="",d="";a&&(y.stdout?.on("data",T=>S+=T.toString()),y.stderr?.on("data",T=>d+=T.toString())),y.on("close",T=>p({exitCode:T??1,output:`${S}
|
|
89
|
+
${d}`})),y.on("error",()=>p({exitCode:1,output:""}))})}import q from"chalk";function se(e){let t=Math.max(0,Math.floor(e/1e3)),s=Math.floor(t/3600),r=Math.floor(t%3600/60),o=t%60;return s>0?`${s}:${r.toString().padStart(2,"0")}:${o.toString().padStart(2,"0")}`:`${r}:${o.toString().padStart(2,"0")}`}function Ve(e){let t=!!process.stdout.isTTY,s=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],r=26,o=Date.now(),n=0,l=0,u=0,c=0,a=0,p=0,f=null;function h(){let S=e===0?100:n/e*100,d=Date.now()-o,P=(n>0?d/n:0)*Math.max(e-n,0),w=Math.round(S/100*r),g=s[c%s.length],V=`[${"=".repeat(w)}${"-".repeat(Math.max(0,r-w))}]`,M=S.toFixed(1).padStart(5);return S<30?M=q.red(M+"%"):S<70?M=q.rgb(255,136,0)(M+"%"):S>99?M=q.green(M+"%"):M=q.yellow(M+"%"),t?`${q.green(g)} ${q.green(V)} ${q.bold(M)} ${n}/${e} | active ${l} | failed ${u} | ETA ${se(P)} | elapsed ${se(d)}`:`progress ${S.toFixed(1)}% ${n}/${e} | active ${l} | failed ${u} | eta ${se(P)} | elapsed ${se(d)}`}function b(S=!1){let d=h();if(c++,t){let P=d.replace(/\x1B\[[0-9;]*[a-zA-Z]/g,"").length;a=Math.max(a,P),process.stdout.write(`\r${d.padEnd(a," ")}`);return}let T=Date.now();(S||T-p>=2e3)&&(console.log(d),p=T)}function v(){!t||f||(f=setInterval(()=>{n>=e&&l===0||b()},120),f.unref?.())}function y(){f&&(clearInterval(f),f=null)}return b(!0),v(),{onStart(){l++,b()},onComplete(S){l=Math.max(0,l-1),n++,S&&u++,b(!0)},finish(){y(),b(!0),t&&process.stdout.write(`
|
|
90
|
+
`)}}}var Be={onStart(){},onComplete(e){},finish(){}};import ct from"fs/promises";import oe from"path";import O from"chalk";function We(e){if(e.length!==0){console.log(`
|
|
91
|
+
${"=".repeat(80)}`),console.log(O.bold.red("\u2716 FAILED TEST FILES (VERBOSE OUTPUT)")),console.log("=".repeat(80));for(let t of e)console.log(`
|
|
92
|
+
${O.red("\u2716")} ${O.red(t.file)} ${O.dim(`(exit ${t.code})`)}`),t.rawOutput?.trim()?console.log(t.rawOutput.trimEnd()):console.log(O.dim("(no child output captured)"));console.log(`
|
|
93
|
+
${"=".repeat(80)}`)}}function Ue(e,t){if(e===0){let s="% Coverage report from v8",r=t.split(`
|
|
94
|
+
`),o=r.findIndex(n=>L(n).includes(s));if(o>=0){let n=r.length;for(let u=o+1;u<r.length;u++){let c=L(r[u]).trimStart();if(c.startsWith("stderr |")||c.startsWith("stdout |")){n=u;break}}if(r.slice(o+1,n).join(`
|
|
95
|
+
`).trimEnd()){let u=r.slice(o,n).join(`
|
|
92
96
|
`).trimEnd();console.log(`
|
|
93
|
-
${
|
|
94
|
-
`)}}}else{let s=
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
\u2705 PASSED (${et}s${Tt})
|
|
97
|
+
${u}
|
|
98
|
+
`)}}}else{let s=t.trimEnd();s&&console.error(s)}}function Nt(e){let t=(o,n)=>n===0?100:parseFloat((o/n*100).toFixed(2)),s={total:{statements:{total:0,covered:0,pct:0},branches:{total:0,covered:0,pct:0},functions:{total:0,covered:0,pct:0},lines:{total:0,covered:0,pct:0}}};for(let[o,n]of Object.entries(e)){let l=Object.keys(n.s??{}),u=l.length,c=l.filter(d=>n.s[d]>0).length,a=Object.keys(n.f??{}),p=a.length,f=a.filter(d=>n.f[d]>0).length,h=0,b=0;for(let d of Object.values(n.b??{}))h+=d.length,b+=d.filter(T=>T>0).length;let v=new Set,y=new Set;for(let[d,T]of Object.entries(n.statementMap??{})){let P=T?.start?.line;P!=null&&(y.add(P),(n.s??{})[d]>0&&v.add(P))}let S={statements:{total:u,covered:c,pct:t(c,u)},branches:{total:h,covered:b,pct:t(b,h)},functions:{total:p,covered:f,pct:t(f,p)},lines:{total:y.size,covered:v.size,pct:t(v.size,y.size)}};s[o]=S;for(let d of["statements","branches","functions","lines"])s.total[d].total+=S[d].total,s.total[d].covered+=S[d].covered}let r=Object.keys(e).length>0;for(let o of["statements","branches","functions","lines"]){let{total:n,covered:l}=s.total[o];s.total[o].pct=r?t(l,n):"Unknown"}return s}function Lt({lines:e,stmts:t,fns:s,branches:r}){let o=[e,t,s,r].filter(ee);return o.length>0?Math.min(...o):null}function pt(e){return e??Number.MAX_VALUE}function _t({lines:e,stmts:t,fns:s,branches:r}){return![e,t,s,r].every(ee)}function Vt({lines:e,stmts:t,fns:s,branches:r}){console.log(`
|
|
99
|
+
${O.bold("Coverage")} ${z(O,e)}% lines ${O.dim("|")} ${z(O,t)}% statements ${O.dim("|")} ${z(O,s)}% functions ${O.dim("|")} ${z(O,r)}% branches`)}async function He(e,t,s=10,r={}){let{silent:o=!1}=r,n=oe.resolve(e,"coverage"),l=t.find(v=>v.startsWith("--coverage.reportsDirectory="));if(l){let v=l.split("=").slice(1).join("=");n=oe.isAbsolute(v)?v:oe.resolve(e,v)}let u;try{let v=await ct.readFile(oe.join(n,"coverage-summary.json"),"utf8");u=JSON.parse(v)}catch{try{let v=await ct.readFile(oe.join(n,"coverage-final.json"),"utf8");u=Nt(JSON.parse(v))}catch{return o||console.log(O.dim(" (no coverage JSON found \u2014 skipping summary)")),null}}let{total:c,...a}=u,p={lines:c.lines?.pct??0,stmts:c.statements?.pct??0,fns:c.functions?.pct??0,branches:c.branches?.pct??0},f=Object.keys(a).length===0&&!Object.values(p).some(ee),h=[],b=0;if(s>0){let v=Object.entries(a).map(([S,d])=>({file:oe.relative(e,S),lines:d.lines?.pct??0,stmts:d.statements?.pct??0,fns:d.functions?.pct??0,branches:d.branches?.pct??0})).map(S=>({row:S,worst:Lt(S)})).filter(({row:S,worst:d})=>_t(S)||d<100).sort((S,d)=>pt(S.worst)-pt(d.worst)),y=v.slice(0,s);o||(console.log(`
|
|
100
|
+
`+O.bold("\u{1F4C9} WORST COVERAGE FILES (lowest metric)")),console.log("-".repeat(80)),y.forEach(({row:{file:S,lines:d,stmts:T,fns:P,branches:w},worst:g})=>{let V=O.dim(`lines ${te(d,0)}% | stmts ${te(T,0)}% | fns ${te(P,0)}% | branches ${te(w,0)}%`);console.log(` ${z(O,g)}% ${O.dim(S)} ${V}`)}),v.length>s&&console.log(O.dim(` ... and ${v.length-s} more files`))),h=y.map(({row:S})=>S),b=v.length}return o||(Vt(p),f&&console.log(O.dim(" No files were measured (the coverage include matched nothing), so every percentage is Unknown and coverage thresholds are skipped."))),{coverageDir:n,total:c,noFilesMeasured:f,worstFiles:h,worstFilesShown:h.length,worstFilesTotal:b,summary:u}}import ce from"fs/promises";import Bt from"fs";import pe from"path";var ut="tmp/vitest-runner",Wt=/^(\d+)-\d+$/;function Ut(e){try{return process.kill(e,0),!0}catch(t){return t.code!=="ESRCH"}}async function ft(e,t){let s=pe.resolve(e,t),r;try{r=await ce.readdir(s,{withFileTypes:!0})}catch{return}for(let o of r){if(!o.isDirectory())continue;let n=o.name.match(Wt);if(!n)continue;let l=parseInt(n[1],10);Ut(l)||await ce.rm(pe.join(s,o.name),{recursive:!0,force:!0}).catch(()=>{})}}async function dt(e,t){let s=pe.resolve(e,t),r=pe.join(s,`${process.pid}-${Date.now()}`);return await ce.mkdir(r,{recursive:!0}),r}async function ze(e,t){let s=pe.join(e,`worker-${t}`);return await ce.mkdir(s,{recursive:!0}),s}async function gt(e){await ce.rm(e,{recursive:!0,force:!0}).catch(()=>{})}function mt(e){try{Bt.rmSync(e,{recursive:!0,force:!0})}catch{}}function ht(e,t,s){let r=e.replace(/\\/g,"/"),o;for(let{pattern:n,heapMb:l}of s)if(r.includes(n)){o=l;break}if(!(o===void 0&&t===void 0))return o===void 0?t:t===void 0?o:Math.max(o,t)}async function vt(e){let t=e.cwd??process.cwd(),s=e.scratchDir??ut,r=e.keepTmp??!1;await ft(t,s);let o=await dt(t,s),n=()=>{mt(o),process.exitCode=130,process.exit()};r||(process.once("SIGINT",n),process.once("SIGTERM",n));try{return await Ht(e,o)}finally{process.removeListener("SIGINT",n),process.removeListener("SIGTERM",n),r||await gt(o)}}async function Ht(e,t){let{cwd:s=process.cwd(),testDir:r,testPatterns:o=[],testListFile:n,testFilePattern:l,vitestArgs:u=[],showErrorDetails:c=!0,coverageQuiet:a=!1,suppressFileOutput:p=!1,suppressPassingFiles:f=!1,topSummary:h=!0,json:b=!1,workers:v=parseInt(process.env.VITEST_WORKERS??"4",10),worstCoverageCount:y=10,blobsDir:S,mergeReports:d=!0,earlyRunPatterns:T=[],exclude:P=[],perFileHeapOverrides:w=[],conditions:g=[],nodeEnv:V="development",_testResultsOverride:M=null}=e,Ge=0,B=e.maxOldSpaceMb??(process.env.VITEST_HEAP_MB?parseInt(process.env.VITEST_HEAP_MB,10):void 0),k=!b,bt=ke(s,"vitest","vitest"),St=await De(s,e.vitestConfig),Se={cwd:s,vitestBin:bt,vitestConfig:St,conditions:g,nodeEnv:V},I=[...u];if(a&&!I.some(i=>i==="--coverage"||i.startsWith("--coverage."))&&I.unshift("--coverage"),I.some(i=>i==="--coverage"||i.startsWith("--coverage."))){let i=ve.resolve(s,S??".vitest-coverage-blobs"),m=ve.resolve(s,".vitest-coverage-tmp");await Promise.all([G.rm(i,{recursive:!0,force:!0}),G.rm(m,{recursive:!0,force:!0})]),await Promise.all([G.mkdir(i,{recursive:!0}),G.mkdir(m,{recursive:!0})]);let E=await me({cwd:s,testDir:r,testPatterns:o,testListFile:n,testFilePattern:l,earlyRunPatterns:T,exclude:P}),D=je(E);if(E.length===0){let F=o.length>0?`\u274C No Vitest test files found matching: ${o.join(", ")}`:"\u274C No Vitest test files found";return k&&console.log(F),b?{exitCode:1,mode:"coverage",message:F,options:{cwd:s,testDir:r,testPatterns:o,testListFile:n,workers:v,coverageQuiet:a,suppressFileOutput:p,suppressPassingFiles:f,topSummary:h,vitestArgs:I}}:1}let N=I.filter(F=>F!=="--coverage"&&F.startsWith("--coverage.")),xe=I.filter(F=>F!=="--coverage"&&!F.startsWith("--coverage.")),le=E.filter(F=>T.some(R=>F.replace(/\\/g,"/").includes(R))),Te=E.filter(F=>!T.some(R=>F.replace(/\\/g,"/").includes(R))),Ee=a||p||b,yt=a&&!b;!a&&!p&&k&&(console.log(`
|
|
101
|
+
\u{1F9EA} Running ${E.length} test files for coverage (blob + merge mode)`),console.log(`\u2699\uFE0F Workers: ${v} (${le.length} solo first, then parallel)`),B&&console.log(`\u{1F9E0} Heap limit: ${B} MB`),console.log(""));let ye=yt?Ve(E.length):Be,_=[],Pe=0,et=async F=>{let R=ve.join(i,`run-${Pe}.blob`);Pe++,!Ee&&k&&(console.log(`
|
|
102
|
+
${"=".repeat(80)}`),console.log(`\u25B6\uFE0F ${F}`),console.log("=".repeat(80))),ye.onStart();let U=ve.join(m,`run-${Pe}`),Pt=[...xe,"--coverage",`--coverage.reportsDirectory=${U}`,"--reporter=default","--reporter=blob",`--outputFile=${R}`],Mt=await ze(t,Ge++),H=await he(F,{...Se,maxOldSpaceMb:ht(F,B,w),vitestArgs:Pt,streamOutput:!Ee,excludePaths:D.get(F),extraEnv:{VITEST_RUNNER_TMP:Mt}});if(_.push(H),ye.onComplete(H.code!==0),!Ee&&k){let ot=(H.duration/1e3).toFixed(2);if(H.code===0){let Rt=H.heapMb?` | ${H.heapMb} MB heap`:"";console.log(`
|
|
103
|
+
\u2705 PASSED (${ot}s${Rt})
|
|
101
104
|
`)}else console.log(`
|
|
102
|
-
\u274C FAILED (exit code ${
|
|
103
|
-
`)}};for(let
|
|
104
|
-
${"=".repeat(80)}`),console.log(`\u{1F4CA} Merging ${
|
|
105
|
-
\u{1F9EA} Running ${J.length} test files matching: ${
|
|
106
|
-
\u{1F9EA} Running ${J.length} test files (${
|
|
107
|
-
${"=".repeat(80)}`),console.log(`\u25B6\uFE0F ${i}`),console.log("=".repeat(80)));let
|
|
108
|
-
\u2705 PASSED (${
|
|
105
|
+
\u274C FAILED (exit code ${H.code}, ${ot}s)
|
|
106
|
+
`)}};for(let F of le)await et(F).catch(R=>{k&&console.error(`Error running ${F}:`,R)});let Me=0,Y=new Set;for(;Me<Te.length||Y.size>0;){for(;Me<Te.length&&Y.size<v;){let F=Te[Me++],R=et(F).catch(U=>{k&&console.error(`Error running ${F}:`,U)}).finally(()=>Y.delete(R));Y.add(R)}Y.size>0&&await Promise.race(Y)}ye.finish();let Re=(await G.readdir(i).catch(()=>[])).filter(F=>F.endsWith(".blob"));if(Re.length===0){let F="\u274C No coverage blobs were generated \u2014 coverage report cannot be produced";return k&&console.error(F),b?{exitCode:1,mode:"coverage",message:F,options:{cwd:s,testDir:r,testPatterns:o,testListFile:n,workers:v,coverageQuiet:a,suppressFileOutput:p,suppressPassingFiles:f,topSummary:h,showErrorDetails:c,worstCoverageCount:y,vitestArgs:I},totals:{testFiles:E.length,failedFiles:_.filter(R=>R.code!==0).length,passedFiles:_.filter(R=>R.code===0).length},results:{all:_,failed:_.filter(R=>R.code!==0)},merge:{blobFiles:0,exitCode:1,output:""},coverageSummary:null}:1}let fe=0,Oe="",tt=null;d&&(!a&&!p&&k&&(console.log(`
|
|
107
|
+
${"=".repeat(80)}`),console.log(`\u{1F4CA} Merging ${Re.length} coverage blobs into final report...`),console.log("=".repeat(80))),{exitCode:fe,output:Oe}=await _e(i,{...Se,maxOldSpaceMb:B,extraCoverageArgs:N,quietOutput:a||b}),a&&k&&Ue(fe,Oe),tt=await He(s,N,y,{silent:b})),await Promise.all([...d?[G.rm(i,{recursive:!0,force:!0}).catch(()=>{})]:[],G.rm(m,{recursive:!0,force:!0}).catch(()=>{})]);let ae=_.filter(F=>F.code!==0);a&&k&&We(ae);let st=ae.length>0?1:fe;if(b){let F=_.filter(R=>R.heapMb!==null);return{exitCode:st,mode:"coverage",options:{cwd:s,testDir:r,testPatterns:o,testListFile:n,workers:v,coverageQuiet:a,suppressFileOutput:p,suppressPassingFiles:f,topSummary:h,showErrorDetails:c,worstCoverageCount:y,vitestArgs:I},totals:{testFiles:E.length,failedFiles:ae.length,passedFiles:_.length-ae.length},results:{all:_,failed:ae},merge:{blobFiles:Re.length,exitCode:fe,output:Oe},coverageSummary:tt,...h?{topMemoryUsers:[...F].sort((R,U)=>U.heapMb-R.heapMb).slice(0,10),topDuration:[..._].sort((R,U)=>U.duration-R.duration).slice(0,10)}:{}}}return st}let J=await me({cwd:s,testDir:r,testPatterns:o,testListFile:n,testFilePattern:l,earlyRunPatterns:T,exclude:P}),$t=je(J);if(J.length===0){let i=o.length>0?`\u274C No Vitest test files found matching: ${o.join(", ")}`:"\u274C No Vitest test files found";return k&&console.log(i),b?{exitCode:1,mode:"standard",message:i,options:{cwd:s,testDir:r,testPatterns:o,testListFile:n,workers:v,coverageQuiet:a,suppressFileOutput:p,suppressPassingFiles:f,topSummary:h,vitestArgs:I}}:1}let Je=J.filter(i=>T.some(m=>i.replace(/\\/g,"/").includes(m))),$e=J.filter(i=>!T.some(m=>i.replace(/\\/g,"/").includes(m))),wt=Date.now(),Ke=new Date().toLocaleTimeString("en-US",{hour12:!1});k&&!p&&o.length>0?console.log(`
|
|
108
|
+
\u{1F9EA} Running ${J.length} test files matching: ${o.join(", ")}`):k&&!p&&console.log(`
|
|
109
|
+
\u{1F9EA} Running ${J.length} test files (${Je.length} solo first, then parallel)`),k&&!p&&(console.log(`\u2699\uFE0F Workers: ${v}`),B&&console.log(`\u{1F9E0} Heap limit: ${B} MB`),I.length>0&&console.log(`\u{1F527} Vitest args: ${I.join(" ")}`),console.log(""));let A=[...M??[]],Qe=async i=>{!p&&k&&(console.log(`
|
|
110
|
+
${"=".repeat(80)}`),console.log(`\u25B6\uFE0F ${i}`),console.log("=".repeat(80)));let m=await ze(t,Ge++),E=await he(i,{...Se,maxOldSpaceMb:ht(i,B,w),vitestArgs:I,streamOutput:!p&&!b,excludePaths:$t.get(i),extraEnv:{VITEST_RUNNER_TMP:m}});if(!p&&k){let D=(E.duration/1e3).toFixed(2);if(E.code===0){let N=E.heapMb?` | ${E.heapMb} MB heap`:"";console.log(`
|
|
111
|
+
\u2705 PASSED (${D}s${N})
|
|
109
112
|
`)}else console.log(`
|
|
110
|
-
\u274C FAILED (exit code ${
|
|
111
|
-
`)}return
|
|
112
|
-
`+"=".repeat(80)),
|
|
113
|
-
`+$.bold("\u{1F9E0} TOP MEMORY USERS")),console.log("-".repeat(80)),[...C].sort((i,
|
|
114
|
-
`+$.bold("\u23F1\uFE0F TOP DURATION")),console.log("-".repeat(80)),[...
|
|
115
|
-
`+"=".repeat(80)),console.log($.bold.green("\u2713 PASSED TEST FILES")),console.log("=".repeat(80)),
|
|
116
|
-
`+$.bold("=".repeat(80))),
|
|
117
|
-
\u274C ${
|
|
118
|
-
Failed Test Files:`)),
|
|
119
|
-
`).map(
|
|
120
|
-
`);console.log(
|
|
121
|
-
\u2705 All ${
|
|
122
|
-
`),0)}var
|
|
113
|
+
\u274C FAILED (exit code ${E.code}, ${D}s)
|
|
114
|
+
`)}return E};if(!M){for(let E of Je){let D=await Qe(E).catch(N=>(k&&console.error(`Error running ${E}:`,N),null));D&&A.push(D)}let i=0,m=new Set;for(;i<$e.length||m.size>0;){for(;i<$e.length&&m.size<v;){let E=$e[i++],D=Qe(E).then(N=>A.push(N)).catch(N=>{k&&console.error(`Error running ${E}:`,N)}).finally(()=>m.delete(D));m.add(D)}m.size>0&&await Promise.race(m)}}let K=A.reduce((i,m)=>i+m.testFilesPass,0),W=A.reduce((i,m)=>i+m.testFilesFail,0),re=A.reduce((i,m)=>i+m.testsPass,0),ne=A.reduce((i,m)=>i+m.testsFail,0),ie=A.reduce((i,m)=>i+(m.testsSkip||0),0),Ft=A.reduce((i,m)=>i+m.duration,0),Q=A.filter(i=>i.code!==0),ue=A.filter(i=>i.code===0),xt=Q.length>0?1:0,Ye=process.memoryUsage(),we=Math.round(Ye.heapUsed/1024/1024),Fe=Math.round(Ye.rss/1024/1024),C=A.filter(i=>i.heapMb!==null),Ze=((Date.now()-wt)/1e3).toFixed(2),Xe=(Ft/1e3).toFixed(2);if(b)return{exitCode:xt,mode:"standard",options:{cwd:s,testDir:r,testPatterns:o,testListFile:n,workers:v,coverageQuiet:a,suppressFileOutput:p,suppressPassingFiles:f,topSummary:h,showErrorDetails:c,worstCoverageCount:y,vitestArgs:I},totals:{testFilesPass:K,testFilesFail:W,testsPass:re,testsFail:ne,testsSkip:ie,totalTests:re+ne+ie},timing:{startAt:Ke,wallClockSeconds:Number(Ze),testsSeconds:Number(Xe)},heap:{scriptHeapMb:we,scriptRssMb:Fe,maxHeapMb:C.length>0?Math.max(...C.map(i=>i.heapMb)):null,avgHeapMb:C.length>0?Number((C.reduce((i,m)=>i+m.heapMb,0)/C.length).toFixed(0)):null},results:{all:A,passed:ue,failed:Q},...h?{topMemoryUsers:[...C].sort((i,m)=>m.heapMb-i.heapMb).slice(0,10),topDuration:[...A].sort((i,m)=>m.duration-i.duration).slice(0,10)}:{}};console.log(`
|
|
115
|
+
`+"=".repeat(80)),h&&C.length>0&&(console.log(`
|
|
116
|
+
`+$.bold("\u{1F9E0} TOP MEMORY USERS")),console.log("-".repeat(80)),[...C].sort((i,m)=>m.heapMb-i.heapMb).slice(0,10).forEach(i=>{console.log(` ${String(i.heapMb).padStart(4)} MB ${$.dim(i.file)}`)})),h&&A.length>0&&(console.log(`
|
|
117
|
+
`+$.bold("\u23F1\uFE0F TOP DURATION")),console.log("-".repeat(80)),[...A].sort((i,m)=>m.duration-i.duration).slice(0,10).forEach(i=>{let m=(i.duration/1e3).toFixed(2);console.log(` ${(m+"s").padStart(8)} ${$.dim(i.file)}`)})),ue.length>0&&!f&&(console.log(`
|
|
118
|
+
`+"=".repeat(80)),console.log($.bold.green("\u2713 PASSED TEST FILES")),console.log("=".repeat(80)),ue.forEach(i=>{let m=(i.duration/1e3).toFixed(2),E=[...i.heapMb?[`${i.heapMb} MB`]:[],`${m}s`],D=i.testsPass>0?` - ${i.testsPass} tests`:"";console.log($.green(`\u2713 ${i.file}${D}`)+$.dim(` (${E.join(", ")})`))})),console.log(`
|
|
119
|
+
`+$.bold("=".repeat(80))),Q.length>0&&(console.log(`
|
|
120
|
+
\u274C ${Q.length} test file(s) failed`),console.log($.bold.red(`
|
|
121
|
+
Failed Test Files:`)),Q.forEach(i=>{let m=(i.duration/1e3).toFixed(2),E=[...i.testsFail>0?[$.red(`${i.testsFail} failed`)]:[],...i.testsPass>0?[$.green(`${i.testsPass} passed`)]:[],...i.testsSkip>0?[$.yellow(`${i.testsSkip} skipped`)]:[]],D=[...i.heapMb?[`${i.heapMb} MB`]:[],`${m}s`],N=E.length>0?` (${E.join(", ")})`:"";if(console.log(` ${$.red("\u2716")} ${i.file}${N}`+$.dim(` [${D.join(", ")}]`)),c&&i.errors.length>0){let xe=Ne(i.errors).split(`
|
|
122
|
+
`).map(le=>le.trim()?` ${le}`:"").join(`
|
|
123
|
+
`);console.log(xe),console.log("")}}),console.log("")),console.log($.bold("=".repeat(80))),W>0&&K>0?console.log(` ${$.bold("Test Files")} ${$.red(`${W} failed`)} ${$.dim("|")} ${$.green(`${K} passed`)} ${$.dim(`(${K+W})`)}`):W>0?console.log(` ${$.bold("Test Files")} ${$.red(`${W} failed`)} ${$.dim(`(${W})`)}`):console.log(` ${$.bold("Test Files")} ${$.green(`${K} passed`)} ${$.dim(`(${K})`)}`);let Tt=re+ne+ie,Et=[...ne>0?[$.red(`${ne} failed`)]:[],...re>0?[$.green(`${re} passed`)]:[],...ie>0?[$.yellow(`${ie} skipped`)]:[]];if(console.log(` ${$.bold("Tests")} ${Et.join(` ${$.dim("|")} `)} ${$.dim(`(${Tt})`)}`),console.log(` ${$.bold("Start at")} ${Ke}`),console.log(` ${$.bold("Duration")} ${Ze}s ${$.dim(`(tests ${Xe}s)`)}`),C.length>0){let i=Math.max(...C.map(E=>E.heapMb)),m=(C.reduce((E,D)=>E+D.heapMb,0)/C.length).toFixed(0);console.log(` ${$.bold("Heap")} max ${i} MB | avg ${m} MB | script ${we} MB (RSS ${Fe} MB)`)}else console.log(` ${$.bold("Heap")} script ${we} MB (RSS ${Fe} MB)`);return Q.length>0?1:(console.log(`
|
|
124
|
+
\u2705 All ${ue.length} test files passed
|
|
125
|
+
`),0)}var x=rt(process.argv.slice(2));x.help&&(nt(),process.exit(0));if((x.coverageQuiet||x.logFile)&&!x.json){let n=function(l){let u=l.toString();return u.startsWith("\r")||/^progress \d+\.\d+%/.test(u)},e=process.cwd(),t=x.logFile?be.isAbsolute(x.logFile)?x.logFile:be.resolve(e,x.logFile):be.join(e,"coverage","coverage-run.log");qt(be.dirname(t),{recursive:!0});let s=zt(t,{flags:"a"}),r=process.stdout.write.bind(process.stdout),o=process.stderr.write.bind(process.stderr);process.stdout.write=(l,u,c)=>(n(l)||s.write(L(l.toString())),r(l,u,c)),process.stderr.write=(l,u,c)=>(n(l)||s.write(L(l.toString())),o(l,u,c)),process.on("exit",()=>s.end())}var Gt=process.cwd(),qe=[...x.vitestPassthroughArgs];x.coverageQuiet&&!qe.some(e=>e==="--coverage"||e.startsWith("--coverage."))&&qe.unshift("--coverage");try{let e=await vt({cwd:Gt,testPatterns:x.testPatterns,testListFile:x.testListFile,testFilePattern:x.testFilePattern,vitestArgs:qe,showErrorDetails:x.showErrorDetails,coverageQuiet:x.coverageQuiet,suppressFileOutput:x.suppressFileOutput,suppressPassingFiles:x.suppressPassingFiles,topSummary:x.topSummary,json:x.json,mergeReports:x.mergeReports,keepTmp:x.keepTmp,...x.blobsDir!==void 0&&{blobsDir:x.blobsDir},...x.workers!==void 0&&{workers:x.workers},...x.soloPatterns.length>0&&{earlyRunPatterns:x.soloPatterns},...x.exclude.length>0&&{exclude:x.exclude},...x.scratchDir!==void 0&&{scratchDir:x.scratchDir}});x.json&&(process.stdout.write(`${JSON.stringify(e,null,2)}
|
|
123
126
|
`),process.exit(typeof e=="object"&&e!==null&&"exitCode"in e?e.exitCode:1)),process.exit(typeof e=="number"?e:1)}catch(e){console.error("Fatal error:",e),process.exit(1)}
|
|
124
127
|
//# sourceMappingURL=vitest-runner.mjs.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,47 +1,46 @@
|
|
|
1
|
-
import
|
|
2
|
-
Test Files`,
|
|
3
|
-
`,
|
|
4
|
-
|
|
1
|
+
import K from"fs/promises";import me from"path";import S from"chalk";import{createRequire as Mt}from"module";import Z from"path";import Et from"fs/promises";import{pathToFileURL as yt}from"url";function Pe(t,e,o=e){let n=Mt(yt(Z.join(t,"package.json"))),s=n.resolve(`${e}/package.json`),r=n(s),c=r.bin?.[o]??r.bin;if(!c)throw new Error(`No bin "${o}" found in ${e}/package.json`);return Z.join(Z.dirname(s),c)}var Pt=Object.freeze(["vitest.config.ts","vitest.config.mts","vitest.config.cts","vitest.config.mjs","vitest.config.js","vitest.config.cjs","vite.config.ts","vite.config.mts","vite.config.mjs","vite.config.js"]);async function Oe(t,e){if(e)return Z.isAbsolute(e)?e:Z.resolve(t,e);for(let o of Pt){let n=Z.join(t,o);try{return await Et.access(n),n}catch{}}}import Ie from"fs/promises";import C from"path";var ot=/\.test\.vitest\.(?:js|mjs|cjs)$/i;function Ot(t){let e=t.replace(/\\/g,"/"),o="";for(let n=0;n<e.length;n++){let s=e[n];s==="*"&&e[n+1]==="*"?(o+=".*",n++):s==="*"?o+="[^/]*":s==="?"?o+="[^/]":o+=s.replace(/[.+^${}()|[\]\\]/g,"\\$&")}return new RegExp(`^${o}$`)}function De(t,e){return!e||e.length===0?!1:e.some(o=>Ot(o).test(t))}async function pe(t,e,o=ot,n=[]){let s=[t],r=[];for(;s.length;){let c=s.pop(),u;try{u=await Ie.readdir(c,{withFileTypes:!0})}catch{continue}for(let f of u){let a=C.relative(e,C.join(c,f.name)).replace(/\\/g,"/");if(f.isDirectory()){if(f.name==="node_modules"||f.name.startsWith(".")||De(a,n)||De(`${a}/`,n))continue;s.push(C.join(c,f.name));continue}if(f.isFile()&&o.test(f.name)){if(De(a,n))continue;r.push(C.relative(e,C.join(c,f.name)))}}}return r}function ue(t,e=[]){let o=[],n=[];for(let s of t){let r=s.replace(/\\/g,"/"),c=e.findIndex(u=>r.includes(u));c!==-1?o.push({file:s,priorityIndex:c}):n.push(s)}return o.sort((s,r)=>s.priorityIndex-r.priorityIndex||s.file.localeCompare(r.file)),n.sort((s,r)=>s.localeCompare(r)),[...o.map(s=>s.file),...n]}function Ae(t){let e=t.map(n=>n.replace(/\\/g,"/")),o=new Map;for(let n=0;n<t.length;n++){let s=[];for(let r=0;r<t.length;r++)n!==r&&e[r].includes(e[n])&&s.push(t[r]);o.set(t[n],s)}return o}async function de(t){let{cwd:e,testDir:o,testPatterns:n=[],testListFile:s,testFilePattern:r=ot,earlyRunPatterns:c=[],exclude:u=[]}=t,f=o?C.isAbsolute(o)?o:C.resolve(e,o):e;if(s){let l=C.isAbsolute(s)?s:C.resolve(e,s),p;try{let m=await Ie.readFile(l,"utf8");p=JSON.parse(m)}catch(m){throw new Error(`Failed to read test list file "${l}": ${m.message}`,{cause:m})}if(!Array.isArray(p))throw new Error(`Test list file "${l}" must contain a JSON array of test file paths`);return console.log(`\u{1F4CB} Loading test list from: ${C.relative(e,l)}`),ue(p,c)}if(n.length===0){let l=await pe(f,e,r,u);return ue(l,c)}let a=[];for(let l of n){let p=C.isAbsolute(l)?l:C.resolve(e,l),m=null;try{m=await Ie.stat(p)}catch{}if(m?.isFile())r.test(p)&&a.push(C.relative(e,p));else if(m?.isDirectory())a.push(...await pe(p,e,r,u));else{let h=(await pe(f,e,r,u)).filter(w=>w.replace(/\\/g,"/").includes(l.replace(/\\/g,"/")));h.length>0?a.push(...h):console.warn(`\u26A0\uFE0F No matches found for: ${l}`)}}return ue([...new Set(a)],c)}import{spawn as je}from"child_process";function L(t){return t.replace(/\x1B\[[0-9;]*[a-zA-Z]/g,"")}function Y(t){return typeof t=="number"&&Number.isFinite(t)}function X(t,e){return Y(t)?t.toFixed(e):"Unknown"}function H(t,e){if(!Y(e))return t.dim(X(e,2).padStart(6));let o=e.toFixed(2).padStart(6);return e>=80?t.green(o):e>=50?t.yellow(o):t.red(o)}function Ce(t){let e=L(t),o={testFilesPass:0,testFilesFail:0,testsPass:0,testsFail:0,testsSkip:0,duration:0,heapMb:null,errors:[]},n=e.match(/Test Files\s+(.+)/);if(n){let f=n[1],a=f.match(/(\d+)\s+passed/),l=f.match(/(\d+)\s+failed/);a&&(o.testFilesPass=parseInt(a[1],10)),l&&(o.testFilesFail=parseInt(l[1],10))}let s=e.match(/^\s*Tests\s+(.+)$/m);if(s){let f=s[1],a=f.match(/(\d+)\s+passed/),l=f.match(/(\d+)\s+failed/),p=f.match(/(\d+)\s+skipped/);a&&(o.testsPass=parseInt(a[1],10)),l&&(o.testsFail=parseInt(l[1],10)),p&&(o.testsSkip=parseInt(p[1],10))}let r=e.match(/Duration\s+([\d.]+)s/);r&&(o.duration=parseFloat(r[1])*1e3);let c=e.match(/(\d+)\s*MB\s+heap\s+used/i);c&&(o.heapMb=parseInt(c[1],10));let u=t.indexOf("Failed Tests");if(u!==-1){let f=t.indexOf(`
|
|
2
|
+
Test Files`,u),a=f!==-1?t.substring(u,f):t.substring(u),l=/FAIL\s*(?:\x1B\[[0-9;]*[a-zA-Z]|\s)*tests\//g,p=[...a.matchAll(l)];for(let m=0;m<p.length;m++){let v=p[m].index,h=a.lastIndexOf(`
|
|
3
|
+
`,v),w=h===-1?0:h,$=m<p.length-1?p[m+1].index:a.length,g=a.lastIndexOf(`
|
|
4
|
+
`,$),x=g===-1?$:g,P=a.substring(w,x).trim();P&&o.errors.push(P)}}return o}function Re(t){let o=t.join(`
|
|
5
5
|
`).split(`
|
|
6
|
-
`),n=new Map,
|
|
7
|
-
`)}function
|
|
8
|
-
${
|
|
9
|
-
${
|
|
10
|
-
`)}}}var
|
|
11
|
-
${"=".repeat(80)}`),console.log(
|
|
12
|
-
${
|
|
13
|
-
${"=".repeat(80)}`)}}function
|
|
14
|
-
`),
|
|
15
|
-
`).trimEnd()){let
|
|
6
|
+
`),n=new Map,s=new Map;o.forEach((c,u)=>{if(c.includes("FAIL")&&c.includes("Config:")){s.set(c,u);let a=L(c).match(/^(.+Config:\s+)'*([^'>]+)'*(.+)$/);if(a){let[,l,p,m]=a,v=`${l.trim()}|||${m.trim()}`;n.has(v)||n.set(v,{lines:[],configs:[]}),n.get(v).lines.push(c),n.get(v).configs.push(p.replace(/'/g,""))}}});let r=new Set;for(let[,c]of n.entries())if(c.configs.length>1){for(let p=1;p<c.lines.length;p++){let m=s.get(c.lines[p]);r.add(m)}let u=c.lines[0],f=`[${c.configs.map(p=>`'${p}'`).join(",")}]`,a=L(u).replace(/(Config:\s+)'*[^'>]+'*/,`$1${f}`),l=s.get(u);o[l]=a}return o.filter((c,u)=>!r.has(u)).join(`
|
|
7
|
+
`)}function ke({maxOldSpaceMb:t,conditions:e=[],base:o=process.env.NODE_OPTIONS??""}){let n=o;for(let s of e){let r=`--conditions=${s}`;n.includes(r)||(n=n?`${n} ${r}`:r)}if(t&&!n.includes("--max-old-space-size")){let s=`--max-old-space-size=${t}`;n=n?`${n} ${s}`:s}return n.trim()}function Ne({maxOldSpaceMb:t,conditions:e=[],nodeEnv:o="development",extraEnv:n={}}){let s={...process.env};s.NODE_ENV||(s.NODE_ENV=o);let r=ke({maxOldSpaceMb:t,conditions:e,base:s.NODE_OPTIONS??""});return r&&(s.NODE_OPTIONS=r),Object.assign(s,n),s}function st(t,e){return[t,...e?["--config",e]:[],"run"]}function ge(t,e){let{cwd:o,vitestBin:n,vitestConfig:s,maxOldSpaceMb:r,conditions:c=[],nodeEnv:u="development",vitestArgs:f=[],streamOutput:a=!0,excludePaths:l=[],extraEnv:p={}}=e;return new Promise(m=>{let v=Date.now(),h=l.flatMap(E=>["--exclude",E]),w=[...st(n,s),...f,...h,t],$=Ne({maxOldSpaceMb:r,conditions:c,nodeEnv:u,extraEnv:p}),g=je(process.execPath,w,{cwd:o,stdio:["ignore","pipe","pipe"],env:$}),x="",P="";g.stdout?.on("data",E=>{x+=E.toString(),a&&process.stdout.write(E)}),g.stderr?.on("data",E=>{P+=E.toString(),a&&process.stderr.write(E)}),g.on("close",E=>{let _=Date.now()-v,N=`${x}
|
|
8
|
+
${P}`,T=Ce(N);m({file:t,code:E??1,duration:T.duration>0?T.duration:_,testFilesPass:T.testFilesPass,testFilesFail:T.testFilesFail,testsPass:T.testsPass,testsFail:T.testsFail,testsSkip:T.testsSkip,heapMb:T.heapMb,errors:T.errors,rawOutput:N})}),g.on("error",E=>{m({file:t,code:1,duration:Date.now()-v,testFilesPass:0,testFilesFail:1,testsPass:0,testsFail:0,testsSkip:0,heapMb:null,errors:[E.message],rawOutput:E.toString()})})})}function Dt(t){let{cwd:e,vitestBin:o,vitestConfig:n,maxOldSpaceMb:s,conditions:r=[],nodeEnv:c="development",vitestArgs:u=[]}=t;return new Promise(f=>{let a=[...st(o,n),...u],l=Ne({maxOldSpaceMb:s,conditions:r,nodeEnv:c}),p=je(process.execPath,a,{cwd:e,stdio:"inherit",env:l});p.on("close",m=>f(m??1)),p.on("error",()=>f(1))})}function Le(t,e){let{cwd:o,vitestBin:n,vitestConfig:s,maxOldSpaceMb:r,conditions:c=[],nodeEnv:u="development",extraCoverageArgs:f=[],quietOutput:a=!1}=e;return new Promise(l=>{let p=s?["--config",s]:[],m=a?["--color"]:[],v=[n,...p,"--mergeReports",t,"--run","--coverage",...m,...f],h=Ne({maxOldSpaceMb:r,conditions:c,nodeEnv:u}),w=je(process.execPath,v,{cwd:o,stdio:a?["ignore","pipe","pipe"]:"inherit",env:h}),$="",g="";a&&(w.stdout?.on("data",x=>$+=x.toString()),w.stderr?.on("data",x=>g+=x.toString())),w.on("close",x=>l({exitCode:x??1,output:`${$}
|
|
9
|
+
${g}`})),w.on("error",()=>l({exitCode:1,output:""}))})}import W from"chalk";function ee(t){let e=Math.max(0,Math.floor(t/1e3)),o=Math.floor(e/3600),n=Math.floor(e%3600/60),s=e%60;return o>0?`${o}:${n.toString().padStart(2,"0")}:${s.toString().padStart(2,"0")}`:`${n}:${s.toString().padStart(2,"0")}`}function _e(t){let e=!!process.stdout.isTTY,o=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"],n=26,s=Date.now(),r=0,c=0,u=0,f=0,a=0,l=0,p=null;function m(){let $=t===0?100:r/t*100,g=Date.now()-s,P=(r>0?g/r:0)*Math.max(t-r,0),E=Math.round($/100*n),_=o[f%o.length],N=`[${"=".repeat(E)}${"-".repeat(Math.max(0,n-E))}]`,T=$.toFixed(1).padStart(5);return $<30?T=W.red(T+"%"):$<70?T=W.rgb(255,136,0)(T+"%"):$>99?T=W.green(T+"%"):T=W.yellow(T+"%"),e?`${W.green(_)} ${W.green(N)} ${W.bold(T)} ${r}/${t} | active ${c} | failed ${u} | ETA ${ee(P)} | elapsed ${ee(g)}`:`progress ${$.toFixed(1)}% ${r}/${t} | active ${c} | failed ${u} | eta ${ee(P)} | elapsed ${ee(g)}`}function v($=!1){let g=m();if(f++,e){let P=g.replace(/\x1B\[[0-9;]*[a-zA-Z]/g,"").length;a=Math.max(a,P),process.stdout.write(`\r${g.padEnd(a," ")}`);return}let x=Date.now();($||x-l>=2e3)&&(console.log(g),l=x)}function h(){!e||p||(p=setInterval(()=>{r>=t&&c===0||v()},120),p.unref?.())}function w(){p&&(clearInterval(p),p=null)}return v(!0),h(),{onStart(){c++,v()},onComplete($){c=Math.max(0,c-1),r++,$&&u++,v(!0)},finish(){w(),v(!0),e&&process.stdout.write(`
|
|
10
|
+
`)}}}var Be={onStart(){},onComplete(t){},finish(){}};import nt from"fs/promises";import te from"path";import y from"chalk";function Ve(t){if(t.length!==0){console.log(`
|
|
11
|
+
${"=".repeat(80)}`),console.log(y.bold.red("\u2716 FAILED TEST FILES (VERBOSE OUTPUT)")),console.log("=".repeat(80));for(let e of t)console.log(`
|
|
12
|
+
${y.red("\u2716")} ${y.red(e.file)} ${y.dim(`(exit ${e.code})`)}`),e.rawOutput?.trim()?console.log(e.rawOutput.trimEnd()):console.log(y.dim("(no child output captured)"));console.log(`
|
|
13
|
+
${"=".repeat(80)}`)}}function Ue(t,e){if(t===0){let o="% Coverage report from v8",n=e.split(`
|
|
14
|
+
`),s=n.findIndex(r=>L(r).includes(o));if(s>=0){let r=n.length;for(let u=s+1;u<n.length;u++){let f=L(n[u]).trimStart();if(f.startsWith("stderr |")||f.startsWith("stdout |")){r=u;break}}if(n.slice(s+1,r).join(`
|
|
15
|
+
`).trimEnd()){let u=n.slice(s,r).join(`
|
|
16
16
|
`).trimEnd();console.log(`
|
|
17
|
-
${
|
|
18
|
-
`)}}}else{let
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
\u2705 PASSED (${Ye}s${Ft})
|
|
17
|
+
${u}
|
|
18
|
+
`)}}}else{let o=e.trimEnd();o&&console.error(o)}}function It(t){let e=(s,r)=>r===0?100:parseFloat((s/r*100).toFixed(2)),o={total:{statements:{total:0,covered:0,pct:0},branches:{total:0,covered:0,pct:0},functions:{total:0,covered:0,pct:0},lines:{total:0,covered:0,pct:0}}};for(let[s,r]of Object.entries(t)){let c=Object.keys(r.s??{}),u=c.length,f=c.filter(g=>r.s[g]>0).length,a=Object.keys(r.f??{}),l=a.length,p=a.filter(g=>r.f[g]>0).length,m=0,v=0;for(let g of Object.values(r.b??{}))m+=g.length,v+=g.filter(x=>x>0).length;let h=new Set,w=new Set;for(let[g,x]of Object.entries(r.statementMap??{})){let P=x?.start?.line;P!=null&&(w.add(P),(r.s??{})[g]>0&&h.add(P))}let $={statements:{total:u,covered:f,pct:e(f,u)},branches:{total:m,covered:v,pct:e(v,m)},functions:{total:l,covered:p,pct:e(p,l)},lines:{total:w.size,covered:h.size,pct:e(h.size,w.size)}};o[s]=$;for(let g of["statements","branches","functions","lines"])o.total[g].total+=$[g].total,o.total[g].covered+=$[g].covered}let n=Object.keys(t).length>0;for(let s of["statements","branches","functions","lines"]){let{total:r,covered:c}=o.total[s];o.total[s].pct=n?e(c,r):"Unknown"}return o}function At({lines:t,stmts:e,fns:o,branches:n}){let s=[t,e,o,n].filter(Y);return s.length>0?Math.min(...s):null}function rt(t){return t??Number.MAX_VALUE}function Ct({lines:t,stmts:e,fns:o,branches:n}){return![t,e,o,n].every(Y)}function Rt({lines:t,stmts:e,fns:o,branches:n}){console.log(`
|
|
19
|
+
${y.bold("Coverage")} ${H(y,t)}% lines ${y.dim("|")} ${H(y,e)}% statements ${y.dim("|")} ${H(y,o)}% functions ${y.dim("|")} ${H(y,n)}% branches`)}async function ze(t,e,o=10,n={}){let{silent:s=!1}=n,r=te.resolve(t,"coverage"),c=e.find(h=>h.startsWith("--coverage.reportsDirectory="));if(c){let h=c.split("=").slice(1).join("=");r=te.isAbsolute(h)?h:te.resolve(t,h)}let u;try{let h=await nt.readFile(te.join(r,"coverage-summary.json"),"utf8");u=JSON.parse(h)}catch{try{let h=await nt.readFile(te.join(r,"coverage-final.json"),"utf8");u=It(JSON.parse(h))}catch{return s||console.log(y.dim(" (no coverage JSON found \u2014 skipping summary)")),null}}let{total:f,...a}=u,l={lines:f.lines?.pct??0,stmts:f.statements?.pct??0,fns:f.functions?.pct??0,branches:f.branches?.pct??0},p=Object.keys(a).length===0&&!Object.values(l).some(Y),m=[],v=0;if(o>0){let h=Object.entries(a).map(([$,g])=>({file:te.relative(t,$),lines:g.lines?.pct??0,stmts:g.statements?.pct??0,fns:g.functions?.pct??0,branches:g.branches?.pct??0})).map($=>({row:$,worst:At($)})).filter(({row:$,worst:g})=>Ct($)||g<100).sort(($,g)=>rt($.worst)-rt(g.worst)),w=h.slice(0,o);s||(console.log(`
|
|
20
|
+
`+y.bold("\u{1F4C9} WORST COVERAGE FILES (lowest metric)")),console.log("-".repeat(80)),w.forEach(({row:{file:$,lines:g,stmts:x,fns:P,branches:E},worst:_})=>{let N=y.dim(`lines ${X(g,0)}% | stmts ${X(x,0)}% | fns ${X(P,0)}% | branches ${X(E,0)}%`);console.log(` ${H(y,_)}% ${y.dim($)} ${N}`)}),h.length>o&&console.log(y.dim(` ... and ${h.length-o} more files`))),m=w.map(({row:$})=>$),v=h.length}return s||(Rt(l),p&&console.log(y.dim(" No files were measured (the coverage include matched nothing), so every percentage is Unknown and coverage thresholds are skipped."))),{coverageDir:r,total:f,noFilesMeasured:p,worstFiles:m,worstFilesShown:m.length,worstFilesTotal:v,summary:u}}import ae from"fs/promises";import it from"fs";import oe from"path";var ct="tmp/vitest-runner",kt=/^(\d+)-\d+$/;function jt(t){try{return process.kill(t,0),!0}catch(e){return e.code!=="ESRCH"}}function Nt(t){return String(t).replace(/[^a-zA-Z0-9_-]+/g,"-").slice(0,80)||"scratch"}async function at(t,e){let o=oe.resolve(t,e),n;try{n=await ae.readdir(o,{withFileTypes:!0})}catch{return}for(let s of n){if(!s.isDirectory())continue;let r=s.name.match(kt);if(!r)continue;let c=parseInt(r[1],10);jt(c)||await ae.rm(oe.join(o,s.name),{recursive:!0,force:!0}).catch(()=>{})}}async function lt(t,e){let o=oe.resolve(t,e),n=oe.join(o,`${process.pid}-${Date.now()}`);return await ae.mkdir(n,{recursive:!0}),n}async function He(t,e){let o=oe.join(t,`worker-${e}`);return await ae.mkdir(o,{recursive:!0}),o}async function ft(t){await ae.rm(t,{recursive:!0,force:!0}).catch(()=>{})}function pt(t){try{it.rmSync(t,{recursive:!0,force:!0})}catch{}}function Lt(t){let e=process.env.VITEST_RUNNER_TMP;if(!e)throw new Error("makeRunTmpDir() requires VITEST_RUNNER_TMP to be set \u2014 call it from a test file run by vitest-runner.");return it.mkdtempSync(oe.join(e,`${Nt(t)}-`))}function ut(t,e,o){let n=t.replace(/\\/g,"/"),s;for(let{pattern:r,heapMb:c}of o)if(n.includes(r)){s=c;break}if(!(s===void 0&&e===void 0))return s===void 0?e:e===void 0?s:Math.max(s,e)}async function yo(t){let e=t.cwd??process.cwd(),o=t.scratchDir??ct,n=t.keepTmp??!1;await at(e,o);let s=await lt(e,o),r=()=>{pt(s),process.exitCode=130,process.exit()};n||(process.once("SIGINT",r),process.once("SIGTERM",r));try{return await _t(t,s)}finally{process.removeListener("SIGINT",r),process.removeListener("SIGTERM",r),n||await ft(s)}}async function _t(t,e){let{cwd:o=process.cwd(),testDir:n,testPatterns:s=[],testListFile:r,testFilePattern:c,vitestArgs:u=[],showErrorDetails:f=!0,coverageQuiet:a=!1,suppressFileOutput:l=!1,suppressPassingFiles:p=!1,topSummary:m=!0,json:v=!1,workers:h=parseInt(process.env.VITEST_WORKERS??"4",10),worstCoverageCount:w=10,blobsDir:$,mergeReports:g=!0,earlyRunPatterns:x=[],exclude:P=[],perFileHeapOverrides:E=[],conditions:_=[],nodeEnv:N="development",_testResultsOverride:T=null}=t,We=0,B=t.maxOldSpaceMb??(process.env.VITEST_HEAP_MB?parseInt(process.env.VITEST_HEAP_MB,10):void 0),O=!v,dt=Pe(o,"vitest","vitest"),gt=await Oe(o,t.vitestConfig),he={cwd:o,vitestBin:dt,vitestConfig:gt,conditions:_,nodeEnv:N},A=[...u];if(a&&!A.some(i=>i==="--coverage"||i.startsWith("--coverage."))&&A.unshift("--coverage"),A.some(i=>i==="--coverage"||i.startsWith("--coverage."))){let i=me.resolve(o,$??".vitest-coverage-blobs"),d=me.resolve(o,".vitest-coverage-tmp");await Promise.all([K.rm(i,{recursive:!0,force:!0}),K.rm(d,{recursive:!0,force:!0})]),await Promise.all([K.mkdir(i,{recursive:!0}),K.mkdir(d,{recursive:!0})]);let F=await de({cwd:o,testDir:n,testPatterns:s,testListFile:r,testFilePattern:c,earlyRunPatterns:x,exclude:P}),D=Ae(F);if(F.length===0){let b=s.length>0?`\u274C No Vitest test files found matching: ${s.join(", ")}`:"\u274C No Vitest test files found";return O&&console.log(b),v?{exitCode:1,mode:"coverage",message:b,options:{cwd:o,testDir:n,testPatterns:s,testListFile:r,workers:h,coverageQuiet:a,suppressFileOutput:l,suppressPassingFiles:p,topSummary:m,vitestArgs:A}}:1}let k=A.filter(b=>b!=="--coverage"&&b.startsWith("--coverage.")),be=A.filter(b=>b!=="--coverage"&&!b.startsWith("--coverage.")),ie=F.filter(b=>x.some(M=>b.replace(/\\/g,"/").includes(M))),Fe=F.filter(b=>!x.some(M=>b.replace(/\\/g,"/").includes(M))),xe=a||l||v,Ft=a&&!v;!a&&!l&&O&&(console.log(`
|
|
21
|
+
\u{1F9EA} Running ${F.length} test files for coverage (blob + merge mode)`),console.log(`\u2699\uFE0F Workers: ${h} (${ie.length} solo first, then parallel)`),B&&console.log(`\u{1F9E0} Heap limit: ${B} MB`),console.log(""));let we=Ft?_e(F.length):Be,j=[],Te=0,Ye=async b=>{let M=me.join(i,`run-${Te}.blob`);Te++,!xe&&O&&(console.log(`
|
|
22
|
+
${"=".repeat(80)}`),console.log(`\u25B6\uFE0F ${b}`),console.log("=".repeat(80))),we.onStart();let U=me.join(d,`run-${Te}`),xt=[...be,"--coverage",`--coverage.reportsDirectory=${U}`,"--reporter=default","--reporter=blob",`--outputFile=${M}`],wt=await He(e,We++),z=await ge(b,{...he,maxOldSpaceMb:ut(b,B,E),vitestArgs:xt,streamOutput:!xe,excludePaths:D.get(b),extraEnv:{VITEST_RUNNER_TMP:wt}});if(j.push(z),we.onComplete(z.code!==0),!xe&&O){let tt=(z.duration/1e3).toFixed(2);if(z.code===0){let Tt=z.heapMb?` | ${z.heapMb} MB heap`:"";console.log(`
|
|
23
|
+
\u2705 PASSED (${tt}s${Tt})
|
|
25
24
|
`)}else console.log(`
|
|
26
|
-
\u274C FAILED (exit code ${
|
|
27
|
-
`)}};for(let
|
|
28
|
-
${"=".repeat(80)}`),console.log(`\u{1F4CA} Merging ${
|
|
29
|
-
\u{1F9EA} Running ${
|
|
30
|
-
\u{1F9EA} Running ${
|
|
31
|
-
${"=".repeat(80)}`),console.log(`\u25B6\uFE0F ${i}`),console.log("=".repeat(80)));let d=await
|
|
25
|
+
\u274C FAILED (exit code ${z.code}, ${tt}s)
|
|
26
|
+
`)}};for(let b of ie)await Ye(b).catch(M=>{O&&console.error(`Error running ${b}:`,M)});let Me=0,Q=new Set;for(;Me<Fe.length||Q.size>0;){for(;Me<Fe.length&&Q.size<h;){let b=Fe[Me++],M=Ye(b).catch(U=>{O&&console.error(`Error running ${b}:`,U)}).finally(()=>Q.delete(M));Q.add(M)}Q.size>0&&await Promise.race(Q)}we.finish();let Ee=(await K.readdir(i).catch(()=>[])).filter(b=>b.endsWith(".blob"));if(Ee.length===0){let b="\u274C No coverage blobs were generated \u2014 coverage report cannot be produced";return O&&console.error(b),v?{exitCode:1,mode:"coverage",message:b,options:{cwd:o,testDir:n,testPatterns:s,testListFile:r,workers:h,coverageQuiet:a,suppressFileOutput:l,suppressPassingFiles:p,topSummary:m,showErrorDetails:f,worstCoverageCount:w,vitestArgs:A},totals:{testFiles:F.length,failedFiles:j.filter(M=>M.code!==0).length,passedFiles:j.filter(M=>M.code===0).length},results:{all:j,failed:j.filter(M=>M.code!==0)},merge:{blobFiles:0,exitCode:1,output:""},coverageSummary:null}:1}let fe=0,ye="",Xe=null;g&&(!a&&!l&&O&&(console.log(`
|
|
27
|
+
${"=".repeat(80)}`),console.log(`\u{1F4CA} Merging ${Ee.length} coverage blobs into final report...`),console.log("=".repeat(80))),{exitCode:fe,output:ye}=await Le(i,{...he,maxOldSpaceMb:B,extraCoverageArgs:k,quietOutput:a||v}),a&&O&&Ue(fe,ye),Xe=await ze(o,k,w,{silent:v})),await Promise.all([...g?[K.rm(i,{recursive:!0,force:!0}).catch(()=>{})]:[],K.rm(d,{recursive:!0,force:!0}).catch(()=>{})]);let ce=j.filter(b=>b.code!==0);a&&O&&Ve(ce);let et=ce.length>0?1:fe;if(v){let b=j.filter(M=>M.heapMb!==null);return{exitCode:et,mode:"coverage",options:{cwd:o,testDir:n,testPatterns:s,testListFile:r,workers:h,coverageQuiet:a,suppressFileOutput:l,suppressPassingFiles:p,topSummary:m,showErrorDetails:f,worstCoverageCount:w,vitestArgs:A},totals:{testFiles:F.length,failedFiles:ce.length,passedFiles:j.length-ce.length},results:{all:j,failed:ce},merge:{blobFiles:Ee.length,exitCode:fe,output:ye},coverageSummary:Xe,...m?{topMemoryUsers:[...b].sort((M,U)=>U.heapMb-M.heapMb).slice(0,10),topDuration:[...j].sort((M,U)=>U.duration-M.duration).slice(0,10)}:{}}}return et}let q=await de({cwd:o,testDir:n,testPatterns:s,testListFile:r,testFilePattern:c,earlyRunPatterns:x,exclude:P}),mt=Ae(q);if(q.length===0){let i=s.length>0?`\u274C No Vitest test files found matching: ${s.join(", ")}`:"\u274C No Vitest test files found";return O&&console.log(i),v?{exitCode:1,mode:"standard",message:i,options:{cwd:o,testDir:n,testPatterns:s,testListFile:r,workers:h,coverageQuiet:a,suppressFileOutput:l,suppressPassingFiles:p,topSummary:m,vitestArgs:A}}:1}let Ke=q.filter(i=>x.some(d=>i.replace(/\\/g,"/").includes(d))),ve=q.filter(i=>!x.some(d=>i.replace(/\\/g,"/").includes(d))),ht=Date.now(),qe=new Date().toLocaleTimeString("en-US",{hour12:!1});O&&!l&&s.length>0?console.log(`
|
|
28
|
+
\u{1F9EA} Running ${q.length} test files matching: ${s.join(", ")}`):O&&!l&&console.log(`
|
|
29
|
+
\u{1F9EA} Running ${q.length} test files (${Ke.length} solo first, then parallel)`),O&&!l&&(console.log(`\u2699\uFE0F Workers: ${h}`),B&&console.log(`\u{1F9E0} Heap limit: ${B} MB`),A.length>0&&console.log(`\u{1F527} Vitest args: ${A.join(" ")}`),console.log(""));let I=[...T??[]],Ge=async i=>{!l&&O&&(console.log(`
|
|
30
|
+
${"=".repeat(80)}`),console.log(`\u25B6\uFE0F ${i}`),console.log("=".repeat(80)));let d=await He(e,We++),F=await ge(i,{...he,maxOldSpaceMb:ut(i,B,E),vitestArgs:A,streamOutput:!l&&!v,excludePaths:mt.get(i),extraEnv:{VITEST_RUNNER_TMP:d}});if(!l&&O){let D=(F.duration/1e3).toFixed(2);if(F.code===0){let k=F.heapMb?` | ${F.heapMb} MB heap`:"";console.log(`
|
|
32
31
|
\u2705 PASSED (${D}s${k})
|
|
33
32
|
`)}else console.log(`
|
|
34
|
-
\u274C FAILED (exit code ${
|
|
35
|
-
`)}return
|
|
36
|
-
`+"=".repeat(80))
|
|
37
|
-
`+
|
|
38
|
-
`+
|
|
39
|
-
`+"=".repeat(80)),console.log(
|
|
40
|
-
`+
|
|
41
|
-
\u274C ${
|
|
42
|
-
Failed Test Files:`)),
|
|
43
|
-
`).map(
|
|
44
|
-
`);console.log(
|
|
45
|
-
\u2705 All ${
|
|
46
|
-
`),0)}export{
|
|
33
|
+
\u274C FAILED (exit code ${F.code}, ${D}s)
|
|
34
|
+
`)}return F};if(!T){for(let F of Ke){let D=await Ge(F).catch(k=>(O&&console.error(`Error running ${F}:`,k),null));D&&I.push(D)}let i=0,d=new Set;for(;i<ve.length||d.size>0;){for(;i<ve.length&&d.size<h;){let F=ve[i++],D=Ge(F).then(k=>I.push(k)).catch(k=>{O&&console.error(`Error running ${F}:`,k)}).finally(()=>d.delete(D));d.add(D)}d.size>0&&await Promise.race(d)}}let G=I.reduce((i,d)=>i+d.testFilesPass,0),V=I.reduce((i,d)=>i+d.testFilesFail,0),se=I.reduce((i,d)=>i+d.testsPass,0),ne=I.reduce((i,d)=>i+d.testsFail,0),re=I.reduce((i,d)=>i+(d.testsSkip||0),0),vt=I.reduce((i,d)=>i+d.duration,0),J=I.filter(i=>i.code!==0),le=I.filter(i=>i.code===0),$t=J.length>0?1:0,Je=process.memoryUsage(),$e=Math.round(Je.heapUsed/1024/1024),Se=Math.round(Je.rss/1024/1024),R=I.filter(i=>i.heapMb!==null),Qe=((Date.now()-ht)/1e3).toFixed(2),Ze=(vt/1e3).toFixed(2);if(v)return{exitCode:$t,mode:"standard",options:{cwd:o,testDir:n,testPatterns:s,testListFile:r,workers:h,coverageQuiet:a,suppressFileOutput:l,suppressPassingFiles:p,topSummary:m,showErrorDetails:f,worstCoverageCount:w,vitestArgs:A},totals:{testFilesPass:G,testFilesFail:V,testsPass:se,testsFail:ne,testsSkip:re,totalTests:se+ne+re},timing:{startAt:qe,wallClockSeconds:Number(Qe),testsSeconds:Number(Ze)},heap:{scriptHeapMb:$e,scriptRssMb:Se,maxHeapMb:R.length>0?Math.max(...R.map(i=>i.heapMb)):null,avgHeapMb:R.length>0?Number((R.reduce((i,d)=>i+d.heapMb,0)/R.length).toFixed(0)):null},results:{all:I,passed:le,failed:J},...m?{topMemoryUsers:[...R].sort((i,d)=>d.heapMb-i.heapMb).slice(0,10),topDuration:[...I].sort((i,d)=>d.duration-i.duration).slice(0,10)}:{}};console.log(`
|
|
35
|
+
`+"=".repeat(80)),m&&R.length>0&&(console.log(`
|
|
36
|
+
`+S.bold("\u{1F9E0} TOP MEMORY USERS")),console.log("-".repeat(80)),[...R].sort((i,d)=>d.heapMb-i.heapMb).slice(0,10).forEach(i=>{console.log(` ${String(i.heapMb).padStart(4)} MB ${S.dim(i.file)}`)})),m&&I.length>0&&(console.log(`
|
|
37
|
+
`+S.bold("\u23F1\uFE0F TOP DURATION")),console.log("-".repeat(80)),[...I].sort((i,d)=>d.duration-i.duration).slice(0,10).forEach(i=>{let d=(i.duration/1e3).toFixed(2);console.log(` ${(d+"s").padStart(8)} ${S.dim(i.file)}`)})),le.length>0&&!p&&(console.log(`
|
|
38
|
+
`+"=".repeat(80)),console.log(S.bold.green("\u2713 PASSED TEST FILES")),console.log("=".repeat(80)),le.forEach(i=>{let d=(i.duration/1e3).toFixed(2),F=[...i.heapMb?[`${i.heapMb} MB`]:[],`${d}s`],D=i.testsPass>0?` - ${i.testsPass} tests`:"";console.log(S.green(`\u2713 ${i.file}${D}`)+S.dim(` (${F.join(", ")})`))})),console.log(`
|
|
39
|
+
`+S.bold("=".repeat(80))),J.length>0&&(console.log(`
|
|
40
|
+
\u274C ${J.length} test file(s) failed`),console.log(S.bold.red(`
|
|
41
|
+
Failed Test Files:`)),J.forEach(i=>{let d=(i.duration/1e3).toFixed(2),F=[...i.testsFail>0?[S.red(`${i.testsFail} failed`)]:[],...i.testsPass>0?[S.green(`${i.testsPass} passed`)]:[],...i.testsSkip>0?[S.yellow(`${i.testsSkip} skipped`)]:[]],D=[...i.heapMb?[`${i.heapMb} MB`]:[],`${d}s`],k=F.length>0?` (${F.join(", ")})`:"";if(console.log(` ${S.red("\u2716")} ${i.file}${k}`+S.dim(` [${D.join(", ")}]`)),f&&i.errors.length>0){let be=Re(i.errors).split(`
|
|
42
|
+
`).map(ie=>ie.trim()?` ${ie}`:"").join(`
|
|
43
|
+
`);console.log(be),console.log("")}}),console.log("")),console.log(S.bold("=".repeat(80))),V>0&&G>0?console.log(` ${S.bold("Test Files")} ${S.red(`${V} failed`)} ${S.dim("|")} ${S.green(`${G} passed`)} ${S.dim(`(${G+V})`)}`):V>0?console.log(` ${S.bold("Test Files")} ${S.red(`${V} failed`)} ${S.dim(`(${V})`)}`):console.log(` ${S.bold("Test Files")} ${S.green(`${G} passed`)} ${S.dim(`(${G})`)}`);let St=se+ne+re,bt=[...ne>0?[S.red(`${ne} failed`)]:[],...se>0?[S.green(`${se} passed`)]:[],...re>0?[S.yellow(`${re} skipped`)]:[]];if(console.log(` ${S.bold("Tests")} ${bt.join(` ${S.dim("|")} `)} ${S.dim(`(${St})`)}`),console.log(` ${S.bold("Start at")} ${qe}`),console.log(` ${S.bold("Duration")} ${Qe}s ${S.dim(`(tests ${Ze}s)`)}`),R.length>0){let i=Math.max(...R.map(F=>F.heapMb)),d=(R.reduce((F,D)=>F+D.heapMb,0)/R.length).toFixed(0);console.log(` ${S.bold("Heap")} max ${i} MB | avg ${d} MB | script ${$e} MB (RSS ${Se} MB)`)}else console.log(` ${S.bold("Heap")} script ${$e} MB (RSS ${Se} MB)`);return J.length>0?1:(console.log(`
|
|
44
|
+
\u2705 All ${le.length} test files passed
|
|
45
|
+
`),0)}export{ke as buildNodeOptions,H as colourPct,_e as createCoverageProgressTracker,Re as deduplicateErrors,pe as discoverFilesInDir,de as discoverVitestFiles,ee as formatDuration,Lt as makeRunTmpDir,Be as noopProgressTracker,Ce as parseVitestOutput,ze as printCoverageSummary,Ue as printMergeOutput,Ve as printQuietCoverageFailureDetails,Pe as resolveBin,Oe as resolveVitestConfig,yo as run,Le as runMergeReports,ge as runSingleFile,Dt as runVitestDirect,ue as sortWithPriority,L as stripAnsi};
|
|
47
46
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cldmv/vitest-runner",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Sequential Vitest runner to avoid OOM issues with large test suites",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"types:check": "tsc -p .configs/tsconfig.json --noEmit",
|
|
40
40
|
"build": "tsup",
|
|
41
41
|
"build:ci": "npm run lint && npm run format:check && npm run types:build && npm run build",
|
|
42
|
-
"prepack": "
|
|
42
|
+
"prepack": "npm run build",
|
|
43
43
|
"fix:headers": "node tools/fix-headers.mjs"
|
|
44
44
|
},
|
|
45
45
|
"keywords": [
|
package/types/src/cli/args.d.mts
CHANGED
|
@@ -65,6 +65,10 @@ export type ParsedArgs = {
|
|
|
65
65
|
* - Path substrings from `--solo-pattern <pattern>` (repeatable).
|
|
66
66
|
*/
|
|
67
67
|
soloPatterns: string[];
|
|
68
|
+
/**
|
|
69
|
+
* - Directory / file globs from `--exclude <glob>` (repeatable), relative to `cwd`, that discovery never enters.
|
|
70
|
+
*/
|
|
71
|
+
exclude: string[];
|
|
68
72
|
/**
|
|
69
73
|
* - Compiled regex from `--file-pattern <regex>`, or undefined.
|
|
70
74
|
*/
|
|
@@ -1,15 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test whether a cwd-relative path matches any of the given exclude globs.
|
|
3
|
+
* Callers checking a directory should also test the path with a trailing
|
|
4
|
+
* slash appended, so a pattern like `tmp/**` prunes the `tmp` directory
|
|
5
|
+
* itself rather than only the files found inside it.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} relPath - Path relative to `cwd`, forward-slash-normalised.
|
|
8
|
+
* @param {string[]} excludePatterns - Glob patterns relative to `cwd`.
|
|
9
|
+
* @returns {boolean}
|
|
10
|
+
* @example
|
|
11
|
+
* isExcluded("tmp/worktree/a.test.vitest.mjs", ["tmp/**"]); // true
|
|
12
|
+
* isExcluded("tmp/", ["tmp/**"]); // true — prunes the directory itself
|
|
13
|
+
*/
|
|
14
|
+
export function isExcluded(relPath: string, excludePatterns: string[]): boolean;
|
|
1
15
|
/**
|
|
2
16
|
* Recursively discover all Vitest test files under a directory.
|
|
3
|
-
* Skips `node_modules` and hidden directories (names starting with `.`)
|
|
17
|
+
* Skips `node_modules` and hidden directories (names starting with `.`),
|
|
18
|
+
* plus any directory or file matching an `exclude` glob.
|
|
4
19
|
*
|
|
5
20
|
* @param {string} dir - Absolute path of the directory to scan.
|
|
6
21
|
* @param {string} cwd - Project root used to compute relative paths.
|
|
7
22
|
* @param {RegExp} [pattern=DEFAULT_TEST_FILE_PATTERN] - Regex tested against the file name.
|
|
23
|
+
* @param {string[]} [exclude=[]] - Directory / file globs, relative to `cwd`, that discovery never enters.
|
|
8
24
|
* @returns {Promise<string[]>} Paths relative to `cwd`.
|
|
9
25
|
* @example
|
|
10
26
|
* const files = await discoverFilesInDir('/project/src/tests', '/project');
|
|
27
|
+
* @example
|
|
28
|
+
* // Skip scratch worktrees carrying their own copy of the suite
|
|
29
|
+
* const files = await discoverFilesInDir('/project', '/project', DEFAULT_TEST_FILE_PATTERN, ['tmp/**']);
|
|
11
30
|
*/
|
|
12
|
-
export function discoverFilesInDir(dir: string, cwd: string, pattern?: RegExp): Promise<string[]>;
|
|
31
|
+
export function discoverFilesInDir(dir: string, cwd: string, pattern?: RegExp, exclude?: string[]): Promise<string[]>;
|
|
13
32
|
/**
|
|
14
33
|
* Sort test files alphabetically while hoisting files matching `earlyRunPatterns`
|
|
15
34
|
* to the front (in pattern-declaration order, then alphabetically within each group).
|
|
@@ -52,6 +71,7 @@ export function computeFilterConflicts(files: string[]): Map<string, string[]>;
|
|
|
52
71
|
* @property {string} [testListFile] - Path to a JSON array of test file paths to run instead of scanning.
|
|
53
72
|
* @property {RegExp} [testFilePattern] - Regex to match file names (default: `DEFAULT_TEST_FILE_PATTERN`).
|
|
54
73
|
* @property {string[]} [earlyRunPatterns=[]] - Path substrings for files that must run solo first.
|
|
74
|
+
* @property {string[]} [exclude=[]] - Directory / file globs, relative to `cwd`, that discovery never enters. Applies to both the default scan and partial-path pattern resolution.
|
|
55
75
|
*/
|
|
56
76
|
/**
|
|
57
77
|
* Discover Vitest test files according to the provided options.
|
|
@@ -95,4 +115,8 @@ export type DiscoverOptions = {
|
|
|
95
115
|
* - Path substrings for files that must run solo first.
|
|
96
116
|
*/
|
|
97
117
|
earlyRunPatterns?: string[];
|
|
118
|
+
/**
|
|
119
|
+
* - Directory / file globs, relative to `cwd`, that discovery never enters. Applies to both the default scan and partial-path pattern resolution.
|
|
120
|
+
*/
|
|
121
|
+
exclude?: string[];
|
|
98
122
|
};
|
|
@@ -25,6 +25,10 @@ export function printMergeOutput(exitCode: number, output: string): void;
|
|
|
25
25
|
/**
|
|
26
26
|
* Compute a coverage-summary-style object from a raw V8/Istanbul `coverage-final.json`.
|
|
27
27
|
*
|
|
28
|
+
* Matches istanbul's own summary: a file with no entries for a metric counts as
|
|
29
|
+
* 100% for that metric, and when there are no files at all every total `pct` is
|
|
30
|
+
* the string `"Unknown"`.
|
|
31
|
+
*
|
|
28
32
|
* @param {Record<string, object>} finalData - Parsed `coverage-final.json` contents.
|
|
29
33
|
* @returns {{ total: object, [filePath: string]: object }} Istanbul coverage-summary format.
|
|
30
34
|
*/
|
|
@@ -39,6 +43,11 @@ export function computeSummaryFromFinal(finalData: Record<string, object>): {
|
|
|
39
43
|
* Tries `coverage-summary.json` first; falls back to computing from
|
|
40
44
|
* `coverage-final.json` if that is not present.
|
|
41
45
|
*
|
|
46
|
+
* A non-numeric `pct` (istanbul reports `"Unknown"` when the coverage `include`
|
|
47
|
+
* matched no files) is printed as `Unknown` and never throws. When no files were
|
|
48
|
+
* measured at all, a note says so: there is nothing for a coverage threshold to
|
|
49
|
+
* measure, and vitest's own threshold check does not fail on an `Unknown` value.
|
|
50
|
+
*
|
|
42
51
|
* @param {string} cwd - Project root (used to make absolute file paths relative).
|
|
43
52
|
* @param {string[]} extraCoverageArgs - Passthrough `--coverage.*` args (checked for `reportsDirectory`).
|
|
44
53
|
* @param {number} [worstCount=10] - Number of worst-coverage files to show (0 = skip table).
|
|
@@ -46,7 +55,8 @@ export function computeSummaryFromFinal(finalData: Record<string, object>): {
|
|
|
46
55
|
* @returns {Promise<{
|
|
47
56
|
* coverageDir: string,
|
|
48
57
|
* total: object,
|
|
49
|
-
*
|
|
58
|
+
* noFilesMeasured: boolean,
|
|
59
|
+
* worstFiles: Array<{file: string, lines: number|string, stmts: number|string, fns: number|string, branches: number|string}>,
|
|
50
60
|
* worstFilesShown: number,
|
|
51
61
|
* worstFilesTotal: number,
|
|
52
62
|
* summary: object
|
|
@@ -57,12 +67,13 @@ export function printCoverageSummary(cwd: string, extraCoverageArgs: string[], w
|
|
|
57
67
|
}): Promise<{
|
|
58
68
|
coverageDir: string;
|
|
59
69
|
total: object;
|
|
70
|
+
noFilesMeasured: boolean;
|
|
60
71
|
worstFiles: Array<{
|
|
61
72
|
file: string;
|
|
62
|
-
lines: number;
|
|
63
|
-
stmts: number;
|
|
64
|
-
fns: number;
|
|
65
|
-
branches: number;
|
|
73
|
+
lines: number | string;
|
|
74
|
+
stmts: number | string;
|
|
75
|
+
fns: number | string;
|
|
76
|
+
branches: number | string;
|
|
66
77
|
}>;
|
|
67
78
|
worstFilesShown: number;
|
|
68
79
|
worstFilesTotal: number;
|
package/types/src/runner.d.mts
CHANGED
|
@@ -102,6 +102,10 @@ export type RunOptions = {
|
|
|
102
102
|
* - Path substrings — matching files run solo before the worker pool.
|
|
103
103
|
*/
|
|
104
104
|
earlyRunPatterns?: string[];
|
|
105
|
+
/**
|
|
106
|
+
* - Directory / file globs, relative to `cwd`, that discovery never enters (e.g. `['tmp/**']`). Applies to both the default scan and partial-path pattern resolution.
|
|
107
|
+
*/
|
|
108
|
+
exclude?: string[];
|
|
105
109
|
/**
|
|
106
110
|
* - Per-file minimum heap overrides.
|
|
107
111
|
*/
|
|
@@ -22,13 +22,39 @@
|
|
|
22
22
|
* stripAnsi('\x1B[32mhello\x1B[0m'); // 'hello'
|
|
23
23
|
*/
|
|
24
24
|
export function stripAnsi(text: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Check whether a coverage percentage is a real number.
|
|
27
|
+
*
|
|
28
|
+
* Istanbul reports a metric's `pct` as the string `"Unknown"` when nothing was
|
|
29
|
+
* measured (e.g. the coverage `include` matched no files), so a `pct` cannot be
|
|
30
|
+
* assumed to be numeric.
|
|
31
|
+
* @param {unknown} pct - Coverage percentage as read from a coverage summary.
|
|
32
|
+
* @returns {pct is number} `true` when `pct` is a finite number.
|
|
33
|
+
* @example
|
|
34
|
+
* isKnownPct(75.5); // true
|
|
35
|
+
* isKnownPct("Unknown"); // false
|
|
36
|
+
*/
|
|
37
|
+
export function isKnownPct(pct: unknown): pct is number;
|
|
38
|
+
/**
|
|
39
|
+
* Format a coverage percentage with a fixed number of decimals, or `Unknown`
|
|
40
|
+
* when the value is not a number.
|
|
41
|
+
* @param {unknown} pct - Coverage percentage as read from a coverage summary.
|
|
42
|
+
* @param {number} digits - Decimal places for a numeric value.
|
|
43
|
+
* @returns {string} The formatted percentage (without a `%` sign).
|
|
44
|
+
* @example
|
|
45
|
+
* formatPct(75.5, 0); // '76'
|
|
46
|
+
* formatPct("Unknown", 0); // 'Unknown'
|
|
47
|
+
*/
|
|
48
|
+
export function formatPct(pct: unknown, digits: number): string;
|
|
25
49
|
/**
|
|
26
50
|
* Colour-code a coverage percentage value using chalk.
|
|
27
|
-
* ≥ 80 % → green, ≥ 50 % → yellow, < 50 % → red.
|
|
51
|
+
* ≥ 80 % → green, ≥ 50 % → yellow, < 50 % → red. A non-numeric value
|
|
52
|
+
* (istanbul's `"Unknown"`) is rendered as a dim `Unknown`.
|
|
28
53
|
* @param {import('chalk').ChalkInstance} chalk - Chalk instance supplied by the caller.
|
|
29
|
-
* @param {
|
|
54
|
+
* @param {unknown} pct - Coverage percentage 0–100, or a non-numeric value such as `"Unknown"`.
|
|
30
55
|
* @returns {string} Chalk-coloured, right-aligned percentage string.
|
|
31
56
|
* @example
|
|
32
57
|
* colourPct(chalk, 75.5); // yellow ' 75.50'
|
|
58
|
+
* colourPct(chalk, "Unknown"); // dim 'Unknown'
|
|
33
59
|
*/
|
|
34
|
-
export function colourPct(chalk: import("chalk").ChalkInstance, pct:
|
|
60
|
+
export function colourPct(chalk: import("chalk").ChalkInstance, pct: unknown): string;
|