requirejs-rails icon indicating copy to clipboard operation
requirejs-rails copied to clipboard

Support and/or documentation for JavaScript tests

Open jwhitley opened this issue 14 years ago • 22 comments

We should lay out a dead-easy path to get Jasmine tests or Buster.js tests up and running.

jwhitley avatar Nov 17 '11 22:11 jwhitley

+1 Do you have any ideas so far?

jmaicher avatar Dec 16 '11 09:12 jmaicher

@jmaicher After I get #13 nailed down (almost done), I'll be working on a Rails demo app (see #8). I plan on getting some simple Jasmine tests in there by way of example, and to explore what, if any, additional support is needed by this gem. Current ETA is early next week.

Thanks!

jwhitley avatar Dec 16 '11 15:12 jwhitley

@jwhitley Got any ideas that I can explore in the meantime? I'm trying to get my tests working again. Here's a pull request in the jasmine-gem that seems like it might address this issue, but it was closed back in August and it doesn't look like it was ever pulled in.

https://github.com/pivotal/jasmine-gem/pull/34

Here are some other relevant links I'm working through to try and figure this out that you may find useful:

http://japhr.blogspot.com/2011/12/jasmine-server-and-backbonejs-requirejs.html http://japhr.blogspot.com/2011/12/jasmine-testing-of-requirejs-powered.html http://groups.google.com/group/jasmine-js/browse_thread/thread/d10f59cba4d97792

andrewdeandrade avatar Dec 17 '11 17:12 andrewdeandrade

Upon further investigation, the most generic solution that would not require explicit require.js support in jasmine would be to allow something more an array of hashes instead of an array of strings in :src_files in jasmine.yml. However I doubt this would ever be pulled in since it would break backward compatibility.

The only other approach I can think of would be similar to the approach suggested by brendanjerwin, which is to add a require_js: helper method to the jasmine gem.

andrewdeandrade avatar Dec 17 '11 18:12 andrewdeandrade

No ideas right norm sorry. I've not been tracking Jasmine stuff too closely; been busy with the gem and other work. I should have more next week as I put the demo app together.

jwhitley avatar Dec 17 '11 21:12 jwhitley

FYI: http://groups.google.com/group/jasmine-js/browse_thread/thread/6ba740ff058d35ea

andrewdeandrade avatar Dec 21 '11 23:12 andrewdeandrade

Thanks for the heads-up. So monkey-patching it is...

jwhitley avatar Dec 21 '11 23:12 jwhitley

Chris Strom did a nice writeup of integration between require.js and the jasmine gem for a Backbone app. See also Chris' demo repo that uses this approach.

This is all a bit unbaked right now, so I'm going to get some experience working with it in an app before implementing/recommending any particular approach just yet.

jwhitley avatar Jan 03 '12 21:01 jwhitley

I'm actually thinking of abandoning Jasmine for Buster.JS, which isn't 1.0 yet, but really really nice. It's also being designed for proper AMD testing. It's from the same guy responsible for Sinon.js

features: -- client side testing ----- headless via PhantomJS ----- browser or command line via a JsTestDriver approach that can be integrated with a CI server like Jenkins or Hudson) -- server-side testing in node

Check it out: http://busterjs.org/

andrewdeandrade avatar Jan 05 '12 02:01 andrewdeandrade

Thanks for the tip. The buzz on Buster seems very positive. I'll dive in shortly and see what's what. Hopefully this issue can be resolved with some quick docs on Buster.js setup.

jwhitley avatar Jan 06 '12 21:01 jwhitley

BTW, I hacked together a quick gem that permits buster.js in a rails project:

https://github.com/malandrew/busterjs_on_rails

My gem is still really raw, but it has the minimum functionality needed to be able to run rake busterjs

I have yet to submit it to rubygems.org, so for the time being you'll have to point your Gemfile at my Github repo. This weekend, I'm going to try to get all the tests working and set up on travis and then I'll submit to rubygems.org

I'm working on a Guard gem for it as well, but I haven't gotten it to work just yet.

andrewdeandrade avatar Jan 06 '12 22:01 andrewdeandrade

