1- // 发版流水线的徽章对齐(release.yml 的 badge job 调用;手动可跑 npm run badge:sync)。
1+ // 发版前对齐徽章(手动跑 npm run badge:sync;release.yml 不再有 badge job ——
2+ // main 受保护,github-actions[bot] 的 GITHUB_TOKEN 绕过不了 required status
3+ // checks,push 必被 GH006 拒)。
24//
35// 做三件事:
4- // 1. 跑一遍全量测试(npm test),取最后的 `pass N` 汇总数 ;
6+ // 1. 跑一遍全量测试(npm test),取套件总数(`ℹ tests N` 汇总行) ;
57// 2. 把双 README 的 tests 徽章(img.shields.io/badge/tests-N%20passed)与
6- // 开发命令注释(# N 个测试 / # N tests)刷成该数字;
8+ // 开发命令注释(# N 个测试 / # 运行 N 个测试 / # N 个 node:test 测试 /
9+ // # N tests)刷成该数字;
710// 3. 有变化就写回文件(由调用方决定是否 commit/push),无变化静默退出。
811//
912// 测试失败(fail>0 或进程非零退出)时以非零退出且不改任何文件——徽章永远
@@ -32,11 +35,14 @@ try {
3235 process . exit ( 1 ) ;
3336}
3437
35- // 2) 取汇总 pass 数(spec reporter 的 `ℹ pass N`;取最后一处防逐用例行干扰)
36- const matches = [ ...output . matchAll ( / p a s s ( \d + ) / g) ] ;
37- const pass = matches . length ? Number ( matches [ matches . length - 1 ] [ 1 ] ) : 0 ;
38- if ( ! pass ) {
39- console . error ( "无法从测试输出解析 pass 数,徽章不更新" ) ;
38+ // 2) 取套件总数(spec reporter 的 `ℹ tests N`;取最后一处防逐用例行干扰)
39+ // 用总数而非 `pass N`:平台条件跳过的用例(如 Windows 未开开发者模式时的
40+ // 符号链接断言)在 pass 里不计、在 tests 里计入,而徽章报的是 CI(ubuntu)
41+ // 口径 —— 用总数则本地在 Windows 跑也得到同一个数,不必手工修。
42+ const matches = [ ...output . matchAll ( / ℹ t e s t s ( \d + ) / g) ] ;
43+ const count = matches . length ? Number ( matches [ matches . length - 1 ] [ 1 ] ) : 0 ;
44+ if ( ! count ) {
45+ console . error ( "无法从测试输出解析套件总数,徽章不更新" ) ;
4046 process . exit ( 1 ) ;
4147}
4248
@@ -49,13 +55,13 @@ let changed = 0;
4955for ( const file of targets ) {
5056 let text = readFileSync ( file , "utf8" ) ;
5157 const next = text
52- . replace ( / t e s t s - \d + % 2 0 p a s s e d - / g, `tests-${ pass } %20passed-` )
53- . replace ( / ( # \s * ) \d + ( 个 测 试 ) / g, `$1${ pass } $2` )
54- . replace ( / ( # \s * ) \d + ( t e s t s ) / g, `$1${ pass } $2` ) ;
58+ . replace ( / t e s t s - \d + % 2 0 p a s s e d - / g, `tests-${ count } %20passed-` )
59+ . replace ( / ( # \s * (?: 运 行 \s * ) ? ) \d + ( 个 (?: \s * n o d e : t e s t ) ? \s * 测 试 ) / g, `$1${ count } $2` )
60+ . replace ( / ( # \s * ) \d + ( t e s t s ) / g, `$1${ count } $2` ) ;
5561 if ( next !== text ) {
5662 writeFileSync ( file , next ) ;
5763 changed += 1 ;
5864 console . log ( `updated: ${ file } ` ) ;
5965 }
6066}
61- console . log ( `pass =${ pass } , files changed=${ changed } ` ) ;
67+ console . log ( `tests =${ count } , files changed=${ changed } ` ) ;
0 commit comments