I'm trying to run Karma/Jasmine from Grunt on a project generated with http://newtriks.com/2013/12/31/automating-react-with-yeoman-and-grunt/
Karma launches PhantomJS (or Chrome) and, depending on singleRun, it either times out or just sits there and does nothing. I've tried changing captureTimeout
and browserNoActivityTimeout
based on reading solutions from people with similar problems, but it doesn't seem to work.
My relevant pacakge versions etc.:
I've found someone with the same problem on OS X:
I've tried updating all my dev dependencies to the latest versions but the problem still remains.
My console output is below. The webpack lines referring to bundle is now VALID/INVALID are worrying, but I can't find any info on what they mean. Here's my console output:
Running "karma:unit" (karma) task DEBUG [config]: autoWatch set to false, because of singleRun DEBUG [plugin]: Loading karma-* from /home/ed/workspace/wwb-app/node_modules DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-chrome-launcher. DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-coffee-preprocessor. DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-firefox-launcher. DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-html2js-preprocessor. DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-jasmine. DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-phantomjs-launcher. DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-requirejs. DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-script-launcher. DEBG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-webpack-plugin. INFO [karma]: Karma v0.12.16 server started at http://localhost:8080/ INFO [launcher]: Starting browser PhantomJS DEBUG [temp-dir]: Creating temp dir at /tmp/karma-98204612 DEBUG [launcher]: /home/ed/workspace/wwb-app/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/bin/phantomjs /tmp/karma-98204612/capture.js Hash: 89285186567c1bc5bb7f Version: webpack 1.1.11 Time: 2ms Asset Size Chunks Chunk Names webpack: bundle is now VALID. webpack: bundle is now INVALID. DEBUG [web-server]: serving: /home/ed/workspace/wwb-app/node_modules/karma/static/client.html DEBUG [web-server]: serving: /home/ed/workspace/wwb-app/node_modules/karma/static/karma.js DEBUG [web-server]: upgrade /socket.io/1/websocket/CjC8pnQq5It2z_kWYB98 DEBUG [karma]: A browser has connected on socket CjC8pnQq5It2z_kWYB98 INFO [PhantomJS 1.9.7 (Linux)]: Connected on socket CjC8pnQq5It2z_kWYB98 with id 98204612 DEBUG [launcher]: PhantomJS (id 98204612) captured in 1.704 secs WARN [PhantomJS 1.9.7 (Linux)]: Disconnected (1 times), because no message in 30000 ms. DEBUG [karma]: Run complete, exitting. DEBUG [launcher]: Disconnecting all browsers DEBUG [launcher]: Process PhantomJS exited with code 0 DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-98204612 Warning: Task "karma:unit" failed. Use --force to continue. Aborted due to warnings.
Here's my karma.conf.js
file:
'use strict'; module.exports = function (config) { config.set({ basePath: '', frameworks: ['jasmine'], files: [ 'test/helpers/**/*.js', 'test/spec/components/**/*.js' ], preprocessors: { 'test/spec/components/**/*.js': ['webpack'] }, webpack: { cache: true, module: { loaders: [{ test: /\.css$/, loader: 'style!css' }, { test: /\.gif/, loader: 'url-loader?limit=10000&minetype=image/gif' }, { test: /\.jpg/, loader: 'url-loader?limit=10000&minetype=image/jpg' }, { test: /\.png/, loader: 'url-loader?limit=10000&minetype=image/png' }, { test: /\.js$/, loader: 'jsx-loader' }] } }, webpackServer: { stats: { colors: true } }, exclude: [], port: 8080, logLevel: config.LOG_DEBUG, colors: true, autoWatch: true, // Start these browsers, currently available: // - Chrome // - ChromeCanary // - Firefox // - Opera // - Safari (only Mac) // - PhantomJS // - IE (only Windows) browsers: ['PhantomJS'], reporters: ['progress'], captureTimeout: 60000, browserNoActivityTimeout: 60000, singleRun: true }); };
Excluding Tests / Specs If you want to exclude a specific test, simply use xit() instead of it() . The x means exclude. describe('description', function () { xit('description', function () {}); }); If you want to exclude an entire describe block, use xdescribe() instead of describe() .
Jasmine is a behavior-driven development framework for testing JavaScript code that plays very well with Karma. Similar to Karma, it's also the recommended testing framework within the Angular documentation as it's setup for you with the Angular CLI. Jasmine is also dependency free and doesn't require a DOM.
Karma is essentially a tool which spawns a web server that executes source code against test code for each of the browsers connected. The results of each test against each browser are examined and displayed via the command line to the developer such that they can see which browsers and tests passed or failed.
I had the same problem. From a related GitHub Issue, I learned that you can extend the inactivity timeout.
Set this Karma config option in your gruntfile or karma config file:
browserNoActivityTimeout: 100000
I set it to 100 seconds and my tests ran successfully. I don't know what's causing the delay.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With