【问题标题】:jest how set file pattern in package.json script开玩笑如何在 package.json 脚本中设置文件模式
【发布时间】:2018-11-30 22:45:26
【问题描述】:

我在 packadge.json 中有

"scripts": {
  "test": "cross-env NODE_ENV=test jest"
},

我想测试所有文件匹配模式

 front/**/*.test.js

但是如果

"scripts": {
  "test": "cross-env NODE_ENV=test jest \"front/**/*.test.js\""
},

我有一个错误

Invalid testPattern front/**/*.test.js supplied. Running all tests instead.

那么,我如何将文件名模式传递给 jest?

谢谢。

【问题讨论】:

    标签: reactjs jestjs


    【解决方案1】:

    根据documentation,您应该为您的模式使用正则表达式。所以在你的情况下,你可能会写这样的东西:

    "scripts": {
        "test": "cross-env NODE_ENV=test jest \"front/.*\\.test\\.js\""
    }
    

    【讨论】:

      【解决方案2】:

      在您的 jest 配置中使用 testRegex 参数来设置文件名模式:

      testRegex: 'front/.*\.test\.js$'
      

      查看文档here

      【讨论】:

      • 问题是如何通过 packedge.json 脚本设置文件模式
      • 我同意,@ghost23 的答案是这个问题的正确答案。
      猜你喜欢
      • 2020-09-18
      • 1970-01-01
      • 1970-01-01
      • 2015-01-23
      • 2020-10-20
      • 1970-01-01
      • 2019-02-25
      • 2021-10-14
      相关资源
      最近更新 更多