From e34d8e4c42b9c23bb8b95385c21b8e4abbcaacd8 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Sat, 6 Jul 2013 14:15:04 -0700 Subject: [PATCH] Display CoffeeScript line numbers in stack traces Use coffeestack to convert stack traces to have CoffeeScript line and column numbers in the output instead of JavaScript line and column numbers. --- package.json | 1 + spec/atom-reporter.coffee | 30 ++++++++++++++++-------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 5c71491d4..c80db2ffd 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "semver": "1.1.4", "guid": "0.0.10", "tantamount": "0.3.0", + "coffeestack": "0.4.0", "c-tmbundle": "1.0.0", "coffee-script-tmbundle": "2.0.0", "css-tmbundle": "1.0.0", diff --git a/spec/atom-reporter.coffee b/spec/atom-reporter.coffee index 90e15106e..106f71519 100644 --- a/spec/atom-reporter.coffee +++ b/spec/atom-reporter.coffee @@ -1,6 +1,19 @@ $ = require 'jquery' {View, $$} = require 'space-pen' _ = require 'underscore' +{convertStackTrace} = require 'coffeestack' + +sourceMaps = {} +formatStackTrace = (stackTrace) -> + return stackTrace unless stackTrace + + jasminePath = require.resolve('jasmine') + jasminePattern = new RegExp("\\(#{_.escapeRegExp(jasminePath)}:\\d+:\\d+\\)\\s*$") + convertedLines = [] + for line in stackTrace.split('\n') + convertedLines.push(line) unless jasminePattern.test(line) + + convertStackTrace(convertedLines.join('\n'), sourceMaps) module.exports = class AtomReporter extends View @@ -42,6 +55,7 @@ class AtomReporter extends View reportSpecResults: (spec) -> @completeSpecCount++ + spec.endedAt = new Date().getTime() @specComplete(spec) @updateStatusView(spec) @@ -99,7 +113,7 @@ class AtomReporter extends View rootSuite = rootSuite.parentSuite while rootSuite.parentSuite @message.text rootSuite.description - time = "#{Math.round((new Date().getTime() - @startedAt.getTime()) / 10)}" + time = "#{Math.round((spec.endedAt - @startedAt.getTime()) / 10)}" time = "0#{time}" if time.length < 3 @time.text "#{time[0...-2]}.#{time[-2..]}s" @@ -166,7 +180,7 @@ class SpecResultView extends View @description.html @spec.description for result in @spec.results().getItems() when not result.passed() - stackTrace = @formatStackTrace(result.trace.stack) + stackTrace = formatStackTrace(result.trace.stack) @specFailures.append $$ -> @div result.message, class: 'resultMessage fail' @div stackTrace, class: 'stackTrace' if stackTrace @@ -174,18 +188,6 @@ class SpecResultView extends View attach: -> @parentSuiteView().append this - formatStackTrace: (stackTrace) -> - return stackTrace unless stackTrace - - jasminePath = require.resolve('jasmine') - jasminePattern = new RegExp("\\(#{_.escapeRegExp(jasminePath)}:\\d+:\\d+\\)\\s*$") - convertedLines = [] - for line in stackTrace.split('\n') - unless jasminePattern.test(line) - convertedLines.push(line) - - convertedLines.join('\n') - parentSuiteView: -> if not suiteView = $(".suite-view-#{@spec.suite.id}").view() suiteView = new SuiteResultView(@spec.suite)