Imagine my surprise when i first looked at the Gruntfile.js of my newly generated angular app and found out that Yeoman is configuring by default only the karma:unit section, missing out the karma:e2e piece. I know the product is fairly new, but i would expect it to be a little more “mature” (spent quite some time figuring out why my e2e tests aren’t working and how to solve the problem).
Anyway, in order to run your e2e tests, you have to do the following:
- Update the Gruntfile.js
karma: { e2e: { configFile: 'karma-e2e.conf.js' }, unit: { ... } },
- Update the karma-e2e.conf.js
urlRoot = '/e2e/'; proxies = { // port has to be the same your web server is running on '/': 'http://localhost:9000' };
Also, if you want Grunt to run your e2e tests without the need to manually run the web server first, you can additionally define the following task:
grunt.registerTask('test:e2e', function () { grunt.task.run([ 'clean:server', 'concurrent:server', 'connect:livereload', 'open', 'karma:e2e' ]); });
(and “test:unit” task accordingly, for consistency sake):
grunt.registerTask('test:unit', [ 'karma:unit' ]);
Thanks a bunch mate! This helped me fix my tests!
Glad i was able to help. Take care.
thanks dude, this was awesome
Thanks man.
Hi, Thanks for your post. I tried what you said but it seems the ‘test’ server (according to default Gruntfile.js) is listenning to port 9001 and not 9000.
I changed the port number from 9000 to 9001 and it worked nicely.