Add event emitter, always name tests

Created an event emitter instance for reporters and the test stack. Currently, the only event that fires is "begin".

All tests are now named, whether by their given name or as the name "Anonymous".
This commit is contained in:
Jesse Gibson
2016-03-03 17:14:52 -07:00
parent 87332c088b
commit 3081fbc9d6
6 changed files with 47 additions and 1 deletions

View File

@@ -23,6 +23,8 @@ function Test(name, cb, time) {
if (typeof name === 'string') {
this.description = name;
} else {
this.description = 'Anonymous';
}
var ctx = new Context(this);

View File

@@ -2,11 +2,13 @@
'use strict';
var route = require('./index');
var event = require('./events');
function bump(ctx) {
route.setup = function (req, res) {
res.status(200).json(ctx);
};
event.emit('begin', ctx);
}
module.exports = bump;

11
server/events.js Normal file
View File

@@ -0,0 +1,11 @@
/*jslint node: true*/
/*
Used to notify reporters and
the test stack when "done",
"progress", "fail" and "pass"
events happen.
*/
var Emitter = require('events');
module.exports = new Emitter();

View File

@@ -1,5 +1,5 @@
/*global jasmine, describe, it, expect*/
/*jslint node: true*/
/*global jasmine, describe, it, expect, pending*/
'use strict';
@@ -37,6 +37,11 @@ describe('The test function', function () {
});
});
it('should name tests without a name "Anonymous"', function () {
var result = test(function () {});
expect(result.description).toBe('Anonymous');
});
it('should remember the test name', function () {
var result = test('fabulous success', function () {});
expect(result.description).toBe('fabulous success');

View File

@@ -5,6 +5,7 @@
var bump = require('../../server/bump');
var route = require('../../server/index');
var axios = require('axios');
var event = require('../../server/events');
var root = String(route);
describe('The bump function', function () {
@@ -25,4 +26,17 @@ describe('The bump function', function () {
done();
});
});
it('should emit the "begin" event', function (done) {
event.on('begin', done);
bump({});
});
it('should provide the context to the "begin" cb', function () {
var obj = {};
event.on('begin', function (ctx) {
expect(ctx).toBe(obj);
});
bump(obj);
});
});

View File

@@ -0,0 +1,12 @@
/*global jasmine, describe, it, expect*/
/*jslint node: true*/
'use strict';
var stream = require('../../server/events');
var EventEmitter = require('events');
describe('The "events" export', function () {
it('should be an instance of EventEmitter', function () {
expect(stream).toEqual(jasmine.any(EventEmitter));
});
});