How to run jasmine tests without browser ?

See original GitHub issue

OS: Ubuntu 14.04.3 in a docker environment, without web browser (it’s actually running in Cloud9)

Version: angular-cli: 1.0.0-beta.11-webpack.8 node: 6.5.0 os: linux x64

Without any browser installed in the os, I cannot find a way to execute jasmine unit tests in spec files.

running ng test :

Could not start watchman; falling back to NodeWatcher for file system events.
Visit http://ember-cli.com/user-guide/#watchman for more info.

WARNING in ./src/app/app.component.ts
[208, 7]: comment must start with a space
[20, 3]: Declaration of public instance member variable not allowed to appear after declaration of public instance member function
...
07 09 2016 20:57:41.939:WARN [karma]: No captured browser, open http://0.0.0.0:9876/
07 09 2016 20:57:41.947:INFO [karma]: Karma v0.13.22 server started at http://0.0.0.0:9876/
07 09 2016 20:57:41.955:INFO [launcher]: Starting browser Chrome
07 09 2016 20:57:41.958:ERROR [launcher]: No binary for Chrome browser on your platform.
  Please, set "CHROME_BIN" env variable.

No error shown even if some tests have expect(true).toEqual(false);

Is there a way to execute these tests in a console-only environment ?

Thanks !

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:20
  • Comments:29 (1 by maintainers)

github_iconTop GitHub Comments

75reactions
oraveczcommented, Sep 8, 2016

Here is how I did it.

$ npm --version
3.10.6
$ ng --version
angular-cli: 1.0.0-beta.11-webpack.8
node: 6.4.0
os: darwin x64

npm i --save-dev karma-phantomjs-launcher

Then I modified the plugins property of the karma.conf.js file, adding the PhantomJS plugin to the list. Also add PhantomJS to the browsers property.

plugins: [
    require( 'karma-jasmine' ),
    require( 'karma-chrome-launcher' ),
    require( 'karma-phantomjs-launcher' ),
    require( 'karma-remap-istanbul' ),
    require( 'angular-cli/plugins/karma' )
],
...
browsers: [ 'PhantomJS', 'Chrome' ],

Since you want a completely headless experience, you can remove Chrome from the browsers property, and remove the karma-chrome-launcher from the plugins array as well.

10reactions
cbeldacapcommented, May 17, 2017

Hi all,

For me it’s still not working. I’ve followed all these steps as well.


1. Install phantomjs:

npm install --save-dev phantomjs phantomjs-prebuilt karma-phantomjs-launcher

2. Add import to karma.conf.js:

require('karma-phantomjs-launcher'),

(...)

browsers: ['PhantomJS'],

3. Install intl

npm install --save-dev intl

4. Uncomment polyfills’ imports:

import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/string';
import 'core-js/es6/array';

import 'intl';  // Run `npm install --save intl`.

5. Target for es5 instead of es6 in tsconfig.spec.json:

"target": "es5",


But still doesn’t work. I receive this from running: ng test --browsers PhantomJS --watch=false

image

Already tried to increase the timeout value but there is no difference.

Does anybody know if I’m skipping some steps here?

Thanks so much in advance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I run tests with a headless browser? - Stack Overflow
Angular provides all what we need to run tests without a browser. Open the karma.conf.js file and add the ChromeHeadless to the browsers...
Read more >
Run Angular Unit Test Cases Without Browser Karma Jasmine
There are two way to configure the Angular unit test cases to run without the browser. From command line. While running the unit...
Read more >
jasmine-headless-webkit - johnbintz.com
jasmine -headless-webkit uses the QtWebKit widget to run your specs without needing to render a pixel. It's nearly as fast as running in...
Read more >
Jasmine & Karma • Angular - codecraft.tv
Karma. Manually running Jasmine tests by refreshing a browser tab repeatedly in different browsers every time we edit some code can become tiresome....
Read more >
Jasmine JS: Start Testing From-Scratch - Testim.io
How do I Run a Unit Test On Jasmine? · Setting up Jasmine · Download and Set Up Jasmine · Executing a Jasmine...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found