From 64b4954492bbd33eababf0ea0b575947ccba21f0 Mon Sep 17 00:00:00 2001 From: Wliu <50Wliu@users.noreply.github.com> Date: Tue, 21 Nov 2017 23:35:26 +0100 Subject: [PATCH 1/3] Improve spec stack traces --- spec/atom-reporter.coffee | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/spec/atom-reporter.coffee b/spec/atom-reporter.coffee index 455afcb27..1df74f64d 100644 --- a/spec/atom-reporter.coffee +++ b/spec/atom-reporter.coffee @@ -9,34 +9,40 @@ ipcHelpers = require '../src/ipc-helpers' formatStackTrace = (spec, message='', stackTrace) -> return stackTrace unless stackTrace + # at ... (.../jasmine.js:1:2) jasminePattern = /^\s*at\s+.*\(?.*[/\\]jasmine(-[^/\\]*)?\.js:\d+:\d+\)?\s*$/ - firstJasmineLinePattern = /^\s*at [/\\].*[/\\]jasmine(-[^/\\]*)?\.js:\d+:\d+\)?\s*$/ + # at jasmine.Something... (.../jasmine.js:1:2) + firstJasmineLinePattern = /^\s*at\s+jasmine\.[A-Z][^\s]*\s+\(?.*[/\\]jasmine(-[^/\\]*)?\.js:\d+:\d+\)?\s*$/ lines = [] for line in stackTrace.split('\n') - lines.push(line) unless jasminePattern.test(line) break if firstJasmineLinePattern.test(line) + lines.push(line) unless jasminePattern.test(line) # Remove first line of stack when it is the same as the error message errorMatch = lines[0]?.match(/^Error: (.*)/) lines.shift() if message.trim() is errorMatch?[1]?.trim() - for line, index in lines - # Remove prefix of lines matching: at jasmine.Spec. (path:1:2) - prefixMatch = line.match(/at jasmine\.Spec\. \(([^)]+)\)/) - line = "at #{prefixMatch[1]}" if prefixMatch + lines = lines.map (line) -> + line = line + # at jasmine.Spec. (path:1:2) -> at path:1:2 + .replace(/at jasmine\.Spec\. \(([^)]+)\)/, 'at $1') + # at it (path:1:2) -> at path:1:2 + .replace(/at f*it \(([^)]+)\)/, 'at $1') + # at spec/file-test.js -> at file-test.js + .replace("at #{spec.specDirectory}#{path.sep}", 'at ') + # (spec/file-test.js:1:2) -> (file-test.js:1:2) + .replace("(#{spec.specDirectory}#{path.sep}", '(') - # Relativize locations to spec directory - if process.platform is 'win32' + if process.platform is 'win32' and /file:\/\/\//.test(line) + # file:///C:/some/file -> C:\some\file line = line.replace('file:///', '').replace(///#{path.posix.sep}///g, path.win32.sep) - line = line.replace("at #{spec.specDirectory}#{path.sep}", 'at ') - lines[index] = line.replace("(#{spec.specDirectory}#{path.sep}", '(') # at step (path:1:2) - lines = lines.map (line) -> line.trim() + return line.trim() + lines.join('\n').trim() module.exports = class AtomReporter - constructor: -> @element = document.createElement('div') @element.classList.add('spec-reporter-container') From 34df49b491f6d98d4eaacadb6956a30d9305a573 Mon Sep 17 00:00:00 2001 From: Wliu <50Wliu@users.noreply.github.com> Date: Wed, 22 Nov 2017 00:02:42 +0100 Subject: [PATCH 2/3] More cleanup --- spec/atom-reporter.coffee | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/spec/atom-reporter.coffee b/spec/atom-reporter.coffee index 1df74f64d..ba06cd31d 100644 --- a/spec/atom-reporter.coffee +++ b/spec/atom-reporter.coffee @@ -23,21 +23,21 @@ formatStackTrace = (spec, message='', stackTrace) -> lines.shift() if message.trim() is errorMatch?[1]?.trim() lines = lines.map (line) -> - line = line - # at jasmine.Spec. (path:1:2) -> at path:1:2 - .replace(/at jasmine\.Spec\. \(([^)]+)\)/, 'at $1') - # at it (path:1:2) -> at path:1:2 - .replace(/at f*it \(([^)]+)\)/, 'at $1') - # at spec/file-test.js -> at file-test.js - .replace("at #{spec.specDirectory}#{path.sep}", 'at ') - # (spec/file-test.js:1:2) -> (file-test.js:1:2) - .replace("(#{spec.specDirectory}#{path.sep}", '(') + line = line.trim() + if line.startsWith('at ') + line = line + # at jasmine.Spec. (path:1:2) -> at path:1:2 + .replace(/^at jasmine\.Spec\. \(([^)]+)\)/, 'at $1') + # at it (path:1:2) -> at path:1:2 + .replace(/^at f*it \(([^)]+)\)/, 'at $1') + # at spec/file-test.js -> at file-test.js + .replace(spec.specDirectory + path.sep, '') - if process.platform is 'win32' and /file:\/\/\//.test(line) - # file:///C:/some/file -> C:\some\file - line = line.replace('file:///', '').replace(///#{path.posix.sep}///g, path.win32.sep) + if process.platform is 'win32' and /file:\/\/\//.test(line) + # file:///C:/some/file -> C:\some\file + line = line.replace('file:///', '').replace(///#{path.posix.sep}///g, path.win32.sep) - return line.trim() + return line lines.join('\n').trim() From 6633714e110a7d5170971e08717d5c99fb57689d Mon Sep 17 00:00:00 2001 From: Wliu <50Wliu@users.noreply.github.com> Date: Wed, 22 Nov 2017 00:31:06 +0100 Subject: [PATCH 3/3] Fix regression and minimize chance for incorrect replacements --- spec/atom-reporter.coffee | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/spec/atom-reporter.coffee b/spec/atom-reporter.coffee index ba06cd31d..a522d9298 100644 --- a/spec/atom-reporter.coffee +++ b/spec/atom-reporter.coffee @@ -23,9 +23,14 @@ formatStackTrace = (spec, message='', stackTrace) -> lines.shift() if message.trim() is errorMatch?[1]?.trim() lines = lines.map (line) -> - line = line.trim() - if line.startsWith('at ') - line = line + # Only format actual stacktrace lines + if /^\s*at\s/.test(line) + # Needs to occur before path relativization + if process.platform is 'win32' and /file:\/\/\//.test(line) + # file:///C:/some/file -> C:\some\file + line = line.replace('file:///', '').replace(///#{path.posix.sep}///g, path.win32.sep) + + line = line.trim() # at jasmine.Spec. (path:1:2) -> at path:1:2 .replace(/^at jasmine\.Spec\. \(([^)]+)\)/, 'at $1') # at it (path:1:2) -> at path:1:2 @@ -33,10 +38,6 @@ formatStackTrace = (spec, message='', stackTrace) -> # at spec/file-test.js -> at file-test.js .replace(spec.specDirectory + path.sep, '') - if process.platform is 'win32' and /file:\/\/\//.test(line) - # file:///C:/some/file -> C:\some\file - line = line.replace('file:///', '').replace(///#{path.posix.sep}///g, path.win32.sep) - return line lines.join('\n').trim()