PhantomJS does not work with Karma in Angular2 project

后端 未结 3 1335
灰色年华
灰色年华 2021-01-18 01:27

I have created an out-of-the box project with the angular cli (1.0.0-rc1.0.0). Then I installed the PhantomJS plugin (npm install karma-phantonjs-launcher). Reprodu

相关标签:
3条回答
  • 2021-01-18 02:01

    My current work around is to target es5 for the tests only.

    tsconfig.spec.json

    {
        "compilerOptions": {
            ...
            "target": "es5",
            ...
    }
    

    .angular-cli.json

    {
        "project": {
            "name": "client"
        },
        "apps": [
            {
                ...
                "tsconfig": "tsconfig.app.json",
                "testTsconfig": "tsconfig.spec.json",
                ...
    
    0 讨论(0)
  • 2021-01-18 02:05

    In fact, you don't have to wait for phantomjs 2.5 release.

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

    • in karma.conf.js

      • add require('karma-phantomjs-launcher') to the plugins section
      • add PhantomJS to the browsers
    • npm install --save intl

    • in src/polyfill.ts
      • add import 'intl'; (uncomment at the bottom)
      • add import "core-js/client/shim"; to the Evergreen requirements section
    • In src/tsconfig.spec.json set the target to es5.

    Ref: https://stackoverflow.com/a/42539894/7683428

    0 讨论(0)
  • 2021-01-18 02:08

    Since Chrome supports now (as of version 59) headless running, there's no reason any more to use outdated PhantomJS. Unless you cannot update/install chrome on target machine. If you have included karma-chrome-launcher in karma.conf you can now just specify:

    browsers: ['ChromeHeadless']
    

    There's also possibility to use the Canary edition via ChromeCanary or ChromeCanaryHeadless.

    0 讨论(0)
提交回复
热议问题