Permalink
Browse files

add export interface style and a bit more commenting to existing

  • Loading branch information...
logicalparadox committed Jul 10, 2012
1 parent 6d05d71 commit 8eb360da54af006ee959e02ce2e309396100db87
Showing with 139 additions and 3 deletions.
  1. +19 −0 benchmark-exports/array.js
  2. +5 −3 bin/matcha
  3. +14 −0 lib/matcha/interfaces/bdd.js
  4. +100 −0 lib/matcha/interfaces/exports.js
  5. +1 −0 lib/matcha/interfaces/index.js
View
@@ -0,0 +1,19 @@
var arr = [1, 2, 3, 4, 5, 6];
exports['array slice'] = {
options: {
iterations: 2000000
}
, bench: {
'Array.prototype.slice': function () {
var args = Array.prototype.slice.call(arr, 1);
}
, 'for loop': function () {
var l = arr.length
, args = new Array(l - 1);
for (var i = 1; i < l; i++) args[i - 1] = arr[i];
}
}
};
View
@@ -23,6 +23,7 @@ program
.option('-h, --help', 'view matcha usage information')
.option('-v, --version', 'view matcha version')
.option('-R, --reporter [default]', 'specify the reporter to use')
.option('-I, --interface [bdd]', 'specify the interface to expect')
.option('--reporters', 'display available reporter')
.action(runSuite);
@@ -60,19 +61,20 @@ function runSuite (argv) {
return _p;
});
var suite = new matcha.Suite();
var style = argv.param('I', 'interface') || 'bdd'
, suite = new matcha.Suite()
, ui = new Interface(suite, { style: style });
load(files, function () {
run(suite, process.exit);
});
function load (files, cb) {
var after = files.length
, ui = new Interface(suite);
files.forEach(function (file) {
delete require.cache[file];
suite.emit('pre-require');
require(file);
suite.emit('require', require(file));
--after || cb();
});
}
@@ -1,6 +1,20 @@
/*!
* Matcha - Interface Manager
* Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
* MIT Licensed
*/
/*!
* Internal Dependancies
*/
var Suite = require('../suite')
, Bench = require('../bench');
/*!
* Primary Export
*/
module.exports = function (interface) {
var suite = interface._suite
, suites = [ suite ];
@@ -0,0 +1,100 @@
/*!
* Matcha - Interface Manager
* Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
* MIT Licensed
*/
/*!
* Internal Dependancies
*/
var Suite = require('../suite')
, Bench = require('../bench');
/*!
* Primary Export
*/
module.exports = function (interface) {
var suite = interface._suite
, suites = [ suite ];
/*!
* Listen for require with given spec
*/
suite.on('require', function (spec) {
/*!
* setOptions
*
* Set options based on the `options`
* object for a given suite.
*
* @api private
*/
function setOptions (suite, opts) {
for (var key in opts) {
suite.setOption(key, opts[key]);
}
}
/*!
* setBefore
*
* Set before functions based on function
* or array of functions for a given suite.
*
* @api private
*/
function setBefore (suite, before) {
if (!Array.isArray(before)) before = [ before ];
before.forEach(suite.addBefore.bind(suite));
}
/*!
* setAfter
*
* Set functions based on function
* or array of functions for a given suite.
*
* @api private
*/
function setAfter (suite, after) {
if (!Array.isArray(after)) after = [ after ];
after.forEach(suite.addAfter.bind(suite));
}
/*!
* setBench
*
* Set benches based on benches object
* of attributed functions for a given suite.
*
* @api private
*/
function setBench (suite, benches) {
for (var title in benches) {
suite.addBench(new Bench(title, benches[title]));
}
}
/*!
* Parse the incoming file
*/
for (var _suite in spec) {
var suite = Suite.create(suites[0], _suite)
, def = spec[_suite];
if (def.options) setOptions(suite, def.options);
if (def.before) setBefore(suite, def.before);
if (def.after) setAfter(suite, def.after);
if (def.bench) setBench(suite, def.bench);
}
});
}
@@ -1 +1,2 @@
exports.bdd = require('./bdd');
exports.exports = require('./exports');

0 comments on commit 8eb360d

Please sign in to comment.