@malandrew Thanks. I'll have a look over the gem in the next day or two. For now, I'm tinkering around with adding Buster.js tests to an existing project to get a feel for it. The buzz on the requirejs list has been very positive.

jwhitley avatar Jan 09 '12 20:01 jwhitley

Rajan Agaskar posted a simple guide in the jasmine-js google group [1] about how to set up jasmine-gem (edge) with the asset pipeline. In another post [2] Scott Burch introduced his jasmine-require helpers [3]. In combination this is pretty straightforward and works for me.

Buster.js sounds really promising but is currently under heavy development (internals rewrite). From what the devs told me it's better to wait a few weeks until the "real" beta starts.

[1] http://groups.google.com/group/jasmine-js/browse_thread/thread/1919f00753d7b8df [2] http://groups.google.com/group/jasmine-js/browse_thread/thread/6ba740ff058d35ea [3] https://github.com/scottburch/jasmine-require

jmaicher avatar Jan 22 '12 16:01 jmaicher

For the record, I'm unhappy with every existing solution for JS testing with RequireJS. I've got a working prototype that I'm going to publish shortly that addresses these concerns. Initially, it will be in the form of a demo Rails app that uses requirejs-rails, for early adopters and to back up a forthcoming issue on jasmine-gem. My goal will be to negotiate how changes can either be adapted into a pull request that Pivotal will be happy with, or else spun out as a separate plugin gem with appropriate config/API support integrated into jasmine-gem (I have to monkey patch jasmine-gem right now :-P )

jwhitley avatar Apr 25 '12 18:04 jwhitley

I've published my take on this as documentation plus a new-Rails 3.2 app at requirejs-rails-jasmine-template. This really is about the integration of jasmine-gem and requirejs-rails, as opposed to the specific testing methodology. Various Jasmine helpers, tools like testr.js, etc. should all work fine in this environment.

jwhitley avatar May 01 '12 18:05 jwhitley

This all looks like great stuff, thanks for looking at it.

I've been using https://github.com/jfirebaugh/konacha, and have got it barely working with some ugly hacks, but only in the browser, not with the selenium/capybara runner. It's not the greatest, but I have really become fond of http://visionmedia.github.com/mocha/ and http://chaijs.com/. Just wanted to throw those into the mix to see if anybody else is using these.

I really just need something that scans a directory of _spec.js files and turns them into a list of module dependencies that can be run with any runner. If I come up with any code or ideas I'll put them here.

smith avatar Jun 16 '12 03:06 smith

Here's a fork of Konacha that integrates requirejs-rails: https://github.com/cramerdev/konacha/tree/requirejs

It works for me, but I don't think it should be part of Konacha, and I'm not sure I want to maintain a separate project, so any thought, comments, or ideas would be appreciated.

smith avatar Jun 17 '12 19:06 smith

Quick update for anyone still watching this thread: I've created a new fork of this that is up to date with konacha as of 2.0.0.beta2 and my own fork of requirejs-rails which is using require.js 2.0.6 and the most recent r.js.

https://github.com/billmag/konacha https://github.com/billmag/requirejs-rails

The error handling for failed module loads isn't as great as I'd like. I posted to the requirejs mailing list, we'll see what comes of that: https://groups.google.com/forum/?fromgroups=#!topic/requirejs/SZgONWezt4s

billmag avatar Oct 03 '12 08:10 billmag

Hey all -- I've updated my konacha fork to track the latest release of the konacha gem. I haven't updated with respect to requirejs-rails in a while, though.

billmag avatar Mar 05 '14 00:03 billmag

:+1:

Pickachu avatar Apr 09 '14 22:04 Pickachu

I've got some Jasmine 2 tests running in Rails 4 via requirejs-rails v0.9.5, taking cues from this post by Cina at Spiceworks:

  • monkeypatching Jasmine via jasmine_helper.rb (instead of jasmine_config.rb)
    • test runner file is specified by Jasmine.runner_template
  • customize jasmine's boot JS to pull the list of specs to run from content in the runner file, and pass it to require as dependencies for starting the test run (instead of starting the run on window.onload)

alxndr avatar Oct 19 '14 23:10 alxndr

@alxndr Thanks for looking into this! I'm going to be investigating further.

carsomyr avatar Oct 20 '14 01:10 carsomyr