From 69288dc2b85eadc2e0a735e6bbe7f5a2a7844e6a Mon Sep 17 00:00:00 2001 From: Pete Hopkins Date: Thu, 13 Jun 2013 13:54:50 -0400 Subject: [PATCH] Intercepts jasmine.Spec to stringify it as "[ Spec ]" instead of JSON. This is required for using jasmine-given with the reporter, as that library sets expectations on jasmine.Specs themselves. When the Spec is stringified as JSON, it ends up stringifying the entire Jasmine environment, including previous ExpectationResults. Since those previous ExpectationResults have had their "expected" values stringified, they may include stringified Specs themselves. This leds to exponential growth in the size of stringified Specs. Special-casing jasmine.Spec prevents the exponential growth by short-circuting the value to a small, still-useful String. --- tasks/jasmine/reporters/PhantomReporter.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tasks/jasmine/reporters/PhantomReporter.js b/tasks/jasmine/reporters/PhantomReporter.js index ebc3595..a1c45ae 100644 --- a/tasks/jasmine/reporters/PhantomReporter.js +++ b/tasks/jasmine/reporters/PhantomReporter.js @@ -114,6 +114,11 @@ phantom.sendMessage = function() { // If we're a node if (value instanceof Node) return '[ Node ]'; + // jasmine-given has expectations on Specs. We intercept to return a + // String to avoid stringifying the entire Jasmine environment, which + // results in exponential string growth + if (value instanceof jasmine.Spec) return '[ Spec: ' + value.description + ' ]'; + // If we're a window (logic stolen from jQuery) if (value.window && value.window === value.window.window) return '[ Window ]';