gpt4 book ai didi

angularjs - Karma/Jasmine/Phantom JS 测试 - SyntaxError : Use of reserved word 'import'

转载 作者:行者123 更新时间:2023-12-04 16:11:23 24 4
gpt4 key购买 nike

我正在尝试纳入 karma 测试。我正在使用 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`

对于我为什么会收到此错误的任何建议,我将不胜感激。我假设这是因为 Phantom 不接受 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
});
};`

最佳答案

在webpack配置文件中添加

module: {
loaders: [
{
test: /\.jsx?$/,
loader: 'babel',
exclude: /node_modules/,
}
]
}

希望这能解决问题

关于angularjs - Karma/Jasmine/Phantom JS 测试 - SyntaxError : Use of reserved word 'import' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40118278/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com