Open applecool opened 7 years ago
Finally the docker - karma - chrome started working for me but without puppeteer.
My Dockerfile has the chromium installation code like this (node10-alpine is my base image) -
RUN apk add --update --no-cache gifsicle ttf-freefont optipng libjpeg-turbo-utils udev chromium
ENV CHROME_BIN=/usr/bin/chromium-browser
RUN export CHROME_BIN=/usr/bin/chromium-browser
ENV LIGHTHOUSE_CHROMIUM_PATH=/usr/bin/chromium-browser
RUN export LIGHTHOUSE_CHROMIUM_PATH=/usr/bin/chromium-browser
I then copy my project source and run npm test in dockerfile itself and that is working.
My karma.config.js is looking like this -
browsers: ['ChromiumNoSandbox'],
customLaunchers: {
ChromiumNoSandbox: {
base: 'ChromiumHeadless',
flags: [
'--no-sandbox',
'--headless',
'--disable-gpu',
'--disable-translate',
'--disable-extensions'
]
}
},
Since no puppeteer no import statement at the beginning of the karma config file.
@ladariha. thanks so much for pointing out the proxy issue, which was exactly my case!
@abhaypuranik : can you please tell me which version of the karma you are using? and also is your framework uses Jasmine or something else? I am using Karma + Jasmine and having problem running tests in docker set up as part of CI approach,,, the headless chrome times out after 6000 ms
struggled with same error in local machine until figured out that above in console there is error of code compilation. Fixed code and now it works
Having the same problem running tests in Docker. @abhaypuranik solution works, but it requires us to install dependencies on top of the regular node:8.12.0-alpine
image. I was hoping to avoid this by using the pre-built puppeteer binary.
Docker image: node:8.12.0-alpine
karma: 1.7.0
karma-chrome-launcher: 2.2.0
puppeteer: 1.9.0
In our case that was some other reason, because we tried different headless chrome options, firefox headless, increasing max_old_space_size
, increasing timeout up to 400000 and other advices. But finally our guys changed hundreds of beforeEach
initialization methods from async to non-async like that from:
beforeEach(async(() => {
TestBed.configureTestingModule({
...
}).compileComponents();
}));
to
beforeEach(() => {
TestBed.configureTestingModule({
...
}).compileComponents();
});
Hope this advice will be helpful for someone.
I had to increase the shared memory for my docker container, e.g. if you use gitlab-runner, the gitlab-runner config has an entry shm_size = 0
. In my case I increased it to 300000000 => 300MB and everything works fine, no more disconnects
@applecool maybe there're some tests failed. In my mac air, if it's my first time to run ng test
command and there are some tests with unexpected outputs(it means some specs failed), I will get the same error info as you.
My solution is to clear some uncertain test specs to make sure there're no faliure test specs for first time, and run ng test
.After the chrome runned all tests, and add the test specs cleared by me before, it can normally show all the test result in chrome now.
If this is karma or jasmine's bug, I wish Angular CLI can offer optional choice for users to use jest when init a project( I think jest's doc is more friendly )
FWIW @saimaheshgaya's suggestion worked for me:
process.env.CHROME_BIN = require('puppeteer').executablePath();
i cant run tests only if i add the "coverage"
reporter.
I am building the app with webpack (outside of karma) with istanbul-instrumenter-loader
then running the resulting tests.js
with karma. The Chrome browser runs as long as i dont use the "coverage"
reporter. Otherwise i see the Disconnect message. This happens with both Chrome and ChromeHeadless. No Problems with Firefox or Firefox headless.
@eydrian suggestion put me on the right track... after trying a bunch of the suggestions - I finally realised that my CI nodes were running on default RAM & Swap space sizes.
I monitored my node's resources during the timeout - and found it was hitting the upper limit of what was available...
Increasing the swap size on slaves solved it for me... Posting in case someone else overlooked, as I did.
For me worked this code with the latest version, the important window size for a headless mode.
<pre>public void GoTest()
{
ChromeOptions options = new ChromeOptions();
options.AddArgument("--window-size=1920,1080");
options.AddArgument("--disable-gpu");
options.AddArgument("--disable-extensions");
options.AddArgument("--proxy-server='direct://'");
options.AddArgument("--proxy-bypass-list=*");
options.AddArgument("--start-maximized");
options.AddArgument("--headless");
options.AddArgument("no-sandbox");
var _driver = new ChromeDriver(options);
_driver.Navigate().GoToUrl("https://www.google.com");
object html = _driver.ExecuteScript("return document.body.parentElement.outerHTML");
_driver.Close();
}
</pre>
Simply adding '--no-proxy-server'
to flags
did the trick for me
For anyone having issues with docker (running alpine:3.7), this is what worked for me.
In the Dockerfile
I added:
RUN apk add --update chromium
ENV CHROME_BIN=/usr/bin/chromium-browser
ENV CHROME_PATH=/usr/lib/chromium/
then I created the the docker image via docker build -t=<your_tag>
and, like in my previous comment (although that part does not relate to docker), adding '--no-proxy-server'
to flags was also important
Has anyone gotten this to work with Chromium 72 on Alpine 3.9?
[launcher]: Launching browser ChromeHeadless_no_sandbox with unlimited concurrency
[launcher]: Starting browser ChromiumHeadless
[HeadlessChrome 72.0.3626 (Linux 0.0.0)]: Connected on socket S_rcdHvHTtkax5kbAAAA with id 83309822
[HeadlessChrome 72.0.3626 (Linux 0.0.0)]: Disconnected (1 times), because no message in 10000 ms.
I've been playing with the flags, but can't seem to get it to work.
ChromeHeadless_no_sandbox: {
base: 'ChromeHeadless',
flags: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--headless',
'--disable-gpu',
'--disable-translate',
'--disable-extensions',
'--disable-dev-shm-usage',
'--window-size=1920,1080',
'--start-maximized',
'--no-proxy-server',
'--remote-debugging-port=9222'
]
}
Is there a posibility that this problem could be related to source maps. Because when I update the command to:
ng test --code-coverage --no-watch --source-map=false
Now everything works without any timeout. If I change the command to:
ng test --code-coverage --watch=false
It starts failing again.
??
I ran into this issue on a CI testing VM and, for me, it appears to have been a resource issue.
I had a set of docker containers running on the box, if I shut them down then the tests would run fine. Start the containers back up and the timeout would happen again (every time).
I resized the VM adding more RAM and now it appears my tests can run with the set of containers running.
Yes, I've also found this is caused by resource constraints. We changed our CI strategy to spin up and down individual resources as needed for each Docker container and that resolved the issues.
Guys, it's all about doing things right.
My problem was caused because of how we create our tests. We didn't mock anything at all, a lot of memory was required because of that and the chrome driver disconnect and there you have all the timeouts.
My solution, use ng-mocks and ng-bullet and all the timeouts are gone. We have 288 tests. Before using mocks everywhere sometimes they took 2min and a half to finish. Now they pass in 8 seconds and with no timeout at all.
So, mock every service, module, component, pipe, etc and you will have a nice deployment (CI).
This is my karma config:
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
process.env.CHROME_BIN = require('puppeteer').executablePath();
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-mocha-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
files: [
{
pattern: './test.ts',
watched: false
},
{
pattern: '../node_modules/cookieconsent/build/cookieconsent.min.js',
watched: true,
included: true,
served: true
}
],
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../coverage'),
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'mocha'],
mochaReporter: {
output: 'minimal'
},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
singleRun: false,
browsers: ['ChromeHeadlessNoSandbox'],
browserDisconnectTolerance: 2,
browserNoActivityTimeout: 10000,
reportSlowerThan: 90,
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
}
}
});
};
Notice reportSlowerThan!!! Here I'm going to leave a complete example:
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {ApplicationNewComponent} from './application-new.component';
import {Application} from '../../shared/application.model';
import Program from '../../../program/shared/program.model';
import {ProgramService} from '../../../program/shared/program.service';
import * as applicationFixture from '../../shared/fixtures/application.json';
import * as programFixture from '../../../../modules/program/shared/fixtures/program.json';
import {of} from 'rxjs';
import {MockComponent, MockModule, MockPipe} from 'ng-mocks';
import {ApplicationPlaceholderComponent} from '../../components/application-placeholder/application-placeholder.component';
import {TranslateService} from '@ngx-translate/core';
import {ApplicationFormComponent} from '../../components/application-form/application-form.component';
import {RouterTestingModule} from '@angular/router/testing';
import {LocalizeRouterPipe, LocalizeRouterService} from 'localize-router';
import {HttpClientTestingModule} from '@angular/common/http/testing';
import {configureTestSuite} from 'ng-bullet';
import {CookieService} from 'ngx-cookie';
import {NgSelectModule} from '@ng-select/ng-select';
describe('ApplicationNewComponent', () => {
let component: ApplicationNewComponent;
let fixture: ComponentFixture<ApplicationNewComponent>;
const programServiceSpy = jasmine.createSpyObj('ProgramService', [
'getProgram'
]);
configureTestSuite(() => {
TestBed.configureTestingModule({
imports: [
MockModule(NgSelectModule),
RouterTestingModule,
HttpClientTestingModule
],
declarations: [
MockComponent(ApplicationPlaceholderComponent),
MockComponent(ApplicationFormComponent),
MockPipe(LocalizeRouterPipe),
ApplicationNewComponent
],
providers: [
{provide: ProgramService, useValue: programServiceSpy},
{
provide: TranslateService, useValue:
{
getBrowserCultureLang: (key) => key,
instant: (key) => key
}
},
{provide: LocalizeRouterService, useValue: {}},
{
provide: CookieService, useValue: {
getObject: () => {
}
}
}
]
});
});
beforeEach(() => {
fixture = TestBed.createComponent(ApplicationNewComponent);
component = fixture.componentInstance;
programServiceSpy.getProgram.and.returnValue(of(programFixture));
component.program = new Program(programFixture);
component.application = new Application(applicationFixture);
component.numberTypes = ProgramService.numberTypes;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
Our results at this moment:
TOTAL: 288 SUCCESS
Finished in 7.817 secs / 2.645 secs @ 13:08:42 GMT+0200 (CEST)
SUMMARY:
✔ 288 tests completed
⚠ 1 test slow
Hope this help someone.
For my use case, either of these approaches worked for keeping my Docker build from stalling when trying to run ChromeHeadless:
adding the --shm-size=1gb
flag to the docker build
adding --disable-dev-shm-usage
to the flags passed when karma/puppeteer starts up chrome
This was based on this section of the puppeteer troubleshooting doc: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#tips
By default, Docker runs a container with a /dev/shm shared memory space 64MB. This is typically too small for Chrome and will cause Chrome to crash when rendering large pages. To fix, run the container with docker run --shm-size=1gb to increase the size of /dev/shm. Since Chrome 65, this is no longer necessary. Instead, launch the browser with the --disable-dev-shm-usage flag
For anyone using Vue and Vuetify, I may have a fix. My issue was similar except most of the tests would actually run, but certain components would run a test or two and then freeze and timeout. Turns out removing this from my test/index.js file fixed it:
const app = document.createElement('div');
app.setAttribute('data-app', true);
document.body.appendChild(app);
Adding this is recommended by one of the Vuetify devs (https://github.com/vuetifyjs/vuetify/issues/1210#issuecomment-319624495) but for some reason, it was causing HTML to actually show up in Karma's window and I'm guessing this had to do with it freezing.
Removing this causes some warnings to display, but you can either ignore them or there are ways to make it so they don't show up (http://nidkil.me/2019/01/18/vuetify-multiple-instances-of-vue-detected/ just change the error message to '[Vuetify] Unable to locate target [data-app]')
For my use case, either of these approaches worked for keeping my Docker build from stalling when trying to run ChromeHeadless:
- adding the
--shm-size=1gb
flag to the docker build- adding
--disable-dev-shm-usage
to the flags passed when karma/puppeteer starts up chromeThis was based on this section of the puppeteer troubleshooting doc: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#tips
By default, Docker runs a container with a /dev/shm shared memory space 64MB. This is typically too small for Chrome and will cause Chrome to crash when rendering large pages. To fix, run the container with docker run --shm-size=1gb to increase the size of /dev/shm. Since Chrome 65, this is no longer necessary. Instead, launch the browser with the --disable-dev-shm-usage flag
This comment helped me a lot for my project where I want to run unit tests inside a Kubernetes container. Saved me a lot of trouble debugging.
@applecool The launcher is starting incorrect browser "Starting browser Chrome". it should launch "ChromeHeadless" Check my log below (mine is OSX as well, not Linux). When logs start flushing from HeadlessChrome 0.0.0 Google chromeheadless stated its execution, means Karma-chrome-launcher is fine. Did you report this to google chrome headless?
@applecool @vargarobert Puppeteer is not mandatory for ChromeHeadless browser in Karma. I can successfully run my tests without puppeteer.
package.json "karma": "^1.7.1", "karma-chrome-launcher": "^2.2.0",
my karma.conf.js starts with module.exports = function (config) { config.set({
My browser in karma.conf.js browsers: ['ChromeHeadless']
Im not using any custom launcher configurations. All options you have given are handled by karma-chrome-launcher line 168 in "node_modules/karma-chrome-launcher/index.js"
This is my log. [exec] Running "karma:unit" (karma) task [exec] 09 10 2017 22:52:13.282:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:8090/ [exec] 09 10 2017 22:52:13.283:INFO [launcher]: Launching browser ChromeHeadless with unlimited concurrency [exec] 09 10 2017 22:52:13.289:INFO [launcher]: Custom Starting browser ChromeHeadless [exec] 09 10 2017 22:52:13.639:INFO [HeadlessChrome 0.0.0 (Mac OS X 10.12.6)]: Connected on socket D6nT8-N4aXCaoUpKAAAA with id 86242225
@kumvem Did you run your test in local? or in any Cloud or pipeline as gitlab, bitbucket or another one?
@severila @Chris2011 Can you check i has been try with severals images but gitlab-ci give always the same error
> ang-cicd@0.0.0 test /app
> ng test
23 08 2019 22:40:00.517:WARN [karma]: No captured browser, open http://localhost:9876/
23 08 2019 22:40:00.609:INFO [karma-server]: Karma v4.1.0 server started at http://0.0.0.0:9876/
23 08 2019 22:40:00.610:INFO [launcher]: Launching browsers ChromeHeadlessNoSandbox with concurrency unlimited
23 08 2019 22:40:00.625:INFO [launcher]: Starting browser ChromeHeadless
23 08 2019 22:40:01.574:ERROR [launcher]: Cannot start ChromeHeadless
/app/node_modules/puppeteer/.local-chromium/linux-674921/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
23 08 2019 22:40:01.574:ERROR [launcher]: ChromeHeadless stdout:
23 08 2019 22:40:01.575:ERROR [launcher]: ChromeHeadless stderr: /app/node_modules/puppeteer/.local-chromium/linux-674921/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
23 08 2019 22:40:01.604:INFO [launcher]: Trying to start ChromeHeadless again (1/2).
23 08 2019 22:40:01.665:ERROR [launcher]: Cannot start ChromeHeadless
/app/node_modules/puppeteer/.local-chromium/linux-674921/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
23 08 2019 22:40:01.666:ERROR [launcher]: ChromeHeadless stdout:
23 08 2019 22:40:01.666:ERROR [launcher]: ChromeHeadless stderr: /app/node_modules/puppeteer/.local-chromium/linux-674921/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
23 08 2019 22:40:01.689:INFO [launcher]: Trying to start ChromeHeadless again (2/2).
23 08 2019 22:40:01.741:ERROR [launcher]: Cannot start ChromeHeadless
/app/node_modules/puppeteer/.local-chromium/linux-674921/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
23 08 2019 22:40:01.741:ERROR [launcher]: ChromeHeadless stdout:
23 08 2019 22:40:01.742:ERROR [launcher]: ChromeHeadless stderr: /app/node_modules/puppeteer/.local-chromium/linux-674921/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
23 08 2019 22:40:01.785:ERROR [launcher]: ChromeHeadless failed 2 times (cannot start). Giving up.
23 08 2019 22:40:07.332:WARN [karma]: No captured browser, open http://localhost:9876/
my karma.config looks like this
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
const process = require('process');
process.env.CHROME_BIN = require('puppeteer').executablePath();
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, './coverage/angCICD'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['ChromeHeadlessNoSandbox'],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox',
'--headless',
'--disable-gpu',
'--disable-translate',
'--disable-extensions'
]
}
},
singleRun: false,
restartOnFileChange: true,
concurrency: Infinity
});
};
protractor.config
// @ts-check
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const puppeteer = require('puppeteer');
const { SpecReporter } = require('jasmine-spec-reporter');
/**
* @type { import("protractor").Config }
*/
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/**/*.e2e-spec.ts'
],
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['--headless', '--no-sandbox'],
binary: puppeteer.executablePath()
}
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: require('path').join(__dirname, './tsconfig.json')
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};
and my gitlab-ci. i try with severals images for the chromeheadlesss test but the error is always the same
variables:
IMG_BUILD: node:latest
IMG_TEST: trion/ng-cli-karma
IMG_TESTING: alekzonder/puppeteer:latest
IMG_TESTING_FINAL: node:8.9.1
IMG_GITLAB_CI: juristr/angular-ci-build:1.0.0
IMG_TESTING_GITLAB: alekzonder/puppeteer:latest
IMG_TESTING_GITLAB2: buildkite/puppeteer
IMG_TESTING_GITLAB3: weltn24/up-docker-node-chrome-headless
stages:
- build
- test
cache:
paths:
- node_modules/
deploy_build:
state: build
image: ${IMG_BUILD}
enviroment: Production
artifacts:
paths:
- dist/
- node_modules/
only:
- master
script:
- rm ./package-lock.json
- npm install
- ./node_modules/@angular/cli/bin/ng build --progress false --prod --base-href testforcast1-stage.surge.sh
deploy_test:
stage: test
image: ${IMG_TESTING_GITLAB3}
environment: Production
cache:
policy: pull
artifacts:
paths:
- node_modules/
only:
- master
script:
- rm ./package-lock.json
- npm install
- ./node_modules/@angular/cli/bin/ng test --no-watch --no-progress
my package.json
{
"name": "ang-cicd",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"test-ci": "ng test --no-watch --no-progress",
"e2e-ci": "ng e2e --protractor-config=e2e/protractor-ci.conf.js",
"deploy": "firebase deploy --token $FIREBASE_TOKEN --non-interactive"
},
"private": true,
"dependencies": {
"@angular/animations": "~8.0.0",
"@angular/common": "~8.0.0",
"@angular/compiler": "~8.0.0",
"@angular/core": "~8.0.0",
"@angular/forms": "~8.0.0",
"@angular/platform-browser": "~8.0.0",
"@angular/platform-browser-dynamic": "~8.0.0",
"@angular/router": "~8.0.0",
"rxjs": "~6.4.0",
"surge": "^0.21.3",
"tslib": "^1.9.0",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.800.0",
"@angular/cli": "~8.0.1",
"@angular/compiler-cli": "~8.0.0",
"@angular/language-service": "~8.0.0",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "^5.0.0",
"firebase-tools": "^7.2.4",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"protractor": "~5.4.0",
"puppeteer": "^1.19.0",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",
"typescript": "~3.4.3"
}
}
also i am using puppeteer for run those test into gitlab-ci, if i execute in my local ng test --no-watch --no-progress all headless test doing good
/angCICD$ ng test --no-watch --no-progress
23 08 2019 20:02:52.192:INFO [karma-server]: Karma v4.1.0 server started at http://0.0.0.0:9876/
23 08 2019 20:02:52.195:INFO [launcher]: Launching browsers ChromeHeadlessNoSandbox with concurrency unlimited
23 08 2019 20:02:52.216:INFO [launcher]: Starting browser ChromeHeadless
23 08 2019 20:03:07.522:INFO [HeadlessChrome 77.0.3844 (Linux 0.0.0)]: Connected on socket f3bv_Arfm_8Y2h-LAAAA with id 54406404
HeadlessChrome 77.0.3844 (Linux 0.0.0): Executed 4 of 4 SUCCESS (0.155 secs / 0.145 secs)
TOTAL: 4 SUCCESS
TOTAL: 4 SUCCESS
Any advices?
Finally the docker - karma - chrome started working for me but without puppeteer.
My Dockerfile has the chromium installation code like this (node10-alpine is my base image) -
RUN apk add --update --no-cache gifsicle ttf-freefont optipng libjpeg-turbo-utils udev chromium ENV CHROME_BIN=/usr/bin/chromium-browser RUN export CHROME_BIN=/usr/bin/chromium-browser ENV LIGHTHOUSE_CHROMIUM_PATH=/usr/bin/chromium-browser RUN export LIGHTHOUSE_CHROMIUM_PATH=/usr/bin/chromium-browser
I then copy my project source and run npm test in dockerfile itself and that is working.
My karma.config.js is looking like this -
browsers: ['ChromiumNoSandbox'], customLaunchers: { ChromiumNoSandbox: { base: 'ChromiumHeadless', flags: [ '--no-sandbox', '--headless', '--disable-gpu', '--disable-translate', '--disable-extensions' ] } },
Since no puppeteer no import statement at the beginning of the karma config file.
do you add those into your script section on gitlab-ci.yml?
RUN apk add --update --no-cache gifsicle ttf-freefont optipng libjpeg-turbo-utils udev chromium
> ENV CHROME_BIN=/usr/bin/chromium-browser
> RUN export CHROME_BIN=/usr/bin/chromium-browser
> ENV LIGHTHOUSE_CHROMIUM_PATH=/usr/bin/chromium-browser
> RUN export LIGHTHOUSE_CHROMIUM_PATH=/usr/bin/chromium-browser
@neilsh in wich place you make that command i read that but was confused for me about where i put it, because i try with a severals image with prebuild stuff like those:
variables:
IMG_BUILD: node:latest
IMG_TEST: trion/ng-cli-karma
IMG_TESTING: alekzonder/puppeteer:latest
IMG_TESTING_FINAL: node:8.9.1
IMG_GITLAB_CI: juristr/angular-ci-build:1.0.0
IMG_TESTING_GITLAB: alekzonder/puppeteer:latest
IMG_TESTING_GITLAB2: buildkite/puppeteer
IMG_TESTING_GITLAB3: weltn24/up-docker-node-chrome-headless
should i add --shm-size=1gb into my scripts on gitlab-ci? i am kinda confused
thx for help
@reduckted Could you please post the karma.conf.js file. Angular unit tests are not running at the jenkins. ERROR: script returned exit code 1.
Been wrestling with this for over a week now: karma.conf.js:
process = require('process');
process.env.CHROME_BIN = require('puppeteer').executablePath();
module.exports = function (config) {
config.set({
frameworks: ['jasmine'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('karma-junit-reporter')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml', 'junit'],
junitReporter: {
outputDir: '../../NgTestResults/', // results will be saved as $outputDir/$browserName.xml
outputFile: undefined, // if included, results will be saved as $outputDir/$browserName/$outputFile
useBrowserName: true, // add browser name to report and classes names
color: false
},
logLevel: config.LOG_DEBUG,
browsers: ['ChromeHeadlessCI'],
captureTimeout: 60000, // it was already there
browserDisconnectTimeout : 10000,
browserDisconnectTolerance : 1,
browserNoActivityTimeout : 60000,//by default 10000
port: 9876,
customLaunchers: {
ChromeHeadlessCI: {
base: 'Chrome',
flags: [
'--no-sandbox',
'--headless',
'--disable-gpu',
'--disable-translate',
'--disable-extensions',
'--disable-dev-shm-usage'
]
}
},
singleRun: false
});
};
npm test
scripted to:
ng tet --no-watch --browsers ChromeHeadlessCI
Container is using mcr.microsoft.com/windows:1809 (but this also happens on mcr.microsoft.com/windows/servercore:1809).
Error:
16:07:17 > Project@0.0.0 test C:\workspace\test\src\Project
16:07:17 > ng test --no-watch --browsers ChromeHeadlessCI
16:07:17
16:07:21 [36m19 09 2019 16:07:20.849:DEBUG [config]: [39mautoWatch set to false, because of singleRun
16:07:21 [36m19 09 2019 16:07:20.855:DEBUG [plugin]: [39mLoading inlined plugin (defining framework:jasmine).
16:07:21 [36m19 09 2019 16:07:20.855:DEBUG [plugin]: [39mLoading inlined plugin (defining launcher:Chrome, launcher:ChromeHeadless, launcher:ChromeCanary, launcher:ChromeCanaryHeadless, launcher:Chromium, launcher:ChromiumHeadless, launcher:Dartium, test).
16:07:21 [36m19 09 2019 16:07:20.855:DEBUG [plugin]: [39mLoading inlined plugin (defining reporter:kjhtml).
16:07:21 [36m19 09 2019 16:07:20.855:DEBUG [plugin]: [39mLoading inlined plugin (defining reporter:coverage-istanbul).
16:07:21 [36m19 09 2019 16:07:20.855:DEBUG [plugin]: [39mLoading inlined plugin (defining reporter:junit).
16:07:21 [36m19 09 2019 16:07:20.855:DEBUG [plugin]: [39mLoading inlined plugin (defining launcher:ChromeHeadlessCI).
16:07:21 [36m19 09 2019 16:07:20.868:DEBUG [web-server]: [39mInstantiating middleware
16:07:21 [36m19 09 2019 16:07:20.891:DEBUG [reporter]: [39mTrying to load reporter: kjhtml
16:07:21 [36m19 09 2019 16:07:20.891:DEBUG [reporter]: [39mTrying to load color-version of reporter: kjhtml (kjhtml_color)
16:07:21 [36m19 09 2019 16:07:20.891:DEBUG [reporter]: [39mCouldn't load color-version.
16:07:21 [36m19 09 2019 16:07:20.891:DEBUG [reporter]: [39mTrying to load reporter: junit
16:07:21 [36m19 09 2019 16:07:20.893:DEBUG [reporter]: [39mTrying to load color-version of reporter: junit (junit_color)
16:07:21 [36m19 09 2019 16:07:20.893:DEBUG [reporter]: [39mCouldn't load color-version.
16:07:21 [32m19 09 2019 16:07:20.925:INFO [karma]: [39mKarma v1.7.1 server started at http://0.0.0.0:9876/
16:07:21 [32m19 09 2019 16:07:20.925:INFO [launcher]: [39mLaunching browser ChromeHeadlessCI with unlimited concurrency
16:07:21 [32m19 09 2019 16:07:20.935:INFO [launcher]: [39mStarting browser Chrome
16:07:21 [36m19 09 2019 16:07:20.936:DEBUG [temp-dir]: [39mCreating temp dir at C:\Users\ContainerAdministrator\AppData\Local\Temp\karma-58795446
16:07:21 [36m19 09 2019 16:07:20.937:DEBUG [launcher]: [39mC:\workspace\test\src\Project\node_modules\puppeteer\.local-chromium\win64-674921\chrome-win\chrome.exe --user-data-dir=C:\Users\ContainerAdministrator\AppData\Local\Temp\karma-58795446 --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-background-timer-throttling --disable-renderer-backgrounding --disable-device-discovery-notifications --no-sandbox --headless --disable-gpu --disable-translate --disable-extensions --disable-dev-shm-usage http://localhost:9876/?id=58795446
16:07:24 [36m19 09 2019 16:07:24.166:DEBUG [launcher]: [39mProcess Chrome exited with code 0
16:07:24 [31m19 09 2019 16:07:24.166:ERROR [launcher]: [39mCannot start Chrome
16:07:24 [0919/160721.587:ERROR:network_change_notifier_win.cc(146)] WSALookupServiceBegin failed with: 0
16:07:24 [0919/160724.123:ERROR:browser_process_sub_thread.cc(203)] Waited 25 ms for network service
16:07:24
16:07:24 [31m19 09 2019 16:07:24.166:ERROR [launcher]: [39mChrome stdout:
16:07:24 [31m19 09 2019 16:07:24.166:ERROR [launcher]: [39mChrome stderr: [0919/160721.587:ERROR:network_change_notifier_win.cc(146)] WSALookupServiceBegin failed with: 0
16:07:24 [0919/160724.123:ERROR:browser_process_sub_thread.cc(203)] Waited 25 ms for network service
16:07:24
16:07:24 [36m19 09 2019 16:07:24.166:DEBUG [temp-dir]: [39mCleaning temp dir C:\Users\ContainerAdministrator\AppData\Local\Temp\karma-58795446
16:07:24 [32m19 09 2019 16:07:24.279:INFO [launcher]: [39mTrying to start Chrome again (1/2).
16:07:24 [36m19 09 2019 16:07:24.279:DEBUG [launcher]: [39mRestarting Chrome
16:07:24 [36m19 09 2019 16:07:24.280:DEBUG [temp-dir]: [39mCreating temp dir at C:\Users\ContainerAdministrator\AppData\Local\Temp\karma-58795446
16:07:24 [36m19 09 2019 16:07:24.280:DEBUG [launcher]: [39mC:\workspace\test\src\Project\node_modules\puppeteer\.local-chromium\win64-674921\chrome-win\chrome.exe --user-data-dir=C:\Users\ContainerAdministrator\AppData\Local\Temp\karma-58795446 --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-background-timer-throttling --disable-renderer-backgrounding --disable-device-discovery-notifications --no-sandbox --headless --disable-gpu --disable-translate --disable-extensions --disable-dev-shm-usage http://localhost:9876/?id=58795446
16:07:27 [36m19 09 2019 16:07:26.771:DEBUG [launcher]: [39mProcess Chrome exited with code 0
16:07:27 [31m19 09 2019 16:07:26.771:ERROR [launcher]: [39mCannot start Chrome
16:07:27 [0919/160724.436:ERROR:network_change_notifier_win.cc(146)] WSALookupServiceBegin failed with: 0
16:07:27 [0919/160726.745:ERROR:browser_process_sub_thread.cc(203)] Waited 24 ms for network service
16:07:27
16:07:27 [31m19 09 2019 16:07:26.771:ERROR [launcher]: [39mChrome stdout:
16:07:27 [31m19 09 2019 16:07:26.771:ERROR [launcher]: [39mChrome stderr: [0919/160724.436:ERROR:network_change_notifier_win.cc(146)] WSALookupServiceBegin failed with: 0
16:07:27 [0919/160726.745:ERROR:browser_process_sub_thread.cc(203)] Waited 24 ms for network service
16:07:27
16:07:27 [36m19 09 2019 16:07:26.771:DEBUG [temp-dir]: [39mCleaning temp dir C:\Users\ContainerAdministrator\AppData\Local\Temp\karma-58795446
16:07:27 [32m19 09 2019 16:07:26.786:INFO [launcher]: [39mTrying to start Chrome again (2/2).
16:07:27 [36m19 09 2019 16:07:26.786:DEBUG [launcher]: [39mRestarting Chrome
16:07:27 [36m19 09 2019 16:07:26.787:DEBUG [temp-dir]: [39mCreating temp dir at C:\Users\ContainerAdministrator\AppData\Local\Temp\karma-58795446
16:07:27 [36m19 09 2019 16:07:26.787:DEBUG [launcher]: [39mC:\workspace\test\src\Project\node_modules\puppeteer\.local-chromium\win64-674921\chrome-win\chrome.exe --user-data-dir=C:\Users\ContainerAdministrator\AppData\Local\Temp\karma-58795446 --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-background-timer-throttling --disable-renderer-backgrounding --disable-device-discovery-notifications --no-sandbox --headless --disable-gpu --disable-translate --disable-extensions --disable-dev-shm-usage http://localhost:9876/?id=58795446
16:07:29 [36m19 09 2019 16:07:29.237:DEBUG [launcher]: [39mProcess Chrome exited with code 0
16:07:29 [31m19 09 2019 16:07:29.238:ERROR [launcher]: [39mCannot start Chrome
16:07:29 [0919/160726.931:ERROR:network_change_notifier_win.cc(146)] WSALookupServiceBegin failed with: 0
16:07:29 [0919/160729.211:ERROR:browser_process_sub_thread.cc(203)] Waited 24 ms for network service
16:07:29
16:07:29 [31m19 09 2019 16:07:29.238:ERROR [launcher]: [39mChrome stdout:
16:07:29 [31m19 09 2019 16:07:29.238:ERROR [launcher]: [39mChrome stderr: [0919/160726.931:ERROR:network_change_notifier_win.cc(146)] WSALookupServiceBegin failed with: 0
16:07:29 [0919/160729.211:ERROR:browser_process_sub_thread.cc(203)] Waited 24 ms for network service
16:07:29
16:07:29 [36m19 09 2019 16:07:29.238:DEBUG [temp-dir]: [39mCleaning temp dir C:\Users\ContainerAdministrator\AppData\Local\Temp\karma-58795446
16:07:29 [31m19 09 2019 16:07:29.347:ERROR [launcher]: [39mChrome failed 2 times (cannot start). Giving up.
16:07:29 [36m19 09 2019 16:07:29.348:DEBUG [karma]: [39mRun complete, exiting.
16:07:29 [36m19 09 2019 16:07:29.349:DEBUG [launcher]: [39mDisconnecting all browsers
16:07:30 powershell.exe : npm : npm ERR! Test failed. See above for more details.
16:07:30 At C:\workspace\test@tmp\durable-f75d1af5\powershellWrapper.ps1:3 char:1
16:07:30 + & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Comm ...
16:07:30 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16:07:30 + CategoryInfo : NotSpecified: (npm : npm ERR! ...r more details.:String) [], RemoteException
16:07:30 + FullyQualifiedErrorId : NativeCommandError
16:07:30
16:07:30 At C:\workspace\test@tmp\durable-f75d1af5\powershellScript.ps1:5 char:7
16:07:30 + npm test
16:07:30 + ~~~~~~~~
16:07:30 + CategoryInfo : NotSpecified: (npm ERR! Test f...r more details.:String) [], RemoteException
16:07:30 + FullyQualifiedErrorId : NativeCommandError
any update here?
Been wrestling with this for over a week now: karma.conf.js:
process = require('process'); process.env.CHROME_BIN = require('puppeteer').executablePath(); module.exports = function (config) { config.set({ frameworks: ['jasmine'], plugins: [ require('karma-jasmine'), require('karma-chrome-launcher'), require('karma-jasmine-html-reporter'), require('karma-coverage-istanbul-reporter'), require('karma-junit-reporter') ], client: { clearContext: false // leave Jasmine Spec Runner output visible in browser }, coverageIstanbulReporter: { reports: ['html', 'lcovonly'], fixWebpackSourcePaths: true }, reporters: ['progress', 'kjhtml', 'junit'], junitReporter: { outputDir: '../../NgTestResults/', // results will be saved as $outputDir/$browserName.xml outputFile: undefined, // if included, results will be saved as $outputDir/$browserName/$outputFile useBrowserName: true, // add browser name to report and classes names color: false }, logLevel: config.LOG_DEBUG, browsers: ['ChromeHeadlessCI'], captureTimeout: 60000, // it was already there browserDisconnectTimeout : 10000, browserDisconnectTolerance : 1, browserNoActivityTimeout : 60000,//by default 10000 port: 9876, customLaunchers: { ChromeHeadlessCI: { base: 'Chrome', flags: [ '--no-sandbox', '--headless', '--disable-gpu', '--disable-translate', '--disable-extensions', '--disable-dev-shm-usage' ] } }, singleRun: false }); };
npm test
scripted to:ng tet --no-watch --browsers ChromeHeadlessCI
Container is using mcr.microsoft.com/windows:1809 (but this also happens on mcr.microsoft.com/windows/servercore:1809).
Error:
16:07:17 > Project@0.0.0 test C:\workspace\test\src\Project 16:07:17 > ng test --no-watch --browsers ChromeHeadlessCI 16:07:17 16:07:21 �[36m19 09 2019 16:07:20.849:DEBUG [config]: �[39mautoWatch set to false, because of singleRun 16:07:21 �[36m19 09 2019 16:07:20.855:DEBUG [plugin]: �[39mLoading inlined plugin (defining framework:jasmine). 16:07:21 �[36m19 09 2019 16:07:20.855:DEBUG [plugin]: �[39mLoading inlined plugin (defining launcher:Chrome, launcher:ChromeHeadless, launcher:ChromeCanary, launcher:ChromeCanaryHeadless, launcher:Chromium, launcher:ChromiumHeadless, launcher:Dartium, test). 16:07:21 �[36m19 09 2019 16:07:20.855:DEBUG [plugin]: �[39mLoading inlined plugin (defining reporter:kjhtml). 16:07:21 �[36m19 09 2019 16:07:20.855:DEBUG [plugin]: �[39mLoading inlined plugin (defining reporter:coverage-istanbul). 16:07:21 �[36m19 09 2019 16:07:20.855:DEBUG [plugin]: �[39mLoading inlined plugin (defining reporter:junit). 16:07:21 �[36m19 09 2019 16:07:20.855:DEBUG [plugin]: �[39mLoading inlined plugin (defining launcher:ChromeHeadlessCI). 16:07:21 �[36m19 09 2019 16:07:20.868:DEBUG [web-server]: �[39mInstantiating middleware 16:07:21 �[36m19 09 2019 16:07:20.891:DEBUG [reporter]: �[39mTrying to load reporter: kjhtml 16:07:21 �[36m19 09 2019 16:07:20.891:DEBUG [reporter]: �[39mTrying to load color-version of reporter: kjhtml (kjhtml_color) 16:07:21 �[36m19 09 2019 16:07:20.891:DEBUG [reporter]: �[39mCouldn't load color-version. 16:07:21 �[36m19 09 2019 16:07:20.891:DEBUG [reporter]: �[39mTrying to load reporter: junit 16:07:21 �[36m19 09 2019 16:07:20.893:DEBUG [reporter]: �[39mTrying to load color-version of reporter: junit (junit_color) 16:07:21 �[36m19 09 2019 16:07:20.893:DEBUG [reporter]: �[39mCouldn't load color-version. 16:07:21 �[32m19 09 2019 16:07:20.925:INFO [karma]: �[39mKarma v1.7.1 server started at http://0.0.0.0:9876/ 16:07:21 �[32m19 09 2019 16:07:20.925:INFO [launcher]: �[39mLaunching browser ChromeHeadlessCI with unlimited concurrency 16:07:21 �[32m19 09 2019 16:07:20.935:INFO [launcher]: �[39mStarting browser Chrome 16:07:21 �[36m19 09 2019 16:07:20.936:DEBUG [temp-dir]: �[39mCreating temp dir at C:\Users\ContainerAdministrator\AppData\Local\Temp\karma-58795446 16:07:21 �[36m19 09 2019 16:07:20.937:DEBUG [launcher]: �[39mC:\workspace\test\src\Project\node_modules\puppeteer\.local-chromium\win64-674921\chrome-win\chrome.exe --user-data-dir=C:\Users\ContainerAdministrator\AppData\Local\Temp\karma-58795446 --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-background-timer-throttling --disable-renderer-backgrounding --disable-device-discovery-notifications --no-sandbox --headless --disable-gpu --disable-translate --disable-extensions --disable-dev-shm-usage http://localhost:9876/?id=58795446 16:07:24 �[36m19 09 2019 16:07:24.166:DEBUG [launcher]: �[39mProcess Chrome exited with code 0 16:07:24 �[31m19 09 2019 16:07:24.166:ERROR [launcher]: �[39mCannot start Chrome 16:07:24 [0919/160721.587:ERROR:network_change_notifier_win.cc(146)] WSALookupServiceBegin failed with: 0 16:07:24 [0919/160724.123:ERROR:browser_process_sub_thread.cc(203)] Waited 25 ms for network service 16:07:24 16:07:24 �[31m19 09 2019 16:07:24.166:ERROR [launcher]: �[39mChrome stdout: 16:07:24 �[31m19 09 2019 16:07:24.166:ERROR [launcher]: �[39mChrome stderr: [0919/160721.587:ERROR:network_change_notifier_win.cc(146)] WSALookupServiceBegin failed with: 0 16:07:24 [0919/160724.123:ERROR:browser_process_sub_thread.cc(203)] Waited 25 ms for network service 16:07:24 16:07:24 �[36m19 09 2019 16:07:24.166:DEBUG [temp-dir]: �[39mCleaning temp dir C:\Users\ContainerAdministrator\AppData\Local\Temp\karma-58795446 16:07:24 �[32m19 09 2019 16:07:24.279:INFO [launcher]: �[39mTrying to start Chrome again (1/2). 16:07:24 �[36m19 09 2019 16:07:24.279:DEBUG [launcher]: �[39mRestarting Chrome 16:07:24 �[36m19 09 2019 16:07:24.280:DEBUG [temp-dir]: �[39mCreating temp dir at C:\Users\ContainerAdministrator\AppData\Local\Temp\karma-58795446 16:07:24 �[36m19 09 2019 16:07:24.280:DEBUG [launcher]: �[39mC:\workspace\test\src\Project\node_modules\puppeteer\.local-chromium\win64-674921\chrome-win\chrome.exe --user-data-dir=C:\Users\ContainerAdministrator\AppData\Local\Temp\karma-58795446 --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-background-timer-throttling --disable-renderer-backgrounding --disable-device-discovery-notifications --no-sandbox --headless --disable-gpu --disable-translate --disable-extensions --disable-dev-shm-usage http://localhost:9876/?id=58795446 16:07:27 �[36m19 09 2019 16:07:26.771:DEBUG [launcher]: �[39mProcess Chrome exited with code 0 16:07:27 �[31m19 09 2019 16:07:26.771:ERROR [launcher]: �[39mCannot start Chrome 16:07:27 [0919/160724.436:ERROR:network_change_notifier_win.cc(146)] WSALookupServiceBegin failed with: 0 16:07:27 [0919/160726.745:ERROR:browser_process_sub_thread.cc(203)] Waited 24 ms for network service 16:07:27 16:07:27 �[31m19 09 2019 16:07:26.771:ERROR [launcher]: �[39mChrome stdout: 16:07:27 �[31m19 09 2019 16:07:26.771:ERROR [launcher]: �[39mChrome stderr: [0919/160724.436:ERROR:network_change_notifier_win.cc(146)] WSALookupServiceBegin failed with: 0 16:07:27 [0919/160726.745:ERROR:browser_process_sub_thread.cc(203)] Waited 24 ms for network service 16:07:27 16:07:27 �[36m19 09 2019 16:07:26.771:DEBUG [temp-dir]: �[39mCleaning temp dir C:\Users\ContainerAdministrator\AppData\Local\Temp\karma-58795446 16:07:27 �[32m19 09 2019 16:07:26.786:INFO [launcher]: �[39mTrying to start Chrome again (2/2). 16:07:27 �[36m19 09 2019 16:07:26.786:DEBUG [launcher]: �[39mRestarting Chrome 16:07:27 �[36m19 09 2019 16:07:26.787:DEBUG [temp-dir]: �[39mCreating temp dir at C:\Users\ContainerAdministrator\AppData\Local\Temp\karma-58795446 16:07:27 �[36m19 09 2019 16:07:26.787:DEBUG [launcher]: �[39mC:\workspace\test\src\Project\node_modules\puppeteer\.local-chromium\win64-674921\chrome-win\chrome.exe --user-data-dir=C:\Users\ContainerAdministrator\AppData\Local\Temp\karma-58795446 --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-background-timer-throttling --disable-renderer-backgrounding --disable-device-discovery-notifications --no-sandbox --headless --disable-gpu --disable-translate --disable-extensions --disable-dev-shm-usage http://localhost:9876/?id=58795446 16:07:29 �[36m19 09 2019 16:07:29.237:DEBUG [launcher]: �[39mProcess Chrome exited with code 0 16:07:29 �[31m19 09 2019 16:07:29.238:ERROR [launcher]: �[39mCannot start Chrome 16:07:29 [0919/160726.931:ERROR:network_change_notifier_win.cc(146)] WSALookupServiceBegin failed with: 0 16:07:29 [0919/160729.211:ERROR:browser_process_sub_thread.cc(203)] Waited 24 ms for network service 16:07:29 16:07:29 �[31m19 09 2019 16:07:29.238:ERROR [launcher]: �[39mChrome stdout: 16:07:29 �[31m19 09 2019 16:07:29.238:ERROR [launcher]: �[39mChrome stderr: [0919/160726.931:ERROR:network_change_notifier_win.cc(146)] WSALookupServiceBegin failed with: 0 16:07:29 [0919/160729.211:ERROR:browser_process_sub_thread.cc(203)] Waited 24 ms for network service 16:07:29 16:07:29 �[36m19 09 2019 16:07:29.238:DEBUG [temp-dir]: �[39mCleaning temp dir C:\Users\ContainerAdministrator\AppData\Local\Temp\karma-58795446 16:07:29 �[31m19 09 2019 16:07:29.347:ERROR [launcher]: �[39mChrome failed 2 times (cannot start). Giving up. 16:07:29 �[36m19 09 2019 16:07:29.348:DEBUG [karma]: �[39mRun complete, exiting. 16:07:29 �[36m19 09 2019 16:07:29.349:DEBUG [launcher]: �[39mDisconnecting all browsers 16:07:30 powershell.exe : npm : npm ERR! Test failed. See above for more details. 16:07:30 At C:\workspace\test@tmp\durable-f75d1af5\powershellWrapper.ps1:3 char:1 16:07:30 + & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Comm ... 16:07:30 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 16:07:30 + CategoryInfo : NotSpecified: (npm : npm ERR! ...r more details.:String) [], RemoteException 16:07:30 + FullyQualifiedErrorId : NativeCommandError 16:07:30 16:07:30 At C:\workspace\test@tmp\durable-f75d1af5\powershellScript.ps1:5 char:7 16:07:30 + npm test 16:07:30 + ~~~~~~~~ 16:07:30 + CategoryInfo : NotSpecified: (npm ERR! Test f...r more details.:String) [], RemoteException 16:07:30 + FullyQualifiedErrorId : NativeCommandError
please correct npm test
with npm run test
@tobiasetter That had no effect. Exact same output.
This is what I did to get it to work. I am running angular 7 and this works on angular 8. I created its own Dockerfile and Compose file. my root repository looks like this:
root-of-repository/
In karma.config:
process.env.NO_PROXY = 'localhost, 0.0.0.0/4201, 0.0.0.0/9876';
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../coverage'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true,
thresholds: {
emitWarning: false,
global: {
lines: 85
},
each: {
lines: 85
}
}
},
customLaunchers: {
ChromeHeadless: {
base: 'Chrome',
flags: [
'--headless',
'--disable-gpu',
'--disable-translate',
'--disable-extensions',
'--disable-web-security',
'--no-sandbox',
'--remote-debugging-port=9222'
]
}
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: true,
exclude: ['**/model/**']
});
};
In the Dockerfile.test:
FROM node
LABEL firstname lastname
WORKDIR /root/
COPY ./ng-app /root/ng-app
WORKDIR /root/ng-app
RUN npm i -g @angular/cli && npm i
# Install Chrome
RUN apt-get update && apt-get install -y --no-install-recommends chromium iceweasel && apt-get clean
CMD ["npm", "run", "test-coverage"]
I prefer to run things in a docker-compose file because it's easier to read... in docker-compose.test.yml file:
version: '3.3'
services:
web:
build:
context: .
dockerfile: Dockerfile.test
command: ['npm', 'run', 'test-coverage']
image: portal/ng-app:latest
volumes:
- ./ng-app:/root/ng-app
ports:
- 9876:9876
environment:
- DISPLAY=:99
- CHROME_BIN=chromium
container_name: test
We had the similar issue on our setup with more than 2500 tests. We found 2 different options to avoid chrome disconnection during test execution.
--source-map=false
for test command like ng test <project_name> --source-map=false
js-flags
property in karma.config to set memory allocated for browser:
customLaunchers: {
ChromeHeadless: {
base: "Chrome",
flags: [
"--headless",
"--disable-gpu",
"--no-sandbox", // required to run without privileges in docker
"--remote-debugging-port=9222", // Without a remote debugging port, Google Chrome exits immediately.
"--js-flags=--max-old-space-size=4096"
]
}
},
For large tests we have also begun converting inline sourcemaps to //# sourceMappingURL=
, significantly reducing both the bytes sent to the browser (for passing runs where no maps are needed) and memory in the browser to store the maps.
For my team, we would get a lot of timeout issues with chrome running tests in docker. increasing the - shm_size: '256m' in our compose file or running docker run ... --shm-size=256m
fixed it for us.
Is there a posibility that this problem could be related to source maps. Because when I update the command to:
ng test --code-coverage --no-watch --source-map=false
Now everything works without any timeout. If I change the command to:
ng test --code-coverage --watch=false
It starts failing again.
??
Incredible how something so trivial as sourceMaps can fix such a seemingly unrelated issue!
Yeah, creating source maps requires a lot of additional memory, so getting rid of them allows tests to pass within some default memory limits, otherwise we need to increase them.
(Notice how I'm not using the puppeteer package)
I'm currently on Windows 10 and running an Angular 9 Workspace with Nx 9 Configurations.
The following is the auto-generated karma.conf.js
file with one change.
Apparantly changing the base of the customLauncher from ChromiumHeadless
to ChromeHeadless
seems to work
const { join } = require('path');
const { constants } = require('karma');
module.exports = () => {
return {
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: join(__dirname, '../../coverage'),
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: constants.LOG_INFO,
autoWatch: true,
browsers: ['ChromiumNoSandbox'],
customLaunchers: {
ChromiumNoSandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox', '--headless', '--disable-gpu', '--disable-translate', '--disable-extensions']
}
},
singleRun: true
};
};
If you're having problems running your CI tests in a docker container, consider checking out the Chromium Docker image base from rastasheep.
watch
Try adding the flag,
'--window-size=1920,1080',
I know its supposed to be headless but setting the window-size seems to work for me.
Here's my config,
customLaunchers: { ChromeCI: { base: 'ChromeHeadless', flags: [ '--disable-gpu', '--window-size=1920,1080', '--remote-debugging-port=9222' ], debug: true } }
I had this error while executing tests on gitlab ci and launching the command ng test --watch=false --browsers=ChromeHeadlessNoSandbox --source-map=false --karmaConfig=karma-ci.conf.js
I tried everything, but only after updating karma-chrome-launcher from 2.2.0 to 3.1.0 I was able to solve my problem
@davidrdz93 what does your karma-ci.conf.js
look like? I just hit this wall of an issue.
I spent a few hours today fighting Karma not working with Chrome in our GitLab CI pipeline and finally got it working, so I figured I'd comment here if it helps anyone. This is a repo that hasn't been touched for several years, so the package versions we're using are severely outdated. But, this is the setup that worked for me in case anyone else is working with ancient versions:
karma.conf.js
:
browsers: ['HeadlessChrome'],
customLaunchers: {
HeadlessChrome: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
}
},
package.json
:
"karma": "0.13.19",
"karma-chrome-launcher": "3.1.0",
"karma-jasmine": "0.1.6",
@DanielLoyAugmedix This is how my file karma-ci.conf.js looks like, I've added puppeteer version 3.0.0 as Headless Chrome to my package.json.
const puppeteer = require('puppeteer');
process.env.CHROME_BIN = puppeteer.executablePath();
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../coverage'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: [
'ChromeHeadlessNoSandbox'
],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: [
'--no-sandbox',
'--headless',
'--disable-gpu',
'--disable-translate',
'--disable-extensions'
]
}
},
singleRun: false
});
};
I had the same problem. I have around 1750 tests which took ~1m30s and the headless chrome gets disconnected way before that. The reason could be the way phantomJS is dealing with memory and garbage collection
I had added the following code in karma.config and that resolved the issue
module.exports = function(config) { config.set({ frameworks: ['parallel', 'jasmine'] }); };
This starts multiple headless chrome instances(in my case) to run the tests in parallel. This not just solved the problem but also, I've seen significant difference in the time it took to run the tests. Almost 30% 🥇
My setup was with WSL2 (Ubuntu 20) on Windows 10, and headless Chrome just didn't respond and timed out. But after I terminated WSL (with the command wslconfig /t Ubuntu
) then tried again, it could run very well without any errors.
Hope it'll help.
I had this error while executing tests on gitlab ci and launching the command ng test --watch=false --browsers=ChromeHeadlessNoSandbox --source-map=false --karmaConfig=karma-ci.conf.js
I tried everything, but only after updating karma-chrome-launcher from 2.2.0 to 3.1.0 I was able to solve my problem
didn't work in my case
Still facing the same issue, Is there no Solution to this problem ??
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
require('karma-trx-reporter'),
require("karma-spec-reporter")
],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
random: false
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../coverage'),
reports: ['html', 'lcovonly', 'text-summary', 'cobertura'],
fixWebpackSourcePaths: true,
thresholds: {
statements: 80,
lines: 80,
branches: 80,
functions: 80
}
},
reporters: ['spec', 'kjhtml', 'trx'],
jasmineHtmlReporter: {
suppressAll: true, // Suppress all messages (overrides other suppress settings)
suppressFailed: true // Suppress failed messages
},
specReporter: {
maxLogLines: 10, // limit number of lines logged per test
suppressErrorSummary: false, // do not print error summary
suppressFailed: false, // do not print information about failed tests
suppressPassed: false, // do not print information about passed tests
suppressSkipped: true, // do not print information about skipped tests
showSpecTiming: false, // print the time elapsed for each spec
failFast: false // test would finish with error when a first fail occurs.
},
trxReporter: { outputFile: 'test-Results.trx', shortTestName: false },
port: 9876,
colors: true,
logLevel: config.LOG_DEBUG,
autoWatch: true,
browsers: ['HeadlessChrome'],
customLaunchers:{
HeadlessChrome:{
base: 'ChromeHeadless',
flags: ['--headless','--remote-debugging-port=9222','--disable-gpu','--no-sandbox','--js-flags=--max-old-space-size=4096',]
}},
singleRun: false,
captureTimeout: 250000,
browserDisconnectTolerance: 2,
browserDisconnectTimeout: 100000,
browserNoActivityTimeout: 80000,
autoWatchBatchDelay: 80000
});
};
it runs 3721 tests and then disconnects. .....
I started seeing this issue in a Bitbucket pipeline using the Docker image atlassianlabs/docker-node-jdk-chrome-firefox
. The tests still work using an older tagged version of that image: atlassianlabs/docker-node-jdk-chrome-firefox:2020-02-03
.
I have configured the headless chrome in my project getting rid of Phantom. When I run the tests on my OSX machine, all the tests get executed with the test runner on the headless chrome. But the same doesn't happen on my linux server. It connects to the socket and then after some time, it disconnects and shows the error message saying "Karma tests failed". Error:
Here is my configuration:
Using
karma-chrome-launcher: "2.1.1"
. Tried with the latest2.2.0
version too. Tried withkarma: "1.5.0"
,"1.6.0"
, and the latest"1.7.1"
.I tried other flags like "
--no-sandbox
", "--disable-web-security
" as suggested on a bunch of issues on karma repo. But still no luck. Is there a fix or workaround for this issue? Is there a reason why it's not working on the Linux server [Ubuntu Server 14.04.5 LTS].