Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

This took me ages to find out but can't seem to find a solution for this one. Using vagrant I run a Fedora 20 guest that runs grunt/karma. The sources I edit on my host but when I save grunt isn't detecting the change so no tests are being done.

Figured it was a configuration problem so tried many combinations of things here without success. Finally I opened a second ssh to the guest vagrang ssh and changed the file in the other ssh terminal echo " " >> app/js/app.js and see that now grunt/karma detects the change and runs the tests again.

Since it has no x windows or anything I'm running the tests with PhantomJS. Another problem was that I had to set EnableSendfile off in the httpd.conf to prevent Apache to send garbage when serving textfiles from the share (that's my project in host and web root in guest). My guess is there may be another setting that needs being done to node so it detects the changes made by the host to the files on the share. It's using virtualBox share.

Has anyone experienced this before and is there a solution for this? Seems that host machine changing files on the share doesn't trigger some event that grunt/karma is listening for to indicate the file has changed.

[update]

Tried NFS and rsync share but NFS didn't work at all and rsync seems to just sync on startup.

[update]

As a temporary solution I have to manually tell the file is updated in the ssh terminal:

#start grunt and give me back command:
grunt &
#when I update a file tell grunt it's updated
touch -d "now" test/unit/loginSpec.js

Funny that if I update app/js/login.js and tell grunt the test/unit/loginSpec.js is updated it will run the tests again but with the old login.js even though it has changed cat app/js/login.js shows the changes. If not for this the solution would be set focus to right window and 2 keystroke (arrow up and enter)

like image 448
HMR Avatar asked Oct 20 '22 05:10

HMR


1 Answers

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!

like image 89
sdude Avatar answered Oct 23 '22 00:10

sdude