1

I'm trying to setup Karma with CoffeeScript and CommonJS pre-processor but I'm getting the error log require is not defined in the terminal.

Seems to be a load order issue because sources and test files are loaded before the common-js bridge js file. How can I specify load order? Or is there any other issue in my config?

My previous error of my config ERROR [preprocessor.coffee]: unexpected MATH was the problem that the preprocessor was applied to all coffee files inside of node_modules folders.

My Karma.config.coffee looks like this:

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      

My directory structure looks like this:

enter image description here

My test file should work because if I run it with jasmine-node like $ node_modules\.bin\jasmine-node spec --coffee --color the test runs successfully. I'd like to use Karma because I couldn't get Istanbul to work with CoffeeScript under Windows 8.1 (64bit) directly (seems to be a command line issue).

At the moment, coverage is not adding anything to the html report but I think that's because of the require undefined issue.

In the browser console I'm getting these errors: enter image description here

4

0 回答 0