Grunt Karma Testing on Vagrant When Host Changes Sources Grunt/Karma Doesn't Detect It

grunt karma testing on vagrant when host changes sources grunt/karma doesn't detect it

This derives from a known bug in the synchronization of vboxsf (Virtualbox “sharded folder” filesystem) and the solution to this issue only can be implemented by the Virtualbox team. People have had similar problems with Gulp, Guard or Meteor.js (to name a few).

There are some workarounds that you could use…

Auto-rsync

Vagrant 1.5 has an auto-synchronization utility (rsync-auto) that watches specified folders, and automatically syncs changes as you make them in real-time. It uses system-specific APIs to detect file changes, rather than polling the file system…

So you just should define your shares in the vagrant file. I.e:

config.vm.synced_folder ".", "/vagrant", type: "rsync"


and open an additional terminal session running:

$ vagrant rsync-auto

However, this alone is not the most efficient option. Here you can find a gruntfile and a vagrant plugin that will help you make your rsync run faster and smoother...

Hope it helps!

Jasmine test runs in grunt but fails in browser when spying $.get

It looks like grunt karma is using an old jasmine that supports andReturn but newer jasmine actually doesn't have such a method when using spyOn.

spyOn($, "get").and.returnValue(promise);

Now works in a browser but fails in grunt. So after changing the package.json to use a newer karma-jasmine "karma-jasmine":"~0.2.2", and an npm install they both work the same.

grunt-karma debug unminified sources

I found a solution to this that does not involve losing coverage data!

Based on this guide for Debugging Karma Unit Tests, I came up with the following, which works in IntelliJ:

var sourcePreprocessors = 'coverage';

var isDebugMode = function () {
return process.argv.some(function (argument) {
return argument === '--debug';
});
};

var hasNoCoverage = function () {
return !(process.argv.some(function (argument) {
return argument.includes("coverage");
}));
};

if (isDebugMode() || hasNoCoverage()) {
console.log("Not generating coverage.");
sourcePreprocessors = '';
}

config.set({
...
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
"WebRoot/js/**/*.js": sourcePreprocessors
},
...
});

NOTE:

Per info mentioned here, adding the following to your karma.conf.js (or however you are configuring Karma) should disable minification:

coverageReporter: {
instrumenterOptions: {
istanbul: { noCompact: true }
}
}

However, this does not remove the coverage data, and the source files still end up getting mangled up:

__cov_SNsw2QFfQtMZHyIEO9CT1A.s['74']++;
my.toPercentageString = function (value) {
__cov_SNsw2QFfQtMZHyIEO9CT1A.f['18']++;
__cov_SNsw2QFfQtMZHyIEO9CT1A.s['75']++;
return numbro(value).format('0.0%');
};
__cov_SNsw2QFfQtMZHyIEO9CT1A.s['76']++;

Grunt watch detects file changes only after 5 seconds with Vagrant and NFS

Try these mount options in your Vagrantfile:

type: "nfs", mount_options: ['actimeo=1']

This will greatly reduce the NFS file attribute caching timeout. I was having similar troubles, seeing large delays with Vagrant/NFS when waiting for gulp and Django server reloads. This fixed it; file changes are now detected instantly.

Karma: System notifications when tests pass or fail

Karma supports Growl/GNTP as a reporter, looks like this could work in Windows and Linux.

I did the following which worked on OSX:

  1. Installed Growl

  2. Installed growly

    npm install growly
  3. Added growl to karma.conf.js

    reporters = ['progress', 'growl'];

Vagrant, Ember-cli, Windows 8.1, Ubuntu. Livereload doesn't work! It doesn't detect changes when I save from Windows

The way Vagrant syncs directories between your desktop and the VM will break the default mechanism ember-cli uses to watch files and cause issues when updates are subsequently compiled.

To restore this functionality, you can either add the following lines to the '.ember-cli' file

"liveReload": true,
"watcher": "polling"

or invoke the serve command using the fallback polling watcher.

ember serve --watcher polling

Live reload browser page. Grunt and Vagrant

You'll want to add a browser plugin to your browser and then have watch notify it. More info here at the bottom:
http://24ways.org/2013/grunt-is-not-weird-and-hard/

Auto-starting Node.js application on Vagrant when there are changes to code

There seem to be other tools you can try on the guest machine as alternatives to nodemon, but watching for file changes will be the fastest on the host machine.

Here's a workaround that has worked for me:

This gist: Use a watcher on the host machine and issue an SSH command to the guest machine to restart the application.

Here's a recipe (you can use any other tools you like):

First, grab pm2:

npm install -g pm2

And launch your Node.js application via pm2:

pm2 app/server.js

Then grab Gulp:

npm install -g gulp-cli
npm install --save-dev gulp

And gulp-shell:

npm install --save-dev gulp-shell

Then create a gulpfile.js:

var gulp = require('gulp');
var shell = require('gulp-shell');

gulp.task('server:watch', function () {
gulp.watch('app/**/*.js', [ 'server:restart' ]);
});

gulp.task('server:restart', shell.task([ 'vagrant ssh -- pm2 restart server' ]));

You're done. To start watching the files and automatically start the server on file changes:

gulp server:watch


Related Topics



Leave a reply



Submit