lathonez / clicker

Ionic 2 + @angular/cli Seed Project : Angular2 + Typescript + Karma + Protractor + Travis
http://lathonez.com/2018/ionic-2-unit-testing/
MIT License
430 stars 137 forks source link

Tests not running fully under PhantomJS #265

Closed ryanki1 closed 7 years ago

ryanki1 commented 7 years ago

Hi Stephen,

I've recently upgraded my ionic project from angular-cli to (at)angular/cli v1.0.0. I've updated my configuration to mirror the test configuration of "clicker" 2.12.0 (2017-04-11).

The good news:

  1. in Chrome with Karma.conf "singleRun: false" the tests run successfully in the console tab,
  2. running the karma command i.e. karma start --browser phantomjs2 the tests also run successfully

The not so good news: when I run "npm test" I get as far as karma 1.4.1 server starting with socket connection but thereafter I get no test results.

I'm running the following ionic environment:

Cordova CLI: 6.5.0 Ionic Framework Version: 3.0.1 Ionic CLI Version: 2.2.1 Ionic App Lib Version: 2.2.0 Ionic App Scripts Version: 1.3.0 ios-deploy version: Not installed ios-sim version: Not installed OS: Windows 7 Node Version: v6.9.5 Xcode version: Not installed

Here's the relevant section of my Karma.conf:


browsers: ['PhantomJS2Custom'],
customLaunchers: {
            'PhantomJS2Custom': {
                base: 'PhantomJS2',
                options: {
                    windowname: 'my-window',
                    settings: {
                        webSecurityEnabled: false
                    }
                },
                flags: ['--load-images=true'],
                debug: true // required to avoid a phantomjs crash when images in page loaded
            }
        },
        phantomjsLauncher: {
            // Have phantomjs exit if a ResourceError is encountered (useful if karma exits without killing phantom)
            exitOnResourceError: true
        },
        singleRun: `true
lathonez commented 7 years ago

Hey Ryan,

TL;dr this project does not support phantom.

I've wasted so much time wrestling with Phantom. Since we switched to Chrome I've had basically zero issues like this.

check the closed issues, some people have posted solutions: https://github.com/lathonez/clicker/issues?utf8=%E2%9C%93&q=is%3Aissue%20phantom

My advice is not to use Phantom - I understand some need to use it due to their CI setup (teamcity). For me this would be a blocker, I wouldn't use any CI platform that forced me onto Phantom.

Good luck & please post here if you find a solution.

Stephen

ryanki1 commented 7 years ago

Thank for your reply Stephen :-) Good news is that everything seems to be working afterall. With my colleague we realized that "ng test" by default runs with watch=true so to have access to the results of the test just needed to make the following call:


ng test --watch=false