Having trouble testing my Angular scripts with Karma and RequireJS, as I keep encountering this error:
Error in Firefox 28.0.0 (Mac OS X 10.9): 'There is no timestamp for /base/app/public/js/test/unit/controllersSpec.js!'
Warning [web-server]: 404: /base/app/public/js/test/unit/controllersSpec.js
Error in Firefox 28.0.0 (Mac OS X 10.9): Error: Script error for: test/unit/controllersSpec http://requirejs.org/docs/errors.html#scripterror at /Users/Masanori/Desktop/FlippySurvey/node_modules/requirejs/require.js:166
Despite trying to alter the baseUrl settings in various ways, the error persists. Anyone able to assist me in resolving this issue? Your help would be greatly appreciated!
My current directory structure looks like this:
app/
public/
vendors/
....
js/
controllers.js
controllers/
mainctrl.js
test
unit
controllersSpec.js
karma.conf.js
test-main.js
Below are excerpts from my test-main.js and karma.conf.js files:
test-main.js'
var allTestFiles = [];
var TEST_REGEXP = /(spec|test)\.js$/i;
var pathToModule = function(path) {
return path.replace(/^\/base\//, '').replace(/\.js$/, '');
};
Object.keys(window.__karma__.files).forEach(function(file) {
if (TEST_REGEXP.test(file)) {
// Normalize paths to RequireJS module names.
allTestFiles.push(pathToModule(file));
}
});
require.config({
paths:{
'angular' : '/base/app/public/vendors/angular/angular',
'angularMocks': '/base/app/public/vendors/angular-mock/angular-mock',
'domReady' : '/base/app/public/vendors/requirejs-domready/domready',
'angularRoute': '/base/app/public/vendors/angular-route/angular-route'
},
baseUrl: '/base/app/public/js',
shim: {
'angular' :{'exports':'angular'},
'angularRoute' :['angular'],
'angularMocks':{
deps: ['angular'],
'exports':'angular.mock'
}
},
deps: allTestFiles,
callback: window.__karma__.start
});
karma.conf.js
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine', 'requirejs'],
files: [
{pattern: 'unit/*.js', included: false},
{pattern: 'unit/**/*.js', included: false},
{pattern: '../app/public/js/**/*.js', included: false},
{pattern: '../app/public/js/*.js', included: false},
{pattern: '../app/public/vendors/**/*.js', included: false},
'test-main.js'
],
exclude: [
],
preprocessors: {
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Firefox'],
singleRun: false
});
};