用途:面向 TypeScript 仓库贡献者,说明如何编写、运行和调试两类测试——编译测试(类型检查、emit、诊断)与 fourslash 测试(补全、悬停、跳转定义等 LSP 功能)。
主要能力: 编译测试为 .ts/.tsx 文件,放在 tsc/testdata/tests/cases/compiler/(回归)或 conformance/<子目录>/(一致性)。可用 // @target:、// @strict:、// @filename: 等注释指令设置选项与多文件;逗号分隔选项可生成多个子测试。 运行方式:推荐 npx hereby test(快速、清理陈旧基线)。调试单个测试可用 go -C ./tsc test ./internal/testrunner/ -run 'TestLocal/名称' -v。 fourslash 测试为 Go 文件,放在 tsc/internal/fourslash/tests/,使用 fourslash_test 包和位置标记(如 /marker1/),通过 f.VerifyQuickInfoAt、f.VerifyCompletions、f.VerifyBaseline* 等方法验证。
基线系统:参考基线在 tsc/testdata/baselines/reference/,本地生成在 local/。查看差异用 git diff --diff-filter=AM --no-index ./tsc/testdata/baselines/reference ./tsc/testdata/baselines/local。接受基线须先运行 npx hereby test,再执行 npx hereby baseline-accept。
适用场景:为编译器行为或语言服务功能添加回归与一致性测试,排查测试失败。
限制:fourslash 测试应手写,不得生成或再生成上游生成套件;接受基线前必须先运行包含清理步骤的测试命令,否则可能接受陈旧结果。其余实现细节暂未提供。