Home > Back-end >  npm test hangs after angular unit tests pass in Github Actions
npm test hangs after angular unit tests pass in Github Actions

Time:01-13

I added a step in my Github Actions workflow to run my Angular tests using the command ng test. The tests run and pass successfully but it never moves onto the next step in my workflow.

What have I tried:

  • Adding the argument watch=false in the step so that "ng test" isn't watching for file changes.
  • Setting singleRun to true in karma.conf.js

Nothing's worked so far and I'm not seeing any other resources that can help me solve this issue.

Here is a snippet of the step in my build-push.yml file:

- name: Run tests
  run: npm test -- --watch=false --browsers=ChromeHeadless

Here is a snippet of my karma.conf.js file:

reporters          : ['progress', 'kjhtml'],
port               : 9876,
colors             : true,
logLevel           : config.LOG_INFO,
autoWatch          : true,
browsers           : ['Chrome'],
singleRun          : true,
restartOnFileChange: true,

Here is the yaml file of the workflow:

name: Build PUSH only
on:
  push

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      SHA: ${{ github.sha }}
      REPO: ${{ github.repository }}
      BRANCH: ${{ github.ref_name }}
      CI: true

    steps:
      - name: Checkout the PR
        uses: actions/checkout@v3
      - name: Set up Node
        uses: actions/setup-node@v3
        with:
          node-version: 16

      - name: Install Azure CLI
        run: curl -sL https://aka.md/InstallAzureCLIDec | sudo bash 
      - name: Install Angular CLI
        run: npm install --location=global @angular/[email protected]
      - name: Install packages
        run: npm install
      - name: Build the UI
        run: ng build -c production
      - name: Run tests
        run: npm test -- --watch=false --browsers=ChromeHeadless

The above image is a screenshot of the workflow running in Github Actions. I expected "Post Set up Node" to run but it just hangs on the tests

The above image is a screenshot of the workflow running in Github Actions. I expected "Post Set up Node" to run but it just hangs on the tests

Any help is greatly appreciated as I've been stuck on this for quite some time now. Thank you all!

CodePudding user response:

Turns out it was an issue with Karam Browserstack. Seems like this is also affecting several people using Angular 14. The only workaround in place currently is to run sed -i -z "s/ removeAllListeners()\n/ removeAllListeners();process.nextTick(() => process.exit(code || 0));\n/g" node_modules/karma/lib/server.js in the workflow before the tests are executed. Link to this solution: https://github.com/karma-runner/karma-browserstack-launcher/issues/195

  • Related