Skip to content

Commit

Permalink
[major] Test, coverage and emit refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd-Eden committed Oct 6, 2014
1 parent 5ddae77 commit b661847
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 132 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
language: node_js
node_js:
- "0.8"
- "0.10"
- "0.11"
before_install:
- "npm install -g [email protected]"
script:
- "npm run test-travis"
after_script:
- "npm install [email protected] && cat coverage/lcov.info | coveralls"
51 changes: 3 additions & 48 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var predefine = require('predefine')
, slice = Array.prototype.slice
, emits = require('emits')
, path = require('path');

/**
Expand Down Expand Up @@ -133,57 +134,11 @@ module.exports = function fuse(Base, inherits, options) {
if (options.defaults === false) return Base;

//
// Inherit some methods from the predefine module
// Inherit some methods from common module we use.
//
if (options.mixin !== false) Base.readable('mixin', predefine.mixin);
if (options.merge !== false) Base.readable('merge', predefine.merge);

/**
* Simple emit wrapper that returns a function that emits an event once it's
* called
*
* ```js
* example.on('close', example.emits('close'));
* ```
*
* @param {String} event Name of the event that we should emit.
* @param {Function} parser The last argument, if it's a function is a arg parser
* @api public
*/
if (options.emits !== false)
Base.readable('emits', function emits() {
var args = slice.call(arguments, 0)
, self = this
, parser;

//
// Automatically prefix the event that we `emit`
//
if ('string' === typeof options.prefix) {
args[0] = options.prefix + args[0];
}

//
// Assume that if the last given argument is a function, it would be
// a parser.
//
if ('function' === typeof args[args.length - 1]) {
parser = args.pop();
}

return function emit(arg) {
if (!self.listeners(args[0]).length) return false;

if (parser) {
arg = parser.apply(self, arguments);
if (!Array.isArray(arg)) arg = [arg];
} else {
arg = slice.call(arguments, 0);
}

return self.emit.apply(self, args.concat(arg));
};
});
if (options.emits !== false) Base.readable('emits', emits);

return Base;
};
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "fusing",
"version": "0.3.2",
"version": "0.4.0",
"description": "Prototype fusion",
"main": "index.js",
"scripts": {
"test": "NODE_ENV=test ./node_modules/.bin/mocha $(find test -name '*.test.js')",
"coverage": "NODE_ENV=test ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha $(find test -name '*.test.js') --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js || true && rm -rf ./coverage"
"coverage": "istanbul cover node_modules/.bin/_mocha -- --reporter spec --ui bdd test.js",
"test": "mocha --reporter spec test.js",
"test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly -- --reporter spec --ui bdd test.js"
},
"repository": {
"type": "git",
Expand All @@ -29,14 +30,13 @@
},
"homepage": "https://github.com/bigpipe/fusing",
"dependencies": {
"emits": "1.0.x",
"predefine": "0.1.x"
},
"devDependencies": {
"chai": "1.9.x",
"coveralls": "2.8.x",
"istanbul": "0.2.x",
"mocha": "1.19.x",
"mocha-lcov-reporter": "0.0.x",
"assume": "0.0.x",
"istanbul": "0.3.x",
"mocha": "1.21.x",
"pre-commit": "0.0.x"
}
}
Loading

0 comments on commit b661847

Please sign in to comment.