caitp / karma-coveralls

A Karma plugin to upload coverage reports to coveralls.io
65 stars 13 forks source link

Can't get it to run. #39

Open wethinkagile opened 7 years ago

wethinkagile commented 7 years ago

Hi thanks for your work on this plugin. I now installed the plugin and sent my built to codeship and also let Karma run beforehand locally, but I dont see any coverage generated. I do not have Mocha, this is a Ionic3/Angular4 project employing only Karma. Do you have an example config for use with Karma (and Codeship)?

caitp commented 7 years ago

I am not familiar with CodeShip, sorry.

wethinkagile commented 7 years ago

My concrete problem is, that we are using typescript.

This is my Karma.conf.js and it is just scanning my polyfills.js for coverage:

// Karma configuration file, see link for more information
// https://karma-runner.github.io/0.13/config/configuration-file.html

module.exports = function(config) {
    config.set({
        basePath: '',
        frameworks: ['jasmine', '@angular/cli'],
        plugins: [
            require('karma-jasmine'),
            require('karma-chrome-launcher'),
            require('karma-coverage'),
            require('karma-coveralls'),
            require('@angular/cli/plugins/karma')
        ],
        client: {
            clearContext: false // leave Jasmine Spec Runner output visible in browser
        },
        files: [{
                pattern: './src/test.ts',
                watched: false
            }
        ],
        preprocessors: {
            './src/test.ts': ['@angular/cli']
        },
        mime: {
            'text/x-typescript': ['ts', 'tsx']
        },
        coverageReporter: {
            type: 'lcov', // lcov or lcovonly are required for generating lcov.info files
            dir: 'coverage/'
        },
        angularCli: {
            environment: 'dev'
        },
        reporters: ['coverage', 'coveralls'],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browsers: ['Chrome'],
        singleRun: false
    });
};

Coverall is only testing my test.ts or my polyfills.js, nothing else, could be misconfig in my test.ts ?

// Then we find all the tests.
const context: any = require.context("./", true, /\.spec\.ts$/);
caitp commented 6 years ago

I mean, I really don't have the answer to this question :( this project sort of predated adoption of TypeScript, from the angular 1.x days. I haven't had the opportunity or need to adapt it to TypeScript just yet.

If you've gotten anywhere with integrating it, I would love it if you could send a pull request (and hopefully some tests to demonstrate that it's doing the right thing correctly, maybe some doc updates for typescript users).

I know it's been a while since this issue was opened, but if anybody else looking at this has time to chip in and make it happen, that would be amazing.

wethinkagile commented 6 years ago

Our Software Testers can't code. Our Developers don't write tests. Our Project Managers have no idea of TDD. Therefore we learned to live with bugs in production and fixing production on a constant emergency basis like von Papen did before Hitler took over. Cheers.

caitp commented 6 years ago

well alright then, leaving this open in case anybody else has a similar problem and can stand to submit a fix.

jgravois commented 6 years ago

its a bit of a beast, but you can see a working TypeScript implementation that generates coverage reports here.

https://github.com/Esri/arcgis-rest-js/blob/master/karma.conf.js

MarkPThomas commented 6 years ago

For me it causes Chrome to throw an exception when running Karma. Testing works if I don't include the 'coveralls' reporter, but when I add it as instructed in the yaml, I get the following:

16 05 2018 10:57:28.747:INFO [karma]: Karma v2.0.2 server started at http://0.0.0.0:9876/ 16 05 2018 10:57:28.748:INFO [launcher]: Launching browser Chrome with unlimited concurrency 16 05 2018 10:57:28.754:INFO [launcher]: Starting browser Chrome 16 05 2018 10:57:31.204:INFO [Chrome 66.0.3359 (Windows 10 0.0.0)]: Connected on socket terYi1eNZPTHl5v_AAAA with id 10964639 Unhandled rejection TypeError: Cannot read property 'push' of undefined at D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\karma\lib\reporters\multi.js:6:25 at Array.forEach () at MultiReporter.addAdapter (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\karma\lib\reporters\multi.js:5:15) at Server. (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\karma\lib\middleware\runner.js:41:18) at Object.onceWrapper (events.js:315:30) at emitOne (events.js:121:20) at Server.emit (events.js:211:7) at Executor.schedule (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\karma\lib\executor.js:26:15) at D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\karma\lib\middleware\runner.js:91:22 at tryCatcher (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\bluebird\js\release\util.js:16:23) at Promise._settlePromiseFromHandler (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\bluebird\js\release\promise.js:512:31) at Promise._settlePromise (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\bluebird\js\release\promise.js:569:18) at Promise._settlePromise0 (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\bluebird\js\release\promise.js:614:10) at Promise._settlePromises (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\bluebird\js\release\promise.js:693:18) at Promise._fulfill (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\bluebird\js\release\promise.js:638:18) at Promise._resolveCallback (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\bluebird\js\release\promise.js:432:57)

