Karma Test Runner RequireJS 404错误,没有提供内容

时间:2015-04-14 20:14:17

标签: node.js requirejs karma-runner karma-jasmine karma-requirejs

我的app.js文件出现了404错误,即使它存在于它所说的URL不存在(与业力一起服务)。知道这是什么以及如何解决? >>疯了。

can't resolve app file

DEBUG [web-server]: serving: /Users/tina/Sites/node_require/client/src/app.js
DEBUG [web-server]: serving: /Users/tina/Sites/node_require/client/src/views/add.js
WARN [web-server]: 404: /base/client/src/app

我的目录结构:

   karma.conf.js
   bower_components/
   client/
      src/
          -app.js
          -main.js

      spec/
          -app.test.js
          -test.main.js
          views/
             -add.test.js

我的karma.conf.js:

// Karma configuration
// Generated on Mon Apr 13 2015 19:36:01 GMT-0400 (EDT)

module.exports = function(config) {
  config.set({

    // base path, that will be used to resolve files and exclude
    basePath:'',


    // frameworks to use
    frameworks: ['jasmine', 'requirejs'],


    // list of files / patterns to load in the browser
    files: [
      //'build/tests.js',
      //{pattern: 'build/tests.js', included: false},
      'client/spec/test-main.js',

      {pattern: 'client/src/**/*.js', included: false},
      {pattern: 'client/spec/**/*.test.js', included: false},
      {pattern: 'bower_components/underscore/underscore.js', included: false},
      {pattern: 'bower_components/jquery/jquery.js', included: false},
      {pattern: 'bower_components/backbone/backbone.js', included: false},
      {pattern: 'bower_components/backbone.marionette/lib/backbone.marionette.js', included: false},
      {pattern: 'bower_components/requirejs-text/text.js', included: false},
      {pattern: 'bower_components/handlebars/handlebars.runtime.js', included: false},
      {pattern: 'bower_components/handlebars/handlebars.js', included: false},
      {pattern: 'bower_components/requirejs-handlebars/hb.js', included: false},
      ],


    // list of files to exclude
    exclude: [
    'client/src/main.js'
    ],


    // test results reporter to use
    // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
    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_DEBUG,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,


    // Start these browsers, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera (has to be installed with `npm install karma-opera-launcher`)
    // - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
    // - PhantomJS
    // - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
    browsers: ['PhantomJS'],


    // If browser does not capture in given timeout [ms], kill it
    captureTimeout: 60000,


    // Continuous Integration mode
    // if true, it capture browsers, run tests and exit
    singleRun: false
  });
};

my test-main.js:

var tests = [];
for (var file in window.__karma__.files) {
    if (/.test\.js$/.test(file)) {
        tests.push(file);
    }
}

requirejs.config({
    // Karma serves files from '/base'
    baseUrl: '/base/client/src/',

   shim: {
    jquery: {
      exports: '$'
    },
    underscore: {
      exports: '_'
    },
    backbone: {
      deps: [
        'jquery',
        'underscore'
      ],
      exports: 'Backbone'
    },
    marionette: {
      deps: [
        'jquery',
        'underscore',
        'backbone'
      ],
      exports: 'Marionette'
    },
    bootstrap: {
      deps: [
        'jquery'
      ]
    },
    'handlebars.runtime': {
        exports: 'handlebars.runtime'
    },
    handlebars: {
        deps: ['handlebars.runtime']
    },
  },
  paths: {
    backbone: '../../bower_components/backbone/backbone',
    marionette: '../../bower_components/backbone.marionette/lib/backbone.marionette',
    jquery: '../../bower_components/jquery/jquery',
    underscore: '../../bower_components/underscore/underscore',
    text: '../../bower_components/requirejs-text/text',
    'handlebars.runtime': '../../bower_components/handlebars/handlebars.runtime',
    handlebars: '../../bower_components/handlebars/handlebars',
    hb: '../../bower_components/requirejs-handlebars/hb',
  },


    // ask Require.js to load these files (all our tests)
    deps: tests,

    // start test run, once Require.js is done
    callback: window.__karma__.start
});

app.test.js(这里的'app'模块永远不会解决)

