【问题标题】:Running CRA Jest in non-interactive mode在非交互模式下运行 CRA Jest
【发布时间】:2017-02-05 01:08:15
【问题描述】:

更新:我的用例主要是在 CI 上运行测试,但我通常想知道覆盖默认 CRA Jest 参数。


我正在使用Jest 运行测试,Create React App 附带的配置。它总是启动到交互模式:

 › Press a to run all tests.
 › Press o to only run tests related to changed files.
 › Press p to filter by a filename regex pattern.
 › Press q to quit watch mode.
 › Press Enter to trigger a test run.

但我不希望它等待我的输入。我希望它运行一次然后终止。我尝试使用--bail--no-watchman 开关,但它仍以交互模式启动。

如果我全局安装 jest,并在我的项目的根目录中运行它,它会执行一次并完成(正如我想要的那样)。但是当我运行 npm test 运行 react-scripts test 时,即使我没有通过 --watch,它也会进入监视模式。

更新:我还在CRA 上提交了一个问题。

【问题讨论】:

    标签: reactjs redux jestjs create-react-app


    【解决方案1】:

    你应该使用Jests --watchAll=false flag

    例如:

    npm test -- --watchAll=false

    注意:这是给react-scripts > 3.00

    对于旧版本:

    • 反应脚本>= 2.1.4 < 3.00

    对于非 ci,例如在本地运行测试,您可以传递 --no-watch 标志:

    npm test --no-watch

    • 反应脚本<= 2.1.3

    CRA 会查找 CI 环境变量,如果它存在,它不会在监视模式下运行。

    CI=true npm test 应该做你正在寻找的东西

    User Guide -> Running Tests -> On your own environment

    【讨论】:

    • 是的,就这个问题而言,没有更简单的方法:github.com/facebookincubator/create-react-app/issues/784
    • 这对我在 react-scripts 3.2.0 上没有任何影响;不起作用。
    • 现在看起来像 --watchAll=false
    • 正如其他答案之一已经指出的那样......它实际上应该是npm test -- --watchAll=false
    • 我更像是一个普通的 webpack 初学者,当我开始工作一个继承的 react-scripts 生成项目时,我无法让脚本自动启动和停止。这正在扼杀我的 CI 管道。这是一个巨大的帮助。
    【解决方案2】:

    在您的 package.json 脚本中:

    "test": "react-scripts test --watchAll=false"

    npm test -- --watchAll=false

    yarn test --watchAll=false

    注意:react-scripts < 3.0 中的标志过去称为--no-watchhttps://github.com/facebook/create-react-app/blob/3.x/CHANGELOG.md#remove---no-watch-flag

    【讨论】:

      【解决方案3】:

      非交互式解决方案:

      npm test a --watchAll=false
      

      yarn test a --watchAll=false
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-06-30
        • 1970-01-01
        • 2023-03-17
        • 1970-01-01
        • 1970-01-01
        • 2012-08-11
        • 2023-04-05
        • 1970-01-01
        相关资源
        最近更新 更多