我正在尝试使用新项目设置Karma,我收到以下错误
'WARNING: Tried to load angular more than once.'
我的karma.conf.js看起来像这样
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: [
'app/bower_components/angular/angular.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'dist/js/combined.bower.js',
'app/js/routes.js',
'app/test/ENV.js',
'app/js/**/*.js',
'app/test/**/*.js'
],
// list of files to exclude
exclude: [
'app/js/filter.list.js'
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'app/js/**/*.js': ['env']
},
envPreprocessor: [
'ENV'
],
// 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,
// 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,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
按顺序,我加载Angular,angular-mocks,我的dist文件夹中的组合bower资源,我的路径,我的角度模块定义(不是我的想法),我需要的环境变量,我想要的javascript控制器测试,我的测试文件夹。如果我不包含我的组合bower文件,我会收到一个错误,指出无法加载jquery,然后是另一个我的其他依赖项。
我该怎么做才能解决这个问题?
答案 0 :(得分:2)
如果combined.bower.js
包含angular
和angular-mocks
bower包(如文件名所示),则这些行
'app/bower_components/angular/angular.js',
'app/bower_components/angular-mocks/angular-mocks.js',
应该省略。