2015-10-22 12 views
8

Sto cercando di ottenere il rapporto di copertura per i miei test ma l'output di copertura per tutti i file è sempre su una singola riga che mostra il fabbisogno con il percorso del file. Per esempio ...Karma + Browserify + Jasmine + Istanbul + Copertura di reazione

enter image description here

Le prove però sono in esecuzione bene. Questo è un progetto di reazione, quindi ho dovuto includere alcuni percorsi aggiuntivi ai file e al preprocessore per eseguire i test.

Non sono sicuro se c'è qualcosa di sbagliato nella mia configurazione di karma? Questo è ciò che la mia configurazione attualmente sembra ...

/* global module */ 
module.exports = function (config) { 
    'use strict'; 
    config.set({ 
     autoWatch: true, 
     singleRun: true, 

     frameworks: ['browserify', 'jasmine'], 

     files: [ 
      'node_modules/karma-babel-preprocessor/node_modules/babel-core/browser-polyfill.js', 
      'node_modules/react/react.js', 
      'src/**/*.jsx', 
      'src/**/!(*spec).js' 
     ], 

     browsers: ['PhantomJS'], 

     preprocessors: { 
      'node_modules/react/react.js': ['browserify', 'sourcemap'], 
      'src/**/*.jsx': ['browserify', 'sourcemap', 'coverage'], 
      'src/**/!(*spec).js': ['browserify', 'sourcemap', 'coverage'], 
     }, 

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

     reporters: ['progress', 'coverage'], 

     coverageReporter: { 
      instrumenters: {isparta: require('isparta')}, 
      instrumenter: { 
       'src/**/*.js': 'isparta', 
       'src/**/*.jsx': 'isparta' 

      }, 
      reporters: [ 
       { 
        type: 'text-summary', 
        subdir: normalizationBrowserName 
       }, 
       { 
        type: 'lcov', 
        subdir: normalizationBrowserName 
       }, 
       { 
        type: 'html', 
        dir: 'coverage/', 
        subdir: normalizationBrowserName 
       } 
      ] 
     } 

    }); 

    function normalizationBrowserName(browser) { 
     return browser.toLowerCase().split(/[ /-]/)[0]; 
    } 

}; 

UPDATE: ho usato un commonjs trasformano come bene e sono riuscito a far funzionare le cose un po 'meglio, ma i test non sarebbero correre e la copertura era il codice trasformato.

risposta

-1

Assicurarsi di includere tutto il codice sorgente per la copertura. Per esempio, ho il seguente karma.conf.js: (controlla la sezione del preprocessore)

// Karma configuration 
// Generated on Mon Sep 07 2015 23:22:13 GMT-0400 (Eastern Daylight Time) 

module.exports = function(config) { 

    var SourceCode = [ 
     'app/app.js', 
     'app/Modules/*.js',      // Basic Path Files (Modules for Source, UnitTests to keep test files separate) 
     'app/Modules/**/_*.init.js',   // Declarative functions needed for next line - Initialization Code 
     'app/Modules/**/*.js', 
     'app/UnitTests/**/*.mock.js',   // Mock Declarations for Tests 
     'app/UnitTests/**/*.test.js' 
    ]; 

    var Libraries = [ 
     'app/bower_components/angular/angular.js', 
     'app/bower_components/angular-animate/angular-animate.js', 
     'app/bower_components/angular-aria/angular-aria.js', 
     'app/bower_components/angular-route/angular-route.js', 
     'app/bower_components/firebase/firebase.js', 
     ... 
// Testing 
     'app/bower_components/angular-mocks/angular-mocks.js', 
     'app/bower_components/angular-material/angular-material-mocks.js', 
     'app/bower_components/mockfirebase/browser/mockfirebase.js', 
     'node_modules/sinon/pkg/sinon.js', 
    ]; 

    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: Libraries.concat(SourceCode), 


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


     // preprocess matching files before serving them to the browser 
     // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor 
     preprocessors: { 
      'app/Modules/**/*.js': ['coverage']   // Ensure all files are in Code Coverage 
     }, 

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

     coverageReporter: { 
      type : 'html', 
      dir : 'docs/coverage/' 
     }, 

     logLevel: 'LOG_DEBUG', 

     // 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: false, 


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


     // Continuous Integration mode 
     // if true, Karma captures browsers, runs the tests and exits 
     singleRun: true 
    }) 
} 
+0

Ho tutti i miei file inclusi. Penso che il problema sia legato a browserify. – Adgezaza

+0

Sfortunatamente, non utilizzo Browserify, ma ho visto anche altri problemi sull'integrazione e sui test. Quando ho riscontrato problemi, ho notato molti articoli su Browserify e domande, quindi purtroppo è probabile che tu debba continuare a cercare. Scusa, non posso aiutare di più. –