Skip to content

Commit

Permalink
fix(empower): bugfix: power-assert output doesn't appear in Node 0.11.x
Browse files Browse the repository at this point in the history
Error#stack is set in AssertionError constructor function.
So I need to instantiate another AssertionError to replace stack.
  • Loading branch information
twada committed Sep 30, 2014
1 parent b220558 commit 53e882e
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions lib/decorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,33 @@ Decorator.prototype.concreteAssert = function (invocation, context) {
};

Decorator.prototype.errorToRethrow = function (e, originalMessage, context) {
var f;
var f, attrs;
if (e.name !== 'AssertionError') {
return e;
}
if (typeof this.receiver.AssertionError !== 'function') {
return e;
}
if (isPhantom) {
f = new this.receiver.AssertionError({
actual: e.actual,
expected: e.expected,
operator: e.operator,
message: e.message
});

attrs = {
actual: e.actual,
expected: e.expected,
operator: e.operator,
message: e.message
};

if (this.config.modifyMessageOnRethrow) {
attrs.message = this.buildPowerAssertText(originalMessage, context);
attrs.stackStartFunction = Decorator.prototype.concreteAssert;
}

if (isPhantom || this.config.modifyMessageOnRethrow) {
f = new this.receiver.AssertionError(attrs);
} else {
f = e;
f.message = attrs.message;
}
if (this.config.modifyMessageOnRethrow) {
f.message = this.buildPowerAssertText(originalMessage, context);
if (typeof e.generatedMessage !== 'undefined') {
f.generatedMessage = false;
}
}

if (this.config.saveContextOnRethrow) {
f.powerAssertContext = context;
}
Expand Down

0 comments on commit 53e882e

Please sign in to comment.