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:
WARN [web-server]: 404: /bower_ponents/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_ponents folder as well.
I think maybe that could be because of my local test server where I'm using this approach:
(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:
module.exports = function(config) {
config.set({
basePath: '.',
frameworks: ['jasmine', 'requirejs'],
files: [
'tests/*.js',
'js/*.js',
'bower_ponents/angular/angular.js',
'bower_ponents/angular-mocks/angular-mocks.js',
'bower_ponents/angular-resource/angular-resource.js',
'bower_ponents/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:
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:
WARN [web-server]: 404: /bower_ponents/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_ponents folder as well.
I think maybe that could be because of my local test server where I'm using this approach: https://github./mhevery/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:
module.exports = function(config) {
config.set({
basePath: '.',
frameworks: ['jasmine', 'requirejs'],
files: [
'tests/*.js',
'js/*.js',
'bower_ponents/angular/angular.js',
'bower_ponents/angular-mocks/angular-mocks.js',
'bower_ponents/angular-resource/angular-resource.js',
'bower_ponents/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:
Share Improve this question edited Oct 10, 2016 at 17:57 isherwood 61.2k16 gold badges121 silver badges170 bronze badges asked Feb 5, 2014 at 15:42 gellygelly 1521 gold badge2 silver badges10 bronze badges 4- 1 Could you add your karma.conf.js code and also your project directory structure? – glepretre Commented Feb 5, 2014 at 15:45
- Not a solution to your problem, but if you look at the angular seed project from the tutorial docs.angularjs/tutorial you get the environment installed, and it does work for testing. Run the server with the batch file/script and it will monitor your directory for changes and run the tests right away. – Steven Scott Commented Feb 5, 2014 at 16:46
-
1
I think the problem is in your karma.conf.js
basepath
: could you try with''
(without dot)? You should also changelogLevel: config.LOG_INFO,
tologLevel: config.LOG_DEBUG,
to see more info in the terminal. – glepretre Commented Feb 6, 2014 at 10:09 - That helped a bit I think, however, now I get: " Uncaught ReferenceError: angular is not defined" in my app.js file. My app.js file looks like this: angular.module('App', [ 'ngResource', 'App.controllers', 'App.factories', 'App.directives', 'App.filters' ]); – gelly Commented Feb 6, 2014 at 10:28
2 Answers
Reset to default 1Now that you've fixed the basepath (from '.' to '', see question ments above), you should change the order of files loading in your 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_ponents/angular/angular.js',
//Then angular-modules
'bower_ponents/angular-resource/angular-resource.js',
'bower_ponents/angular-mocks/angular-mocks.js',
//Other libs
'bower_ponents/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
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.
Your problem is probably the order you're loading your files in.
You may need to change the order to something like:
files: [
'bower_ponents/angular/angular.js',
'bower_ponents/angular-mocks/angular-mocks.js',
'bower_ponents/angular-resource/angular-resource.js',
'bower_ponents/d3/d3.js',
'js/*.js',
'tests/*.js'
],
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744179800a4561929.html
评论列表(0条)