如何设置Karma配置以使用CoffeeScript& CommonJS pre。?

时间:2015-07-14 23:38:16

标签: javascript coffeescript karma-runner karma-coverage

我尝试使用CoffeeScript和CommonJS预处理器设置Karma,但我在终端中收到错误日志require is not defined

似乎是一个加载顺序问题,因为源和测试文件是在common-js bridge js文件之前加载的。如何指定加载顺序?或者我的配置中还有其他问题吗?

我之前的配置ERROR [preprocessor.coffee]: unexpected MATH错误是预处理器应用于node_modules文件夹中的所有咖啡文件的问题。

我的Karma.config.coffee看起来像这样:

module.exports = (config) ->
  config.set
   frameworks: ['jasmine', 'commonjs']

  preprocessors:
    # source files, that you wanna generate coverage for
    # do not include tests or libraries
    # (these files will be instrumented by Istanbul)
    'src/**/*.coffee': ['coffee', 'commonjs', 'coverage']
    'spec/**/*.coffee': ['coffee']

  coffeePreprocessor:
    # options passed to the coffee compiler
    options:
    bare: true
    sourceMap: false
  # transforming the filenames
  # transformPath: (path) ->
  #   path.replace(/\.coffee$/, '.js')

  commonjsPreprocessor:
    basePath: '../'
    options:
      isCoffeeScript: true
    pathReplace: (path) ->
      path.replace(/^src\//, '')

  # coverage reporter generates the coverage
  reporters: ['progress', 'coverage']

  files: [
    './node_modules/karma-commonjs/client/commonjs_bridge.js'
    'src/**/*.coffee'
    'spec/**/*.coffee'
  ]

  # optionally, configure the reporter
  coverageReporter:
    type : 'html'
    dir : 'coverage/'

  plugins: [
    require './node_modules/karma-commonjs-preprocessor/index'
    'karma-commonjs-preprocessor'
    'karma-coverage'
    'karma-jasmine'
    'karma-commonjs'
    'karma-coffee-preprocessor'
    'karma-firefox-launcher'
  ]

  # level of logging
  # possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
  logLevel: config.LOG_DEBUG      

我的目录结构如下所示:

enter image description here

我的测试文件应该可以工作,因为如果我使用像$ node_modules\.bin\jasmine-node spec --coffee --color这样的jasmine-node运行它,测试就会成功运行。我想使用Karma,因为我无法让伊斯坦布尔直接在Windows 8.1(64位)下使用CoffeeScript(似乎是命令行问题)。

目前,报道并未在html报告中添加任何内容,但我认为这是因为require undefined问题。

在浏览器控制台中,我收到了以下错误: enter image description here

0 个答案:

没有答案