Merge pull request #1984 from RodericDay/newlines-in-error-messages

Handle newlines in error messages, fixes #1495
This commit is contained in:
Isiah Meadows 2017-10-28 20:20:34 -04:00 committed by GitHub
commit 3c608f26b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View file

@ -30,6 +30,7 @@
- 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))
#### Bug fixes

View file

@ -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
}

View file

@ -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