Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle mocha hook failures #163

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion lib/reporter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function Reporter(MochaReporter, coverage, root) {
_.extend(Reporter.prototype, {
// Called when the Feathers application is set up with the event
// services for runs, suites and tests (which are event emitters)
setup: function(runs, suites, tests, coverages, logs) {
setup: function(runs, suites, tests, hooks, coverages, logs) {
debug('setting up Mocha command line reporter');

runs.on('error', this.proxy('error'));
Expand All @@ -62,6 +62,9 @@ _.extend(Reporter.prototype, {
tests.on('created', this.proxy('startTest'));
tests.on('patched', this.proxy('updateTest'));

hooks.on('created', this.proxy('createHook'));
hooks.on('patched', this.proxy('updateHook'));

logs.on('created', this.proxy('captureLog'));

coverages.on('created', this.proxy('reportCoverage'));
Expand Down Expand Up @@ -255,6 +258,54 @@ _.extend(Reporter.prototype, {
buffer.emit('test end', test);
},

createHook: function(data) {
debug('creating hook', data);
this.buffers.updateCache(data);

// Create a new Mocha hook instance without details
var hook = new mocha.Hook(data.title, true);
var parent = this._mochaObjects[data.parent];

if (!parent) {
throw new Error('No parent suite found for hook ' + JSON.stringify(data));
}

_.extend(hook, { parent: parent });
this._mochaObjects[data.id] = hook;
this.buffers.get(data.id).emit('hook', hook);
},

updateHook: function(data) {
debug('updating hook', data);
this.buffers.updateCache(data);

var hook = this._mochaObjects[data.id];
var buffer = this.buffers.get(data.id);

if (!hook || !buffer) {
throw new Error('No hook information found for ' + JSON.stringify(data));
}

// Update the existing hook any new properties we got
_.extend(hook, _.pick(data, testProperties));

// emit the events on the runner appropriate for the hook result
switch(data.status) {
case 'running':
debug('running hook', data);
buffer.emit('hook', hook);
break;
case 'ended':
debug('ending hook', data);
buffer.emit('hook end', hook);
break;
case 'failed':
debug('failing hook', data);
buffer.emit('fail', hook, data.err);
break;
}
},

reportCoverage: function(data) {
debug('reportCoverage() received coverage', data);
var options = this.coverage;
Expand Down
1 change: 1 addition & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var api = exports.api = function () {
.use('/runs', memory())
.use('/suites', memory())
.use('/tests', memory())
.use('/hooks', memory())
.use('/coverages', memory())
.use('/logs', memory());
};
Expand Down
2 changes: 1 addition & 1 deletion lib/testee.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ _.extend(Testee.prototype, {
// Bind Feathers service .lookup
var lookup = self.api.service.bind(self.api);
debug('hooking up services to Mocha reporter');
reporter.setup(lookup('runs'), lookup('suites'), lookup('tests'), lookup('coverages'), lookup('logs'));
reporter.setup(lookup('runs'), lookup('suites'), lookup('tests'), lookup('hooks'), lookup('coverages'), lookup('logs'));

self.reporter = reporter;
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"miner": "^0.2.1",
"mocha": "^3.2.0",
"path": "^0.12.7",
"testee-client": "^0.5.0",
"testee-client": "github:bitovi/testee-client#handle-hook-failures",
"useragent": "^2.0.9"
},
"devDependencies": {
Expand Down