2

我最终决定从 testacular (0.4.0) 迁移到 karma 0.8.5。我的测试是用 CoffeeScript 编写的 Jasmine。

这是输出karma start path/to/karma.conf.js

INFO [karma]: Karma server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 26.0 (Mac)]: Connected on socket id MOOnxLR89NKLGrrzbTI_

Chrome 26.0 (Mac) ERROR
Uncaught SyntaxError: Unexpected string
at /Users/genghis/Projects/chirper/client/test/spec/authenticationSpec.coffee:1
Chrome 26.0 (Mac): Executed 0 of 0 ERROR (1.246 secs / 0 secs)

查看调试器控制台,每个测试文件都有类似的错误。我已经配置了预处理器,但似乎没有编译咖啡脚本?这是我的karma.conf.js

basePath = '';

files = [
  JASMINE,
  JASMINE_ADAPTER,
  '../app/components/angular/angular.js',
  '../app/components/angular-mocks/angular-mocks.js',
  '../app/scripts/*.js',
  '../app/scripts/**/*.js',
  '../app/components/socket.io-client/dist/socket.io.js',
  '../test/spec/**/*.coffee'
];

exclude = [];
reporter = 'progress';
port = 9876;
runnerPort = 9100;
colors = true;
logLevel = LOG_INFO;
autoWatch = true;
browsers = ['Chrome'];
singleRun = false;

preprocessors = {
  '**/*.coffee': 'coffee'
};

有任何想法吗?提前致谢!

更新:

我可以通过使用节点 cli 运行 CS 测试文件来重现错误。所以很明显咖啡脚本没有被编译。文件的第一行(失败)如下所示:

describe 'Authentication', ->
4

2 回答 2

1

编辑:在指定预处理器时尝试更改'coffee'为。['coffee']

对于未来的人:

我也为此苦苦挣扎。

我无法告诉你使它工作的确切修复,但这是我的配置文件。(它在 coffeescipt 中,但除了将其保存为 .coffee 之外,不应该有所作为)。

请注意,我已经明确设置了插件、coffeePreprocessor、预处理器和 basePath 的具体值。

# Karma configuration

module.exports = (config) ->
    config.set({

        basePath: '../',

        frameworks: ['jasmine'],

        preprocessors: {
          '**/*.coffee': ['coffee']
        },

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

        files: [
          'app/assets/vendor/angular.js'
          'app/assets/vendor/angular-mocks.js'
          'app/assets/javascript/*.coffee'
          'spec/clientjs/**/*Spec.*',

        ],

        reporters: ['progress'],

        port: 9876,

        colors: true,

        logLevel: config.LOG_INFO,


        plugins: [
            'karma-coffee-preprocessor',
            'karma-jasmine',
            'karma-chrome-launcher']

        autoWatch: true,

        browsers: ['Chrome'],

        captureTimeout: 60000,

        singleRun: false
    })
于 2013-12-11T11:41:01.203 回答
0

记者 = '进展';

应该

记者 = ['进度'];

另外,你的错误在于 spec/authenticationSpec.coffee

于 2013-04-26T20:14:43.877 回答