mirror of
https://github.com/gundb/panic-server.git
synced 2026-04-15 03:00:16 -04:00
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:
@@ -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);
|
||||
|
||||
@@ -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
11
server/events.js
Normal 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();
|
||||
@@ -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');
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
12
spec/server/events.spec.js
Normal file
12
spec/server/events.spec.js
Normal 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));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user