Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Enable require.js mode. #34

Closed
wants to merge 2 commits into from

Conversation

brendanjerwin
Copy link

If the yml file contains a require_js element with the url fragment to require.js, then the server will switch to CommonJS amd module mode.

It will no longer directly load any source files, but will expect that the specs are declared as modules taking dependencies on the appropriate source files.

Anyone interested in playing with this, I have a gem you can try out:

https://github.com/downloads/brendanjerwin/jasmine-gem/jasmine-1.0.3.0pre.gem

If the yml file contains a `require_js` element with the url fragment to require.js, then the server will switch to CommonJS amd module mode.

It will no longer directly load any source files, but will expect that the specs are declared as modules taking dependencies on the appropriate source files.
@brendanjerwin
Copy link
Author

I did not add an example section in the yml file. I think I saw more than one and wasn't sure which to modify.

@brendanjerwin
Copy link
Author

Be sure to add a single item to the yml file, not a list:

require_js: lib/require.js

not

require_js: 
    - lib/require.js

@aiwilliams
Copy link

Unless I'm mistaken, it looks like this will have the helpers loading before the src files that are required. That's not how it worked before, with the src files before the helpers. Helpers may use code from the src files.

@brendanjerwin
Copy link
Author

True enough. I should remove the loading of helpers all together and let require.js handle the loading. Then any dependencies /load order issues can be taken care of correctly.

Modified the erb to expect that the require.js configuration be an array. Now any require.js configuration can be done prior to using require.js.
@brendanjerwin
Copy link
Author

There, now it ignores helpers. It works fine to simply require the helpers needed, and if they need access to the code under test, they can just require those modules.

Also, now the require_js configuration option is expected to be an array. If something must load before the specs, it can be put there.

@jgonera
Copy link

jgonera commented Aug 7, 2011

Will this get merged to the official gem at some point?

@brendanjerwin
Copy link
Author

Probably not as is. This works for us but I think it's best thought of as a proof if concept.

@ragaskar
Copy link
Contributor

Yeah, I feel like it's best for us to put off addressing this issue until the next release, where we can take on all the new JS challenges that Rails 3.1 and other frameworks are now presenting. Apologies for making it difficult for those of you that use require_js, but we want to get 1.1 (mostly bugfixes and a minor gem refactor) out within the week. We'll probably have a substantial refactoring of Jasmine coming soon, as it's getting pretty creaky.

@ragaskar ragaskar closed this Aug 27, 2011
@brendanjerwin
Copy link
Author

Another thing to keep in mind when enabling require_js support for real: https://github.com/JamesMaroney/requirejs-isolate

This plugin helps to isolate the code under test.

@andrewdeandrade
Copy link

Now that Jasmine is at 1.1, can we get this issue reopened? jwhitley's requirejs-rails gem is now at 0.5.1 and one of the items slated for the 1.0 build is jasmine support. From what I've grokked so far, the only way to get require.js support working in his gem would be to get support for require.js into the jasmine gem.

https://github.com/jwhitley/requirejs-rails/

@nfedyashev
Copy link

@malandrew
+1 for reopening

Meanwhile:

https://github.com/millermedeiros/amd-utils/tree/master/tests perhaps this may help someone

@jmaicher
Copy link

I'd love to see some official support, too!
Meanwhile this could also help: https://github.com/scottburch/jasmine-require

@tatemae
Copy link

tatemae commented Mar 10, 2012

+1 for require.js support. We're in the process of trying to hack a solution together, but it would be nice to have official support.

@flipkick
Copy link

+1 for reopening

@infews
Copy link
Contributor

infews commented Aug 14, 2012

We still plan on better async loading support in a future release. In the meantime: https://github.com/mattfysh/testr.js is your best bet.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants