From ef369da11536e77c6962a1e35d2e5da8acc5fccd Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 17 Aug 2017 18:38:32 -0700 Subject: [PATCH 1/2] Don't use unnecessary stubs Stubs permanently record the arguments for every call, i.e. they leak memory. Don't use them unless you actually need to inspect the arguments. --- src/util/window.js | 4 ++-- test/suite_implementation.js | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/util/window.js b/src/util/window.js index 00ad87ac62a..4573a9c4d45 100644 --- a/src/util/window.js +++ b/src/util/window.js @@ -42,7 +42,7 @@ function restore(): Window { }; window.useFakeHTMLCanvasGetContext = function() { - this.HTMLCanvasElement.prototype.getContext = sinon.stub().returns('2d'); + this.HTMLCanvasElement.prototype.getContext = function() { return '2d'; }; }; window.useFakeXMLHttpRequest = function() { @@ -55,7 +55,7 @@ function restore(): Window { window.restore = restore; - window.ImageData = window.ImageData || sinon.stub().returns(false); + window.ImageData = window.ImageData || function() { return false; }; util.extend(module.exports, window); diff --git a/test/suite_implementation.js b/test/suite_implementation.js index 4ccf8a04c4b..e99a8633ae5 100644 --- a/test/suite_implementation.js +++ b/test/suite_implementation.js @@ -1,7 +1,6 @@ 'use strict'; const ajax = require('../src/util/ajax'); -const sinon = require('sinon'); const request = require('request'); const PNG = require('pngjs').PNG; const Map = require('../src/ui/map'); @@ -126,7 +125,7 @@ function cached(data, callback) { }); } -sinon.stub(ajax, 'getJSON').callsFake(({ url }, callback) => { +ajax.getJSON = function({ url }, callback) { if (cache[url]) return cached(cache[url], callback); return request(url, (error, response, body) => { if (!error && response.statusCode >= 200 && response.statusCode < 300) { @@ -142,9 +141,9 @@ sinon.stub(ajax, 'getJSON').callsFake(({ url }, callback) => { callback(error || new Error(response.statusCode)); } }); -}); +}; -sinon.stub(ajax, 'getArrayBuffer').callsFake(({ url }, callback) => { +ajax.getArrayBuffer = function({ url }, callback) { if (cache[url]) return cached(cache[url], callback); return request({ url, encoding: null }, (error, response, body) => { if (!error && response.statusCode >= 200 && response.statusCode < 300) { @@ -154,9 +153,9 @@ sinon.stub(ajax, 'getArrayBuffer').callsFake(({ url }, callback) => { callback(error || new Error(response.statusCode)); } }); -}); +}; -sinon.stub(ajax, 'getImage').callsFake(({ url }, callback) => { +ajax.getImage = function({ url }, callback) { if (cache[url]) return cached(cache[url], callback); return request({ url, encoding: null }, (error, response, body) => { if (!error && response.statusCode >= 200 && response.statusCode < 300) { @@ -169,15 +168,15 @@ sinon.stub(ajax, 'getImage').callsFake(({ url }, callback) => { callback(error || new Error(response.statusCode)); } }); -}); +}; -sinon.stub(browser, 'getImageData').callsFake((img) => { +browser.getImageData = function(img) { return new Uint8Array(img.data); -}); +}; // Hack: since node doesn't have any good video codec modules, just grab a png with // the first frame and fake the video API. -sinon.stub(ajax, 'getVideo').callsFake((urls, callback) => { +ajax.getVideo = function(urls, callback) { return request({ url: urls[0], encoding: null }, (error, response, body) => { if (!error && response.statusCode >= 200 && response.statusCode < 300) { new PNG().parse(body, (err, png) => { @@ -195,4 +194,4 @@ sinon.stub(ajax, 'getVideo').callsFake((urls, callback) => { callback(error || new Error(response.statusCode)); } }); -}); +}; From 05903ab16d2dcf661e19c19f43ed6e913c6ab366 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 17 Aug 2017 18:50:06 -0700 Subject: [PATCH 2/2] Use default Circle CI resource class --- .circleci/config.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 59e008f664a..ed30dfad694 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -21,7 +21,6 @@ jobs: docker: - image: mbgl/ci:r4-linux-gl-js working_directory: ~/mapbox-gl-js - resource_class: large steps: - checkout - restore_cache: @@ -47,7 +46,6 @@ jobs: docker: - image: mbgl/ci:r4-linux-gl-js working_directory: ~/mapbox-gl-js - resource_class: large steps: - checkout - restore_cache: