hanaa
hanaa

Reputation: 405

Ionic : npm test command hangs in azure DevOps pipeline

I am creating a pipeline for my ionic project (desktop, android, and iOS): a job for each platform.

the first job is as follows:

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'
  

everything works fine till the script npm test --watch=false, where it hangs. the output of this script is :

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

So I guess there are no issues in my test. Any ideas why it freezes on this command?

Upvotes: 0

Views: 2075

Answers (2)

Patrick Gorman
Patrick Gorman

Reputation: 154

I had a similar issue with getting my jest tests to run. They ran fine locally, but not in Azure Pipelines. I ended up discovering that there was a hanging process that was never closed after my tests were done causing it to freeze.

I used the command jest ./tests --detectOpenHandles to find the process and after I made sure the process was closed, the tests ran fine in Azure.

Upvotes: 0

Levi Lu-MSFT
Levi Lu-MSFT

Reputation: 30313

I encountered a similar issue. And it was fixed by set the singleRun to true in karma.conf.js. If true, Karma captures browsers, runs the tests and exits. The value is false by default if not set explicitly.

See below:

autoWatch: false,
singleRun: true

Upvotes: 3

Related Questions