From ec0b4a2dc6ae950902ea39712c4ec09630085114 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 22 Apr 2014 10:43:55 -0700 Subject: [PATCH] Move deprecation output to its own function --- spec/spec-helper.coffee | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index e64d999cc..af7629f3f 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -125,14 +125,7 @@ afterEach -> jasmine.unspy(atom, 'saveSync') ensureNoPathSubscriptions() atom.syntax.off() - deprecations = Grim.getDeprecations() - if deprecations.length > 0 - for deprecation in deprecations - console.log deprecation - for stack in deprecations.stacks - console.log stack - throw new Error("#{deprecations.length} deprecated methods were called.") - + ensureNoDeprecatedFunctionsCalled() waits(0) # yield to ui thread to make screen update more frequently ensureNoPathSubscriptions = -> @@ -141,6 +134,27 @@ ensureNoPathSubscriptions = -> if watchedPaths.length > 0 throw new Error("Leaking subscriptions for paths: " + watchedPaths.join(", ")) +ensureNoDeprecatedFunctionsCalled = -> + deprecations = Grim.getDeprecations() + if deprecations.length > 0 + originalPrepareStackTrace = Error.prepareStackTrace + Error.prepareStackTrace = (error, stack) -> + output = [] + for deprecation in deprecations + output.push "#{deprecation.originName} is deprecated" + output.push _.multiplyString("-", output[output.length - 1].length) + for stack in deprecation.getStacks() + for {functionName, location} in stack + output.push "#{functionName} -- #{location}" + output.push "" + output.join("\n") + + error = new Error("Deprecated function(s) #{deprecations.map(({originName}) -> originName).join ', '}) were called.") + error.stack + Error.prepareStackTrace = originalPrepareStackTrace + + throw error + emitObject = jasmine.StringPrettyPrinter.prototype.emitObject jasmine.StringPrettyPrinter.prototype.emitObject = (obj) -> if obj.inspect