Skip to content

Loading…

Improve Growl message for failed tests #667

Closed
wants to merge 1 commit into from

4 participants

@andreyvit

Growl enough information to allow debugging of simple failures based solely on the information provided by Growl.

Specifically, instead of the traditional notification like

Title: Failed

1 of 40 tests failed

display a more detailed notification like

Title: 1 of 40 tests failed

Session should monitor the added projects and issue reload requests

session.js:40

ReferenceError: foo is not defined

This is a very simple patch; didn't try to make it an option or something. I welcome your suggestions.

@andreyvit andreyvit Improve Growl message for failed tests
Growl enough information to allow debugging of simply failures based
solely on the information provided by Growl.

Specifically, instead of the traditional notification like

    Title: Failed

    1 of 40 tests failed

display a more detailed notification like

    Title: 1 of 40 tests failed

    Session should monitor the added projects and issue reload requests

    session.js:40

    ReferenceError: foo is not defined
ad18df9
@itsjamie

:+1: This would be nice! :)

@guileen

+1

@travisjeffery
Mocha.js member

i don't think growl should do the same job as a reporter. i haven't a seen test lib + growl combo that shows info detailed to that extent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 23, 2012
  1. @andreyvit

    Improve Growl message for failed tests

    andreyvit committed
    Growl enough information to allow debugging of simply failures based
    solely on the information provided by Growl.
    
    Specifically, instead of the traditional notification like
    
        Title: Failed
    
        1 of 40 tests failed
    
    display a more detailed notification like
    
        Title: 1 of 40 tests failed
    
        Session should monitor the added projects and issue reload requests
    
        session.js:40
    
        ReferenceError: foo is not defined
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 1 deletion.
  1. +19 −1 lib/mocha.js
View
20 lib/mocha.js
@@ -153,7 +153,25 @@ Mocha.prototype._growl = function(runner, reporter) {
var stats = reporter.stats;
if (stats.failures) {
var msg = stats.failures + ' of ' + runner.total + ' tests failed';
- notify(msg, { name: 'mocha', title: 'Failed', image: image('error') });
+ var title = 'Failed';
+ if (reporter.failures.length > 0) {
+ var test = reporter.failures[0];
+ title = msg;
+ msg = test.fullTitle();
+
+ var err = test.err
+ , message = err.message || (err.stack && err.stack.split("\n")[0].trim()) || ''
+ , stack = err.stack || message
+ , index = stack.indexOf(message) + message.length
+ , friendlyMessage = stack.slice(0, index)
+ , stackitem = stack.slice(index ? index + 1 : index).trim().split("\n")[0]
+ , m = stackitem.match(/\((.*):(\d+):\d+\)/);
+ if (m) {
+ msg += "\n\n" + path.basename(m[1]) + ":" + m[2];
+ }
+ msg += "\n\n" + friendlyMessage;
+ }
+ notify(msg, { name: 'mocha', title: title, image: image('error') });
} else {
notify(stats.passes + ' tests passed in ' + stats.duration + 'ms', {
name: 'mocha'
Something went wrong with that request. Please try again.