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
Any help is greatly appreciated as I’ve been stuck on this for quite some time now. Thank you all!
2
Answers
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/195I 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 butnpm test
would hang. The reason isng 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 thedevelopment
orproduction
configurations fromangular.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(or this if you have
ng
installed globally)