skip to Main Content

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!

2

Answers


  1. Chosen as BEST ANSWER

    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


  2. I had a similar problem on my local machine (so I’m not sure if it would work in github actions). karma start would run perfectly but npm test would hang. The reason is ng test is doing something that karma is not, I am unsure of what exactly since I don’t have a lot of experience with angular, but I am guessing it is packaging the application using one of the development or production configurations from angular.json.

    However what fixed the problem for me was generating the karma.conf.js file with angular’s own command. Run in the root folder of your project

    npx ng generate config karma
    

    (or this if you have ng installed globally)

    ng generate config karma
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search