【问题标题】:Testing - How to split up pre-commit unit tests and CI end-to-end tests测试 - 如何拆分预提交单元测试和 CI 端到端测试
【发布时间】:2020-08-10 14:57:12
【问题描述】:

场景

我正在开发一个应用程序,该应用程序具有快速的单元/功能笑话测试以及较慢的端到端 jest-puppeteer 测试。我想将它们分开,以便我可以将更快的测试作为 git pre-commit 钩子的一部分运行,并在代码最终推送到源后让端到端测试在 CI 上运行。

问题

如何定义在预提交时运行的特定测试?特别是通过类似于 jest moduleNameMapper 的正则表达式,例如 <rootDir>/__tests__/[a-z]+\.unit\.test\.js


  • 迄今为止最好的主意:

package.json 中添加 test:pre,它使用 bash find . -regex 和 bash for do 来运行所需的“预提交”测试

【问题讨论】:

  • 你坚持哪一部分?如何运行脚本预提交?如何为您要选择的测试编写模式(它们有什么区别)?如何将其传递给 Jest(您是否阅读过 jestjs.io/docs/en/cli.html)?

标签: unit-testing jestjs jest-puppeteer


【解决方案1】:

我已经添加了

"test:pre": "PRE=1 npm test -- test/pre-*test.js" 
# everything after -- is a kind of regex filter for matching file names

到我的 package.json 脚本和我的 jest-puppeteer global-setup.js 我正在使用

if(+process.env.PRE) return;

在所有 puppeteer 附加功能开始之前。所以现在我可以

$ npm run test:pre

和中提琴

【讨论】:

    猜你喜欢
    • 2014-03-20
    • 2016-06-07
    • 1970-01-01
    • 2011-02-06
    • 1970-01-01
    • 2018-06-26
    • 2018-04-17
    • 1970-01-01
    • 2018-07-23
    相关资源
    最近更新 更多