grunt-karma icon indicating copy to clipboard operation
grunt-karma copied to clipboard

No Captured Browser when using with watch

Open matthughes opened this issue 11 years ago • 12 comments

Using the following config:

  grunt.initConfig({
    karma: {
      unit: {
        options: {
          autoWatch: false,
          singleRun: true,
        }
      },
      watch: {
        options: {
          autoWatch: false,
          singleRun: false
        },
        background: true,
      },
      options: {
        configFile: '<%= testFiles.karmaUnit %>',
        browsers: browsers || ['Chrome']
      }
    },

    watch: {
      karma: {
        files: ['karma.conf.js', 'src/main/resources/**/*.js', 'src/test/**/*.js'],
        tasks: ['karma:unit:run']
      },
      options: {
        atBegin: true
      }
    }
  });

  grunt.loadNpmTasks('grunt-karma');
  grunt.loadNpmTasks('grunt-contrib-watch');

  grunt.registerTask('testwatch', ['karma:watch:start', 'watch:karma']);

My goal is to have karma start up the background thread and then repeatedly run tests against it when files change. However, when I run 'testwatch', it appears the karma:unit:run tries to run before the Karma server really has had a chance to finish starting:

Running "karma:watch:start" (karma) task

Running "watch:karma" (watch) task
Waiting...OK

Running "karma:unit:run" (karma) task
[2014-01-06 12:11:25.495] [DEBUG] config - Loading config /Users/mhughes/ccad/development/firebird/core-plugins/silk/certificate-management/ui/karma.conf.js
No captured browser, open http://localhost:9876/

My browser does start and is connected to the aforementioned address, but it just appears to be a timing issue. If I modify a file after the initial startup, the tests run and are able to connect to the browser. That makes me think that 'karma:watch:start' does not wait until the browser is truly up and connected.

matthughes avatar Jan 06 '14 17:01 matthughes

@matthughes is this still an issue with the latest versions of grunt-karma/karma?

dignifiedquire avatar Sep 04 '14 12:09 dignifiedquire

I'm able to reproduce this on grunt-karma 0.9.0 with karma 0.12.24.

When a watched file changes, Karma loads the config, then I get one of the following:

  • It says No captured browser, open http://localhost:9876/, as @matthughes got.
  • It says There is no server listening on port 9876.
  • It says Waiting for previous execution....
  • it hangs for many minutes until the socket is closed (Fatal error: read ECONNRESET)

I'm using PhantomJS as a browser and webpack for preprocessing.

Running singleRun tests without watch works fine.

Here's my config:

grunt.initConfig({
    // ...
    karma: {
      options: {
        configFile: 'karma.config.js',
      },
      unit: {
        singleRun: true
      },
      watch: {
        background: true,
        singleRun: false,
        autoWatch: false
      }
    },

    watch: {
       test: {
          options: {
            spawn: false,
            interrupt:true
          },
          files: ["test/**/*.js","src/**/*.js"],
          tasks: ["karma:watch:run"]
       }
   }
});

grunt.registerTask("test", "karma:unit");
grunt.registerTask("testWatch", ["karma:watch:start", "watch:test"]);

mxdubois avatar Oct 09 '14 20:10 mxdubois

Have you installed the appropriate launchers (e.g. karma-runner/karma-chrome-launcher for Chrome)? Because I had the very same issue until I found out that launchers are separate plugins although Karma config documentation says that the launcher for Chrome comes installed with Karma.

ewie avatar Jan 04 '15 20:01 ewie

Yeah I have the phantomjs launcher installed and it works fine when I run it normally. This problem only occurs with watch.

On Sun, Jan 4, 2015 at 1:29 PM, erik wienhold [email protected] wrote:

Have you installed the appropriate launchers (e.g. karma-runner/karma-chrome-launcher https://github.com/karma-runner/karma-chrome-launcher for Chrome)? Because I had the very same issue until I found out that launchers are separate plugins.

— Reply to this email directly or view it on GitHub https://github.com/karma-runner/grunt-karma/issues/84#issuecomment-68647581 .

mxdubois avatar Jan 04 '15 22:01 mxdubois

Have anyone come with a solution to this problem yet?

Abrissirba avatar Feb 07 '15 12:02 Abrissirba

I'm also struggling with this issue, anyone got a fix?

What I've been doing is using nodemon to kick of my tests when something changes, rather than using grunt watch, but I'd prefer to use watch

gavD avatar Jun 12 '15 11:06 gavD

I'm seeing this same issue with a very vanilla karma install (no grunt etc)

uberspeck avatar Jul 25 '15 13:07 uberspeck

I solved this problem by downgrading to Phantom 1.9.8, seemed to work OK once I'd done this

gavD avatar Jul 25 '15 20:07 gavD

+1

attila226 avatar Feb 24 '16 18:02 attila226

I see this warning although my tests seem to be running OK anyway.

jcrben avatar Mar 08 '16 18:03 jcrben

Lol

ghost avatar Oct 03 '16 11:10 ghost

Same problem here... does only occur when autowach is active

bierik avatar Dec 01 '16 15:12 bierik