diff --git a/modules/core/history.js b/modules/core/history.js index e32cdf8bd..0f330b2a7 100644 --- a/modules/core/history.js +++ b/modules/core/history.js @@ -321,15 +321,7 @@ export function coreHistory(context) { } }); }); - if (window.mocha) { - var arr = []; - s.forEach(function(v) { arr.push(v); }); - return arr; - } else { - return Array.from(s); - } - // var arr = _map(_stack.slice(1, _index + 1), 'imageryUsed'); - // return _without(_uniq(_flatten(arr)), 'Custom'); + return Array.from(s); } }, diff --git a/package.json b/package.json index 602aeb18c..deee233bc 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "imagery": "node data/update_imagery", "lint": "eslint *.js test/spec modules", "start": "node development_server.js develop", + "phantom": "phantomjs --web-security=no node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js test/phantom.html spec", "test": "npm-run-all -s lint build test:**", "test:phantom": "phantomjs --web-security=no node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js test/index.html spec", "translations": "node data/update_locales" diff --git a/test/phantom.html b/test/phantom.html new file mode 100644 index 000000000..162d87283 --- /dev/null +++ b/test/phantom.html @@ -0,0 +1,39 @@ + + + + + + Mocha Tests + + + + + + +
+ + + + + + + + + + + + + + + + + + + + diff --git a/test/spec/phantom.js b/test/spec/phantom.js new file mode 100644 index 000000000..6d0616e0d --- /dev/null +++ b/test/spec/phantom.js @@ -0,0 +1,7 @@ +describe('test some capabilities of PhantomJS', function () { + it('Array.from(Set)', function () { + var s = new Set([1,1]); + var result = Array.from(s); + expect(result).to.eql([1]); + }); +}); diff --git a/test/spec/spec_helpers.js b/test/spec/spec_helpers.js index c1bd68a53..1453e023f 100644 --- a/test/spec/spec_helpers.js +++ b/test/spec/spec_helpers.js @@ -36,4 +36,18 @@ mocha.setup({ expect = chai.expect; -window.d3 = iD.d3; // TODO: remove +window.d3 = iD.d3; // TODO: remove if we can avoid exporting all of d3.js + + +// workaround for `Array.from` polyfill in PhantomJS +// https://github.com/openstreetmap/iD/issues/6087#issuecomment-476219308 +var __arrayfrom = Array.from; +Array.from = function(what) { + if (what instanceof Set) { + var arr = []; + what.forEach(function(v) { arr.push(v); }); + return arr; + } else { + return __arrayfrom.apply(null, arguments); + } +};