Reputation: 6007
In my Angular project I try to use Google Chrome for testing with Karma & Jasmine in a GitHub Action.
The Google Chrome start with multiple errors, and then dies after some tests. I tried several tips from StackOverflow ansers in this topic, but nothing helped.
I use this versions:
I have this karma.conf.js
file:
module.exports = function (config) {
config.set({
browserNoActivityTimeout: 500000,
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-coverage'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false
},
coverageReporter: {
dir: 'reports/coverage',
reporters: [
{ type: 'html', subdir: 'report-html' },
{ type: 'lcov', subdir: 'report-lcov' }
],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome', 'ChromeHeadless', 'ChromeHeadlessCI'],
customLaunchers: {
ChromeHeadlessCI: {
base: 'ChromeHeadless',
flags: ['--no-sandbox', '--disable-gpu']
}
},
singleRun: false,
restartOnFileChange: true
});
};
Here is my GitHub Action yml file:
name: Angular test
on: [push]
jobs:
ng-test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm ci
run: npm ci
- name: Angular test in production mode
run: npm run test:ci
In the package.json
this is the scripts part:
"test:ci": "ng test --watch=false --code-coverage --source-map true",
And I get this errors:
> ng test --watch=false --code-coverage --source-map true
- Generating browser application bundles (phase: setup)...
- @auth0/angular-jwt [es2015/esm2015] (git+https://github.com/auth0/angular2-jwt)
- ngx-bootstrap/tabs [es2015/esm2015] (git+ssh://[email protected]/valor-software/ngx-bootstrap.git)
- @fortawesome/angular-fontawesome [es2015/esm2015] (https://github.com/FortAwesome/angular-fontawesome)
- ddata-ui-common [es2015/esm2015] ()
- ddata-ui-dialog [es2015/esm2015] ()
- @tinymce/tinymce-angular [es2015/esm2015] (https://github.com/tinymce/tinymce-angular.git)
- ngx-color-picker [es2015/esm2015] ()
- ngx-material-timepicker [es2015/esm2015] (https://github.com/Agranom/ngx-material-timepicker.git)
✔ Browser application bundle generation complete.
10 03 2022 14:44:41.942:INFO [karma-server]: Karma v6.3.16 server started at http://localhost:9876/
10 03 2022 14:44:41.953:INFO [launcher]: Launching browsers Chrome, ChromeHeadless, ChromeHeadlessCI with concurrency unlimited
10 03 2022 14:44:41.958:INFO [launcher]: Starting browser Chrome
10 03 2022 14:44:42.055:INFO [launcher]: Starting browser ChromeHeadless
10 03 2022 14:44:42.141:INFO [launcher]: Starting browser ChromeHeadless
10 03 2022 14:44:43.220:INFO [Chrome Headless 98.0.4758.102 (Linux x86_64)]: Connected on socket eilZCAlj3zsV4RbPAAAD with id 4879597
10 03 2022 14:44:43.239:INFO [Chrome Headless 98.0.4758.102 (Linux x86_64)]: Connected on socket 03Ia71912SRh3xC_AAAC with id 64299573
10 03 2022 14:44:44.357:ERROR [launcher]: Cannot start Chrome
[0310/144442.711534:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[0310/144442.711623:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)
10 03 2022 14:44:44.357:ERROR [launcher]: Chrome stdout:
10 03 2022 14:44:44.357:ERROR [launcher]: Chrome stderr: [0310/144442.711534:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[0310/144442.711623:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)
10 03 2022 14:44:44.394:INFO [launcher]: Trying to start Chrome again (1/2).
10 03 2022 14:44:44.819:ERROR [launcher]: Cannot start Chrome
[0310/144444.585530:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[0310/144444.585587:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)
10 03 2022 14:44:44.819:ERROR [launcher]: Chrome stdout:
10 03 2022 14:44:44.819:ERROR [launcher]: Chrome stderr: [0310/144444.585530:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[0310/144444.585587:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)
10 03 2022 14:44:44.823:INFO [launcher]: Trying to start Chrome again (2/2).
10 03 2022 14:44:45.296:ERROR [launcher]: Cannot start Chrome
[0310/144445.046018:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[0310/144445.046104:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)
10 03 2022 14:44:45.297:ERROR [launcher]: Chrome stdout:
10 03 2022 14:44:45.297:ERROR [launcher]: Chrome stderr: [0310/144445.046018:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[0310/144445.046104:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)
10 03 2022 14:44:45.299:ERROR [launcher]: Chrome failed 2 times (cannot start). Giving up.
Chrome Headless 98.0.4758.102 (Linux x86_64): Executed 0 of 530 SUCCESS (0 secs / 0 secs)
Chrome Headless 98.0.4758.102 (Linux x86_64): Executed 0 of 530 SUCCESS (0 secs / 0 secs)
Chrome Headless 98.0.4758.102 (Linux x86_64): Executed 0 of 530 SUCCESS (0 secs / 0 secs)
Chrome Headless 98.0.4758.102 (Linux x86_64): Executed 0 of 530 SUCCESS (0 secs / 0 secs)
Chrome Headless 98.0.4758.102 (Linux x86_64): Executed 1 of 530 SUCCESS (0 secs / 0.505 secs)
Chrome Headless 98.0.4758.102 (Linux x86_64): Executed 1 of 530 SUCCESS (0 secs / 0.503 secs)
Chrome Headless 98.0.4758.102 (Linux x86_64): Executed 1 of 530 SUCCESS (0 secs / 0.505 secs)
Chrome Headless 98.0.4758.102 (Linux x86_64): Executed 1 of 530 (skipped 509) SUCCESS (0 secs / 0.503 secs)
Chrome Headless 98.0.4758.102 (Linux x86_64): Executed 1 of 530 (skipped 529) SUCCESS (1.435 secs / 0.505 secs)
Chrome Headless 98.0.4758.102 (Linux x86_64): Executed 1 of 530 (skipped 529) SUCCESS (1.584 secs / 0.503 secs)
Chrome Headless 98.0.4758.102 (Linux x86_64): Executed 1 of 530 (skipped 529) SUCCESS (1.435 secs / 0.505 secs)
TOTAL: 2 SUCCESS
TOTAL: 2 SUCCESS
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test:ci: `ng test --watch=false --code-coverage --source-map true`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test:ci script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2022-03-10T14_44_49_345Z-debug.log
Error: Process completed with exit code 1.
As you see tests started, and after 2 tests it's die. But there are 530 tests written.
Any idea how can I fix this?
Upvotes: 2
Views: 4439
Reputation: 4964
Per latest angular docs the command has changed slightly again with Angular 17
ng test --no-watch --no-progress --browsers=ChromeHeadless
Upvotes: 1
Reputation: 24234
For GitHub Actions, As of 27th August 2022, the command changed again!
"test:ci": "ng test --no-watch --no-progress --code-coverage --browsers=ChromeHeadlessCI",
Also be sure to have karma conf setup correctly in karma.conf.js
:
browsers: ['ChromeHeadlessCI'],
customLaunchers: {
ChromeHeadlessCI: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
}
}
Here's the link to the documentation.
Upvotes: 4
Reputation: 846
Dunno if GitHub action is same like Jenkins. But on Jenkins you need to run test with --browsers=ChromeHeadless. And the error looks like that GitHub is trying to open Chrome.
So try to change your test:ci in package.json
"test:ci": "ng test --browsers=ChromeHeadless --progress=false --watch=false --code-coverage --source-map=false",
Upvotes: 6