From 69045af46c842eae1af76b90e1ba39c131f000b9 Mon Sep 17 00:00:00 2001 From: Roderic Day Date: Tue, 10 Oct 2017 22:53:19 -0400 Subject: [PATCH] Handle newlines in error messages, fixes #1495 --- docs/change-log.md | 7 +++++++ ospec/ospec.js | 5 ++++- ospec/tests/test-ospec.js | 12 ++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/docs/change-log.md b/docs/change-log.md index 92106045..6d60789f 100644 --- a/docs/change-log.md +++ b/docs/change-log.md @@ -21,6 +21,13 @@ - core: don't call `onremove` on the children of components that return null from the view [#1921](https://github.com/MithrilJS/mithril.js/issues/1921) [octavore](https://github.com/octavore) ([#1922](https://github.com/MithrilJS/mithril.js/pull/1922)) - hypertext: correct handling of shared attributes object passed to `m()`. Will copy attributes when it's necessary [#1941](https://github.com/MithrilJS/mithril.js/issues/1941) [s-ilya](https://github.com/s-ilya) ([#1942](https://github.com/MithrilJS/mithril.js/pull/1942)) +#### Ospec improvements + +- Added support for async functions and promises in tests - ([#1928](https://github.com/MithrilJS/mithril.js/pull/1928)) +- Error handling for async tests with `done` callbacks supports error as first argument +- Error messages which include newline characters do not swallow the stack trace [#1495](https://github.com/MithrilJS/mithril.js/issues/1495) ([#1984](https://github.com/MithrilJS/mithril.js/pull/1984), [@ RodericDay](https://github.com/RodericDay)) + + --- ### v1.1.5 diff --git a/ospec/ospec.js b/ospec/ospec.js index 147e2dc4..5c9b223a 100644 --- a/ospec/ospec.js +++ b/ospec/ospec.js @@ -49,6 +49,9 @@ module.exports = new function init(name) { spy.callCount = 0 return spy } + o.cleanStackTrace = function(stack) { + return stack.match(/^(?:(?!Error|[\/\\]ospec[\/\\]ospec\.js).)*$/gm).pop() + } o.run = function() { results = [] start = new Date @@ -235,7 +238,7 @@ module.exports = new function init(name) { var status = 0 for (var i = 0, r; r = results[i]; i++) { if (!r.pass) { - var stackTrace = r.error.match(/^(?:(?!Error|[\/\\]ospec[\/\\]ospec\.js).)*$/m) + var stackTrace = o.cleanStackTrace(r.error) console.error(r.context + ":\n" + highlight(r.message) + (stackTrace ? "\n\n" + stackTrace + "\n\n" : ""), hasProcess ? "" : "color:red", hasProcess ? "" : "color:black") status = 1 } diff --git a/ospec/tests/test-ospec.js b/ospec/tests/test-ospec.js index 69f2e1f1..9b9f24d5 100644 --- a/ospec/tests/test-ospec.js +++ b/ospec/tests/test-ospec.js @@ -149,6 +149,18 @@ o.spec("ospec", function() { }) }) + o.spec('stack trace cleaner', function() { + o('handles line breaks', function() { + try { + throw new Error('line\nbreak') + } catch(error) { + var trace = o.cleanStackTrace(error.stack) + o(trace).notEquals('break') + o(trace.includes("test-ospec.js")).equals(true) + } + }) + }) + o.spec("async promise", function() { var a = 0, b = 0