Karma + phamtonJS + Angular 7错误意外令牌

问题描述 投票:0回答:1

我尝试在angular 7项目中执行ng测试。何时配置业力以使用Chrome运行测试,结果还可以,但是使用PhantomJS却出现以下错误。

PhantomJS 2.1.1 (Linux 0.0.0) ERROR
{
   "message": "SyntaxError: Unexpected token ','\nat http://localhost:9876/_karma_webpack_/vendor.js:98290:0",
   "str": "SyntaxError: Unexpected token ','\nat http://localhost:9876/_karma_webpack_/vendor.js:98290:0"
}

PhantomJS 2.1.1 (Linux 0.0.0) ERROR
{
  "message": "SyntaxError: Unexpected token ','\nat http://localhost:9876/_karma_webpack_/vendor.js:98290:0",
  "str": "SyntaxError: Unexpected token ','\nat http://localhost:9876/_karma_webpack_/vendor.js:98290:0"
}

此错误开始于在项目中安装dygraph 2.1.0时

karma.conf.js

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-phantomjs-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    browserNoActivityTimeout: 100000,
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      reports: [ 'html', 'lcovonly' ],
      fixWebpackSourcePaths: true
    },
    angularCli: {
      environment: 'dev'
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['PhantomJS'],
    singleRun: true
  });
};

tsconfig.spec.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/spec",
    "types": [
      "jasmine",
      "node"
    ]
  },
  "files": [
    "test.ts",
    "polyfills.ts"
  ],
  "include": [
    "**/*.spec.ts",
    "**/*.d.ts"
  ]
}

在我的polyfill.ts中,导入:core-js / es6 / reflect,core-js / es7 / reflect,core-js / client / shim,intl

enter image description here

版本:

    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "karma-phantomjs-launcher": "^1.0.4",
    "dygraphs": "^2.1.0",
javascript angular phantomjs karma-runner dygraphs
1个回答
0
投票

也许PhantomJS不支持ECMA 6,所以箭头功能破坏了这一切:D

© www.soinside.com 2019 - 2024. All rights reserved.