Karma (mocha) - 每当单元测试失败时出现意外的令牌 N

Karma (mocha) - Unexpected token N whenever unit test fails

我正在使用 Karma + Mocha 来 运行 我的单元测试,一切都很好,除非测试失败, 当我 运行 像

这样的测试时
expect(player).to.be.an('object');

它失败了我希望它说 "Object was expected but string given" 或类似的东西,相反我得到的是(对于每一个失败的测试,不管它是如何失败的,即使我试图资产真实假):

SyntaxError: Unexpected token N
        at Object.parse (native)
        at Array.map (native)

我知道我的代码中没有语法错误,所以我猜这与 karma/mocha 以及他们处理失败测试的方式有关。我只是不知道去哪里找。 . 这是我的 gulp 任务:

var karmaServer = require('karma').server;

gulp.task('test', function (done) {
    gutil.log('preparing tests.');
    var runOnlyOnce = true;
    // check if a parameter named "watch" is passed. if so - run tests in watch mode.
    if (argv.watch){
        runOnlyOnce = false;
    }

    if (runOnlyOnce){
        gutil.log('Running only once.\nTo run in "watch" mode try: gulp test --watch');
    } else {
        gutil.log('Running in watch mode. Oh yeah.');
    }

    karmaServer.start({
        configFile: __dirname +'/karma.conf.js',
        singleRun: runOnlyOnce
    }, function(exitCode) {
      gutil.log('Karma has exited with ' + exitCode);
      if (exitCode != 0){
        gutil.log(gutil.colors.bgRed("Test(s) failed."));
      }
      process.exit(exitCode);
    });
});

这是我的 karma.conf 文件:

module.exports = function (config) {
    'use strict';
    config.set({

        basePath: '',

         frameworks: ['browserify',  'mocha',  'source-map-support'],

        // reporters configuration 
        reporters: ['mocha'],

        preprocessors: {
            'test/**/*.spec.js': ['browserify']
        },

        files: [
            {pattern: 'app/**/*.js', watched: true, included: false, served: false}, // watch these files, but dont bundle them for tests
            'test/**/*.spec.js'
        ],

        browserify: {
            debug: true,
            transform: ['babelify']
        },

        plugins: [
            'karma-mocha-reporter',
            'karma-mocha',
            'karma-phantomjs-launcher',
            'karma-chrome-launcher',
            'karma-browserify',
            'babel-plugin-espower',
            'karma-ie-launcher',
            'karma-source-map-support'
        ],

        port: 9876,
        colors: true,
        usePolling: true,
        atomic_save: false,
        autoWatch : 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,

        browsers: ["Chrome"] //, "IE", 'PhantomJS'

    });
};

任何帮助将不胜感激!!!谢谢!

所以我发现了问题,我所做的就是从 karma.conf 文件中删除调试标志.. 而不是

 browserify: {
            debug: true,
            transform: ['babelify']
        },

我做到了:

 browserify: {
            debug: false,
            transform: ['babelify']
        },

成功了。

希望对大家有所帮助!干杯!