Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed issues with various kinds of custom builds, added testsuite

  • Loading branch information...
commit 8f453158e58516ff8c80c595eb507fb67eb78245 1 parent 8c1c16e
@asciidisco authored
View
1  .gitignore
@@ -1,2 +1,3 @@
/node_modules/
+/fixtures/
.DS_Store
View
7 .jshintrtc → .jshinttrc
@@ -10,5 +10,10 @@
"boss": true,
"eqnull": true,
"node": true,
- "es5": true
+ "es5": true,
+ globals: {
+ "exports": true,
+ "require": true,
+ "module": true
+ }
}
View
7 CHANGELOG
@@ -1,3 +1,10 @@
+v0.1.3:
+ date: 2012-11-23
+ changes:
+ - Added testsuite
+ - Fixed issues regarding the removal of the extend method (Builds without view)
+ - Fixed issues of the Router only build not working
+
v0.1.2:
date: 2012-11-22
changes:
View
111 grunt.js
@@ -4,31 +4,6 @@ module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
- pkg: '<json:package.json>',
- meta: {
- banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %>\n' +
- '------------------------------\n' +
- 'Build @ <%= grunt.template.today("yyyy-mm-dd") %>\n' +
- 'Documentation and Full License Available at:\n' +
- '<%= pkg.homepage %>\n' +
- '<%= pkg.repository.url %>\n' +
- 'Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author %>\n\n' +
- 'Permission is hereby granted, free of charge, to any person obtaining a\n' +
- 'copy of this software and associated documentation files (the "Software"),\n' +
- 'to deal in the Software without restriction, including without limitation\n' +
- 'the rights to use, copy, modify, merge, publish, distribute, sublicense,\n' +
- 'and/or sell copies of the Software, and to permit persons to whom the\n\n' +
- 'Software is furnished to do so, subject to the following conditions:\n' +
- 'The above copyright notice and this permission notice shall be included in\n' +
- 'all copies or substantial portions of the Software.\n\n' +
- 'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\n' +
- 'EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n' +
- 'FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n' +
- 'IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n' +
- 'DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\n' +
- 'ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n' +
- 'IN THE SOFTWARE.*/'
- },
test: {
files: ['test/**/*.js']
@@ -43,28 +18,84 @@ module.exports = function(grunt) {
tasks: 'default'
},
+ qunit: {
+ files: [
+ 'test/backbonetestsuite/test_view.html',
+ 'test/backbonetestsuite/test_model.html',
+ 'test/backbonetestsuite/test_collection.html',
+ 'test/backbonetestsuite/test_events.html',
+ 'test/backbonetestsuite/test_router.html',
+ 'test/backbonetestsuite/test_setdomlibrary.html',
+ 'test/backbonetestsuite/test_sync.html',
+ 'test/backbonetestsuite/test_noconflict.html',
+ ]
+ },
+
jshint: {
options: {
- curly: true,
- eqeqeq: true,
- immed: true,
- latedef: true,
- newcap: true,
- noarg: true,
- sub: true,
- undef: true,
- boss: true,
- eqnull: true,
- node: true,
- es5: true
+ "curly": true,
+ "eqeqeq": true,
+ "immed": true,
+ "latedef": true,
+ "newcap": true,
+ "noarg": true,
+ "sub": true,
+ "undef": true,
+ "boss": true,
+ "eqnull": true,
+ "node": true,
+ "es5": true
},
- globals: {}
+ globals: {
+ "exports": true,
+ "require": true,
+ "module": true
+ }
}
+
+ });
+
+ // Helper tasks, used to create various custtom builds to test against
+ var combinations = [['View'], ['Model'], ['Events'], ['Collection'], ['Router']];
+ grunt.registerTask('setUp', function () {
+ var done = this.async();
+ var builder = require(__dirname + '/lib/builder').init(grunt);
+ var steps = combinations.length;
+ var stepsDone = 0;
+ var checkDone = function () {
+ if (steps === stepsDone) {
+ done();
+ }
+ };
+
+ // build test fixtures
+ combinations.forEach(function (part) {
+ builder.build({
+ config: {include: part}
+ }, function (transport) {
+ grunt.log.writeln('Prepared custom ' + part.join(',') + ' fixture');
+ grunt.file.write(__dirname + '/fixtures/backbone.custom.' + part.join('.') + '.js', transport.content);
+ stepsDone++;
+ checkDone();
+ });
+ });
+
+ });
+
+ grunt.registerTask('tearDown', function () {
+ var fs = require('fs');
+ // delete test fixtures
+ combinations.forEach(function (part) {
+ grunt.log.writeln('Deleting fixture backbone.custom.' + part.join('.') + '.js');
+ fs.unlinkSync(__dirname + '/fixtures/backbone.custom.' + part.join('.') + '.js');
+ });
+
+ fs.rmdirSync(__dirname + '/fixtures');
});
// Default task.
- grunt.registerTask('default', 'lint test');
+ grunt.registerTask('default', 'setUp lint test qunit tearDown');
// Default task.
- grunt.registerTask('travis', 'lint test');
+ grunt.registerTask('travis', 'setUp lint test qunit tearDown');
};
View
51 lib/builder.js
@@ -1,5 +1,3 @@
-/*global exports:true, require:true */
-
/*
* grunt-backbonebuilder
* https://github.com/asciidisco/grunt-backbonebuilder
@@ -14,12 +12,12 @@
var fs = require('fs');
var _ = null;
var combinations = {
- Collection: ['Header', 'Setup', 'Events', 'Model', 'Collection', 'sync', 'Helpers'],
- Model: ['Header', 'Setup', 'Events', 'Model', 'sync', 'Helpers'],
+ Collection: ['Header', 'Setup', 'Events', 'Model', 'Collection', 'Sync', 'Helpers'],
+ Model: ['Header', 'Setup', 'Events', 'Model', 'Collection', 'Sync', 'Helpers'],
View: ['Header', 'Setup', 'Events', 'View', 'Helpers'],
Router: ['Header', 'Setup', 'Events', 'Router', 'History', 'Helpers'],
Events: ['Header', 'Setup', 'Events', 'Helpers'],
- All: ['Header', 'Setup', 'Events', 'Model', 'Collection', 'View', 'History', 'Helpers']
+ All: ['Header', 'Setup', 'Events', 'Model', 'Collection', 'Router', 'View', 'History', 'Sync', 'Helpers']
};
// extract a part by its character index
@@ -38,7 +36,7 @@
Router: '// Backbone.Router',
History: '// Backbone.History',
View: '// Backbone.View',
- sync: '// Backbone.sync',
+ Sync: '// Backbone.sync',
Helpers: '// Helpers'
};
@@ -64,7 +62,7 @@
var allCombinations = [];
parts.forEach(function (part) {
- allCombinations.push(combinations[part.toLowerCase() !== 'sync' ? _.str.capitalize(part.toLowerCase()) : part.toLowerCase()]);
+ allCombinations.push(combinations[_.str.capitalize(part.toLowerCase())]);
});
var neededParts = _.union.apply(_, allCombinations);
@@ -72,9 +70,46 @@
var finalCombination = _.intersection(combinations.All, neededParts);
finalCombination.forEach(function (part) {
- src += backboneParts[part.toLowerCase() !== 'sync' ? _.str.capitalize(part.toLowerCase()) : part.toLowerCase()];
+ src += backboneParts[_.str.capitalize(part.toLowerCase())];
+
+ if (part.toLowerCase() === 'view') {
+ src = src.replace('Model.extend = Collection.extend = Router.extend = View.extend = extend;', '');
+ }
+ });
+
+ var extender = '';
+ if(!_.contains(finalCombination, 'View') && !_.contains(finalCombination, 'view')) {
+ extender += ' var extend = function (protoProps, classProps) {\n';
+ extender += ' var child = inherits(this, protoProps, classProps)\n';
+ extender += ' child.extend = this.extend;\n';
+ extender += ' return child;\n';
+ extender += ' };\n\n';
+ }
+
+ // add the extend chain
+ finalCombination.forEach(function (extendo) {
+ var lowerEx = extendo.toLowerCase();
+ if (lowerEx === 'model') {
+ extender += 'Model.extend = ';
+ }
+
+ if (lowerEx === 'collection') {
+ extender += 'Collection.extend = ';
+ }
+
+ if (lowerEx === 'router') {
+ extender += 'Router.extend = ';
+ }
+
+ if (lowerEx === 'view') {
+ extender += 'View.extend = ';
+ }
});
+ extender += 'extend;';
+
+ src = src.replace('// Helpers', extender + '\n\n // Helpers');
+
return src;
};
View
2  package.json
@@ -1,7 +1,7 @@
{
"name": "grunt-backbonebuilder",
"description": "Backbone custom builds builder",
- "version": "0.1.2",
+ "version": "0.1.3",
"homepage": "https://github.com/asciidisco/grunt-backbonebuilder",
"author": {
"name": "asciidisco",
View
2  tasks/backbonebuilder.js
@@ -1,5 +1,3 @@
-/*global require: true */
-
/*
* grunt-backbonebuilder
* https://github.com/asciidisco/grunt-backbonebuilder
View
51 test/backbonebuilder_test.js
@@ -1,12 +1,57 @@
-'use strict';
-
var grunt = require('grunt');
// Load local tasks.
grunt.loadTasks('tasks');
exports['require'] = {
setUp: function(done) {
+ 'use strict';
// setup here
done();
- }
+ },
+ // test if building from a custom minified file fails
+ 'testIfBuildingFromMinifiedFails': function(test) {
+ 'use strict';
+ var builder = require(__dirname + '/../lib/builder').init(grunt);
+ test.expect(2);
+
+ // tests here
+ builder.build({
+ config: {include: ['View'], src: __dirname + '/../node_modules/backbone/backbone-min.js'}
+ }, function (transport) {
+ test.equal(transport.type, 'error', 'Error has been detected');
+ test.equal(transport.content.search('unminified'), 26, 'Correct error message has been send');
+ test.done();
+ });
+ },
+ // test if building from a custom input file works
+ 'testIfBuildingFromCustomInputWorks': function(test) {
+ 'use strict';
+ var builder = require(__dirname + '/../lib/builder').init(grunt);
+ test.expect(2);
+
+ // tests here
+ builder.build({
+ config: {include: ['All'], src: __dirname + '/../node_modules/backbone/backbone.js'}
+ }, function (transport) {
+ test.equal(transport.type, 'content', 'Transport type set correctly');
+ test.equal(transport.content.length, 53107, 'File could be build');
+ test.done();
+ });
+ },
+ // test if building from a custom input file works
+ 'testIfBuildingFromNonExistingFileFails': function(test) {
+ 'use strict';
+ var builder = require(__dirname + '/../lib/builder').init(grunt);
+ test.expect(2);
+
+ // tests here
+ builder.build({
+ config: {include: ['All'], src: __dirname + 'xxx.js'}
+ }, function (transport) {
+ test.equal(transport.type, 'error', 'Transport type set correctly');
+ test.equal(transport.content.search('Could not load given'), 0, 'Correct error message has been send');
+ test.done();
+ });
+ },
+
};
View
27 test/backbonetestsuite/test_collection.html
@@ -0,0 +1,27 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Backbone Test Suite</title>
+ <link rel="stylesheet" href="../../node_modules/backbone/test/vendor/qunit.css" type="text/css" media="screen" />
+ <script src="../../node_modules/backbone/test/vendor/json2.js"></script>
+ <script src="../../node_modules/backbone/test/vendor/jquery-1.7.1.js"></script>
+ <script src="../../node_modules/backbone/test/vendor/qunit.js"></script>
+ <script type="text/javascript">
+ QUnit.config.reorder = false;
+ </script>
+ <script src="../../node_modules/backbone/test/vendor/jslitmus.js"></script>
+ <script src="../../node_modules/backbone/test/vendor/underscore-1.3.1.js"></script>
+ <script src="../../fixtures/backbone.custom.Collection.js"></script>
+ <script src="../../node_modules/backbone/test/collection.js"></script>
+</head>
+<body>
+ <h1 id="qunit-header">Backbone Test Suite</h1>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ <br /><br />
+ <h1 id="qunit-header"><a href="#">Backbone Speed Suite</a></h1>
+ <div id="jslitmus_container" style="margin: 20px 10px;"></div>
+</body>
+</html>
View
24 test/backbonetestsuite/test_events.html
@@ -0,0 +1,24 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Backbone Test Suite</title>
+ <link rel="stylesheet" href="../../node_modules/backbone/test/vendor/qunit.css" type="text/css" media="screen" />
+ <script src="../../node_modules/backbone/test/vendor/json2.js"></script>
+ <script src="../../node_modules/backbone/test/vendor/jquery-1.7.1.js"></script>
+ <script src="../../node_modules/backbone/test/vendor/qunit.js"></script>
+ <script type="text/javascript">
+ QUnit.config.reorder = false;
+ </script>
+ <script src="../../node_modules/backbone/test/vendor/underscore-1.3.1.js"></script>
+ <script src="../../node_modules/backbone/backbone.js"></script>
+
+ <script src="../../fixtures/backbone.custom.Events.js"></script>
+</head>
+<body>
+ <h1 id="qunit-header">Backbone Test Suite</h1>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+</body>
+</html>
View
24 test/backbonetestsuite/test_model.html
@@ -0,0 +1,24 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Backbone Test Suite</title>
+ <link rel="stylesheet" href="../../node_modules/backbone/test/vendor/qunit.css" type="text/css" media="screen" />
+ <script src="../../node_modules/backbone/test/vendor/json2.js"></script>
+ <script src="../../node_modules/backbone/test/vendor/jquery-1.7.1.js"></script>
+ <script src="../../node_modules/backbone/test/vendor/qunit.js"></script>
+ <script type="text/javascript">
+ QUnit.config.reorder = false;
+ </script>
+ <script src="../../node_modules/backbone/test/vendor/underscore-1.3.1.js"></script>
+ <script src="../../fixtures/backbone.custom.Model.js"></script>
+
+ <script src="../../node_modules/backbone/test/model.js"></script>
+</head>
+<body>
+ <h1 id="qunit-header">Backbone Test Suite</h1>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+</body>
+</html>
View
24 test/backbonetestsuite/test_noconflict.html
@@ -0,0 +1,24 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Backbone Test Suite</title>
+ <link rel="stylesheet" href="../../node_modules/backbone/test/vendor/qunit.css" type="text/css" media="screen" />
+ <script src="../../node_modules/backbone/test/vendor/json2.js"></script>
+ <script src="../../node_modules/backbone/test/vendor/jquery-1.7.1.js"></script>
+ <script src="../../node_modules/backbone/test/vendor/qunit.js"></script>
+ <script type="text/javascript">
+ QUnit.config.reorder = false;
+ </script>
+ <script src="../../node_modules/backbone/test/vendor/underscore-1.3.1.js"></script>
+ <script src="../../fixtures/backbone.custom.Router.js"></script>
+
+ <script src="../../node_modules/backbone/test/noconflict.js"></script>
+</head>
+<body>
+ <h1 id="qunit-header">Backbone Test Suite</h1>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+</body>
+</html>
View
24 test/backbonetestsuite/test_router.html
@@ -0,0 +1,24 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Backbone Test Suite</title>
+ <link rel="stylesheet" href="../../node_modules/backbone/test/vendor/qunit.css" type="text/css" media="screen" />
+ <script src="../../node_modules/backbone/test/vendor/json2.js"></script>
+ <script src="../../node_modules/backbone/test/vendor/jquery-1.7.1.js"></script>
+ <script src="../../node_modules/backbone/test/vendor/qunit.js"></script>
+ <script type="text/javascript">
+ QUnit.config.reorder = false;
+ </script>
+ <script src="../../node_modules/backbone/test/vendor/underscore-1.3.1.js"></script>
+ <script src="../../fixtures/backbone.custom.Router.js"></script>
+
+ <script src="../../node_modules/backbone/test/router.js"></script>
+</head>
+<body>
+ <h1 id="qunit-header">Backbone Test Suite</h1>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+</body>
+</html>
View
24 test/backbonetestsuite/test_setdomlibrary.html
@@ -0,0 +1,24 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Backbone Test Suite</title>
+ <link rel="stylesheet" href="../../node_modules/backbone/test/vendor/qunit.css" type="text/css" media="screen" />
+ <script src="../../node_modules/backbone/test/vendor/json2.js"></script>
+ <script src="../../node_modules/backbone/test/vendor/jquery-1.7.1.js"></script>
+ <script src="../../node_modules/backbone/test/vendor/qunit.js"></script>
+ <script type="text/javascript">
+ QUnit.config.reorder = false;
+ </script>
+ <script src="../../node_modules/backbone/test/vendor/underscore-1.3.1.js"></script>
+ <script src="../../fixtures/backbone.custom.View.js"></script>
+
+ <script src="../../node_modules/backbone/test/setDomLibrary.js"></script>
+</head>
+<body>
+ <h1 id="qunit-header">Backbone Test Suite</h1>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+</body>
+</html>
View
24 test/backbonetestsuite/test_sync.html
@@ -0,0 +1,24 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Backbone Test Suite</title>
+ <link rel="stylesheet" href="../../node_modules/backbone/test/vendor/qunit.css" type="text/css" media="screen" />
+ <script src="../../node_modules/backbone/test/vendor/json2.js"></script>
+ <script src="../../node_modules/backbone/test/vendor/jquery-1.7.1.js"></script>
+ <script src="../../node_modules/backbone/test/vendor/qunit.js"></script>
+ <script type="text/javascript">
+ QUnit.config.reorder = false;
+ </script>
+ <script src="../../node_modules/backbone/test/vendor/underscore-1.3.1.js"></script>
+ <script src="../../fixtures/backbone.custom.Collection.js"></script>
+
+ <script src="../../node_modules/backbone/test/sync.js"></script>
+</head>
+<body>
+ <h1 id="qunit-header">Backbone Test Suite</h1>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+</body>
+</html>
View
26 test/backbonetestsuite/test_view.html
@@ -0,0 +1,26 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Backbone Test Suite</title>
+ <link rel="stylesheet" href="../../node_modules/backbone/test/vendor/qunit.css" type="text/css" media="screen" />
+ <script src="../../node_modules/backbone/test/vendor/json2.js"></script>
+ <script src="../../node_modules/backbone/test/vendor/jquery-1.7.1.js"></script>
+ <script src="../../node_modules/backbone/test/vendor/qunit.js"></script>
+ <script type="text/javascript">
+ QUnit.config.reorder = false;
+ </script>
+ <script src="../../node_modules/backbone/test/vendor/underscore-1.3.1.js"></script>
+ <script src="../../fixtures/backbone.custom.View.js"></script>
+
+ <script src="../../node_modules/backbone/test/view.js"></script>
+</head>
+<body>
+ <h1 id="qunit-header">Backbone Test Suite</h1>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ <br /><br />
+ <h1 id="qunit-header"><a href="#">Backbone Speed Suite</a></h1>
+</body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.