6

Geçerli AngularJS projemi Karma Kapsamı ile entegre etmeye çalışıyorum. Lütfen package.json ve karma-config karma-yapılandırmasını aşağıda bulabilirsiniz.AngularJS + Karma + Jasmine + Karma Kapsamı: Boş yayın raporu

Package.json

{ 
    "name": "Project", 
    "description": "Description", 
    "repository": "https://www.repo.com", 
    "devDependencies": { 
    "karma": "~0.10.9", 
    "karma-junit-reporter": "~0.2.1", 
    "karma-jasmine": "~0.1.5", 
    "karma-ng-scenario": "~0.1", 
    "karma-script-launcher": "~0.1.0", 
    "karma-chrome-launcher": "~0.1.3", 
    "karma-firefox-launcher": "~0.1.3", 
    "karma-phantomjs-launcher": "~0.1.4", 
    "karma-ng-html2js-preprocessor": "~0.1", 
    "karma-coverage": "~0.1" 
    } 
} 

Karma yapılandırma

'use strict'; 

module.exports = function (config) { 
    config.set({ 
    basePath: '../../public/', 
    logLevel: config.LOG_DEBUG, 
    frameworks: ['jasmine'], 
    singleRun: true, 
    files: [ 
     'libs/jquery/jquery-1.9.0.js', 
     'libs/angular/1.2.10/angular.js', 
     'libs/angular/**/*.js', 
     'libs/angular/*.js', 
     'libs/vendor/*.js', 
     'libs/test/**/*.js', 

     // fixtures 
     {pattern: 'test/mock-data/helloworld/*.json', watched: true, served: true, included: false}, 

     'apps/helloworld/**/*.js', 
     'apps/helloworld/*.js', 
     'test/helloworld/unit/**/*.js', 
     'test/helloworld/*.js', 
     'views/helloworld/directives/*.html' 
    ], 

    exclude: [ 
     'libs/angular/1.2.10/*.min.js', 
     'libs/angular/angular-animate.js' 
    ], 

    browsers: ['PhantomJS'], 

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

    preprocessor: { 
     'apps/helloworld/**/*.js': ['coverage'], 
     '*.html': ['ng-html2js'] 
    } 
    }) 
}; 

ben çalıştırmayı denediğinizde "node_modules/.bin/karma başlangıç ​​conf/danışman/karma.conf.js" Tüm testler başarıyla yürütülür, ancak karma kapsam raporu tamamen boştur. Birkaç seçenek denedim ama raporların görünmesini sağlayamıyorum.

enter image description here

konsol çıkış kapsamı için önişlemci asla kaçmaz. Aslında html2js için çalıştığını görebiliyorum.

DEBUG [plugin]: Loading karma-* from /Users/alansouza/workspace/helloworld/node_modules 
DEBUG [plugin]: Loading plugin /Users/alansouza/workspace/helloworld/node_modules/karma-chrome-launcher. 
DEBUG [plugin]: Loading plugin /Users/alansouza/workspace/helloworld/node_modules/karma-coffee-preprocessor. 
DEBUG [plugin]: Loading plugin /Users/alansouza/workspace/helloworld/node_modules/karma- coverage. 
DEBUG [plugin]: Loading plugin /Users/alansouza/workspace/helloworld/node_modules/karma-firefox-launcher. 
DEBUG [plugin]: Loading plugin /Users/alansouza/workspace/helloworld/node_modules/karma-html2js-preprocessor. 
DEBUG [plugin]: Loading plugin /Users/alansouza/workspace/helloworld/node_modules/karma-jasmine. 
DEBUG [plugin]: Loading plugin /Users/alansouza/workspace/helloworld/node_modules/karma-junit-reporter. 
DEBUG [plugin]: Loading plugin /Users/alansouza/workspace/helloworld/node_modules/karma-ng-html2js-preprocessor. 
DEBUG [plugin]: Loading plugin /Users/alansouza/workspace/helloworld/node_modules/karma-ng-scenario. 
DEBUG [plugin]: Loading plugin /Users/alansouza/workspace/helloworld/node_modules/karma-phantomjs-launcher. 
DEBUG [plugin]: Loading plugin /Users/alansouza/workspace/helloworld/node_modules/karma-requirejs. 
DEBUG [plugin]: Loading plugin /Users/alansouza/workspace/helloworld/node_modules/karma-script-launcher. 
INFO [karma]: Karma v0.10.10 server started at http://localhost:9876/ 
INFO [launcher]: Starting browser PhantomJS 
DEBUG [launcher]: Creating temp dir at /var/folders/8_/vw105h0j3vn66cgzttktdjmm0000gn/T/karma-29140367 
DEBUG [launcher]: /Users/alansouza/workspace/helloworld/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/bin/phantomjs /var/folders/8_/vw105h0j3vn66cgzttktdjmm0000gn/T/karma-29140367/capture.js 
DEBUG [watcher]: Excluded file "/Users/alansouza/workspace/helloworld/public/libs/angular/1.2.10/angular-animate.min.js" 
DEBUG [watcher]: Excluded file "/Users/alansouza/workspace/helloworld/public/libs/angular/1.2.10/angular-resource.min.js" 
DEBUG [watcher]: Excluded file "/Users/alansouza/workspace/helloworld/public/libs/angular/1.2.10/angular-route.min.js" 
DEBUG [watcher]: Excluded file "/Users/alansouza/workspace/helloworld/public/libs/angular/1.2.10/angular-sanitize.min.js" 
DEBUG [watcher]: Excluded file "/Users/alansouza/workspace/helloworld/public/libs/angular/1.2.10/angular.min.js" 
DEBUG [preprocessor.html2js]: Processing "/Users/alansouza/workspace/helloworld/public/views/advisor/directives/av-product-total.html". 
DEBUG [preprocessor.html2js]: Processing "/Users/alansouza/workspace/helloworld/public/views/advisor/directives/av-product.html". 
DEBUG [preprocessor.html2js]: Processing "/Users/alansouza/workspace/helloworld/public/views/advisor/directives/av-select-product.html". 
DEBUG [watcher]: Resolved files: 

