diff --git a/app/templates/Gruntfile.js b/app/templates/Gruntfile.js index 995cc3f06..998ca5620 100644 --- a/app/templates/Gruntfile.js +++ b/app/templates/Gruntfile.js @@ -167,7 +167,16 @@ module.exports = function (grunt) { options: { jshintrc: 'server/.jshintrc' }, - src: [ 'server/{,*/}*.js'] + src: [ + 'server/**/*.js', + '!server/**/*.spec.js' + ] + }, + serverTest: { + options: { + jshintrc: 'server/.jshintrc-spec' + }, + src: ['server/**/*.spec.js'] }, all: [ '<%%= yeoman.client %>/{app,components}/**/*.js', diff --git a/app/templates/client/app/account(auth)/settings/settings.controller(coffee).coffee b/app/templates/client/app/account(auth)/settings/settings.controller(coffee).coffee index 4cb856146..d591f1fbe 100644 --- a/app/templates/client/app/account(auth)/settings/settings.controller(coffee).coffee +++ b/app/templates/client/app/account(auth)/settings/settings.controller(coffee).coffee @@ -8,9 +8,9 @@ angular.module '<%= scriptAppName %>' $scope.email = {} getEmail = (user) -> - return [null, null] unless $scope.user.credentials.length + return [null, null] unless user.credentials.length - for c in $scope.user.credentials when c.type is 'email' + for c in user.credentials when c.type is 'email' return [c.value, c.confirmed] [null, null] diff --git a/app/templates/client/app/account(auth)/settings/settings.controller(js).js b/app/templates/client/app/account(auth)/settings/settings.controller(js).js index 2fcf3cbf7..3f8c04828 100644 --- a/app/templates/client/app/account(auth)/settings/settings.controller(js).js +++ b/app/templates/client/app/account(auth)/settings/settings.controller(js).js @@ -8,13 +8,15 @@ angular.module('<%= scriptAppName %>') $scope.email = {}; var getEmail = function(user) { - if (!$scope.user.credentials.length) { + if (!user.credentials.length) { return null; } - for(var i in $scope.user.credentials) { - var c = $scope.user.credentials[i]; - if(c.type==='email') return [c.value, c.confirmed]; + for(var i in user.credentials) { + var c = user.credentials[i]; + if (c.type === 'email') { + return [c.value, c.confirmed]; + } } }; @@ -36,7 +38,7 @@ angular.module('<%= scriptAppName %>') $scope.message = ''; }); } - } + }; $scope.changePassword = function() { $scope.pwd.submitted = true; diff --git a/app/templates/client/app/admin(auth)/admin.controller(js).js b/app/templates/client/app/admin(auth)/admin.controller(js).js index 97214bc5f..913e27bf7 100644 --- a/app/templates/client/app/admin(auth)/admin.controller(js).js +++ b/app/templates/client/app/admin(auth)/admin.controller(js).js @@ -8,6 +8,6 @@ angular.module('<%= scriptAppName %>') $scope.delete = <% if(filters.uibootstrap) { %>Modal.confirm.delete(<% } %>function(user) { User.remove({ id: user._id }); - _.remove($scope.users, user) + _.remove($scope.users, user); }<% if(filters.uibootstrap) { %>)<% } %>; }); diff --git a/app/templates/client/app/main/main.controller(coffee).coffee b/app/templates/client/app/main/main.controller(coffee).coffee index 9e7c06110..143e7f387 100644 --- a/app/templates/client/app/main/main.controller(coffee).coffee +++ b/app/templates/client/app/main/main.controller(coffee).coffee @@ -1,7 +1,7 @@ 'use strict' angular.module '<%= scriptAppName %>' -.controller 'MainCtrl', ($scope, $http<% if(filters.socketio) { %>, socket<% } %><% if(filters.uibootstrap && filters.mongoose) { %>, Modal<% } %>) -> +.controller 'MainCtrl', ($scope, $http<% if(filters.socketio) { %>, socket<% } %>) -> $scope.awesomeThings = [] $http.get('/api/things').success (awesomeThings) -> @@ -19,4 +19,4 @@ angular.module '<%= scriptAppName %>' $http.delete '/api/things/' + thing._id<% } %><% if(filters.socketio) { %> $scope.$on '$destroy', -> - socket.unsyncUpdates 'thing'<% } %> \ No newline at end of file + socket.unsyncUpdates 'thing'<% } %> diff --git a/app/templates/client/app/main/main.controller(js).js b/app/templates/client/app/main/main.controller(js).js index f322d5e6e..433a10fe4 100644 --- a/app/templates/client/app/main/main.controller(js).js +++ b/app/templates/client/app/main/main.controller(js).js @@ -1,7 +1,7 @@ 'use strict'; angular.module('<%= scriptAppName %>') - .controller('MainCtrl', function ($scope, $http<% if(filters.socketio) { %>, socket<% } %><% if(filters.uibootstrap && filters.mongoose) { %>, Modal<% } %>) { + .controller('MainCtrl', function ($scope, $http<% if(filters.socketio) { %>, socket<% } %>) { $scope.awesomeThings = []; $http.get('/api/things').success(function(awesomeThings) { @@ -24,4 +24,4 @@ angular.module('<%= scriptAppName %>') $scope.$on('$destroy', function () { socket.unsyncUpdates('thing'); });<% } %> - }); \ No newline at end of file + }); diff --git a/app/templates/server/.jshintrc b/app/templates/server/.jshintrc index 79a89d230..d7b958e7c 100644 --- a/app/templates/server/.jshintrc +++ b/app/templates/server/.jshintrc @@ -4,7 +4,7 @@ "bitwise": true, "eqeqeq": true, "immed": true, - "latedef": true, + "latedef": "nofunc", "newcap": true, "noarg": true, "regexp": true, @@ -12,4 +12,4 @@ "smarttabs": true, "asi": true, "debug": true -} \ No newline at end of file +} diff --git a/app/templates/server/.jshintrc-spec b/app/templates/server/.jshintrc-spec new file mode 100644 index 000000000..b6b55cbf9 --- /dev/null +++ b/app/templates/server/.jshintrc-spec @@ -0,0 +1,11 @@ +{ + "extends": ".jshintrc", + "globals": { + "describe": true, + "it": true, + "before": true, + "beforeEach": true, + "after": true, + "afterEach": true + } +} diff --git a/app/templates/server/api/thing/thing.spec.js b/app/templates/server/api/thing/thing.spec.js index fb7745d5b..17c8c6cd0 100644 --- a/app/templates/server/api/thing/thing.spec.js +++ b/app/templates/server/api/thing/thing.spec.js @@ -17,4 +17,4 @@ describe('GET /api/things', function() { done(); }); }); -}); \ No newline at end of file +}); diff --git a/app/templates/server/api/user(auth)/user.model.js b/app/templates/server/api/user(auth)/user.model.js index d363b1ed3..bd1b82237 100644 --- a/app/templates/server/api/user(auth)/user.model.js +++ b/app/templates/server/api/user(auth)/user.model.js @@ -81,7 +81,7 @@ UserSchema // returns only first found email // TODO: in case of multiple emails, should prioritize confirmed ones return this.credentials.filter(function(c) { - return c.type==='email'; + return c.type === 'email'; })[0].value; }); @@ -90,7 +90,7 @@ UserSchema .virtual('emails') .get(function() { return this.credentials - .filter(function(c) { return c.type==='email'; }) + .filter(function(c) { return c.type === 'email'; }) .map(function(c) { return c.value; }); }); @@ -98,13 +98,13 @@ UserSchema UserSchema .pre('save', function(next) {<% if (filters.oauth) { %> if(!this.localEnabled) { - if (Object.keys(this.strategies).length===0) { + if (Object.keys(this.strategies).length === 0) { return next(new Error('No connected accounts')); } return next(); }<% } %> - mongoose.models['User']<% if (filters.oauth) { %> + mongoose.models.User<% if (filters.oauth) { %> .find({ localEnabled:true })<% } %> .where('credentials.type').equals('email') .where('credentials.value').equals(this.email) @@ -132,7 +132,7 @@ UserSchema.methods = { }, confirm: function(emailOrPhone, cb) { this.credentials.forEach(function(c) { - if (c.value===emailOrPhone) { + if (c.value === emailOrPhone) { c.confirmed = true; } }); @@ -140,7 +140,7 @@ UserSchema.methods = { }, changeEmail: function(oldEmail, newEmail, cb) { this.credentials.forEach(function(c) { - if (c.value===oldEmail) { + if (c.value === oldEmail) { c.value = newEmail; c.confirmed = false; } @@ -177,14 +177,14 @@ UserSchema.statics = { var dataFormatted; dataFormatted = []; - if (data.email != null) { + if (data.email !== null) { dataFormatted.push({ 'credentials.type': 'email', 'credentials.value': data.email }); } - if (data.phone != null) { + if (data.phone !== null) { dataFormatted.push({ 'credentials.type': 'phone', 'credentials.value': data.phone @@ -195,11 +195,11 @@ UserSchema.statics = { .or(dataFormatted) .exec(function(err, users) { if (err) return cb(err); - if (users.length===0) return cb(null, null); + if (users.length === 0) return cb(null, null); cb(null, users); }); }<% } %> }; -module.exports = mongoose.model('User', UserSchema); \ No newline at end of file +module.exports = mongoose.model('User', UserSchema); diff --git a/app/templates/server/api/user(auth)/user.model.spec.js b/app/templates/server/api/user(auth)/user.model.spec.js index 1781521dc..229d8cce0 100644 --- a/app/templates/server/api/user(auth)/user.model.spec.js +++ b/app/templates/server/api/user(auth)/user.model.spec.js @@ -51,10 +51,10 @@ describe('User Model', function() { }); it("should authenticate user if password is valid", function() { - user.authenticate('password').should.be.true; + return user.authenticate('password').should.be.true; }); it("should not authenticate user if password is invalid", function() { - user.authenticate('blah').should.not.be.true; + return user.authenticate('blah').should.not.be.true; }); -}); \ No newline at end of file +}); diff --git a/app/templates/server/auth(auth)/facebook(facebookAuth)/passport.js b/app/templates/server/auth(auth)/facebook(facebookAuth)/passport.js index 205803ab0..cb4d981ed 100644 --- a/app/templates/server/auth(auth)/facebook(facebookAuth)/passport.js +++ b/app/templates/server/auth(auth)/facebook(facebookAuth)/passport.js @@ -21,7 +21,7 @@ exports.setup = function (User, config) { }, function (err, users) { if (err) return done(err); if (users) { - var user = users[0]; + user = users[0]; user.absorb(profile.provider, profile); // we can do that because we have it handled by Facebook @@ -29,7 +29,7 @@ exports.setup = function (User, config) { return done(null, user); } - var user = new User({ + user = new User({ name: profile.displayName, email: profile.emails[0].value, username: profile.username, @@ -46,4 +46,4 @@ exports.setup = function (User, config) { }); } )); -}; \ No newline at end of file +}; diff --git a/app/templates/server/auth(auth)/google(googleAuth)/passport.js b/app/templates/server/auth(auth)/google(googleAuth)/passport.js index dfcf4e5b4..c75241648 100644 --- a/app/templates/server/auth(auth)/google(googleAuth)/passport.js +++ b/app/templates/server/auth(auth)/google(googleAuth)/passport.js @@ -21,7 +21,7 @@ exports.setup = function (User, config) { }, function (err, users) { if (err) return done(err); if (users) { - var user = users[0]; + user = users[0]; user.absorb(profile.provider, profile); // we can do that because we have it handled by Google @@ -29,7 +29,7 @@ exports.setup = function (User, config) { return done(null, user); } - var user = new User({ + user = new User({ name: profile.displayName, email: profile.emails[0].value, username: profile.username, @@ -46,4 +46,4 @@ exports.setup = function (User, config) { }); } )); -}; \ No newline at end of file +}; diff --git a/test/test-file-creation.js b/test/test-file-creation.js index bea7ae79c..2dc0ee548 100644 --- a/test/test-file-creation.js +++ b/test/test-file-creation.js @@ -54,7 +54,7 @@ describe('angular-fullstack generator', function () { }); describe('running app', function() { -; + beforeEach(function() { this.timeout(20000); fs.mkdirSync(__dirname + '/temp/client'); @@ -77,6 +77,16 @@ describe('angular-fullstack generator', function () { }); }); + it('should pass jshint', function(done) { + this.timeout(60000); + gen.run({}, function () { + exec('grunt jshint', function (error, stdout, stderr) { + expect(stdout).to.contain('Done, without errors.'); + done(); + }); + }); + }); + it('should run server tests successfully', function(done) { this.timeout(60000); gen.run({}, function () { @@ -161,8 +171,7 @@ describe('angular-fullstack generator', function () { this.timeout(60000); gen.run({}, function () { exec('grunt jshint', function (error, stdout, stderr) { - expect(stdout).to.contain('Running "jshint:server" (jshint) task\u001b[24m\n\n✔ No problems'); - expect(stdout).to.contain('Running "jshint:all" (jshint) task\u001b[24m\n\n✔ No problems'); + expect(stdout).to.contain('Done, without errors.'); done(); }); }); @@ -203,13 +212,12 @@ describe('angular-fullstack generator', function () { }); }); }); - + it('should pass jshint', function(done) { this.timeout(60000); gen.run({}, function () { exec('grunt jshint', function (error, stdout, stderr) { - expect(stdout).to.contain('Running "jshint:server" (jshint) task\u001b[24m\n\n✔ No problems'); - expect(stdout).to.contain('Running "jshint:all" (jshint) task\u001b[24m\n\n✔ No problems'); + expect(stdout).to.contain('Done, without errors.'); done(); }); }); @@ -255,8 +263,7 @@ describe('angular-fullstack generator', function () { this.timeout(60000); gen.run({}, function () { exec('grunt jshint', function (error, stdout, stderr) { - expect(stdout).to.contain('Running "jshint:server" (jshint) task\u001b[24m\n\n✔ No problems'); - expect(stdout).to.contain('Running "jshint:all" (jshint) task\u001b[24m\n\n✔ No problems'); + expect(stdout).to.contain('Done, without errors.'); done(); }); }); @@ -299,4 +306,4 @@ describe('angular-fullstack generator', function () { }); }); }); -}); \ No newline at end of file +});