Skip to content

Commit

Permalink
Build: Add
Browse files Browse the repository at this point in the history
> [email protected] build /home/havvy/tennu/after-events
> gulp build

[20:45:41] Using gulpfile ~/tennu/after-events/gulpfile.js
[20:45:41] Starting 'build'...
[20:45:42] Finished 'build' after 1.12 s, Test: listener independence
  • Loading branch information
Havvy committed Apr 25, 2015
1 parent 13eb0ac commit 735b122
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 24 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Event Emitter with hooks for listener return values",
"main": "after-events.js",
"scripts": {
"test": "mocha test.js"
"test": "mocha test.js -R spec",
"build": "gulp build"
},
"repository": {
"type": "git",
Expand Down
28 changes: 28 additions & 0 deletions test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 49 additions & 23 deletions test.sjs
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
const sinon = require('sinon');
const assert = require('better-assert');
const equal = require('deep-eql');
const inspect = require('util').inspect;
const format = require('util').format;
const sinon = require("sinon");
const assert = require("better-assert");
const equal = require("deep-eql");
const inspect = require("util").inspect;
const format = require("util").format;

const debug = false;
const log = debug ? console.log.bind(console) : function () {};

const EventEmiter = require('./after-events.js');
const EventEmiter = require("./after-events.js");

describe 'After Event Emitter' {
describe "After Event Emitter" {
var EE;

beforeEach {
log(/* newline */);
EE = EventEmiter();
}

it 'works as an event emitter.' (done) {
EE.on('x', function (arg1, arg2) {
it "works as an event emitter." (done) {
EE.on("x", function (arg1, arg2) {
assert(arg1 === true);
assert(arg2 === false);
done()
});

EE.emit('x', true, false);
EE.emit("x", true, false);
}

it 'does not throw on non-existent events.' (done) {
EE.emit('y');
it "does not throw on non-existent events." (done) {
EE.emit("y");
done();
}

describe '#after' {
it 'takes a function, which it calls after the listener returns.' (done) {
EE.on('x', function () {return true;});
describe "#after" {
it "takes a function, which it calls after the listener returns." (done) {
EE.on("x", function () {return true;});
EE.after(function (err, ret, emitted, arg1, arg2) {
assert(err === undefined);
assert(ret === true);
assert(emitted === 'x');
assert(emitted === "x");
assert(arg1 === true);
assert(arg2 === false);
done();
});
EE.emit('x', true, false);
EE.emit("x", true, false);
}

it 'passes the error to err if an error is thrown' (done) {
it "passes the error to err if an error is thrown" (done) {
const error = new Error();
EE.on('x', function () {throw error});
EE.on("x", function () {throw error});
EE.after(function (err, ret, emitted) {
assert(err === error);
assert(ret === undefined);
done();
});
EE.emit('x');
EE.emit("x");
}

it 'can take multiple functions, and call them in order' (done) {
it "can take multiple functions, and call them in order" (done) {
var callCount = 0;

EE.on('x', function () { return true; });
EE.on("x", function () { return true; });
EE.after(function (err, ret, emitted) {
try {
assert(callCount === 0);
Expand All @@ -78,7 +78,33 @@ describe 'After Event Emitter' {
}
});

EE.emit('x');
EE.emit("x");
}
}

it "performs each callback in isolation" (done) {
var error = new Error();
var result = {};
EE.on("x", function () { throw error; });
EE.on("x", function () { return result; });

var callCount = 0;
var errCount = 0;
var resCount = 0;

EE.after(function state (err, ret, emitted) {
callCount += 1;

if (err) { errCount += 1; }
if (ret) { resCount += 1; }

if (callCount === 2) {
assert(errCount === 1);
assert(resCount === 1);
done();
}
});

EE.emit("x")
}
}

0 comments on commit 735b122

Please sign in to comment.