Skip to content

Fix cross-platform test runner#25

Open
Yulin-Bi wants to merge 1 commit intoLiuMengxuan04:mainfrom
Yulin-Bi:main
Open

Fix cross-platform test runner#25
Yulin-Bi wants to merge 1 commit intoLiuMengxuan04:mainfrom
Yulin-Bi:main

Conversation

@Yulin-Bi
Copy link
Copy Markdown

windows可以快速测试。

@LiuMengxuan04
Copy link
Copy Markdown
Owner

抱歉,我没看懂这个pr做了什么?可否请你更详细的解释一下本次修改的具体行为?(最好可以参考本项目的pr规范)

@Yulin-Bi
Copy link
Copy Markdown
Author

提交说明 / Submission Note

1、背景 / Background

项目原有测试脚本使用 test/*.test.ts 作为测试文件匹配路径:

"test": "node --import tsx --test test/*.test.ts"

该写法依赖 shell 对 glob 的展开能力。在 Windows PowerShell 环境下,test/*.test.ts 不会自动展开为具体文件列表,Node.js 会收到字面量路径并报错:

Could not find '...\test\*.test.ts'

这会导致 Windows 用户无法直接通过 npm test 运行项目测试。

2、目标 / Goal

修复 npm test 在 Windows 环境下无法识别测试文件的问题。

同时保持测试入口简单、稳定,并兼容不同操作系统和 shell 环境,使开发者可以在 Windows、macOS、Linux 上使用同一条命令运行测试:

npm test

3、修改方向 / Direction

package.json 中的测试命令改为调用一个 Node.js 测试启动脚本:

"test": "node test/run-tests.mjs"

新增 test/run-tests.mjs,由脚本负责:

  • 读取 test/ 目录;
  • 筛选所有以 .test.ts 结尾的测试文件;
  • 按文件名排序,保证测试输入稳定;
  • 将真实文件路径传给 Node.js test runner;
  • 在没有测试文件时显式报错,避免误判测试通过。

这种方式不依赖 shell glob 展开,因此可以解决 Windows PowerShell 下测试命令失效的问题。

4、验收标准 / Acceptance Criteria

本次修改满足以下验收标准:

  • npm test 能在 Windows 环境下正确发现并运行 test/*.test.ts 测试文件;
  • 测试脚本不依赖 shell glob 展开;
  • 没有测试文件时,命令会返回失败并输出明确错误;
  • TypeScript 类型检查通过:
npm run check
  • 全量测试通过:
npm test

当前验证结果:

109 tests passed
0 failed

@GateJustice
Copy link
Copy Markdown
Collaborator

感谢提交这个 PR!我们之前的开发环境一直聚焦在 Linux,确实疏忽了 Windows 下的兼容性问题。感谢你的补全,我会立即联络项目负责人,尽快安排 review 并在完成后合入。

@Yulin-Bi
Copy link
Copy Markdown
Author

Yulin-Bi commented May 1, 2026

这个项目对我学习帮助很大,这是我应该做的,希望越来越好!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants