2016-03-22 40 views
4

私のプロジェクトでKarma Angular Mocha Chaiを使用しています。私はTDDをやっていて、私の変更をテストしたいと思います。私はconsole.logをtest.jsファイルに入れましたが、karma consoleは表示されません。私はそれを可能にする方法もわからないのですか?Angular Karma console.logが機能しません

は、ここに私のkarma.config.jsである:ここでは

module.exports = function(config) { 
    config.set({ 

    // base path that will be used to resolve all patterns (eg. files, exclude) 
    basePath: '', 


    // frameworks to use 
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter 
    frameworks: ['mocha', 'chai'], 


    // list of files/patterns to load in the browser 
    files: [ 
     'src/main/webapp/js/angular.js', 
     'src/main/webapp/js/angular-simple-logger.js', 
     'src/main/webapp/js/services/myservice-test.js', 
     'src/main/webapp/js/controllers/*.js', 
     'src/test/webapp/**/*.js' 
    ], 

    // list of files to exclude 
    exclude: [ 
    ], 

    client : { 
     captureConsole : true 
    }, 

    // preprocess matching files before serving them to the browser 
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor 
    preprocessors: { 
    }, 


    // test results reporter to use 
    // possible values: 'dots', 'progress' 
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter 
    reporters: ['progress'], 


    // web server port 
    port: 9876, 


    // enable/disable colors in the output (reporters and logs) 
    colors: 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, 


    // enable/disable watching file and executing tests whenever any file changes 
    autoWatch: true, 


    // start these browsers 
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher 
    browsers: ['Chrome'], 


    // Continuous Integration mode 
    // if true, Karma captures browsers, runs the tests and exits 
    singleRun: false, 

    // Concurrency level 
    // how many browser should be started simultaneous 
    concurrency: Infinity 
    }) 
} 

である私のpackage.json

{ 
    "name": "myapp", 
    "version": "0.0.1", 
    "description": "my App", 
    "main": "src/main/webapp/index.html", 
    "directories": { 
    "doc": "docs" 
    }, 
    "scripts": { 
    "test": "node_modules/.bin/karma start karma.config.js" 
    }, 
    "repository": { 
    "type": "git", 
    "url": "" 
    }, 
    "author": "", 
    "license": "ISC", 
    "devDependencies": { 
    "chai": "^3.5.0", 
    "karma": "^0.13.22", 
    "karma-chai": "^0.1.0", 
    "karma-chrome-launcher": "^0.2.2", 
    "karma-mocha": "^0.2.2", 
    "mocha": "^2.4.5" 
    }, 
    "dependencies": { 
    "angular": "^1.5.1", 
    "angular-mocks": "^1.5.1" 
    } 
} 
+0

あなたの設定は私には似ていますが、関連する可能性のあるGitHubの問題があります:https://github.com/karma-runner/karma-mocha/issues/47 – eppsilon

答えて

8

があなたのconfig.setに

browserConsoleLogOptions: { 
    level: 'log' 
}, 

を追加します。これはカルマ行動の新しい(カルマ1.5.0、circa 2017-02-20)改良である。 https://github.com/karma-runner/karma/issues/2582

+0

これは私を助け、答えを受け入れてください。 –

+0

[この回答](https://stackoverflow.com/a/42379383/23118)も参照してください。 – hlovdal

関連する問題