我们将非常感谢您的帮助。
我目前正在使用angular/cli构建一个angular 5项目。我在项目中构建了很好的一部分,并且没有遇到任何关于构建或服务命令的问题。
我正在尝试运行我的测试套件,但出现以下错误:

27 02 2018 14:22:58.588:WARN [karma]: No captured browser, open http://localhost:9876/
27 02 2018 14:22:58.601:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9876/
27 02 2018 14:22:58.601:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
27 02 2018 14:22:58.608:INFO [launcher]: Starting browser PhantomJS
 10% building modules 3/3 modules 0 active(node:82890) DeprecationWarning: loaderUtils.parseQuery() received a non-string value which can be problematic, see https://github.com/webpack/loader-utils/issues/56
parseQuery() will be replaced with getOptions() in the next major version of loader-utils.
27 02 2018 14:23:06.801:WARN [karma]: No captured browser, open http://localhost:9876/
27 02 2018 14:23:06.988:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket BcW5WVSiPfS1DRQdAAAA with id 61500965
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  SyntaxError: Unexpected token 'const'
  at http://localhost:9876/_karma_webpack_/vendor.bundle.js:28
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  SyntaxError: Unexpected token 'const'
  at http://localhost:9876/_karma_webpack_/vendor.bundle.js:28

PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  SyntaxError: Unexpected token 'const'
  at http://localhost:9876/_karma_webpack_/vendor.bundle.js:28
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  SyntaxError: Unexpected token 'const'
  at http://localhost:9876/_karma_webpack_/vendor.bundle.js:28

我已经检查了我的tsconfig文件,并且都将目标设置为“es5”。
我正在使用幻像浏览器进行浏览器测试,我试图收集收集覆盖报告与CoBurTura。
请参阅下面的文件了解我的设置。
提前谢谢。
tsconfig.json文件:
{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noEmitHelpers": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

src/tsconfig.spec.json格式:
{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/spec",
    "baseUrl": "./",
    "module": "commonjs",
    "target": "es5",
    "types": [
      "jasmine",
      "node"
    ]
  },
  "files": [
    "test.ts"
  ],
  "include": [
    "**/*.spec.ts",
    "**/*.d.ts"
  ]
}

业力形态:
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular/cli'],
    plugins: [
      require('karma-jasmine'),
      require('karma-phantomjs-launcher'),
      require('karma-junit-reporter'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular/cli/plugins/karma')
    ],
    client: {
      clearContext: true // leave Jasmine Spec Runner output visible in browser
    },
    coverageReporter: {
      type: 'cobertura'
    },
    coverageIstanbulReporter: {
      reports: ['html', 'cobertura'],
      fixWebpackSourcePaths: true
    },
    remapIstanbulReporter: {
      reports: {
        cobertura: './coverage/cobertura.xml'
      }
    },
    remapCoverageReporter: {
      cobertura: './coverage/cobertura.xml'
    },
    angularCli: {
      environment: 'dev'
    },
    junitReporter: {
      outputDir: 'phantomjs',
      outputFile: 'test.xml'
    },
    reporters: ['progress', 'kjhtml', 'junit'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['PhantomJS'],
    singleRun: false
  });
};

.angular-cli.json文件:
{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "my.project"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico",
        "web.config"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "styles.scss"
      ],
      "scripts": [],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "develop": "environments/environment.develop.ts",
        "test": "environments/environment.test.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "lint": [
    {
      "project": "src/tsconfig.app.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "src/tsconfig.spec.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "e2e/tsconfig.e2e.json",
      "exclude": "**/node_modules/**"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "scss",
    "component": {}
  }
}

最佳答案

在评论中从axl-code推荐后,切换到使用无头Chrome浏览器修复我所拥有的问题,希望这有帮助!

09-16 15:31