0
我正在使用具有工作業力設置的構建。Karma w/RequireJS獲取404加載文件
我正在嘗試將require.js用法集成到測試中。我主要按照Karma RequireJS文檔頁面中的說明轉換我的「karma.conf.js」並構建「test-main.js」。
當我運行測試,我看到這樣的事情:
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.
我跑噶有:
node node_modules/karma/bin/karma start horizon/karma.conf.js --single-run
注意,我從運行此目錄中有「.venv」文件夾並且404中提到的文件確實存在於該位置。
這裏是我的「視界/ karma.conf.js」文件:
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是我的「視界/測試main.js」(請注意,我試圖內聯可變參考值,沒有幫助):
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
});
有什麼明顯的錯誤,或者有什麼我可以做得到更多的信息?我在CentOS 7.0上運行這個。
感謝回答。將「../test-main.js」引用移動到頂部是唯一的更改嗎?如果是這樣,輸出中的唯一更改是將「沒有.venv的時間戳」更改爲「沒有/.venv的時間戳」。我沒有特別期待這個工作,因爲我整合了karma/requirejs的一個較老的應用程序最後有「測試 - 主要」引用。 –
然而,我然後回覆了這個改變,它仍然說「/.venv」,所以我不知道爲什麼發生了。 –
如果你使用'{pattern:'**/*。js',包含:false}'這樣的模式,我敢肯定你應該把'test-main.js'放在最前面,因爲我們碰到了這個用法,我們對此仍有評論。無論如何,我們錯過了一些東西(其他)。我沒有完全看到你的文件夾結構,你確定'basePath:'./static /','?這顯然看起來像一個路徑問題。 – glepretre