Skip to content
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
5 changes: 2 additions & 3 deletions lib/run-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ function sum(arr, key) {
}

function normalizeError(err) {
if (!isObj(err)) {
if (!isObj(err) || typeof err.message !== 'string') {
err = {
message: err,
stack: err
message: String(err)
};
}

Expand Down
5 changes: 5 additions & 0 deletions lib/serialize-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ function filter(propertyName, isRoot, source, target) {
return true;
}

if ((propertyName === 'name' || propertyName === 'stack') &&
typeof source[propertyName] !== 'string') {
Copy link
Member

Choose a reason for hiding this comment

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

@sindresorhus any thoughts on this? XO doesn't complain 😉

Copy link
Member

Choose a reason for hiding this comment

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

Why should it have complained?

Copy link
Member

Choose a reason for hiding this comment

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

Figured it may have opinions on if condition indenting.

return false;
}

if (propertyName === 'stack') {
target.stack = beautifyStack(source.stack);
return false;
Expand Down
29 changes: 29 additions & 0 deletions test/run-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,32 @@ test('calculate remaining test count', t => {
t.end();
});

test('handle non-object rejections', t => {
const runStatus = new RunStatus();

runStatus.on('error', err => {
t.deepEqual(err, {
file: 'foo.js',
message: '42',
type: 'rejection'
});
t.end();
});

runStatus.handleRejections({file: 'foo.js', rejections: [42]});
});

test('handle non-object exceptions', t => {
const runStatus = new RunStatus();

runStatus.on('error', err => {
t.deepEqual(err, {
file: 'bar.js',
message: '/ab/g',
type: 'exception'
});
t.end();
});

runStatus.handleExceptions({file: 'bar.js', exception: /ab/g});
});
11 changes: 11 additions & 0 deletions test/serialize-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,14 @@ test('does not call toJSON() when serializing actual and expected', t => {
t.notSame(serializedErr.actual, serializedErr.expected);
t.end();
});

test('remove non-string error properties', t => {
const err = {
name: [42],
stack: /re/g
};
const serializedErr = serialize(err);
t.is(serializedErr.name, undefined);
t.is(serializedErr.stack, undefined);
t.end();
});