jimivdw / grunt-mutation-testing

JavaScript Mutation Testing as grunt plugin. Tests your tests by mutating the code.
MIT License
50 stars 11 forks source link

Fatal error: Could not connect to a Karma server #51

Open skolorz opened 8 years ago

skolorz commented 8 years ago

Hi

I can't get it working with karma, I receive following output:

$ grunt
Running "mutationTest:goals" (mutationTest) task
(13:38:25.033) DEBUG [KarmaServerManager]: 29 01 2016 13:38:25.033:INFO [karma]: Karma v0.13.15 server started at http://localhost:12111/

Fatal error: Could not connect to a Karma server on port 12111 within 30 seconds

(I tried with longer timeout, didn't help) Here's my Gruntfile.js

"use strict";
/* global module */
module.exports = function (grunt) {
    grunt.initConfig({
        mutationTest: {
            options: {
                logLevel: "DEBUG",
                mutateProductionCode: true,
                configFile: "karma.conf.js",
                karma: {
                    waitForServerTime: 90
                }
            },
            goals: {
                code: "build/assets/js/**/*.js",
                specs: "build/assets/js/spec/subapps/goals/**/*.js",
                mutate: "build/assets/js/app/subapps/goals/goals.subapp.js"
            }
        }
    });

    grunt.loadNpmTasks("grunt-mutation-testing");
    grunt.registerTask("default", ["mutationTest"]);
};

Am I doing something wrong? My karma.conf is ok, it works.

jimivdw commented 8 years ago

Hi @skolorz,

You made a small mistake in configuring your karma config file. This should be a child option of the karma configuration option (and camelCase karmaConfig), resulting in the following configuration:

"use strict";
/* global module */
module.exports = function (grunt) {
    grunt.initConfig({
        mutationTest: {
            options: {
                logLevel: "DEBUG",
                mutateProductionCode: true,
                karma: {
                    configFile: "karma.conf.js",
                    waitForServerTime: 90
                }
            },
            goals: {
                code: "build/assets/js/**/*.js",
                specs: "build/assets/js/spec/subapps/goals/**/*.js",
                mutate: "build/assets/js/app/subapps/goals/goals.subapp.js"
            }
        }
    });

    grunt.loadNpmTasks("grunt-mutation-testing");
    grunt.registerTask("default", ["mutationTest"]);
};

In addition to that, it could be the case that the Karma server was actually started on a different port from the port it was configured to start on. You could experiment with setting different values for the karma.port option if the issue persists after fixing the karma config configuration and upgrading to the latest version of grunt-mutation-testing (1.3.2 at the time of writing).

-- Jimi

prmag commented 8 years ago

Hi there,

I'm running into the same problem, I've tried to change the task in a billion different ways and still without resolution.

The karma.conf.js works just fine when running the unit tests, but I simply cannot get the grunt-mutation-testing to connect to the Karma server. My task is as follows:

karma: {                               
    options: {                         
        code: srcFiles,                
        specs: ['/tests/**/*.js'],     
        mutate: ['app/**/*.js'], 
        logLevel: 'DEBUG',  
        karma: {                       
            configFile: 'karma.conf.js'
        }                                        
    }                                  
}          

The code is all written using AngularJS (dunno if that makes any difference or not). Do you see anything wrong with this setup (srcFiles is ofc an array with all the files belonging to the project)?

When running the task in --verbose mode i get this:

Running "mutationTest:karma" (mutationTest) task
Verifying property mutationTest.karma exists in config...OK
File: [no files]

I've tried including testFramework: 'karma' and a lot of other options but I allways end up with the same error. I've even stopped using the karma.conf.js file and set it up manually in multiple ways and still nothing.

ethan-far commented 8 years ago

I'm running into the same problem. I've tried all the examples of usage available on GitHub but to no avail.

Changing logLevel to 'ALL' now shows the following stack trace (not sure if it helps):

(11:04:58.584) TRACE [KarmaServerManager]: Starting a Karma server on port 12111... (11:04:58.585) TRACE [KarmaServerManager]: Server status changed to: INITIALIZING (11:04:59.628) DEBUG [KarmaServerManager]: 29 03 2016 11:04:59.625:DEBUG [plugin]: Loading karma-* from C:\Users\eitanf\workspace\ac-infra\node_modules\grunt-mutation-testing\node_modules

(11:05:08.603) TRACE [KarmaServerManager]: Server status changed to: DEFUNCT Fatal error: Could not connect to a Karma server on port 12111 within 10 seconds

events.js:72 throw er; // Unhandled 'error' event ^ Error: channel closed at ChildProcess.target.send (child_process.js:406:26) at KarmaServerManager.stop (C:\Users\eitanf\workspace\ac-infra\node_modules\grunt-mutation-testing\lib\karma\KarmaServerManager.js:123:29) at C:\Users\eitanf\workspace\ac-infra\node_modules\grunt-mutation-testing\lib\karma\KarmaServerPool.js:90:56 at arrayEach (C:\Users\eitanf\workspace\ac-infra\node_modules\grunt-mutation-testing\node_modules\lodash\index.js:1314:13) at Function. (C:\Users\eitanf\workspace\ac-infra\node_modules\grunt-mutation-testing\node_modules\lodash\index.js:3355:13) at KarmaServerPool.stopAllInstances (C:\Users\eitanf\workspace\ac-infra\node_modules\grunt-mutation-testing\lib\karma\KarmaServerPool.js:89:7) at stopServers (C:\Users\eitanf\workspace\ac-infra\node_modules\grunt-mutation-testing\tasks\mutation-testing-karma.js:57:20) at process. (C:\Users\eitanf\workspace\ac-infra\node_modules\grunt-mutation-testing\tasks\mutation-testing-karma.js:101:13) at process.emit (events.js:117:20) at process.exit (node.js:734:17) at tryToExit (C:\Users\eitanf\workspace\ac-infra\node_modules\grunt\node_modules\exit\lib\exit.js:17:15) at Object.exit (C:\Users\eitanf\workspace\ac-infra\node_modules\grunt\node_modules\exit\lib\exit.js:34:3) at Object.fail.fatal (C:\Users\eitanf\workspace\ac-infra\node_modules\grunt\lib\grunt\fail.js:57:14) at process.uncaughtHandler (C:\Users\eitanf\workspace\ac-infra\node_modules\grunt\lib\grunt.js:130:10) at process.emit (events.js:95:17) at process._fatalException (node.js:295:26)

simondel commented 8 years ago

Hey @eitanfar, @Ecleipse and @skolorz,

Are you using Jasmine? If so, could you try if stryker works for you? Right now it only supports Jasmine tests, but we plan on adding support for more frameworks in the future.

I had a chat with @jimivdw, @paysdoc and @nicojs tonight and we decided that we will (eventually) migrate everything to the stryker project.

ethan-far commented 8 years ago

Hi,

I am using Jasmine. I wasn't aware of the stryker project, I'll give it a try.

Thanks, Eitan בתאריך 7 באפר׳ 2016 23:18,‏ "Simon de Lang" notifications@github.com כתב:

Hey eitanfar,

Are you using Jasmine? If so, could you try if stryker https://github.com/infosupport/stryker works for you? Right now it only supports Jasmine tests, but we plan on adding support for more frameworks in the future.

I had a chat with @jimivdw https://github.com/jimivdw, @paysdoc https://github.com/paysdoc and @nicojs https://github.com/nicojs tonight and we decided that we will (eventually) migrate everything to the stryker project.

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/jimivdw/grunt-mutation-testing/issues/51#issuecomment-207072772

nicojs commented 8 years ago

Yeah stryker is a new project. We're still working on it but it can be used. We'll work on making it more accessible and extendable next.

prmag commented 8 years ago

Sounds interesting, I'll try to give it a go next week. :)

Thanks for the answer!

ethan-far commented 8 years ago

Hi Nico,

I just finished taking a look at the project. It seems very nice. It seems that it's still lacking some features we need though (grunt plugin, html support for angular, etc.). I saw that you have opened a list of feature requests for yourselves on these issues. I would love to give it a try once it's a little more mature.

Thanks for your efforts !

Eitan בתאריך 8 באפר׳ 2016 13:42,‏ "Nico Jansen" notifications@github.com כתב:

Yeah stryker is a new project. We're still working on it but it can be used. We'll work on making it more accessible and extendable next.

— You are receiving this because you were mentioned.

Reply to this email directly or view it on GitHub https://github.com/jimivdw/grunt-mutation-testing/issues/51#issuecomment-207370418