From 644a407b43d2376e51e6348c0faf1b9d1ddce6dd Mon Sep 17 00:00:00 2001 From: Denis Bardadym Date: Sat, 10 Dec 2016 13:38:57 +0300 Subject: [PATCH] Release 11.1.2 --- History.md | 5 +++++ package.json | 4 ++-- should.js | 37 +++++++++++++++++++++++++++++++++---- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/History.md b/History.md index 2d9eb46..798f462 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,8 @@ +11.1.2 / 2016-12-10 +=================== + + * Added workaround for runtimes where error's stack populated eagerly + 11.1.1 / 2016-10-10 =================== diff --git a/package.json b/package.json index 0669146..00bc09d 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "should", "description": "test framework agnostic BDD-style assertions", - "version": "11.1.1", - "author": "TJ Holowaychuk , Denis Bardadym and other contributors", + "version": "11.1.2", + "author": "TJ Holowaychuk , Denis Bardadym ", "repository": { "type": "git", "url": "https://github.com/shouldjs/should.js.git" diff --git a/should.js b/should.js index eab4d20..a6cb90f 100644 --- a/should.js +++ b/should.js @@ -1,7 +1,7 @@ /*! * should - test framework agnostic BDD-style assertions - * @version v11.1.1 - * @author TJ Holowaychuk , Denis Bardadym and other contributors + * @version v11.1.2 + * @author TJ Holowaychuk , Denis Bardadym * @link https://github.com/shouldjs/should.js * @license MIT */ @@ -1500,6 +1500,28 @@ } }); + // a bit hacky way how to get error to do not have stack + function LightAssertionError(options) { + merge(this, options); + + if (!options.message) { + Object.defineProperty(this, 'message', { + get: function() { + if (!this._message) { + this._message = this.generateMessage(); + this.generatedMessage = true; + } + return this._message; + } + }); + } + } + + LightAssertionError.prototype = { + generateMessage: AssertionError.prototype.generateMessage + }; + + /** * should Assertion * @param {*} obj Given object for assertion @@ -1562,7 +1584,11 @@ params.assertion = this; - throw new AssertionError(params); + if (this.light) { + throw new LightAssertionError(params); + } else { + throw new AssertionError(params); + } }, /** @@ -1635,12 +1661,13 @@ value: function() { var context = new Assertion(this.obj, this, name); context.anyOne = this.anyOne; + context.light = true; try { func.apply(context, arguments); } catch (e) { // check for fail - if (e instanceof AssertionError) { + if (e instanceof AssertionError || e instanceof LightAssertionError) { // negative fail if (this.negate) { this.obj = context.obj; @@ -1654,6 +1681,7 @@ // positive fail context.negate = false; + context.light = false; context.fail(); } // throw if it is another exception @@ -1664,6 +1692,7 @@ if (this.negate) { context.negate = true; // because .fail will set negate context.params.details = 'false negative fail'; + context.light = false; context.fail(); }