Soru: burada yanlış mı yapıyorum? Src js dosyalarınımı yüklemek için karma kapsamı nasıl oluşturulur?

cevap

3

Sorunu gideremedim. Eksik bir "s" idi. Karma yapılandırmam başlangıçta önişlemci idi; burada önişlemciler olmalıdır. Doğru karma yapılandırma aşağıda bulabilirsiniz: Burada

'use strict'; 

    module.exports = function (config) { 
    config.set({ 
    basePath: '../../public/', 
    logLevel: config.LOG_DEBUG, 
    frameworks: ['jasmine'], 
    singleRun: true, 
    files: [ 
     'libs/jquery/jquery-1.9.0.js', 
     'libs/angular/1.2.10/angular.js', 
     'libs/angular/**/*.js', 
     'libs/angular/*.js', 
     'libs/vendor/*.js', 
     'libs/test/**/*.js', 

     // fixtures 
     {pattern: 'test/mock-data/helloworld/*.json', watched: true, served: true, included: false}, 

     'apps/helloworld/**/*.js', 
     'apps/helloworld/*.js', 
     'test/helloworld/unit/**/*.js', 
     'test/helloworld/*.js', 
     'views/helloworld/directives/*.html' 
    ], 

    exclude: [ 
     'libs/angular/1.2.10/*.min.js', 
     'libs/angular/angular-animate.js' 
    ], 

    browsers: ['PhantomJS'], 

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

    preprocessors: { 
     'apps/helloworld/**/*.js': ['coverage'], 
     '*.html': ['ng-html2js'] 
    } 
    }) 
    }; 

en ilginç nokta şudur: (benim direktifleri test geçerken) ng-html2js için önişlemcisine ile daha önce çalışıyordu. Kapsamı tanıttığımda sorun oluşmaya başladı.

4

preprocessors özelliğine ve coverageReporter özelliğine sahip değilsiniz.

senin karma yapılandırma dosyası için bu bölümü ekleyin:

preprocessors: { 
     'apps/helloworld/**/*.js':['coverage'] 
    }, 
coverageReporter:{ 
     type:'html', 
     dir:'C:/Dev/coverage/' 
    }, 

İstediğinizi için coverageReporter çıkış dizini değiştirebilirsiniz.

+0

Aslında yaptığım yapılandırmada kapsam önişlemcisini içerir. ScopeReporter, varsayılan olarak html'ye atanan isteğe bağlı bir parametredir. Çalışıp çalışmadığını görmek için farklı bir çıktı (ör. Txt) eklemeyi denedim. –

+0

Ah, haklısın. Görünüşe göre yeterince uzağa gitmedim. Bu problemi Karma 0.10 ile hatırlıyorum ama 0.12'ye güncellediğimde sabit görünüyor. Belki de ona bir girdap verir misin? – MBielski

+0

0.12 veya 0.11 için güncellemeye çalıştım ve yönerge testinde sorun yaşıyorum. Html modüllerini (html2js) yüklemez. Herhangi bir fikir?! –