Ionic:npm 测试命令挂在 azure DevOps 管道中

问题描述 投票:0回答:2

我正在为我的离子项目(桌面、Android 和 iOS)创建一个管道:每个平台都有一个

job

第一份工作如下:

jobs:

- job: Build_Ionic

  pool:
    vmImage: 'macos-latest'

  steps:
  - task: NodeTool@0
    inputs:
     versionSpec: '12.0.x'
     checkLatest: true
    displayName: 'install NodeJS'

  - task: CmdLine@2
    inputs:
     script: |
      npm install
      npm test --watch=false

  - task: ArchiveFiles@2
    inputs:
      rootFolderOrFile: '$(Build.BinariesDirectory)'
      includeRootFolder: true
      archiveType: 'zip'
      archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
      replaceExistingArchive: true

  - task: PublishPipelineArtifact@1
    inputs:
      targetPath: '$(Build.ArtifactStagingDirectory)/'
      artifact: 'dist'
      publishLocation: 'pipeline'
  

一切正常,直到脚本

npm test --watch=false
挂起。 该脚本的输出是:

26 08 2020 10:02:36.978:WARN [karma]: No captured browser, open http://localhost:9876/
26 08 2020 10:02:36.984:INFO [karma-server]: Karma v5.0.9 server started at http://0.0.0.0:9876/
26 08 2020 10:02:36.984:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
26 08 2020 10:02:36.987:INFO [launcher]: Starting browser Chrome
26 08 2020 10:02:42.476:WARN [karma]: No captured browser, open http://localhost:9876/
26 08 2020 10:02:42.689:INFO [Chrome 84.0.4147.135 (Mac OS 10.15.6)]: Connected on socket UU2YzJ0dLFGblvfdAAAA with id 31198897
Chrome 84.0.4147.135 (Mac OS 10.15.6): Executed 0 of 1 SUCCESS (0 secs / 0 secs)
WARN: ''mobile-app-root' is not a known element:
1. If 'mobile-app-root' is an Angular component, then verify that it is part of this module.
2. If 'mobile-app-root' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
Chrome 84.0.4147.135 (Mac OS 10.15.6): Executed 0 of 1 SUCCESS (0 secs / 0 secs)
WARN: ''mobile-app-root' is not a known element:
1. If 'mobile-app-root' is an Angular component, then verify that it is part of this module.
2. If 'mobile-app-root' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
Chrome 84.0.4147.135 (Mac OS 10.15.6): Executed 1 of 1 SUCCESS (0 secs / 0.06 secs)
Chrome 84.0.4147.135 (Mac OS 10.15.6): Executed 1 of 1 SUCCESS (0.081 secs / 0.06 secs)
TOTAL: 1 SUCCESS
TOTAL: 1 SUCCESS

所以我想我的测试没有问题。你知道为什么它会在这个命令上冻结吗?

angular ionic-framework azure-devops azure-pipelines
2个回答
3
投票

我遇到了类似的问题。通过在 karma.conf.js 中将

singleRun
设置为
true
来修复此问题。如果为 true,Karma 会捕获浏览器、运行测试并退出。如果没有显式设置,该值默认为 false。

见下图:

autoWatch: false,
singleRun: true

0
投票

我在运行

jest
测试时遇到了类似的问题。它们在本地运行良好,但在 Azure Pipelines 中运行不佳。我最终发现有一个挂起的进程在我的测试完成后从未关闭,导致它冻结。

我使用命令

jest ./tests --detectOpenHandles
来查找进程,在确保进程关闭后,测试在 Azure 中运行良好。

© www.soinside.com 2019 - 2024. All rights reserved.