Skip to content

Commit

Permalink
baseapp first shot
Browse files Browse the repository at this point in the history
  • Loading branch information
zzo committed Jun 24, 2013
0 parents commit 5a21226
Show file tree
Hide file tree
Showing 247 changed files with 61,561 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
.grunt
build
node_modules
268 changes: 268 additions & 0 deletions Gruntfile.js
@@ -0,0 +1,268 @@
var path = require('path');
var exec = require('child_process').exec;

module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
jshint: {
all: ['Gruntfile.js', 'public/javascripts/**/*.js', 'spec/**/*.js', 'app.js']
, options: {
globals: {
jQuery: true
}
, 'laxcomma': true
, 'multistr': true
}
},
jasmine : {
test: {
src : 'public/javascripts/**/*.js',
options : {
specs : 'spec/client/**/*.js'
// , keepRunner: true
, vendor: [
'public/vendor/jquery-2.0.2.min.js'
, 'public/vendor/jasmine-jquery.js'
, 'public/vendor/dust-core-1.2.3.min.js'
, 'vendor/bootstrap/js/bootstrap.min.js'
]
, junit: {
path: "./build/reports/jasmine/"
, consolidate: true
}
, template: require('grunt-template-jasmine-istanbul')
, templateOptions: {
coverage: 'public/coverage/client/coverage.json'
, report: 'public/coverage/client'
}

}
}
},
express: {
server: {
options: {
server: path.resolve('./app.js')
, debug: true
, bases: 'public'
, host : 'http://<%= env.options.HOST %>:<%= env.options.PORT %>'
}
}
},
dustjs: {
compile: {
files: {
"public/javascripts/templates.js": ["views/**/*.dust"]
}
}
}
, env: {
options : {
//Shared Options Hash
HOST: '127.0.0.1'
, PORT: 3000
}
, test: {
NODE_ENV : 'test'
, HOST: '127.0.0.1'
}
, coverage: {
COVERAGE: true
, HOST: '127.0.0.1'
}
}
, watch: {
jshint: {
files: '<%= jshint.all %>'
, tasks: ['jshint'],
}
, jasmine_client: {
files: [ '<%= jasmine.test.src %>', '<%= jasmine.test.options.specs %>' ]
, tasks: ['jasmine'],
}
, jasmine_server: {
files: [ '<%= jasmine_node_coverage.options.specDir %>', 'routes/' ]
, tasks: ['jasmine_node_coverage'],
}
, webdriver: {
files: [ '<%= webd.options.tests %>', 'routes/' ]
, tasks: ['webdriver'],
}

}
, jasmine_node_coverage: {
options: {
coverDir: 'public/coverage/server'
, specDir: 'spec/server'
, junitDir: './build/reports/jasmine_node/'
}
}
, webd: {
options: {
tests: 'spec/webdriver/*.js'
, junitDir: './build/reports/webdriver/'
, coverDir: 'public/coverage/webdriver'
}
}
, total_coverage: {
options: {
coverageDir: './build/reports'
, outputDir: 'public/coverage/total'
}
}
, plato: {
dashr: {
options : {
jshint : false
}
, files: {
'public/plato': ['public/javascripts/**/*.js', 'spec/**/*.js'],
}
}
, options: {
jshint: {
globals: {
jQuery: true
}
, 'laxcomma': true
, 'multistr': true
}
}
},
});

// Load the plugins
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.loadNpmTasks('grunt-express');
grunt.loadNpmTasks('grunt-dustjs');
grunt.loadNpmTasks('grunt-env');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-plato');

// Default task(s).
grunt.registerTask('default', ['jshint']);

grunt.registerTask('test', [
'jshint',
'jasmine',
'jasmine_node_coverage',
'dustjs',
'webdriver_coverage',
'total_coverage',
'plato'
]);

// webdriver tests with coverage
grunt.registerTask('webdriver_coverage', [
'env:test' // use test db
, 'env:coverage' // server sends by coverage'd JS files
, 'express'
, 'webd:coverage'
]);

// webdriver tests without coverage
grunt.registerTask('webdriver', [
'env:test' // use test db
, 'express'
, 'webd'
]);

grunt.registerTask('jasmine_node_coverage', 'Istanbul code coverage for jasmine_node', function() {
var done = this.async()
, options = this.options()
;

var coverCmd = 'node_modules/istanbul/lib/cli.js cover '
.concat('--dir ')
.concat(options.coverDir)
.concat(' -x ' + "'**/spec/**'" + ' jasmine-node')
.concat(' -- ' )
.concat(options.specDir)
.concat(' --forceexit --junitreport --output ')
.concat(options.junitDir);

exec(coverCmd, { }, function(err, stdout, stderr) {
grunt.log.write(stdout);
grunt.log.write('Server-side coverage available at: ' +
path.join(options.coverDir, 'lcov-report', 'index.html'));
done();
});
});

