如何使用Angular Deferred Bootstrap设置Karma&加载JSON文件?

时间:2015-07-30 23:27:17

标签: angularjs karma-runner karma-jasmine

我一直在尝试为一个新的角度项目设置Karma配置,该项目使用Angular Deferred Bootstrap加载配置文件(JSON)。当Karma加载时,它会给我一些无法找到app.json文件的错误。

这是我的角度模块。

angular.module('CareerPortal', ['ngAnimate', 'ngCookies', 'ngTouch', 'ngSanitize']);

// Defer the application until we have the configuration for the app!
deferredBootstrapper.bootstrap({
  element: document.body,
  module: 'MyApp',
  resolve: {
    configuration: ['$http', function ($http) {
        return $http.get('app.json');
    }]
  }
});

这是我的业力配置

function listFiles() {
var wiredepOptions = _.extend({}, conf.wiredep, {
    dependencies: true,
    devDependencies: true
});

return wiredep(wiredepOptions).js
    .concat([
        path.join(conf.paths.tmp, '/serve/app/index.module.js'),
        path.join(conf.paths.src, '/**/*.spec.js'),
        path.join(conf.paths.src, '/**/*.mock.js'),
        path.join(conf.paths.src, '/**/*.html')
    ]);
}

module.exports = function (config) {
  var configuration = {
    files: listFiles(),

    singleRun: true,

    autoWatch: false,

    debug: true,

    frameworks: ['jasmine'],

    ngHtml2JsPreprocessor: {
        stripPrefix: 'src/',
        moduleName: 'CareerPortal'
    },

    browsers: ['PhantomJS'],

    plugins: [
        'karma-phantomjs-launcher',
        'karma-jasmine',
        'karma-ng-html2js-preprocessor'
    ],

    preprocessors: {
        'src/**/*.html': ['ng-html2js']
    }
  };

  config.set(configuration);
};

然后JSON文件只是一个标准的JSON文件。

这是我得到的错误

INFO [karma]: Karma v0.12.37 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.8 (Mac OS X 0.0.0)]: Connected on socket 6MHhNTNq1d3djLp7R0z3 with id 21194787
WARN [web-server]: 404: /app.json
PhantomJS 1.9.8 (Mac OS X 0.0.0): Executed 0 of 0 ERROR (0.001 secs / 0 secs)
[18:23:44] Finished 'test' after 1.71 s

0 个答案:

没有答案