caitp commented 6 years ago

@MarkPThomas just for fun, try applying the following diff and lets see if it works after that --- if it does, can you send a pull request with the change applied?

diff --git a/lib/index.js b/lib/index.js
index e7dfe44..104a2e7 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -5,7 +5,8 @@ var through2 = require('through2');
 var lcovResultMerger = require('lcov-result-merger');
 var coveralls = require('coveralls');

-var CoverallsReporter = function(rootConfig, helper, logger) {
+var CoverallsReporter = function(initBaseReporter, rootConfig, helper, logger) {
+  initBaseReporter(this);
   var log = logger.create('coveralls.io');
   var config = rootConfig.coverallsReporter || {};
   var reporters = (rootConfig.reporters || []);
@@ -137,7 +138,7 @@ var CoverallsReporter = function(rootConfig, helper, logger) {
   }
 };

-CoverallsReporter.$inject = ['config', 'helper', 'logger'];
+CoverallsReporter.$inject = ['baseReporterDecorator', 'config', 'helper', 'logger'];

 module.exports = {
   'reporter:coveralls': ['type', CoverallsReporter]
MarkPThomas commented 6 years ago

@caitp Hmmm...

17 05 2018 08:43:57.885:ERROR [reporter]: Can not load "coveralls"! Error: coverage reporter should precede coveralls at CoverallsReporter (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\karma-coveralls\lib\index.js:15:11) at invoke (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\di\lib\injector.js:75:15) at Array.instantiate (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\di\lib\injector.js:59:20) at Injector.get (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\di\lib\injector.js:48:43) at D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\karma\lib\reporter.js:127:75 at Array.forEach () at createReporters (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\karma\lib\reporter.js:112:9) at Array.invoke (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\di\lib\injector.js:75:15) at Injector.get (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\di\lib\injector.js:48:43) at get (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\di\lib\injector.js:54:19) at D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\di\lib\injector.js:71:14 at Array.map () at Injector.invoke (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\di\lib\injector.js:70:31) at createWebServer (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\karma\lib\web-server.js:67:24) at Array.invoke (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\di\lib\injector.js:75:15) at Injector.get (D:\wamp_remote\notOnWebsite\continuous-integration-js\node_modules\di\lib\injector.js:48:43) 17 05 2018 08:43:57.914:INFO [karma]: Karma v2.0.2 server started at http://0.0.0.0:9876/ 17 05 2018 08:43:57.914:ERROR [karma]: Found 1 load error

It looks like it should be working. Strange...

var reporters = (rootConfig.reporters || []); var coverage = reporters.indexOf('coverage'); if (coverage < 0 || coverage > reporters.indexOf('coveralls')) { throw new Error("coverage reporter should precede coveralls"); }

I can see that reporters is coming in as [ 'coveralls', 'intellij_c831a91b03572bad3b3db88354641e3b' ] even though I have it written in the config as reporters: ['coverage', 'coveralls'],. BTW, I am running this in PhpStorm 2018.1.3, in case that helps.

caitp commented 6 years ago

whats the intellij thing coming from? Nvm, you said PhpStorm.. hmm. Still, seems like its being mutated along the way somewhere.

Maybe there’s a way to get the plugin name programmatically in case it’s mutated? If there is, we should do that.

caitp commented 6 years ago

I think it will work in this case if you change it to a coverage < 0 || (coverage && reporters.indexOf(“coveralls”) > coverage)

If we can’t figure out the renaming thing, that should work in your case