Reputation: 15215
I'm working with a build that has a working karma setup.
I'm trying to integrate require.js usage into the tests. I mostly followed the instructions in the Karma RequireJS doc page to convert my "karma.conf.js" and build the "test-main.js".
When I run the tests, I see something like this:
DEBUG [watcher]: Resolved files:
...
/home/<myuid>/work/horizon/.venv/lib/python2.7/site-packages/xstatic/pkg/angular/data/angular.js
...
PhantomJS 1.9.8 (Linux) ERROR: 'There is no timestamp for .venv/lib/python2.7/site-packages/xstatic/pkg/angular/data/angular.js!'
...
WARN [web-server]: 404: /.venv/lib/python2.7/site-packages/xstatic/pkg/angular/data/angular.js
DEBUG [PhantomJS 1.9.8 (Linux)]: Disconnected during run, waiting 2000ms for reconnecting.
DEBUG [launcher]: Process PhantomJS exited with code 1
ERROR [launcher]: PhantomJS crashed.
I run Karma with:
node node_modules/karma/bin/karma start horizon/karma.conf.js --single-run
Note that the directory I run this from has the ".venv" folder and the file mentioned in the 404 does exist in that location.
Here is my "horizon/karma.conf.js" file:
module.exports = function(config){
// Path to xstatic pkg path.
var xstaticPath = '../../.venv/lib/python2.7/site-packages/xstatic/pkg/';
config.set({
preprocessors: {
// Used to collect templates for preprocessing.
// NOTE: the templates must also be listed in the files section below.
'./**/*.html': ['ng-html2js'],
// Used to indicate files requiring coverage reports.
'./**/!(*spec).js': ['coverage']
},
// Sets up module to process templates.
ngHtml2JsPreprocessor: {
prependPrefix: '/static/',
moduleName: 'templates'
},
// Assumes you're in the top-level horizon directory.
basePath : './static/',
// Contains both source and test files.
files : [
{pattern: xstaticPath + '**/*.js', included: false},
{pattern: '../../test-shim.js', included: false},
{pattern: 'horizon/**/*.js', included: false},
{pattern: 'dashboard-app/**/*.js', included: false},
{pattern: 'framework/**/*.js', included: false},
{pattern: '**/*.spec.js', included: false},
'../test-main.js'
],
autoWatch : true,
frameworks: ['jasmine', 'requirejs'],
browsers : ['PhantomJS'],
phantomjsLauncher: {
// Have phantomjs exit if a ResourceError is encountered
// (useful if karma exits without killing phantom)
exitOnResourceError: true
},
reporters : [ 'progress', 'coverage' ],
plugins : [
'karma-phantomjs-launcher',
'karma-firefox-launcher',
'karma-jasmine',
'karma-ng-html2js-preprocessor',
'karma-coverage',
'karma-requirejs'
],
logLevel: config.LOG_INFO,
coverageReporter: {
type : 'html',
dir : '../.coverage-karma/'
}
});
};
ere is my "horizon/test-main.js" (note that I tried to inline the variable reference value, which didn't help):
var allTestFiles = [];
var TEST_REGEXP = /\.spec\.js$/;
Object.keys(window.__karma__.files).forEach(function(file) {
if (window.__karma__.files.hasOwnProperty(file)) {
if (TEST_REGEXP.test(file)) {
// Normalize paths to RequireJS module names.
allTestFiles.push(file);
}
}
});
var xstaticPath = '../../.venv/lib/python2.7/site-packages/xstatic/pkg/';
require.config({
baseUrl: '/base',
paths: {
'test-shim': '../../test-shim',
'jquery': xstaticPath + 'jquery/data/jquery',
//'angular': xstaticPath + 'angular/data/angular',
'angular': '../../.venv/lib/python2.7/site-packages/xstatic/pkg/angular/data/angular',
'angular-mocks': xstaticPath + 'angular/data/angular-mocks',
'angular-cookies': xstaticPath + 'angular/data/angular-cookies',
'angular-bootstrap': xstaticPath + 'angular_bootstrap/data/angular-bootstrap',
'angular-sanitize': xstaticPath + 'angular/data/angular-sanitize',
'd3': xstaticPath + 'd3/data/d3',
'rickshaw': xstaticPath + 'rickshaw/data/rickshaw',
'smart-table': xstaticPath + 'angular_smart_table/data/smart-table',
'lrdragndrop': xstaticPath + 'angular_lrdragndrop/data/lrdragndrop',
'spin': xstaticPath + 'spin/data/spin',
'spin-jquery': xstaticPath + 'spin/data/spin.jquery',
'magic-search': xstaticPath + 'magic_search/data/magic_search'
},
shim: {
'underscore': {
exports: '_'
}
},
deps: allTestFiles,
callback: window.__karma__.start
});
Is there something obviously wrong, or is there something I can do to get more information? I'm running this on CentOS 7.0.
Upvotes: 0
Views: 483
Reputation: 8167
Change your karma.conf.js
to this:
files : [
// Must be before xstaticPath + '**/*.js' to be included
'../test-main.js',
{pattern: xstaticPath + '**/*.js', included: false},
{pattern: '../../test-shim.js', included: false},
{pattern: 'horizon/**/*.js', included: false},
{pattern: 'dashboard-app/**/*.js', included: false},
{pattern: 'framework/**/*.js', included: false},
{pattern: '**/*.spec.js', included: false}
],
Upvotes: 0