From 562f04a396bf1ca3d33fe1bbb21a499bda60ec3e Mon Sep 17 00:00:00 2001 From: James Talmage Date: Tue, 15 Dec 2015 16:58:57 -0500 Subject: [PATCH] WIP - capture and log assertion messages. --- lib/test.js | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/test.js b/lib/test.js index 0cb9aea8b..2c00c7541 100644 --- a/lib/test.js +++ b/lib/test.js @@ -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; @@ -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);