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

Support for runnung tests in PhantomJS broken after upgrading to Ionic 2.1.0 #235

Closed vbolshutkin closed 7 years ago

vbolshutkin commented 7 years ago

I'm using your great project as a reference, but I need the tests to be run in PhantomJS. Earlier it worked well after small modifications:

in package.json under devDepenencies "karma-phantomjs-launcher": "^1.0.2",

in karma.conf.js add require('karma-phantomjs-launcher'), and set browsers: ['PhantomJS']

After recent commit 13a6cd6ac94de0897b0e0d3dca65261f9c7ac3a8 it fails with the following message:

PhantomJS 2.1.1 (Linux 0.0.0) ERROR SyntaxError: Unexpected token 'const'

I believe, this is related to babel preset, but didn't find a workaround yet

vbolshutkin commented 7 years ago

Figured it out: new tsconfig is set up for es6 as target. Also, some polyfills are disabled by default in @angular/cli 1.0.0-rc.0

The workaround is to write the following code in src/tsconfig.spec.json

    "lib": [
      "es2016","es6", "dom"
    ],
    "target": "es5",

and uncomment the last line in polyfills.ts

import 'intl';

lathonez commented 7 years ago

Thanks a lot for providing the solution. Out of interest, why do you need to use Phantom?

ValterSantosMatos commented 7 years ago

@lathonez if you use temacity as your CI you cannot spawn chrome instances when the build is running, check this in the Karma documentation: http://karma-runner.github.io/1.0/plus/teamcity.html

andreddosantos commented 5 years ago

Hello i've had this error now, i've performed the changes in "src/tsconfig.spec.json" and the problem remains