Skip to content

Commit 2bd6ab8

Browse files
committed
consistent error determination
The child processes determine whether the test had an error based on its `error` property not being `undefined`. However they then change this property to an empty object if there was no error. The API determines whether a test had an error based on its (empty) error object having a `message` property. If a test did not have an error, its `error` property is set to `null`. This prevents errors without messages from being reported correctly. Instead set `error` to `null` in the child processes and rely on that in the API. I've added a test to validate errors without messages get reported.
1 parent 3c12940 commit 2bd6ab8

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

api.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ Api.prototype._handleStats = function (stats) {
114114
Api.prototype._handleTest = function (test) {
115115
test.title = this._prefixTitle(test.file) + test.title;
116116

117-
var isError = test.error.message;
118-
119-
if (isError) {
117+
if (test.error) {
120118
if (test.error.powerAssertContext) {
121119
var message = formatter(test.error.powerAssertContext);
122120

@@ -132,8 +130,6 @@ Api.prototype._handleTest = function (test) {
132130
}
133131

134132
this.errors.push(test);
135-
} else {
136-
test.error = null;
137133
}
138134

139135
this.emit('test', test);

index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ function test(props) {
4646
return;
4747
}
4848

49-
props.error = hasError ? serializeError(props.error) : {};
50-
51-
if (props.error.stack) {
52-
props.error.stack = beautifyStack(props.error.stack);
49+
if (hasError) {
50+
props.error = serializeError(props.error);
51+
if (props.error.stack) {
52+
props.error.stack = beautifyStack(props.error.stack);
53+
}
54+
} else {
55+
props.error = null;
5356
}
5457

5558
send('test', props);

test/api.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,17 @@ test('uncaught exception will throw an error', function (t) {
279279
});
280280
});
281281

282+
test('errors can occur without messages', function (t) {
283+
t.plan(2);
284+
285+
var api = new Api([path.join(__dirname, 'fixture/error-without-message.js')]);
286+
api.run()
287+
.then(function () {
288+
t.is(api.failCount, 1);
289+
t.is(api.errors.length, 1);
290+
});
291+
});
292+
282293
test('stack traces for exceptions are corrected using a source map file', function (t) {
283294
t.plan(4);
284295

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import test from '../../';
2+
3+
test('throw an error without a message', () => {
4+
throw new Error();
5+
});

test/hooks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ test('don\'t display hook title if it did not fail', function (t) {
309309
fork(path.join(__dirname, 'fixture', 'hooks-passing.js'))
310310
.run()
311311
.on('test', function (test) {
312-
t.same(test.error, {});
312+
t.same(test.error, null);
313313
t.is(test.title, 'pass');
314314
})
315315
.then(function () {

0 commit comments

Comments
 (0)