From 6ddf64568eaa1176427056010edec7b00f21eac5 Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Mon, 26 Jun 2017 19:10:19 -0700 Subject: [PATCH 1/8] Add Promise checking to eq Fixes #1314 --- spec/core/matchers/matchersUtilSpec.js | 10 ++++++++++ src/core/base.js | 4 ++++ src/core/matchers/matchersUtil.js | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/spec/core/matchers/matchersUtilSpec.js b/spec/core/matchers/matchersUtilSpec.js index f30621a0..08a50506 100644 --- a/spec/core/matchers/matchersUtilSpec.js +++ b/spec/core/matchers/matchersUtilSpec.js @@ -166,6 +166,16 @@ describe("matchersUtil", function() { expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(true); }); + + it("passes for equivalent Promises (GitHub issue #1314)", function() { + if (typeof Promise === 'undefined') { return; } + + var p1 = new Promise(function () {}), + p2 = new Promise(function () {}); + + expect(jasmineUnderTest.matchersUtil.equals(p1, p1)).toBe(true); + expect(jasmineUnderTest.matchersUtil.equals(p1, p2)).toBe(false); + }); describe("when running in a browser", function() { function isNotRunningInBrowser() { diff --git a/src/core/base.js b/src/core/base.js index 949f9f29..3955c6a5 100644 --- a/src/core/base.js +++ b/src/core/base.js @@ -75,6 +75,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) { return obj.nodeType > 0; }; + j$.isPromise = function(obj) { + return (typeof Promise !== 'undefined') && obj.constructor === Promise; + }; + j$.fnNameFor = function(func) { if (func.name) { return func.name; diff --git a/src/core/matchers/matchersUtil.js b/src/core/matchers/matchersUtil.js index 1ed2ee34..98735f2c 100644 --- a/src/core/matchers/matchersUtil.js +++ b/src/core/matchers/matchersUtil.js @@ -209,6 +209,12 @@ getJasmineRequireObj().matchersUtil = function(j$) { diffBuilder.record(a, b); return false; } + + var aIsPromise = j$.isPromise(a); + var bIsPromise = j$.isPromise(b); + if (aIsPromise && bIsPromise) { + return a === b; + } // Assume equality for cyclic structures. The algorithm for detecting cyclic // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`. From 554d0efab75758e3babe9b8b38eb2390ef7dfaf4 Mon Sep 17 00:00:00 2001 From: sgravrock Date: Wed, 25 Oct 2017 11:28:47 -0700 Subject: [PATCH 2/8] Point CodeClimate at the right repo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 14951bde..01196ada 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [](http://jasmine.github.io) [![Build Status](https://travis-ci.org/jasmine/jasmine.svg?branch=master)](https://travis-ci.org/jasmine/jasmine) -[![Code Climate](https://codeclimate.com/github/pivotal/jasmine.svg)](https://codeclimate.com/github/pivotal/jasmine) +[![Code Climate](https://codeclimate.com/github/jasmine/jasmine.svg)](https://codeclimate.com/github/jasmine/jasmine) ======= From c260c67e7e4f13169a932b96c51d0dfb8ac21349 Mon Sep 17 00:00:00 2001 From: Aaron Ang Date: Thu, 26 Oct 2017 04:56:44 -0700 Subject: [PATCH 3/8] Add instruction to sync local master with upstream --- .github/CONTRIBUTING.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index eb9eb5b5..8bd2f92a 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -16,7 +16,8 @@ Please submit pull requests via feature branches using the semi-standard workflo git clone git@github.com:yourUserName/jasmine.git # Clone your fork cd jasmine # Change directory git remote add upstream https://github.com/jasmine/jasmine.git # Assign original repository to a remote named 'upstream' -git fetch upstream # Pull in changes not present in your local repository +git fetch upstream # Fetch changes not present in your local repository +git merge upstream/master # Sync local master with upstream repository git checkout -b my-new-feature # Create your feature branch git commit -am 'Add some feature' # Commit your changes git push origin my-new-feature # Push to the branch From b4dfdd7a48f5f2de8a6906e97d1b2121b0cb0b35 Mon Sep 17 00:00:00 2001 From: Benjamin Mularczyk Date: Wed, 1 Nov 2017 01:01:26 +0100 Subject: [PATCH 4/8] Fix equality computation for ES6 Sets. --- spec/core/matchers/matchersUtilSpec.js | 16 +++++++++++++++- src/core/matchers/matchersUtil.js | 22 +++++++++++++++++----- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/spec/core/matchers/matchersUtilSpec.js b/spec/core/matchers/matchersUtilSpec.js index 98795db5..0214f84d 100644 --- a/spec/core/matchers/matchersUtilSpec.js +++ b/spec/core/matchers/matchersUtilSpec.js @@ -393,13 +393,27 @@ describe("matchersUtil", function() { expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true); }); - it("passes when comparing identical sets with different insertion order", function() { + it("passes when comparing identical sets with different insertion order and simple elements", function() { jasmine.getEnv().requireFunctioningSets(); var setA = new Set([3, 6]); var setB = new Set([6, 3]); expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true); }); + it("passes when comparing identical sets with different insertion order and complex elements 1", function() { + jasmine.getEnv().requireFunctioningMaps(); + var setA = new Set([new Set([['a', 3], [6, 1]]), new Set([['y', 3], [6, 1]])]); + var setB = new Set([new Set([[6, 1], ['a', 3]]), new Set([[6, 1], ['y', 3]])]); + expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true); + }); + + it("passes when comparing identical sets with different insertion order and complex elements 2", function() { + jasmine.getEnv().requireFunctioningMaps(); + var setA = new Set([[[1,2], [3,4]], [[5,6], [7,8]]]); + var setB = new Set([[[5,6], [7,8]], [[1,2], [3,4]]]); + expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true); + }); + it("fails for sets with different elements", function() { jasmine.getEnv().requireFunctioningSets(); var setA = new Set([6, 3, 5]); diff --git a/src/core/matchers/matchersUtil.js b/src/core/matchers/matchersUtil.js index 71fc0047..07d191e9 100644 --- a/src/core/matchers/matchersUtil.js +++ b/src/core/matchers/matchersUtil.js @@ -296,24 +296,36 @@ getJasmineRequireObj().matchersUtil = function(j$) { // For both sets, check they are all contained in the other set var setPairs = [[a, b], [b, a]]; - var baseIter, baseValueIt, baseValue; - var otherSet, otherIter, otherValueIt, otherValue, found; + var stackPairs = [[aStack, bStack], [bStack, aStack]]; + var baseIter, baseValueIt, baseValue, baseStack; + var otherSet, otherIter, otherValueIt, otherValue, otherStack; + var found; + var prevStackSize; for (i = 0; result && i < setPairs.length; i++) { baseIter = setPairs[i][0].values(); otherSet = setPairs[i][1]; + baseStack = stackPairs[i][0]; + otherStack = stackPairs[i][1]; // For each value in the base set... baseValueIt = baseIter.next(); while (result && !baseValueIt.done) { baseValue = baseValueIt.value; // ... test that it is present in the other set - otherIter = otherSet.values(); - otherValueIt = otherIter.next(); // Optimisation: start looking for value by object identity found = otherSet.has(baseValue); + if (!found) { + otherIter = otherSet.values(); + otherValueIt = otherIter.next(); + } // If not found, compare by value equality while (!found && !otherValueIt.done) { otherValue = otherValueIt.value; - found = eq(baseValue, otherValue, aStack, bStack, customTesters, j$.NullDiffBuilder()); + prevStackSize = baseStack.length; + found = eq(baseValue, otherValue, baseStack, otherStack, customTesters, j$.NullDiffBuilder()); + if (!found && prevStackSize !== baseStack.length) { + baseStack.splice(prevStackSize); + otherStack.splice(prevStackSize); + } otherValueIt = otherIter.next(); } result = result && found; From 2be5e0a9620bb1dff4bbe3530f481a73ef48c73c Mon Sep 17 00:00:00 2001 From: Julian Lannigan Date: Thu, 9 Nov 2017 19:43:48 -0500 Subject: [PATCH 5/8] Allowed async functions to be passed into spy#callFake --- lib/jasmine-core/jasmine.js | 2 +- spec/core/SpyStrategySpec.js | 24 ++++++++++++++++++++++++ src/core/SpyStrategy.js | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index e54501e8..f30b7b00 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -5010,7 +5010,7 @@ getJasmineRequireObj().SpyStrategy = function(j$) { * @param {Function} fn The function to invoke with the passed parameters. */ this.callFake = function(fn) { - if(!j$.isFunction_(fn)) { + if(!(j$.isFunction_(fn) || j$.isAsyncFunction_(fn))) { throw new Error('Argument passed to callFake should be a function, got ' + fn); } plan = fn; diff --git a/spec/core/SpyStrategySpec.js b/spec/core/SpyStrategySpec.js index 0965c04c..2002af76 100644 --- a/spec/core/SpyStrategySpec.js +++ b/spec/core/SpyStrategySpec.js @@ -92,16 +92,40 @@ describe("SpyStrategy", function() { expect(returnValue).toEqual(67); }); + it("allows a fake async function to be called instead", async function(done) { + try { + var originalFn = jasmine.createSpy("original"), + fakeFn = jasmine.createSpy("fake").and.callFake(async function () { return 67; }), + spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn}), + returnValue; + + spyStrategy.callFake(fakeFn); + returnValue = await spyStrategy.exec(); + + expect(originalFn).not.toHaveBeenCalled(); + expect(returnValue).toEqual(67); + + done(); + } catch (err) { + done.fail(err); + } + }); + it('throws an error when a non-function is passed to callFake strategy', function() { var originalFn = jasmine.createSpy('original'), spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn}), invalidFakes = [5, 'foo', {}, true, false, null, void 0, new Date(), /.*/]; spyOn(jasmineUnderTest, 'isFunction_').and.returnValue(false); + spyOn(jasmineUnderTest, 'isAsyncFunction_').and.returnValue(false); expect(function () { spyStrategy.callFake(function() {}); }).toThrowError(/^Argument passed to callFake should be a function, got/); + + expect(function () { + spyStrategy.callFake(async function() {}); + }).toThrowError(/^Argument passed to callFake should be a function, got/); }); it("allows a return to plan stubbing after another strategy", function() { diff --git a/src/core/SpyStrategy.js b/src/core/SpyStrategy.js index 5af7cbee..b0c716f7 100644 --- a/src/core/SpyStrategy.js +++ b/src/core/SpyStrategy.js @@ -88,7 +88,7 @@ getJasmineRequireObj().SpyStrategy = function(j$) { * @param {Function} fn The function to invoke with the passed parameters. */ this.callFake = function(fn) { - if(!j$.isFunction_(fn)) { + if(!(j$.isFunction_(fn) || j$.isAsyncFunction_(fn))) { throw new Error('Argument passed to callFake should be a function, got ' + fn); } plan = fn; From 6ef0e93880e63b9b213dfdcfeb6716c6d39f743e Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Thu, 9 Nov 2017 20:57:01 -0800 Subject: [PATCH 6/8] Revert "Removed IE 8 and 9 from the testing matrix" In case we end doing another 2.x release. This reverts commit 0e95b04900604a1d5ac05a404b91f556951eaee9. --- .travis.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.travis.yml b/.travis.yml index b8663be6..9d1f7567 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,6 +45,14 @@ matrix: - JASMINE_BROWSER="internet explorer" - SAUCE_OS="Windows 8" - SAUCE_BROWSER_VERSION=10 + - env: + - JASMINE_BROWSER="internet explorer" + - SAUCE_OS="Windows 7" + - SAUCE_BROWSER_VERSION=9 + - env: + - JASMINE_BROWSER="internet explorer" + - SAUCE_OS="Windows 7" + - SAUCE_BROWSER_VERSION=8 - env: - JASMINE_BROWSER="chrome" - SAUCE_OS="Linux" From 7ac1244f58eb1faa37ae2862e167363b891c4b19 Mon Sep 17 00:00:00 2001 From: Julian Lannigan Date: Fri, 10 Nov 2017 10:17:48 -0500 Subject: [PATCH 7/8] changed tests to work in environments that dont support async/await --- spec/core/SpyStrategySpec.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/spec/core/SpyStrategySpec.js b/spec/core/SpyStrategySpec.js index 2002af76..16f1af18 100644 --- a/spec/core/SpyStrategySpec.js +++ b/spec/core/SpyStrategySpec.js @@ -92,23 +92,22 @@ describe("SpyStrategy", function() { expect(returnValue).toEqual(67); }); - it("allows a fake async function to be called instead", async function(done) { - try { - var originalFn = jasmine.createSpy("original"), - fakeFn = jasmine.createSpy("fake").and.callFake(async function () { return 67; }), - spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn}), - returnValue; - - spyStrategy.callFake(fakeFn); - returnValue = await spyStrategy.exec(); + it("allows a fake async function to be called instead", function(done) { + jasmine.getEnv().requireAsyncAwait(); + var originalFn = jasmine.createSpy("original"), + fakeFn = jasmine.createSpy("fake").and.callFake(eval("async () => { return 67; }")), + spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn}), + returnValue; + spyStrategy.callFake(fakeFn); + spyStrategy.exec().then(function (returnValue) { expect(originalFn).not.toHaveBeenCalled(); + expect(fakeFn).toHaveBeenCalled(); expect(returnValue).toEqual(67); - done(); - } catch (err) { + }).catch(function (err) { done.fail(err); - } + }) }); it('throws an error when a non-function is passed to callFake strategy', function() { @@ -124,7 +123,7 @@ describe("SpyStrategy", function() { }).toThrowError(/^Argument passed to callFake should be a function, got/); expect(function () { - spyStrategy.callFake(async function() {}); + spyStrategy.callFake(function() {}); }).toThrowError(/^Argument passed to callFake should be a function, got/); }); From 2eef0747a0301d3f355860c4ba2a4ce58239c173 Mon Sep 17 00:00:00 2001 From: Julian Lannigan Date: Fri, 10 Nov 2017 10:22:58 -0500 Subject: [PATCH 8/8] Added test steps for other major node versions addresses https://www.pivotaltracker.com/story/show/152685778 --- .travis.yml | 11 ++++++++++- travis-node-script.sh | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b8663be6..db5fb003 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,16 @@ matrix: include: - env: - USE_SAUCE=false - - TEST_COMMAND="bash travis-node-script.sh" + - TEST_COMMAND="bash travis-node-script.sh v0.12.18" + - env: + - USE_SAUCE=false + - TEST_COMMAND="bash travis-node-script.sh v4" + - env: + - USE_SAUCE=false + - TEST_COMMAND="bash travis-node-script.sh v8" + - env: + - USE_SAUCE=false + - TEST_COMMAND="bash travis-node-script.sh v9" - env: - JASMINE_BROWSER="safari" - SAUCE_OS="OS X 10.11" diff --git a/travis-node-script.sh b/travis-node-script.sh index 6fa0ded0..fe3859b7 100644 --- a/travis-node-script.sh +++ b/travis-node-script.sh @@ -4,7 +4,7 @@ rm -rf ~/.nvm git clone https://github.com/creationix/nvm.git ~/.nvm (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) source ~/.nvm/nvm.sh -nvm install v0.12.18 +nvm install ${1:-"v0.12.18"} npm install npm test