jejacks0n / teaspoon

Teaspoon: Javascript test runner for Rails. Use Selenium, BrowserStack, or PhantomJS.
1.43k stars 243 forks source link

RequireJS and Coverage? #220

Closed davestevens closed 9 years ago

davestevens commented 10 years ago

I've been trying to get Teaspoon to work with both RequireJS and Coverage.

I can get both working independently, but it seems the what i switch the boot_partial to boot_require_js and try and run the specs with coverage the specs run but the coverage coming back on result in lib/teaspoon/runner.rb is always nil.

I tried to have a look into it and it seems that the add? method in Teaspoon::Instrumentation never returns true when using RequireJS so no files are being marked for coverage.

Looking at asset_url in lib/teaspoon/suite.rb the asset_url is being appended with ?instrument=1 for my js files.

Have you had any problems with this before? or are you able to point me in the right direction?

aaronmcadam commented 10 years ago

:+1:

sparksp commented 10 years ago

:+1:

jejacks0n commented 10 years ago

Given that I'm not a fan of requireJS, I won't be trying to figure this out. However, I'm willing to provide the information needed while someone attempts it.

First things first.. when you have instrumenting enabled, can you get an instrumented file and does calling a method in that file change the coverage information? Removing teaspoon from the equation, I would suggest using istanbul directly for this.

Second thing.. I suspect that RequireJS simply doesn't work when instrumented without some work. Instrumenting for coverage reports literally rewrites your js files so they're entirely unreadable. A good way to check this is to run one of your files through istanbul to see the output.. then run that file and see if you have access to the instrumented data. This is what I did when I added coverage.

JohnRiv commented 10 years ago

I'm close to getting this working. It worked in 0.7.8 but 0.8.0 broke it. All that is needed is to get the &instrument=1 query string added to the JS files included in _boot_require_js.html.erb via <%= javascript_include_tag @suite.helper %>. I assume bringing back the javascript_include_tag_for_teaspoon method for that partial will do the trick.

Once I get that working I'll submit a pull request.

jejacks0n commented 9 years ago

This is sort of in the works, but we have to figure out how best to do it.. check #277 if you want to track that conversation.

davestevens commented 9 years ago

Thanks for getting back about this, I've just made a pull request #315 which seems to allow requirejs to be used along with the coverage.