16

Running Guard with Spin works great to keep my testing fast, except when assets are relevant and need compiling. It seems that the test environments recompiles all assets whenever I change something in them. I've seen examples of deployment scripts that only recompile assets whose source has changed. Can this be done for testing too? Or is there another way to speed up asset compilation for tests?

I'm using a rather specific setup so I'll be happy to supply more information if needed, though I feel the answer from this question might be of use in many more cases than just mine.

Sage Mitchell
  • 1,563
  • 8
  • 31
Jasper Kennis
  • 3,225
  • 6
  • 41
  • 74
  • This is a good question! so i am voting this up as I suffered from similar issue of time consuming on pre-compiling the assets. However, up to my knowledge there is not much available on speeding of pre-compiling the assets! Good Luck – RajG Nov 23 '12 at 11:21
  • 1
    I generally precompile assets before running the suite. If you're running rails 3.2+ there's https://github.com/ndbroadbent/turbo-sprockets-rails3. With this the full compile will be much faster. If you're suite is long-running and / or runs on CI and you do a complete precompile I have a S3 solution available as well. Let me know what version of rails you're running – mnelson Nov 24 '12 at 05:01
  • That all sounds promising. I'm on Rails 3.2.8 right now, will update to 3.2.9 very soon. I'm very interested in your S3 solution, since I'm running my tests with guard (I think that's what you mean by long-running), so just precompiling wouldn't be enough. – Jasper Kennis Nov 24 '12 at 15:04
  • 1
    If you're using guard and randomly hitting asset-dependent specs then you're probably better off compiling on demand. By long-running I just meant the duration of your suite. Here's the S3 solution we use for our CI (download before suite, precompile, upload after suite). https://gist.github.com/4141068 – mnelson Nov 24 '12 at 19:21
  • Hm, yeah true, I was hoping there would be a smart way to precompile and then recompile partially after altering some assets. Maybe I'll setup CI and use js tests as validators more than for tdd purposes. Does that make sens? – Jasper Kennis Nov 25 '12 at 18:36

3 Answers3

1

You can take a look at this article written two months ago . It seems rather complex task . Nathan has written a gem that precompiles only changes , made to assets . It can be used in development and testing env.

EDIT : Here is another article , related with speeding up our tests . It has a different point of view about js testing .

Community
  • 1
  • 1
R Milushev
  • 4,295
  • 3
  • 27
  • 35
  • Like the suggestions but this doesn't really seem to speed up my tests, mainly because it seems that the test environment always has to compile the assets when it's started. I think that ideally the testsuite should wait until the compiling is done. – Jasper Kennis Nov 19 '12 at 11:08
  • It's remarkable , that there is a special site , dedicated to the subject . I heard about if from [Ruby5](http://ruby5.envylabs.com/) and it's called (you'll not believe) [fastrailstests.com](http://www.fastrailstests.com). As Mikael Jackson once have said : "You are not alone" . – R Milushev Nov 19 '12 at 19:44
  • Well that site contains no info at all, and I'm not just giving away my email adres, I'm getting enough spam as it is. I'm looking for a clear answer to my problem;) And `michael != mikael`, but The King sure said that;) – Jasper Kennis Nov 19 '12 at 22:08
  • You're absolutely right about The King . Anyway , I'm about to watch what's up with this new site . – R Milushev Nov 20 '12 at 06:11
0

You can for example avoid adding require_tree in Your application js and css files.

In addition, use proper file extensions - if something is js - then name it like normal js files. Same for css and scss.

You can also precompile assets locally to have it compiled locally on development by command rake assets:precompile - but remember to delete it after tests to see changes in assets next time (it can be generated in vendor folder)

lukaszkups
  • 5,790
  • 9
  • 47
  • 85
  • These are true but they were also in Qumara's answer. I know assets:precompile, something similar would be great for testing, because now some tests fail because they have to wait for the assets to compile. – Jasper Kennis Nov 19 '12 at 22:10
-2

I am sure but you can try:

In application.js file write all js file in tree order like this:

//= require jquery

//= require jquery_ui

//= require jquery.ui.core

prasad_g
  • 139
  • 8