karma-runner / grunt-karma

Grunt plugin for Karma.
MIT License
468 stars 116 forks source link

No Captured Browser when using with watch #84

Open matthughes opened 10 years ago

matthughes commented 10 years ago

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.

dignifiedquire commented 10 years ago

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

mxdubois commented 10 years ago

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:

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"]);
ewie commented 9 years ago

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.

mxdubois commented 9 years ago

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 notifications@github.com 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 .

Abrissirba commented 9 years ago

Have anyone come with a solution to this problem yet?

gavD commented 9 years ago

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

uberspeck commented 9 years ago

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

gavD commented 9 years ago

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

attila226 commented 8 years ago

+1

jcrben commented 8 years ago

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

ghost commented 8 years ago

Lol

bierik commented 7 years ago

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