grunt.registerTask('webd', 'Webdriver with optional coverage', function(coverage) {
var done = this.async()
, options = this.options()
;

grunt.task.requires('env:test');
grunt.task.requires('express');

if (coverage) {
grunt.task.requires('env:coverage');
}

var testCmd = 'jasmine-node '
.concat(options.tests)
.concat(' --forceexit --junitreport --output ')
.concat(options.junitDir);

exec(testCmd, { }, function(err, stdout, stderr) {
if (err || stderr) {
if (stderr && stderr.match('connect ECONNREFUSED')) {
grunt.log.writeln("Cannot connect to the Selenium JAR - is it running?");
grunt.log.writeln("In another window try:");
grunt.log.writeln("% java -jar " + path.resolve('./node_modules/webdriverjs/bin/selenium-server-standalone-2.31.0.jar'));
} else {
if (stderr) {
grunt.log.writeln(stderr);
}
}
grunt.fatal();
} else {
if (coverage) {
var coverCmd = 'node_modules/istanbul/lib/cli.js report --root '
.concat(options.junitDir)
.concat(' --dir ')
.concat(options.coverDir);

exec(coverCmd, { }, function(err, stdout, stderr) {
grunt.log.write(stdout);
grunt.log.writeln('For coverage point yer browser to: ' +
path.resolve(options.coverDir, 'lcov-report', 'index.html'));
done();
});
} else {
done();
}
}
});
});

// aggregate all coverage data from all tests
grunt.registerTask('total_coverage', 'Aggregate coverage from all tests', function() {
var done = this.async()
, options = this.options()
;

var aggCmd = 'node_modules/istanbul/lib/cli.js report --root'
.concat(options.coverageDir)
.concat(' --dir ')
.concat(options.outputDir)
;

exec(aggCmd, { }, function(err, stdout, stderr) {
grunt.log.write(stdout);
grunt.log.writeln('Total coverage available at: ' +
path.join(options.outputDir, 'lcov-report', 'index.html'));

// output cobertura for jenkins
aggCmd += ' cobertura';
exec(aggCmd, { }, function(err, stdout, stderr) {
grunt.log.write(stdout);
done();
});
});

});
};
47 changes: 47 additions & 0 deletions README.md
@@ -0,0 +1,47 @@
baseapp using:
- [grunt](http://gruntjs.com/)
- [jshint](http://www.jshint.com/)
- [dustjs-linkedin](http://linkedin.github.io/dustjs/)
- [express](http://expressjs.com/)
- [jasmine](http://pivotal.github.io/jasmine/)
- [jasmine-node](https://github.com/mhevery/jasmine-node)
- [webdriver](https://github.com/camme/webdriverjs)
- [redis](http://redis.io/)
- [authentication](http://redis.io/topics/twitter-clone)
- [istanbul](https://github.com/gotwarlost/istanbul)
- [plato](https://github.com/jsoverson/plato)
- [karma](http://karma-runner.github.io/0.8/index.html)
- [phantomjs](http://phantomjs.org/)
- [bootstrap](http://twitter.github.io/bootstrap/)

====

All available grunt tasks:

- jshint - Run jshint on all files
- dustjs - compile all templates (in views/**) and create a single template.js file
- jasmine - Run all client-side unit tests in spec/client/** with code coverage
- jasmine_node_coverage - Run server-side jasmine unit tests in spec/server/** with code coverage
- webdriver_coverage - Run all jasmine webdriver tests in spec/webdriver with code coverage
- webdriver - Run all jasmine webdriver tests in spec/webdriver WITHOUT code coverage (why would you wanna do that?)
- express - Start your express server (will only run during the lifetime of the grunt process)
- total_coverage - aggragates all coverage info into one mongo report
- plato - run plato report on entire codebase
- watch - Watch all files and run tests accordingly
- test - run:
- jshint
- jasmine
- jasmine_node_coverage
- webdriver_coverage
- total_coverage
- plato

All test and coverage output go to the build/ directory (JUnit XML for all tests and LCOV+HTML for all coverage info)

====

A karma.conf.js file is provided for all the client-side unit-tests

====

let 'er rip!

0 comments on commit 5a21226

Please sign in to comment.