grunt-karma
grunt-karma copied to clipboard
No Captured Browser when using with watch
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 is this still an issue with the latest versions of grunt-karma/karma?
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"]);
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.
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 .
Have anyone come with a solution to this problem yet?
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
I'm seeing this same issue with a very vanilla karma install (no grunt etc)
I solved this problem by downgrading to Phantom 1.9.8, seemed to work OK once I'd done this
+1
I see this warning although my tests seem to be running OK anyway.
Lol
Same problem here... does only occur when autowach
is active