Azure Dev Ops react-scripts 测试永远挂起

IT技术 reactjs azure-devops yaml azure-pipelines
2021-05-20 11:50:03

我正在尝试在 Azure Dev Ops 中运行我的 React 应用程序测试我不知道如何在测试运行后停止执行。它只是挂在那里,将管道永远保持在运行模式。这是一个简单的 create-react-app 应用程序,它有几个测试。下面是我的管道的 YAML:

trigger: none

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'

- script: |
    npm install
    npm run build
  displayName: 'npm install and build'

- script: npm run citest

- task: PublishPipelineArtifact@0
  inputs:
    artifactName: 'react'
    targetPath: './build'

我刚刚在测试步骤中使用了“- script: npm test”,但是,按照facebook github 中的说明我创建了一个新的测试脚本(称为 citest):set CI=true && react-scripts test a但它仍然不起作用。我在 dev ops 控制台中得到以下输出,并且任务一直在运行:

> set CI=true && react-scripts test a
PASS src/components/landing/landing.test.js (6.008s)
PASS src/components/navbar/NavBar.test.js
PASS src/components/app/App.test.js
Test Suites: 3 passed, 3 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        7.573s
Ran all test suites matching /a/i.

我已经没有什么可以尝试的想法了 - 感谢任何帮助!

2个回答

像这样更新脚本:

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "citest":"CI=true react-scripts test"
  },

我通过将它放在我的管道 YAML 文件中解决了同样的问题:

- script: set CI=true&&npm test
  displayName: Test

官方文档:https : //create-react-app.dev/docs/running-tests/#continuous-integration