Karma coverage预处理器无法正确解析CoffeeScript

时间:2014-06-30 15:06:03

标签: angularjs coffeescript karma-runner

我的代码是:

  $scope.$watch(->
    userService.getUser()
  , ->
    user = userService.getUser()
    $scope.authRoles = user.authRoles
  )

非常无害。但是当我进行测试时,我得到了:

ERROR [preprocessor.coverage]: Syntax error on line 19, column 6: unexpected ',' (\u002C)
16 :
17 :       $scope.$watch(->
18 :         userService.getUser()
19 :       , ->
^^ :~~~~~~^
20 :         user = userService.getUser()
21 :         $scope.authRoles = user.authRoles
22 :       )

我的karma.conf.coffee看起来像是:

module.exports = (config) ->
  config.set
    basePath: '../../'

    files: [
      'dist/assets/vendor.js'
      'bower_components/angular-mocks/angular-mocks.js'
      'public/scripts/**/*.coffee'
      'test/webapp/unit/**/*.coffee'
    ]

    preprocessors:
      'public/scripts/**/*.coffee': ['coverage']
      'test/webapp/unit/**/*.coffee': ['coffee']

    singleRun: true

    frameworks: ['jasmine']

    browsers: ['PhantomJS']

    reporters: ['story', 'coverage']

    coverageReporter:
      type: 'html'
      dir: 'test/webapp/coverage/'

有任何帮助吗?谢谢!

1 个答案:

答案 0 :(得分:1)

在coffeescript中完成代码覆盖的方式还有很多不足之处。它使用仍未完成的特定编译器(CoffeeScriptRedux)。尝试使用间距(多一个级别的缩进?)或提取此函数并将其名称放在此处。你别无选择。