【发布时间】:2016-05-16 21:13:49
【问题描述】:
我正在尝试使用新项目设置 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 文件夹中的组合凉亭资产、我的路由、我的角度模块定义所在的位置(不是我的想法)、我需要的环境变量、我想要的 javascript 控制器测试,我的测试文件夹。如果我不包含组合的 bower 文件,我会收到一个关于无法加载 jquery 的错误,然后我的每个其他依赖项都会出现另一个错误。
我能做些什么来解决这个问题?
【问题讨论】:
标签: angularjs gruntjs karma-runner