审查生成的类型覆盖运行器

来自 类型覆盖率
TypeScript 6 高级 6分钟 找出 4处问题

在把这个生成的覆盖率运行器加入 CI 前,对它进行审查。

读取不可信 JSON 配置并验证,不通过 shell 为项目运行一次类型覆盖率,执行配置的最低门槛,并可靠报告失败。

TypeScript
import { exec } from "node:child_process";

type Config = {
  project: string;
  files: string[];
  minimum: number;
};

function check(configText: string): void {
  const config = JSON.parse(configText) as Config;
  for (const file of config.files) {
    const command = `npx type-coverage -p ${config.project} -- ${file}`;
    exec(command, (error, stdout) => {
      const match: any = stdout.match(/([0-9.]+)%/);
      const percent = Number(match[1]);
      console.log(`${file}: ${percent} >= ${config.minimum}`);
      if (error) process.exitCode = 1;
    });
  }
}

check(process.argv[2]!);

生成代码仅作示例,不代表任何特定模型

在试验场中打开
报告错误