Skip to content
Closed
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
32 changes: 29 additions & 3 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,24 @@ Test.prototype._publicApi = function () {
self._assert();
}

function stringify(arg) {
return JSON.stringify(arg);
}

function onAssertionEvent(event) {
var message;

if (event.originalMessage) {
message = event.originalMessage;
} else if (event.powerAssertContext) {
message = event.powerAssertContext.source.content;
} else {
message = 't.' + event.methodName + '(' + event.args.slice(0, event.numArgs).map(stringify).join(', ') + ')';
}
// TODO(jamestalmage): This will not work great for enhanced = false, since args could be complex.

console.log(message);

if (event.assertionThrew) {
event.error.powerAssertContext = event.powerAssertContext;
event.error.originalMessage = event.originalMessage;
Expand All @@ -259,16 +276,25 @@ Test.prototype._publicApi = function () {
return null;
}

function identitiy(event) {
return event;
}

var enhanced = enhanceAssert({
assert: assert,
onSuccess: onAssertionEvent,
onError: onAssertionEvent
onSuccess: identitiy,
onError: identitiy
});

// Patched assert methods: increase assert count and store errors.
Object.keys(assert).forEach(function (el) {
api.skip[el] = skipFn;
api[el] = enhanced[el].bind(enhanced);
api[el] = function () {
var event = enhanced[el].apply(enhanced, arguments);
event.methodName = el;
event.numArgs = arguments.length;
return onAssertionEvent(event);
};
});

api._capt = enhanced._capt.bind(enhanced);
Expand Down