用Angular、Babel(ES6)、Webpack和Mocha设置Karma

3
我正在尝试在一个带有Angular的项目上设置Karma。我目前收到的错误是:
错误:[$injector:nomod]模块'app'不可用!您可能拼错了模块名称或忘记加载它。如果要注册一个模块,请确保将依赖项指定为第二个参数。 http://errors.angularjs.org/1.4.7/$injector/nomod?p0=app 位于/htdocs/src/javascript/app/controllers/fixedQuoteFormController_test.js:2073
我想做的只是初始设置,因为我显然没有测试。它似乎不喜欢我的控制器的module.export。任何有关如何使此设置工作的帮助都将不胜感激!
我的Karma.conf文件:
// Karma configuration
// Generated on Tue Nov 17 2015 13:05:37 GMT-0600 (CST)

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', 'chai'],

plugins: [
  require("karma-webpack"),
  require("karma-mocha"),
  require("karma-phantomjs-launcher"),
  require("karma-chai")
],

// list of files / patterns to load in the browser
files: [
  'node_modules/angular/angular.js',
  'node_modules/angular-mocks/angular-mocks.js',
  'src/javascript/app/**/*_test.js',
  'src/javascript/app/**/**/*_test.js'
],

// list of files to exclude
exclude: [
],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
  // add webpack as preprocessor
  'src/javascript/app/*_test.js': ['webpack'],
  'src/javascript/app/**/*_test.js': ['webpack']
},

webpack: {
  // karma watches the test entry points
  // (you don't need to specify the entry option)
  // webpack watches dependencies
  // webpack configuration
},

webpackMiddleware: {
  // webpack-dev-middleware configuration
  // i. e.
  noInfo: true
},

// 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: true,

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS'],

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,

// Concurrency level
// how many browser should be started simultanous
concurrency: Infinity,
  })
}

我的测试文件:(只是尝试要求控制器)

const testCont = require('./testCont');

我的控制器

module.exports = angular.module('app').controller('testCont', testCont);

/* @ngInject */
function testCont() {
    return 1;
}
1个回答

2
我有一个概念证明,我一直在努力工作,它作为Angular+Webpack+ES6+Karma+Mocha+Chai的成功工作设置。
也许它会给你一些启示或帮助解决你的问题。随意分叉它并试一试,看看这个设置是否适合你。我的Webpack.config.js和Karma.conf.js在不同的文件中。
它可以作为一个更清晰的起点。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接