define([
    'app', 
    'marionette',
],
function (App, Marionette) {
    'use strict';

    describe('App', function() {
        var app = new App();
        it('should have a start function', function() {
            expect(app.start).toBeDefined();
        });
    ....

调试日志:

INFO [launcher]: Starting browser PhantomJS
DEBUG [launcher]: Creating temp dir at /var/folders/lz/rp48gjr977n5bq684cbydpcw0000gn/T/karma-16204309
DEBUG [launcher]: /Users/tina/Sites/node_require/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/bin/phantomjs /var/folders/lz/rp48gjr977n5bq684cbydpcw0000gn/T/karma-16204309/capture.js
DEBUG [watcher]: Excluded file "/Users/tina/Sites/node_require/client/src/main.js"
DEBUG [watcher]: Resolved files:
    /Users/tina/Sites/node_require/node_modules/requirejs/require.js
    /Users/tina/Sites/node_require/node_modules/karma-requirejs/lib/adapter.js
    /Users/tina/Sites/node_require/node_modules/karma-jasmine/lib/jasmine.js
    /Users/tina/Sites/node_require/node_modules/karma-jasmine/lib/adapter.js
    /Users/tina/Sites/node_require/client/spec/test-main.js
    /Users/tina/Sites/node_require/client/src/app.js
    /Users/tina/Sites/node_require/client/src/collections/contacts.js
    /Users/tina/Sites/node_require/client/src/controller.js
    /Users/tina/Sites/node_require/client/src/models/contact.js
    /Users/tina/Sites/node_require/client/src/router.js
    /Users/tina/Sites/node_require/client/src/views/add.js
    /Users/tina/Sites/node_require/client/src/views/contact_details.js
    /Users/tina/Sites/node_require/client/src/views/contacts.js
    /Users/tina/Sites/node_require/client/spec/app.test.js
    /Users/tina/Sites/node_require/client/spec/views/add.test.js
    /Users/tina/Sites/node_require/bower_components/underscore/underscore.js
    /Users/tina/Sites/node_require/bower_components/jquery/jquery.js
    /Users/tina/Sites/node_require/bower_components/backbone/backbone.js
    /Users/tina/Sites/node_require/bower_components/backbone.marionette/lib/backbone.marionette.js
    /Users/tina/Sites/node_require/bower_components/requirejs-text/text.js
    /Users/tina/Sites/node_require/bower_components/handlebars/handlebars.runtime.js
    /Users/tina/Sites/node_require/bower_components/handlebars/handlebars.js
    /Users/tina/Sites/node_require/bower_components/requirejs-handlebars/hb.js
DEBUG [web-server]: serving: /Users/tina/Sites/node_require/node_modules/karma/static/client.html
DEBUG [web-server]: serving: /Users/tina/Sites/node_require/node_modules/karma/static/karma.js
DEBUG [karma]: A browser has connected on socket Bl_al5KEDvICYzohgJV7
INFO [PhantomJS 1.9.8 (Mac OS X)]: Connected on socket Bl_al5KEDvICYzohgJV7
DEBUG [karma]: All browsers are ready, executing
DEBUG [web-server]: serving: /Users/tina/Sites/node_require/node_modules/karma/static/context.html
DEBUG [web-server]: serving: /Users/tina/Sites/node_require/node_modules/requirejs/require.js
DEBUG [web-server]: serving: /Users/tina/Sites/node_require/node_modules/karma-requirejs/lib/adapter.js
DEBUG [web-server]: serving: /Users/tina/Sites/node_require/node_modules/karma-jasmine/lib/adapter.js
DEBUG [web-server]: serving: /Users/tina/Sites/node_require/node_modules/karma-jasmine/lib/jasmine.js
DEBUG [web-server]: serving: /Users/tina/Sites/node_require/client/spec/test-main.js
DEBUG [web-server]: serving: /Users/tina/Sites/node_require/client/spec/app.test.js
DEBUG [web-server]: serving: /Users/tina/Sites/node_require/client/spec/views/add.test.js
DEBUG [web-server]: serving: /Users/tina/Sites/node_require/client/src/app.js
DEBUG [web-server]: serving: /Users/tina/Sites/node_require/client/src/views/add.js
WARN [web-server]: 404: /base/client/src/app
ERROR: 'There is no timestamp for /base/client/src/app!'
PhantomJS 1.9.8 (Mac OS X): Executed 0 of 0 SUCCESS (0 secs / 0 secs)
DEBUG [web-server]: serving: /Users/tina/Sites/node_require/client/src/collections/contacts.js
DEBUG [web-server]: serving: /Users/tina/Sites/node_require/client/src/models/coPhantomJS 1.9.8 (Mac OS X) ERROR
    Error: Script error for: /base/client/src/app
    http://requirejs.org/docs/errors.html#scripterror
    at /Users/tina/Sites/node_require/node_modules/requirejs/require.js:141
PhantomJS 1.9.8 (Mac OS X): Executed 0 of 0 ERROR (0 secs / 0 secs)
DEBUG [web-server]: serving: /Users/tina/Sites/node_require/bower_components/reqPhantomJS 1.9.8 (Mac OS X): Executed 0 of 0 ERROR (0.04 secs / 0 secs)
DEBUG [launcher]: Disconnecting all browsers
DEBUG [launcher]: Killing PhantomJS
DEBUG [web-server]: serving: /Users/tina/Sites/node_require/bower_components/jquery/jquery.js
DEBUG [launcher]: Process PhantomJS exitted with code 0
DEBUG [launcher]: Cleaning temp dir /var/folders/lz/rp48gjr977n5bq684cbydpcw0000gn/T/karma-16204309
Warning: Task "karma:test" failed. Use --force to continue.

1 个答案:

答案 0 :(得分:4)

错误是由于我忘记在我的conf文件中包含我的模板目录,这对于我的views / add.test.js文件正确运行是必要的。这修好了它:

  {pattern: 'client/templates/*.hbs', included: false},

似乎当依赖关系在任何测试文件中都未解析时,它会传播到404:/ base / client / src / app error