2

我有 Jest 作为我的测试运行者。我的提交钩子里也有哈士奇。我想在每次提交、受我的更改和相关更改影响的测试上运行。

我在 Jest 的文档中看到了以下选项,但我在使它们起作用方面没有取得进展:

--findRelatedTests -> To find the related test to my changes 
--testPathPattern -> To execute tests only on specific folders

您是否有文档或任何可能有用的示例。或者向我解释我怎么能做到这一点。?谢谢!!

4

1 回答 1

0

查看packages/jest-cli/src/cli/args.ts我们可以找到:

throw new Error(
  'The --findRelatedTests option requires file paths to be specified.\n' +
    'Example usage: jest --findRelatedTests ./src/source.js ' +
    './src/index.js.',
);

我知道它在某些情况下可能不起作用(它在我的一个项目中起作用而在另一个项目中不起作用,配置非常接近但版本不同),所以即使它不起作用也要记住 - 它仍然可能不起作用因为配置错误或类似的。

testPathPattern通常通过package.json's jestsection ->指定,testMatch例如:

"testMatch": ["**/?(*.)+(spec).js"]
于 2020-07-13T16:55:30.147 回答