Permalink
Browse files

'define' now works for nodejs

instead of picking 'require' for node and 'define' for the browser
  • Loading branch information...
1 parent 229c999 commit de1f5b248f1743e52f2c8b99d21acf03278224c5 @philschatz philschatz committed Jul 4, 2013
Showing with 18 additions and 8 deletions.
  1. +1 −1 package.json
  2. +14 −1 specs/requirejs-wrapper-template.js
  3. +1 −3 specs/toc-node.spec.coffee
  4. +2 −3 specs/tree.spec.coffee
View
@@ -9,7 +9,7 @@
"scripts": {
"install": "./install-libs.sh",
"update": "./install-libs.sh"
- "test": "jasmine-node --coffee --runWithRequireJs --requireJsSetup ./specs/requirejs-wrapper-template.js ./specs/"
+ "test": "jasmine-node --verbose --coffee --runWithRequireJs --requireJsSetup ./specs/requirejs-wrapper-template.js ./specs/"
},
"dependencies": {
"github-client": "*",
@@ -78,4 +78,17 @@ requirejs.config = function(config){
};
require = requirejs;
-define = requirejs.define;
+
+var jasmineCounter = 0;
+define = function(name, deps, callback) {
+ if (typeof name == 'string') {
+ return requirejs.define(name, deps, callback);
+ } else {
+ callback = deps;
+ deps = name;
+ jasmineCounter++;
+ requirejs.define('__jasmine-node__' + jasmineCounter, deps, callback);
+
+ return require(['__jasmine-node__' + jasmineCounter], function(obj) {return obj;});
+ }
+};
@@ -1,9 +1,7 @@
-REQUIRE = (if exports? then require else define)
-
Backbone = null
TocNode = null
-describe 'A Toc Node Mixin2', ->
+describe 'A Toc Node', ->
it 'should exist', ->
runs () ->
@@ -1,6 +1,4 @@
-REQUIRE = (if window? then define else require)
-
-REQUIRE ['backbone', 'cs!mixins/tree'], (Backbone, treeMixin) ->
+define ['backbone', 'cs!mixins/tree'], (Backbone, treeMixin) ->
class TreeNode extends Backbone.Model
initialize: (options={}) ->
@@ -19,3 +17,4 @@ REQUIRE ['backbone', 'cs!mixins/tree'], (Backbone, treeMixin) ->
it 'should initially have an empty Collection', ->
node = new TreeNode()
expect(node.getChildren().length).toBe 0
+

0 comments on commit de1f5b2

Please sign in to comment.