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

Event data improvements #193

Merged
merged 1 commit into from
Nov 11, 2015
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
10 changes: 4 additions & 6 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,14 @@ function stats(stats) {
}

function test(data) {
var isError = data.err.message;

var prefix = '';
var isError = data.error.message;

if (fileCount > 1) {
prefix = prefixTitle(data.file);
data.title = prefixTitle(data.file) + data.title;
}

if (isError) {
log.error(prefix + data.title, chalk.red(data.err.message));
log.error(data.title, chalk.red(data.error.message));

errors.push(data);
} else {
Expand All @@ -100,7 +98,7 @@ function test(data) {
return;
}

log.test(null, prefix + data.title, data.duration);
log.test(data);
}
}

Expand Down
14 changes: 6 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,24 @@ var isFailed = false;

Error.stackTraceLimit = Infinity;

function test(err, title, duration, type) {
function test(props) {
if (isFailed) {
return;
}

// don't display anything, if it's a passed hook
if (!err && type !== 'test') {
if (!props.error && props.type !== 'test') {
return;
}

props.error = props.error ? serializeError(props.error) : {};

process.send({
name: 'test',
data: {
err: err ? serializeError(err) : {},
title: title,
duration: duration
}
data: props
});

if (err && hasFlag('fail-fast')) {
if (props.error && hasFlag('fail-fast')) {
isFailed = true;
exit();
}
Expand Down
10 changes: 5 additions & 5 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ x.writelpad = log.writelpad.bind(log);
x.success = log.success.bind(log);
x.error = log.error.bind(log);

x.test = function (err, title, duration) {
if (err) {
log.error(title, chalk.red(err.message));
x.test = function (props) {
if (props.err) {
log.error(props.title, chalk.red(props.err.message));
return;
}

Expand All @@ -45,8 +45,8 @@ x.test = function (err, title, duration) {

// display duration only over a threshold
var threshold = 100;
var dur = duration > threshold ? chalk.gray.dim(' (' + prettyMs(duration) + ')') : '';
log.success(title + dur);
var dur = props.duration > threshold ? chalk.gray.dim(' (' + prettyMs(props.duration) + ')') : '';
log.success(props.title + dur);
};

x.errors = function (results) {
Expand Down
7 changes: 4 additions & 3 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,15 @@ Runner.prototype._addTestResult = function (test) {
this.stats.failCount++;
}

this.results.push({
var props = {
duration: test.duration,
title: test.title,
error: test.assertError,
type: test.type
});
};

this.emit('test', test.assertError, test.title, test.duration, test.type);
this.results.push(props);
this.emit('test', props);
};

Runner.prototype.run = function () {
Expand Down
18 changes: 9 additions & 9 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,10 @@ test('runner have test event', function (t) {
a.end();
});

runner.on('test', function (err, title, duration) {
t.error(err);
t.equal(title, 'foo');
t.ok(duration !== undefined);
runner.on('test', function (props) {
t.error(props.error);
t.equal(props.title, 'foo');
Copy link
Member

Choose a reason for hiding this comment

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

Just fyi, tape supports t.is as an alias, so we could use that. Probably better as a separate PR though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, as part of that whole cleanup process.

t.notEqual(props.duration, undefined);
t.end();
});

Expand Down Expand Up @@ -847,11 +847,11 @@ test('test types and titles', function (t) {
{type: 'hook', title: 'pass'}
];

runner.on('test', function (err, title, duration, type) {
runner.on('test', function (props) {
var test = tests.shift();

t.is(test.title, title);
t.is(test.type, type);
t.is(test.title, props.title);
t.is(test.type, props.type);
});

runner.run().then(t.end);
Expand Down Expand Up @@ -956,7 +956,7 @@ test('don\'t display hook title if it did not fail', function (t) {

fork(path.join(__dirname, 'fixture', 'hooks-passing.js'))
.on('test', function (test) {
t.deepEqual(test.err, {});
t.deepEqual(test.error, {});
t.is(test.title, 'pass');
})
.then(function () {
Expand All @@ -969,7 +969,7 @@ test('display hook title if it failed', function (t) {

fork(path.join(__dirname, 'fixture', 'hooks-failing.js'))
.on('test', function (test) {
t.is(test.err.name, 'AssertionError');
t.is(test.error.name, 'AssertionError');
t.is(test.title, 'beforeEach for "pass"');
})
.then(function () {
Expand Down