我正在尝试为我的javascript项目制作测试环境,但由于There is no timestamp for
问题和问题我遇到了问题
WARN [web-server]: 404: /base/app/templates/setting.html
,我的模板位于与基本文件夹不同的文件夹中。这是我的目录结构
.
|--app
|--js
|--lib
|--model
|--view
|--app.js
|--main.js
|--routes.js
|--templates
|--setting.html
|--project.html
|--index.html
|--test
|--model
|--view
|--karma.conf.js
|--test-main.js
这是我对karma.conf.js的配置
// Karma configuration
// Generated on Tue May 12 2015 20:44:23 GMT+0700 (WIB)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'requirejs'],
// list of files / patterns to load in the browser
files: [
'test-main.js',
{pattern: 'app/js/lib/**/*.js', included: false},
{pattern: 'app/js/service/*.js', included: false},
{pattern: 'app/js/model/*.js', included: false},
{pattern: 'app/js/test/view/settingView_spec.js', included: false},
{pattern: 'app/js/view/*.js', included: false}
],
// list of files to exclude
exclude: [
'app/js/app.js',
'app/js/main.js'
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};
和我的test-main.js
(目前我只尝试过一个测试文件)
require.config({
// Karma serves files under /base, which is the basePath from your config file
baseUrl: '/base/app/js',
paths: {
'jquery': 'lib/jquery/jquery',
'underscore': 'lib/underscore/underscore',
'backbone': 'lib/backbone/backbone',
'text': 'lib/text/text',
'templates': '../../templates'
},
// dynamically load all test files
deps: ['test/view/settingView_spec'],
// allTestFiles,
// we have to kickoff jasmine, as it is asynchronous
callback: window.__karma__.start
});
和main.js
的配置:
require.config({
paths: {
jquery: 'lib/jquery/jquery',
backbone: 'lib/backbone/backbone',
underscore: 'lib/underscore/underscore',
text: 'lib/text/text',
templates: '../../templates'
}
});
正如您在test-main.js
中看到的那样,我为../../templates, but when I try to run the karma it says
WARN [web-server]:404:/ base / app / templates / setting.html`
我该如何解决?
答案 0 :(得分:1)
我已经弄清楚了。不幸的是,我没有将模板中的所有html文件放入karma.conf.js
。所以在其中,文件将是:
// list of files / patterns to load in the browser
files: [
'test-main.js',
{pattern: 'app/js/lib/**/*.js', included: false},
{pattern: 'app/js/service/*.js', included: false},
{pattern: 'app/js/model/*.js', included: false},
{pattern: 'app/js/test/view/settingView_spec.js', included: false},
{pattern: 'app/js/view/*.js', included: false},
{pattern: 'app/templates/*.html', included: false}
],