我正在尝试纳入业力测试。我正在使用angular 1.5,webpack和gulp。当我karma start
时,我在终端中收到以下内容:
`18 10 2016 13:52:03.082:WARN [karma]: No captured browser, open http://localhost:9876/
18 10 2016 13:52:03.100:WARN [karma]: Port 9876 in use
18 10 2016 13:52:03.101:INFO [karma]: Karma v1.1.2 server started at http://localhost:9877/
18 10 2016 13:52:03.101:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
18 10 2016 13:52:03.125:INFO [launcher]: Starting browser PhantomJS
18 10 2016 13:52:06.629:WARN [karma]: No captured browser, open http://localhost:9877/
18 10 2016 13:52:06.649:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket /#EcTUgwnkFnvZHyN0AAAA with id 14262338
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
SyntaxError: Use of reserved word 'import'
at Project/src/app/index.js:14`
如果我收到此错误,我将不胜感激。我假设这是因为幻影不接受es6。我已经尝试过karma-es6-shim和其他一些事情但没有成功
这是我的档案:
karma.conf.js
`var webpackConfig = require('./webpack.config');
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '../',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],`
// list of files / patterns to load in the browser
files: [
{ pattern: './Project/node_modules/jquery/dist/jquery.js'},
{ pattern: './Project/node_modules/angular/angular.js' },
{ pattern: './Project/node_modules/angular-mocks/angular-mocks.js'},
{ pattern: './Project/src/app/index.js'},
{ pattern: './Project/src/app/Test/**/*.spec.js', watched: false}
],
// list of files to exclude
exclude: [
'lambda/*/*.js'
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'./src/app/**/*.js': ['babel'],
'./src/app/**/index.js': ['webpack'],
'./src/app/Test/**/index.js': ['webpack'],
'./src/app/Test/**/.js': ['babel']
},
webpack: webpackConfig('module'),
webpackMiddleware: {
noInfo: true
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
//port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO.DEBUG,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
plugins: [
require('karma-babel-preprocessor'),
require('karma-jasmine'),
require('karma-webpack'),
// require('karma-chrome-launcher')
require('karma-phantomjs-launcher')
],
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
});
};`
答案 0 :(得分:1)
在webpack配置文件中添加
module: {
loaders: [
{
test: /\.jsx?$/,
loader: 'babel',
exclude: /node_modules/,
}
]
}
希望这能解决问题