javascript Karma 找不到配置文件中指定的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21581700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Karma doesn't find files specified in config file
提问by gelly
I'm writing Jasmine tests to my Angularjs app. I generated karma.conf.js using karma init but when I run karma start i get warnings like this:
我正在为我的 Angularjs 应用编写 Jasmine 测试。我使用 karma init 生成了 karma.conf.js,但是当我运行 karma start 时,我收到如下警告:
WARN [web-server]: 404: /bower_components/angular/angular.js
WARN [web-server]: 404: /js/app.js
karma.conf.js is in my app folder, which is the place for the bower_components folder as well.
karma.conf.js 在我的 app 文件夹中,这也是 bower_components 文件夹的位置。
I think maybe that could be because of my local test server where I'm using this approach: https://github.com/mhevery/angular-node-socketio
我想这可能是因为我使用这种方法的本地测试服务器:https: //github.com/mheevery/angular-node-socketio
(I've been able to set up the tests like this in other project without a test server)
(我已经能够在没有测试服务器的其他项目中设置这样的测试)
Can anybody please point me in the right direction here?
有人可以在这里指出我正确的方向吗?
Update:
更新:
My karma.conf.js looks like this:
我的 karma.conf.js 看起来像这样:
module.exports = function(config) {
config.set({
basePath: '.',
frameworks: ['jasmine', 'requirejs'],
files: [
'tests/*.js',
'js/*.js',
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'bower_components/angular-resource/angular-resource.js',
'bower_components/d3/d3.js'
],
exclude: [],
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
captureTimeout: 60000,
singleRun: false
});
};
Here's my directory structure:
这是我的目录结构:
回答by glepretre
Now that you've fixed the basepath (from '.' to '', see question comments above), you should change the order of files loading in your karma.conf.js :
既然您已经修复了基本路径(从 '.' 到 '',请参阅上面的问题评论),您应该更改 karma.conf.js 中文件加载的顺序:
module.exports = function(config) {
config.set({
basePath: '.',
frameworks: ['jasmine', 'requirejs'],
files: [
//load angular.js first
//(unless if you use jQuery which must be first if I remember well)
'bower_components/angular/angular.js',
//Then angular-modules
'bower_components/angular-resource/angular-resource.js',
'bower_components/angular-mocks/angular-mocks.js',
//Other libs
'bower_components/d3/d3.js',
//Your app scripts
'js/*.js',
//And your specs
'tests/*.js'
],
exclude: [],
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
captureTimeout: 60000,
singleRun: false
});
};
You can find more info here: http://karma-runner.github.io/0.10/config/files.html
您可以在此处找到更多信息:http: //karma-runner.github.io/0.10/config/files.html
Ordering
- The order of patterns determines the order of files in which they are included in the browser.
- Multiple files matching a single pattern are sorted alphabetically.
- Each file is included exactly once. If multiple patterns match the same file, it's included as if it only matched the first pattern.
订购
- 模式的顺序决定了它们包含在浏览器中的文件的顺序。
- 匹配单个模式的多个文件按字母顺序排序。
- 每个文件只包含一次。如果多个模式匹配同一个文件,则将其包含在内,就好像它只匹配第一个模式一样。
回答by thelastshadow
Your problem is probably the order you're loading your files in.
您的问题可能是您加载文件的顺序。
You may need to change the order to something like:
您可能需要将顺序更改为:
files: [
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'bower_components/angular-resource/angular-resource.js',
'bower_components/d3/d3.js',
'js/*.js',
'tests/*.js'
],