【问题标题】:Karma + phamtonJS + Angular 7 Error unexpected tokenKarma + phamtonJS + Angular 7 Error 意外令牌
【发布时间】:2019-03-18 21:51:12
【问题描述】:

我尝试在 Angular 7 项目中运行 ng test。何时配置 karma 以使用 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

版本:

    "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】:

    也许 PhantomJS 不支持 ECMA 6,所以箭头函数打破了一切:D

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-12
      • 2019-02-01
      • 1970-01-01
      • 2017-12-19
      • 2018-01-20
      • 2018-09-12
      • 2017-09-04
      • 2016-07-22
      相关资源
      最近更新 更多