cucumber/cucumber-js — pull request #62 by renier (2012-05-10 15:01:57+00:00)
Title: Use requirejs style for loading modules.

* Remove underscore dependency by adding array utilities.
Necessary to unhinge the library from a node-specific
environment. Added a an array utility function to replace it
with tests.

* Make requirejs modules callable from Node.
By using amddefine node module.

* Add usage information for -format option. In preparation
to add more formatters.

* Make example code run against requirejs-using Cucumber now.

* Remove browserify dependency. This was something else that
tightly bound the library to Node.

Of note:

Had to fix circular requirejs dependencies that broke cucumber in the browser in my previous pull request. Now everything looks like it's ok. Cucumber/Jasmime tests all pass. Tested the example server page. Tested in phantomjs with dojo toolkit.

Unfortunately, the way that jasmine requires a scope object to spy on a method, prevents you from requiring a dependency directly in the requirejs scope. So you have to require a level above you so that the tests can pass. But this gets you into a circular dependency situation. Thankfully, requirejs allows for a way to resolve this at module runtime by providing a synchronous version of require() after all modules have loaded.

Removing dependency on Browserify and underscore was necessary. The problem was that it tied cucumber-js to Node. You had to run a Node server. While making it possible to run in a browser, in order to do that Browserify defines it's own set of require/define functions a'la Node (strict CommonJS) in the browser. This makes it awkward to use cucumber with other JavaScript toolkits that already have their set of AMD require/define functions. For example, require.js is one package that defines the AMD functions. Dojo is another that defines the AMD functions (based largely on require.js and 100% compatible). jQuery is also compatible with AMD and requirejs. With this, now you can take cucumber-js and run it in any server with any number of javascript toolkits that support AMD.