我尝试在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
版本:
"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",
答案 0 :(得分:0)
也许PhantomJS不支持ECMA 6,所以箭头功能会破坏所有的:D