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

Notebook updates #136

Merged
merged 7 commits into from
Aug 7, 2014
Merged
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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
test:
@node ./bin/_lab -f -m 800
@node ./bin/_lab -f -m 1000
test-cov:
@node ./bin/_lab -f -t 100 -m 800
@node ./bin/_lab -f -t 100 -m 1000
test-cov-html:
@node ./bin/_lab -f -r html -m 800 -o coverage.html
@node ./bin/_lab -f -r html -m 1000 -o coverage.html

.PHONY: test test-cov test-cov-html
37 changes: 33 additions & 4 deletions lib/reporters/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,44 @@ internals.Reporter.prototype.end = function (notebook) {
return !!test.err;
});

var errors = notebook.errors || [];

var output = '';
var message;
var stack;
var index;


if (errors.length) {
output += 'Session errors:\n\n';
for (var i = 0, il = errors.length; i < il; ++i) {
var error = errors[i];
message = error.message || error;
stack = error.stack || message;
index = stack.indexOf(message) + message.length;

stack = stack.slice(index + 1).replace(/^/gm, ' ');

// remove node_modules folders and only show the first 5 lines of the stack
stack = stack.split('\n').filter(function (line) {

return !(/\/node_modules\//.test(line));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline after function

}).slice(0,5).join('\n');

output += red(message) + '\n';
output += gray(stack) + '\n\n';
}
output += red('There were ' + errors.length + ' session error(s).') + '\n\n'
}

if (failures.length) {
output += 'Failed tests:\n\n';

for (var i = 0, il = failures.length; i < il; ++i) {
var test = failures[i];
var message = test.err.message || '';
var stack = test.err.stack || message;
var index = stack.indexOf(message) + message.length;
message = test.err.message || '';
stack = test.err.stack || message;
index = stack.indexOf(message) + message.length;

// Actual vs Expected

Expand Down Expand Up @@ -154,7 +183,7 @@ internals.Reporter.prototype.end = function (notebook) {

if (!test.timeout) {
var isChai = stack.indexOf('chai') !== -1;
stack = stack.slice(index ? index + 1 : index).replace(/^/gm, ' ');
stack = stack.slice(index + 1).replace(/^/gm, ' ');
if (isChai) {
stack = stack.split('\n').filter(function (line) { return !(/\/chai\//.test(line)); })[0];
}
Expand Down
2 changes: 1 addition & 1 deletion lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,4 @@ internals.failTest = function (test, state, skip, err) {
test.duration = 0;
state.report.tests.push(test);
state.reporter.test(test);
};
};
55 changes: 55 additions & 0 deletions test/reporters.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,61 @@ describe('Reporter', function () {
done();
});
});

it('displays session errors if there in an error in "before"', function (done) {

var script = Lab.script();
script.experiment('test', function () {

script.before(function (done) {

done(new Error('there was an error in the before function'));
});

script.test('works', function (finished) {
Lab.expect(true).to.equal(true, 'Working right');
finished();
});
});

Lab.report(script, { reporter: 'console', colors: false }, function (err, code, output) {

var result = output.replace(/\/[\/\w]+\.js\:\d+\:\d+/g, '<trace>');

expect(code).to.equal(1);
expect(result).to.contain('There were 1 session error(s).');
expect(result).to.contain('there was an error in the before function');
done();
});
});

it('displays session errors if there in an error in "afterEach"', function (done) {

var script = Lab.script();
script.experiment('test', function () {

script.afterEach(function (done) {

done('there was an error in the afterEach function');
});

script.test('works', function (finished) {
Lab.expect(true).to.equal(true, 'Working right');
finished();
});
});

Lab.report(script, { reporter: 'console', colors: false }, function (err, code, output) {

var result = output.replace(/\/[\/\w]+\.js\:\d+\:\d+/g, '<trace>');

expect(code).to.equal(1);
expect(result).to.contain('There were 1 session error(s).');
expect(result).to.contain('there was an error in the afterEach function');
done();
});
});

});

describe('json', function () {
Expand Down