Skip to content
This repository has been archived by the owner on Mar 26, 2018. It is now read-only.

Backbone mocha test generation : closes #161 #177

Merged
merged 3 commits into from
Dec 26, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
temp/
coverage/
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ contributing.md
.npmignore
test
.travis.yml
coverage/
18 changes: 15 additions & 3 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@ var Generator = module.exports = function Generator(args, options, config) {
this.hookFor(this.testFramework, {
as: 'app',
options: {
options: {
'skip-install': this.options['skip-install']
}
'skip-install': this.options['skip-install'],
'ui': this.options.ui
}
});
}

this.config.defaults({
ui: this.options.ui,
coffee: this.options.coffee,
testFramework: this.testFramework,
templateFramework: this.templateFramework,
compassBootstrap: this.compassBootstrap,
includeRequireJS: this.includeRequireJS
});

this.indexFile = this.readFileAsString(path.join(this.sourceRoot(), 'index.html'));

this.on('end', function () {
Expand Down Expand Up @@ -74,13 +82,17 @@ Generator.prototype.askFor = function askFor() {
// we change a bit this way of doing to automatically do this in the self.prompt() method.
this.compassBootstrap = hasFeature('compassBootstrap');
this.includeRequireJS = hasFeature('requirejs');
this.config.set('compassBootstrap', this.compassBootstrap);


if (!this.options.coffee) {
this.options.coffee = hasFeature('coffee');
this.config.set('coffee', this.options.coffee);
}

if (!this.options.requirejs) {
this.options.requirejs = this.includeRequireJS;
this.config.set('includeRequireJS', this.includeRequireJS);
}
cb();
}.bind(this));
Expand Down
2 changes: 1 addition & 1 deletion app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"grunt-open": "~0.2.0",
"load-grunt-tasks": "~0.1.0",
"connect-livereload": "~0.2.0",
"time-grunt": "~0.1.1",
"time-grunt": "~0.2.1",
"jshint-stylish": "~0.1.3"
},
"engines": {
Expand Down
14 changes: 13 additions & 1 deletion collection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@ function Generator() {
var dirPath = this.options.coffee ? '../templates/coffeescript/' : '../templates';
this.sourceRoot(path.join(__dirname, dirPath));

// required for collection.js template which uses `appname`
var testOptions = {
as: 'collection',
args: [this.name],
options: {
coffee: this.config.get('coffee'),
ui: this.config.get('ui')
}
};

if (this.geneateTests()) {
this.hookFor('backbone-mocha', testOptions);
}

}

util.inherits(Generator, scriptBase);
Expand Down
13 changes: 13 additions & 0 deletions model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ function Generator() {
};
});

var testOptions = {
as: 'model',
args: [this.name],
options: {
coffee: this.config.get('coffee'),
ui: this.config.get('ui')
}
};

if (this.geneateTests()) {
this.hookFor('backbone-mocha', testOptions);
}

}

util.inherits(Generator, scriptBase);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
},
"peerDependencies": {
"generator-mocha": "~0.1.1",
"generator-backbone-mocha": "~0.0.2",
"yo": ">=1.0.0-rc.1.1"
},
"devDependencies": {
Expand Down
13 changes: 12 additions & 1 deletion router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@ function Generator() {
var dirPath = this.options.coffee ? '../templates/coffeescript/' : '../templates';
this.sourceRoot(path.join(__dirname, dirPath));

// required for router.js template which uses `appname`
var testOptions = {
as: 'router',
args: [this.name],
options: {
coffee: this.config.get('coffee'),
ui: this.config.get('ui')
}
};

if (this.geneateTests()){
this.hookFor('backbone-mocha', testOptions);
}
}

util.inherits(Generator, scriptBase);
Expand Down
3 changes: 3 additions & 0 deletions script-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,6 @@ Generator.prototype.writeTemplate = function writeTemplate(source, destination,
this.template(source + ext, destination + ext, data);
};

Generator.prototype.geneateTests = function geneateTests(){
return this.config.get('testFramework') == 'mocha' && !this.config.get('includeRequireJS')
}
3 changes: 0 additions & 3 deletions test/test-coffee-requirejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ describe('Backbone generator test with --coffee and --requirejs option', functio
]);
this.backbone.app.options['skip-install'] = true;

this.backbone.app.options.coffee = true;
this.backbone.app.options.requirejs = true;

helpers.mockPrompt(this.backbone.app, {
features: ['compassBootstrap', 'coffee', 'requirejs']
});
Expand Down
28 changes: 24 additions & 4 deletions test/test-coffee.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ describe('Backbone generator test with --coffee option', function () {
it('creates backbone model', function (done) {

this.backbone.app.run([], function () {
var model = helpers.createGenerator('backbone:model', ['../../model'], ['foo']);
var model = helpers.createGenerator('backbone:model', [
'../../model', [
helpers.createDummyGenerator(),
'backbone-mocha:model'
]
], ['foo']);
model.run([], function () {
helpers.assertFiles([
['app/scripts/models/foo.coffee', /class temp.Models.FooModel extends Backbone.Model/]
Expand All @@ -82,7 +87,12 @@ describe('Backbone generator test with --coffee option', function () {
it('creates backbone collection', function (done) {

this.backbone.app.run({}, function () {
var collection = helpers.createGenerator('backbone:collection', ['../../collection'], ['foo']);
var collection = helpers.createGenerator('backbone:collection', [
'../../collection', [
helpers.createDummyGenerator(),
'backbone-mocha:collection'
]
], ['foo']);

collection.run([], function () {
helpers.assertFiles([
Expand All @@ -98,7 +108,12 @@ describe('Backbone generator test with --coffee option', function () {
it('creates backbone router', function (done) {

this.backbone.app.run({}, function () {
var router = helpers.createGenerator('backbone:router', ['../../router'], ['foo']);
var router = helpers.createGenerator('backbone:router', [
'../../router', [
helpers.createDummyGenerator(),
'backbone-mocha:router'
]
], ['foo']);

router.run([], function () {
helpers.assertFiles([
Expand All @@ -114,7 +129,12 @@ describe('Backbone generator test with --coffee option', function () {
it('creates backbone view', function (done) {

this.backbone.app.run({}, function () {
var view = helpers.createGenerator('backbone:view', ['../../view'], ['foo']);
var view = helpers.createGenerator('backbone:view', [
'../../view', [
helpers.createDummyGenerator(),
'backbone-mocha:view'
]
], ['foo']);

view.run([], function () {
helpers.assertFiles([
Expand Down
13 changes: 13 additions & 0 deletions view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ function Generator() {
var dirPath = this.options.coffee ? '../templates/coffeescript/' : '../templates';
this.sourceRoot(path.join(__dirname, dirPath));

var testOptions = {
as: 'view',
args: [this.name],
options: {
coffee: this.config.get('coffee'),
ui: this.config.get('ui')
}
};

if (this.geneateTests()) {
this.hookFor('backbone-mocha', testOptions);
}

}

util.inherits(Generator, scriptBase);
Expand Down