4

我正在尝试为我的 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`

我如何解决它?

4

1 回答 1

2

我已经想通了。不幸的是,我没有将模板中的所有 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}
],
于 2015-05-13T06:41:34.020 回答