【问题标题】:npm test does not detect new test file changes in jenkinsnpm test 未检测到 jenkins 中的新测试文件更改
【发布时间】:2020-02-05 17:18:23
【问题描述】:

Jenkins/jest 和 CI,

我使用 create-react-app 创建了一个 React APP,我使用 JEST 进行测试,我在创建 app.test.js 并提交到 git-hub 的文件中做了一些新的更改——用 jenkins 钩住它——当我在本地机器上运行 npm test 测试运行良好并且它们都通过了.. 但是当我运行 jenkins 管道脚本时,它会显示以下内容:

No tests found related to files changed since last commit.
Press a to run all tests, or run Jest with --watchAll.

Watch Usage
› Press a to run all tests.
› Press p to filter by a filename regex pattern.
› Press q to quit watch mode.
› Press Enter to trigger a test run.

我已尝试更改 app.test.js - 创建了一个新文件提交更改,然后在 jenkins 中创建了一个新管道并再次尝试(我也尝试过这里讨论的这些:https://github.com/facebookincubator/create-react-app/issues/930)但我仍然收到上述错误:我的管道脚本如下所示:

   node{
        stage "CI"    
        git 'https://github.com/NaveenDK/mentalshortcuts.git' 
        bat "npm install"  
        stage " Unit testing" 
        bat "npm test" 
    }
        def notify(status){
        emailext (
          to: "dd@dd.com",
          subject: "${status}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
          body: """<p>${status}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
            <p>Check console output at <a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a></p>""",
        )

    }

    node {
        notify("Deploy to staging?")
    }
    input 'Deploy to Staging?'


    node {
        bat "npm run-script build"
    }

任何帮助任何链接任何东西都会很棒!

【问题讨论】:

  • 大家好,我已经用一个从头开发的新应用程序尝试了 npm test 命令,但问题仍然存在......

标签: reactjs jenkins jenkins-pipeline jestjs


【解决方案1】:

测试没有在 jenkins 上运行,因为 Jenkins 在 Windows 上运行,并且 Windows 不支持 glob,即 src/**/*.js。

在安装在 Linux 操作系统上的 Jenkins 上构建项目时没有遇到此问题!

【讨论】:

    【解决方案2】:

    我也遇到了同样的问题。正如上面 Naveen 所说,Windows 不支持 glob,即 src/**/*.js。 这就是为什么在 Jenkins 配置中,将标签更改为 Linux。在这里查看预览。 Jenkins configuration

    然后在构建部分,添加以下行作为 shell 命令:

    npm install
    npm run build
    CI=true npm test
    

    始终先运行npm install。它将安装所有软件包。 然后运行npm run build 构建应用程序 最后,一定要写CI=true npm test。它只会运行一次测试用例。如果你改为写npm test,那么它将运行测试并永远进入监视模式。

    我希望这会有所帮助。

    【讨论】:

    • 这个答案应该被接受为正确的,它很有帮助
    【解决方案3】:

    我在本地机器上遇到这样的问题,

    "test": "jest --watchAll"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多