diff --git a/Gruntfile.js b/Gruntfile.js index da36a12..5a07ada 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -24,6 +24,11 @@ module.exports = function(grunt) { qunit: { index: ['test/index.html'] }, + mochaTest: { + test: { + src: ['test/mocha-*.js'] + } + }, watch: { files: ['', 'test/**'], tasks: ['jshint', 'qunit'] @@ -32,7 +37,8 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-qunit'); + grunt.loadNpmTasks('grunt-mocha-test'); // Default task. - grunt.registerTask('default', ['jshint', 'qunit']); + grunt.registerTask('default', ['jshint', 'qunit', 'mochaTest']); }; diff --git a/backbone-nested.js b/backbone-nested.js index 8f6261a..5052396 100644 --- a/backbone-nested.js +++ b/backbone-nested.js @@ -6,8 +6,19 @@ * Copyright (c) 2011-2012 Aidan Feldman * MIT Licensed (LICENSE) */ -/*global $, _, Backbone */ -(function(){ +/*global define, require, module */ +(function(root, factory){ + if (typeof exports !== 'undefined') { + // Define as CommonJS export: + module.exports = factory(require("jquery"), require("underscore"), require("backbone")); + } else if (typeof define === 'function' && define.amd) { + // Define as AMD: + define(["jquery", "underscore", "backbone"], factory); + } else { + // Just run it: + factory(root.$, root._, root.Backbone); + } +}(this, function($, _, Backbone) { 'use strict'; var _delayedTriggers = [], @@ -359,4 +370,5 @@ }); -}()); + return Backbone; +})); diff --git a/package.json b/package.json index 86668b6..7db828b 100644 --- a/package.json +++ b/package.json @@ -7,14 +7,18 @@ "test": "grunt" }, "dependencies": { + "jquery": ">=1.8.3", + "underscore": ">=1.5.0", "backbone": ">=0.9.2" }, "devDependencies": { "grunt": "~0.4.1", "grunt-contrib-qunit": "~0.2.2", "grunt-contrib-jshint": "~0.6.4", + "grunt-mocha-test": "~0.8.2", "grunt-contrib-watch": "~0.5.3", - "jslitmus": "~0.1.0" + "jslitmus": "~0.1.0", + "mocha": "~1.17.1" }, "peerDependencies": { "grunt-cli": "*", diff --git a/test/mocha-require.js b/test/mocha-require.js new file mode 100644 index 0000000..d894ae9 --- /dev/null +++ b/test/mocha-require.js @@ -0,0 +1,11 @@ +/*global describe, it*/ +var assert = require('assert'); + +var Backbone = require('backbone'); +require('../backbone-nested'); + +describe("CommonJS support", function() { + it('should attach to Backbone when require backbone-nested', function() { + assert.ok(Backbone.NestedModel); + }); +});