Skip to content

Commit

Permalink
'define' now works for nodejs
Browse files Browse the repository at this point in the history
instead of picking 'require' for node and 'define' for the browser
  • Loading branch information
philschatz committed Jul 4, 2013
1 parent 229c999 commit de1f5b2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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": "*",
Expand Down
15 changes: 14 additions & 1 deletion specs/requirejs-wrapper-template.js
Expand Up @@ -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;});
}
};
4 changes: 1 addition & 3 deletions specs/toc-node.spec.coffee
@@ -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 () ->
Expand Down
5 changes: 2 additions & 3 deletions specs/tree.spec.coffee
@@ -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={}) ->
Expand All @@ -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.