-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added code coverage and couple other things.
- Loading branch information
Spencer Alger
committed
Mar 5, 2014
1 parent
40b3021
commit 94c1458
Showing
16 changed files
with
1,250 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,29 @@ | ||
module.exports = function (grunt) { | ||
return { | ||
test: { | ||
files: ['<%= unitTestDir %>/**/*.js'], | ||
files: [ | ||
'<%= unitTestDir %>/**/*.js' | ||
], | ||
tasks: ['mocha:unit'] | ||
}, | ||
less: { | ||
files: [ | ||
'<%= app %>/**/*.less', | ||
'<%= src %>/courier/**/*.less' | ||
'<%= app %>/**/styles/**/*.less', | ||
'!<%= src %>/**/_*.less' | ||
], | ||
tasks: ['less'] | ||
}, | ||
jade: { | ||
files: [ | ||
'<%= root %>/**/*.jade', | ||
'!<%= root %>/node_modules/**/*', | ||
'!<%= src %>/bower_components/**/*' | ||
'<%= unitTestDir %>/index.jade' | ||
], | ||
tasks: ['jade:test'] | ||
}, | ||
clientside_jade: { | ||
files: [ | ||
'<%= testUtilsDir %>/istanbul_reporter/report.clientside-jade' | ||
], | ||
tasks: ['jade'] | ||
tasks: ['jade:clientside'] | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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});'); | ||
}); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
var Istanbul = require('istanbul'); | ||
var i = new Istanbul.Instrumenter({ | ||
embedSource: true, | ||
preserveComments: true, | ||
noAutoWrap: true | ||
}); | ||
|
||
module.exports = function instrumentationMiddleware(opts) { | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
// for root directory that files will be served from | ||
var root = opts.root || '/'; | ||
|
||
// the root directory used to create a relative file path | ||
// for display in coverage reports | ||
var displayRoot = opts.displayRoot || null; | ||
|
||
// filter the files in root that can be instrumented | ||
var filter = opts.filter || function (filename) { | ||
// by default only instrument *.js files | ||
return /\.js$/.test(filename); | ||
}; | ||
|
||
// cache filename resolution | ||
var fileMap = {}; | ||
|
||
function filenameForReq(req) { | ||
if (!~req.url.indexOf('instrument=true')) return false; | ||
|
||
// expected absolute path to the file | ||
var filename = path.join(root, req._parsedUrl.pathname); | ||
|
||
// shortcut for dev where we could be reloading on every save | ||
if (fileMap[filename] !== void 0) return fileMap[filename]; | ||
|
||
var ret = filename; | ||
|
||
if (!fs.existsSync(filename) || !opts.filter(filename)) { | ||
ret = false; | ||
} | ||
|
||
// cache the return value for next time | ||
fileMap[filename] = ret; | ||
return ret; | ||
} | ||
|
||
return function (req, res, next) { | ||
// resolve the request to a readable filename | ||
var filename = filenameForReq(req); | ||
// the file either doesn't exist of it was filtered out by opts.filter | ||
if (!filename) return next(); | ||
|
||
fs.readFile(filename, 'utf8', function (err, content) { | ||
if (err) { | ||
if (err.code !== 'ENOENT') { | ||
// other issue, report! | ||
return next(err); | ||
} | ||
|
||
// file was deleted, clear cache and move on | ||
delete fileMap[filename]; | ||
return next(); | ||
} | ||
|
||
res.statusCode = 200; | ||
res.setHeader('Content-Type', 'application/javascript'); | ||
res.end(i.instrumentSync( | ||
content, | ||
// make file names easier to read | ||
displayRoot ? path.relative(displayRoot, filename) : filename | ||
)); | ||
}); | ||
}; | ||
|
||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,42 @@ | ||
<!DOCTYPE html><html><head><title>Kibana4 Tests</title><link rel="stylesheet" href="mocha.css"></head><body><div id="mocha"></div><script src="expect.js"></script><script src="mocha.js"></script><script>mocha.setup('bdd'); | ||
// sauce labs & selenium inject global variables that break this | ||
// mocha.checkLeaks(); | ||
// mocha.globals(['mochaRunner', 'angular']);</script><script src="bower_components/requirejs/require.js"></script><script src="kibana/require.config.js"></script><script type="text/javascript">require.config({ | ||
paths: { | ||
sinon: '../sinon' | ||
}, | ||
shim: { | ||
'sinon/sinon': { | ||
deps: [ | ||
'sinon/sinon-timers-1.8.2' | ||
], | ||
exports: 'sinon' | ||
} | ||
} | ||
<!DOCTYPE html><html><head><title>Kibana4 Tests</title><link rel="stylesheet" href="/node_modules/mocha/mocha.css"></head><body><div id="mocha"></div><script src="/node_modules/expect.js/expect.js"></script><script src="/node_modules/mocha/mocha.js"></script><script src="/src/bower_components/requirejs/require.js"></script><script src="/src/kibana/require.config.js"></script><script type="text/javascript">window.COVERAGE = !!(/coverage=true/i.test(location.search)); | ||
mocha.setup('bdd'); | ||
|
||
require.config({ | ||
baseUrl: '/src/kibana', | ||
paths: { | ||
sinon: '../../test/utils/sinon', | ||
istanbul_reporter: '../../test/utils/istanbul_reporter' | ||
}, | ||
shim: { | ||
'sinon/sinon': { | ||
deps: [ | ||
'sinon/sinon-timers-1.8.2' | ||
], | ||
exports: 'sinon' | ||
} | ||
}, | ||
// mark all requested files with instrument query param | ||
urlArgs: COVERAGE ? 'instrument=true' : void 0 | ||
}); | ||
require(["/fixtures/field_mapping.js","/specs/apps/dashboard/index.js","/specs/apps/dashboard/mocks/modules.js","/specs/calculate_indices.js","/specs/courier.js","/specs/data_source.js","/specs/mapper.js"], function () { | ||
window.mochaRunner = mocha.run().on('end', function () { | ||
window.mochaResults = this.stats; | ||
|
||
function setupCoverage(done) { | ||
document.title = document.title.replace('Tests', 'Coverage'); | ||
require(['istanbul_reporter/reporter'], function (IstanbulReporter) { | ||
mocha.reporter(IstanbulReporter); | ||
done(); | ||
}); | ||
});</script></body></html> | ||
} | ||
|
||
function runTests() { | ||
require(["../../test/unit/specs/apps/dashboard/index","../../test/unit/specs/apps/dashboard/mocks/modules","../../test/unit/specs/calculate_indices","../../test/unit/specs/courier","../../test/unit/specs/data_source","../../test/unit/specs/mapper"], function () { | ||
window.mochaRunner = mocha.run().on('end', function () { | ||
window.mochaResults = this.stats; | ||
}); | ||
}); | ||
} | ||
|
||
if (COVERAGE) { | ||
setupCoverage(runTests); | ||
} else { | ||
runTests(); | ||
}</script></body></html> |
Oops, something went wrong.