Skip to content

Commit

Permalink
Merge pull request #18 from spenceralger/master
Browse files Browse the repository at this point in the history
Implemented code coverage
  • Loading branch information
spenceralger committed Mar 6, 2014
2 parents 69c1ab9 + 94c1458 commit 93488cf
Show file tree
Hide file tree
Showing 25 changed files with 1,334 additions and 128 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-jade": "~0.10.0",
"grunt-contrib-less": "~0.9.0",
"grunt-cli": "~0.1.13"
"grunt-cli": "~0.1.13",
"istanbul": "~0.2.4",
"path-browserify": "0.0.0"
},
"scripts": {
"test": "grunt test",
Expand Down
12 changes: 12 additions & 0 deletions src/courier/courier.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,5 +286,17 @@ define(function (require) {
this.fetch('doc');
};

// get the list of open data source objects
// primarily for testing purposes
Courier.prototype._openSources = function (type) {
if (!type) {
return _.transform(this._refs, function (open, refs) {
[].push.apply(open, refs);
}, []);
}

return this._refs[type] || [];
};

return Courier;
});
3 changes: 2 additions & 1 deletion src/kibana/require.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ require.config({
lodash: '../bower_components/lodash/dist/lodash',
moment: '../bower_components/moment/moment',
gridster: '../bower_components/gridster/dist/jquery.gridster',
config: '../config'
configFile: '../config',
bower_components: '../bower_components'
},
shim: {
angular: {
Expand Down
65 changes: 52 additions & 13 deletions tasks/config/connect.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,59 @@
module.exports = function (grunt) {
var instrumentationMiddleware = require('../utils/instrumentation');
var amdWrapMiddleware = require('../utils/amd-wrapper');

return {
dev: {
options: {
base: '<%= src %>'
}
},
test: {
options: {
base: [
'<%= unitTestDir %>',
'<%= testUtilsDir %>',
'<%= src %>',
'<%= root %>/node_modules/mocha',
'<%= root %>/node_modules/expect.js'
],
port: 8001
middleware: function (connect, options, stack) {
stack = stack || [];

var root = grunt.config.get('root');

// when a request for an intrumented file comes in (?instrument=true)
// and it is included in `pattern`, it will be handled
// by this middleware
stack.push(instrumentationMiddleware({
// root that files should be served from
root: root,

// make file names easier to read
displayRoot: grunt.config.get('src'),

// filter the filenames that will be served
filter: function (filename) {
// return true if the filename should be
// included in the coverage report (results are cached)
return grunt.file.isMatch([
'**/src/**/*.js',
'!**/src/bower_components/**/*',
'!**/src/kibana/utils/{event_emitter,next_tick}.js'
], filename);
}
}));

// minimize code duplication (especially in the istanbul reporter)
// by allowing node_modules to be requested in an AMD wrapper
stack.push(amdWrapMiddleware({
root: root
}));

// standard static middleware reading from the root
stack.push(connect.static(root));

// allow browsing directories
stack.push(connect.directory(root));

// redirect requests for '/' to '/src/'
stack.push(function (req, res, next) {
if (req.url !== '/') return next();
res.statusCode = 303;
res.setHeader('Location', '/src/');
res.end();
});

return stack;
}
}
}
};
Expand Down
49 changes: 33 additions & 16 deletions tasks/config/jade.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
module.exports = function (grunt) {
var path = require('path');

return {
options: {
compileDebug: false
},
test: {
src: [
'<%= unitTestDir %>/**/*.jade',
'<%= app %>/partials/**/*.jade',
'<%= app %>/apps/**/*.jade'
],
expand: true,
ext: '.html',
files: {
'<%= unitTestDir %>/index.html': '<%= unitTestDir %>/index.jade'
},
options: {
data: function (src, dest) {
var pattern = grunt.config.process('<%= unitTestDir %>/**/*.js');
var tests = grunt.file.expand({}, pattern).map(function (filename) {
return filename.replace(grunt.config.get('unitTestDir'), '');
});
return { tests: JSON.stringify(tests) };
},
client: false
var unitTestDir = grunt.config.get('unitTestDir');

// filter for non unit test related files
if (!~path.dirname(src).indexOf(unitTestDir)) return;

var pattern = unitTestDir + '/specs/**/*.js';
var appdir = grunt.config.get('app');

return {
tests: grunt.file.expand({}, pattern).map(function (filename) {
return path.relative(appdir, filename).replace(/\.js$/, '');
})
};
}
}
},
clientside: {
files: {
'<%= testUtilsDir %>/istanbul_reporter/report.jade.js': '<%= testUtilsDir %>/istanbul_reporter/report.clientside-jade'
},
options: {
client: true,
amd: true,
namespace: false // return the template directly in the amd wrapper
}
}
};
};

};
7 changes: 6 additions & 1 deletion tasks/config/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ module.exports = function (config) {
// just lint the source dir
source: {
files: {
src: ['Gruntfile.js', '<%= src %>/**/*.js', '<%= unitTestDir %>/**/*.js', '<%= root %>/tasks/**/*.js']
src: [
'Gruntfile.js',
'<%= src %>/**/*.js',
'<%= unitTestDir %>/**/*.js',
'<%= root %>/tasks/**/*.js'
]
}
},
options: {
Expand Down
3 changes: 1 addition & 2 deletions tasks/config/less.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module.exports = {
src: {
src: [
'<%= app %>/styles/**/*.less',
'<%= app %>/apps/**/*.less',
'<%= app %>/**/styles/**/*.less',
'!<%= src %>/**/_*.less'
],
expand: true,
Expand Down
12 changes: 7 additions & 5 deletions tasks/config/mocha.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
module.exports = {
options: {
log: true,
logErrors: true,
run: false
},
unit: {
options: {
log: true,
logErrors: true,
urls: [
'http://localhost:8001/'
],
run: false
'http://localhost:8000/test/unit/'
]
}
}
};
22 changes: 14 additions & 8 deletions tasks/config/watch.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
module.exports = function (grunt) {
return {
test: {
files: ['<%= unitTestDir %>/*.jade', '<%= unitTestDir %>/**/*.js'],
tasks: ['jade:test', 'mocha:unit']
files: [
'<%= unitTestDir %>/**/*.js'
],
tasks: ['mocha:unit']
},
less: {
files: [
'<%= app %>/**/*.less',
'<%= src %>/courier/**/*.less'
'<%= app %>/**/styles/**/*.less',
'!<%= src %>/**/_*.less'
],
tasks: ['less']
},
jade: {
files: [
'<%= app %>/**/*.jade',
'<%= src %>/courier/**/*.jade',
'!<%= unitTestDir %>/**/*.jade'
'<%= unitTestDir %>/index.jade'
],
tasks: ['jade:test']
},
clientside_jade: {
files: [
'<%= testUtilsDir %>/istanbul_reporter/report.clientside-jade'
],
tasks: ['jade']
tasks: ['jade:clientside']
}
};
};
7 changes: 6 additions & 1 deletion tasks/dev.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
module.exports = function (grunt) {
grunt.registerTask('dev', ['less', 'jade', 'connect:dev', 'watch']);
grunt.registerTask('dev', [
'less',
'jade',
'connect:dev',
'watch'
]);
};
1 change: 0 additions & 1 deletion tasks/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
module.exports = function (grunt) {
grunt.registerTask('server', ['connect:dev:keepalive']);
grunt.registerTask('test_server', ['connect:test:keepalive']);
};
12 changes: 9 additions & 3 deletions tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ module.exports = function (grunt) {
/* jshint scripturl:true */
grunt.registerTask('test', [
'jshint',
'connect:test',
'jade:test',
'connect:dev',
'jade',
'mocha:unit'
]);

grunt.registerTask('coverage', [
'blanket',
'connect:dev',
'mocha:coverage'
]);

grunt.registerTask('test:watch', [
'connect:test',
'connect:dev',
'watch:test'
]);
};
26 changes: 26 additions & 0 deletions tasks/utils/amd-wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = function amdWrapMiddleware(opts) {
opts = opts || {};

var root = opts.root || '/';
var path = require('path');
var fs = require('fs');
var pathPrefix = opts.pathPrefix || '/amd-wrap/';

return function (req, res, next) {
// only allow prefixed requests
if (req.url.substring(0, pathPrefix.length) !== pathPrefix) return next();

// strip the prefix and form the filename
var filename = path.join(root, req._parsedUrl.pathname.replace('/amd-wrap/', ''));

fs.readFile(filename, 'utf8', function (err, contents) {
// file does not exist
if (err) return next(err.code === 'ENOENT' ? void 0 : err);

// respond with the wrapped code
res.statusCode = 200;
res.setHeader('Content-Type', 'application/javascript');
res.end('define(function (require, exports, module) {\n' + contents + '\n});');
});
};
};
Loading

0 comments on commit 93488cf

Please sign in to comment.