From 39472ab63915207f0c9f639d0f873364350fcc3b Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Sat, 26 Oct 2019 17:11:01 +0200 Subject: [PATCH 01/24] Added nyc for testint coverage --- .gitignore | 2 ++ package.json | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 239ecff..c7e268f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules yarn.lock +.nyc_output/ +coverage/ diff --git a/package.json b/package.json index cc8f490..e4430ee 100644 --- a/package.json +++ b/package.json @@ -7,14 +7,15 @@ "author": { "name": "Addy Osmani", "email": "addyosmani@gmail.com", - "url": "addyosmani.com" + "url": "https://addyosmani.com" }, "bin": "cli.js", "engines": { "node": ">=6" }, "scripts": { - "test": "xo && mocha" + "test": "xo && mocha", + "coverage": "nyc --reporter=html --reporter=text mocha" }, "files": [ "cli.js", @@ -49,6 +50,7 @@ "devDependencies": { "chai": "^4.2.0", "mocha": "^6.0.2", + "nyc": "^14.1.1", "xo": "^0.24.0" }, "xo": { From 1f65651239b336384fbe4465e9f4ac9208690e0d Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Sat, 26 Oct 2019 18:49:01 +0200 Subject: [PATCH 02/24] Added index test --- test/index.test.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 test/index.test.js diff --git a/test/index.test.js b/test/index.test.js new file mode 100644 index 0000000..807f393 --- /dev/null +++ b/test/index.test.js @@ -0,0 +1,14 @@ +/* eslint-env mocha */ +const {expect} = require('chai'); + +const psi = require('..'); + +describe('Index file', () => { + it('should throw an error if no url is passed to cli', async () => { + await psi('') + .then(result => result) + .catch(error => { + expect(error.message).to.eql('URL required'); + }); + }); +}); From e95fe41fb8d44e66125fbc07da9e70ac6047c6a6 Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Sun, 27 Oct 2019 12:48:32 +0100 Subject: [PATCH 03/24] Added test to check handleOpts method in index file --- package.json | 1 + test/index.test.js | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/package.json b/package.json index cc8f490..27eebe6 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "devDependencies": { "chai": "^4.2.0", "mocha": "^6.0.2", + "rewire": "^4.0.1", "xo": "^0.24.0" }, "xo": { diff --git a/test/index.test.js b/test/index.test.js index 807f393..21e9289 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,5 +1,9 @@ /* eslint-env mocha */ const {expect} = require('chai'); +const rewire = require('rewire'); + +const psiWired = rewire('..'); +const handleOptions = psiWired.__get__('handleOpts'); const psi = require('..'); @@ -11,4 +15,24 @@ describe('Index file', () => { expect(error.message).to.eql('URL required'); }); }); + describe('handleOpts method', () => { + const defaultConfig = { + nokey: true, + url: 'http://addyosmani.com' + }; + it('should return strategy "mobile" if no strategy is passed', () => { + const expectedOutput = { + ...defaultConfig, + strategy: 'mobile' + }; + expect(handleOptions('http://addyosmani.com')).to.eql(expectedOutput); + }); + it('should return strategy "desktop" if "desktop" is passed as strategy', () => { + const expectedOutput = { + ...defaultConfig, + strategy: 'desktop' + }; + expect(handleOptions('http://addyosmani.com', {strategy: 'desktop'})).to.eql(expectedOutput); + }); + }); }); From 57fd768327eb0524de196b0495f15bc70cc5c16f Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Fri, 8 Nov 2019 21:55:47 +0100 Subject: [PATCH 04/24] Tests improvements - Removed call to api. - Added test to options handler instead --- package.json | 2 +- test/api-response.test.js | 32 ++++++++++++++++---------------- test/index.test.js | 3 ++- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 65142d8..918bfdb 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "node": ">=6" }, "scripts": { - "test": "xo && mocha" + "test": "mocha" }, "files": [ "cli.js", diff --git a/test/api-response.test.js b/test/api-response.test.js index 6571bb8..1c4d193 100644 --- a/test/api-response.test.js +++ b/test/api-response.test.js @@ -1,20 +1,20 @@ /* eslint-env mocha */ -'use strict'; -const {assert} = require('chai'); -const psi = require('..'); +// 'use strict'; +// const {assert} = require('chai'); +// const psi = require('..'); -describe('API', function () { - this.timeout(50000); +// describe('API', function () { +// this.timeout(50000); - it('should get data from PageSpeed Insights', () => { - return psi('addyosmani.com/').then(data => { - assert.include(data.data.id, 'addyosmani.com'); - }); - }); +// it('should get data from PageSpeed Insights', () => { +// return psi('addyosmani.com/').then(data => { +// assert.include(data.data.id, 'addyosmani.com'); +// }); +// }); - it('should support options', () => { - return psi('addyosmani.com/', {locale: 'no'}).then(data => { - assert.strictEqual(data.data.lighthouseResult.configSettings.locale, 'no'); - }); - }); -}); +// it('should support options', () => { +// return psi('addyosmani.com/', {locale: 'no'}).then(data => { +// assert.strictEqual(data.data.lighthouseResult.configSettings.locale, 'no'); +// }); +// }); +// }); diff --git a/test/index.test.js b/test/index.test.js index 21e9289..478564a 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -15,11 +15,12 @@ describe('Index file', () => { expect(error.message).to.eql('URL required'); }); }); - describe('handleOpts method', () => { + describe('handleOpts method', async () => { const defaultConfig = { nokey: true, url: 'http://addyosmani.com' }; + it('should return strategy "mobile" if no strategy is passed', () => { const expectedOutput = { ...defaultConfig, From 21a15616bd96079fe1956f4afb69372a7fa2b015 Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Sat, 9 Nov 2019 18:03:33 +0100 Subject: [PATCH 05/24] Updated some npm dependencies --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 918bfdb..337dea0 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,8 @@ "dependencies": { "chalk": "^2.4.2", "download": "^7.0.0", - "googleapis": "^38.0.0", - "humanize-url": "^1.0.1", + "googleapis": "^45.0.0", + "humanize-url": "^2.1.0", "lodash": "^4.17.11", "meow": "^5.0.0", "pify": "^4.0.0", @@ -50,7 +50,7 @@ "chai": "^4.2.0", "mocha": "^6.0.2", "rewire": "^4.0.1", - "xo": "^0.24.0" + "xo": "^0.25.3" }, "xo": { "space": true From 695a877b2d4944cd8a168466c34a28135f2d6d03 Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Wed, 20 Nov 2019 00:02:39 +0100 Subject: [PATCH 06/24] Removed commented tests --- test/api-response.test.js | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 test/api-response.test.js diff --git a/test/api-response.test.js b/test/api-response.test.js deleted file mode 100644 index 1c4d193..0000000 --- a/test/api-response.test.js +++ /dev/null @@ -1,20 +0,0 @@ -/* eslint-env mocha */ -// 'use strict'; -// const {assert} = require('chai'); -// const psi = require('..'); - -// describe('API', function () { -// this.timeout(50000); - -// it('should get data from PageSpeed Insights', () => { -// return psi('addyosmani.com/').then(data => { -// assert.include(data.data.id, 'addyosmani.com'); -// }); -// }); - -// it('should support options', () => { -// return psi('addyosmani.com/', {locale: 'no'}).then(data => { -// assert.strictEqual(data.data.lighthouseResult.configSettings.locale, 'no'); -// }); -// }); -// }); From a05bdfa84e95c0d2284db8f9b710996110bec7bd Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Thu, 21 Nov 2019 18:51:55 +0100 Subject: [PATCH 07/24] Update test/index.test.js Co-Authored-By: Shane Exterkamp --- test/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.test.js b/test/index.test.js index 478564a..e968c41 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -28,7 +28,7 @@ describe('Index file', () => { }; expect(handleOptions('http://addyosmani.com')).to.eql(expectedOutput); }); - it('should return strategy "desktop" if "desktop" is passed as strategy', () => { + it('should respect passed strategy options', () => { const expectedOutput = { ...defaultConfig, strategy: 'desktop' From 6a37baad3fcf84915914b3258d19d44e30a9ef17 Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Thu, 21 Nov 2019 18:52:05 +0100 Subject: [PATCH 08/24] Update test/output.test.js Co-Authored-By: Shane Exterkamp --- test/output.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/output.test.js b/test/output.test.js index 989cea0..d834983 100644 --- a/test/output.test.js +++ b/test/output.test.js @@ -11,7 +11,7 @@ describe('getThreshold method', () => { expect(getThreshold(false)).to.equal(70); expect(getThreshold(101)).to.equal(70); }); - it('should return the passed threshold value if correct', () => { + it('should respect passed threshold values', () => { expect(getThreshold(80)).to.equal(80); }); }); From 862aa5896927771f3acb3740334fd17569960667 Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Thu, 21 Nov 2019 19:09:13 +0100 Subject: [PATCH 09/24] Reverted api-response.test --- test/api-response.test.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/api-response.test.js diff --git a/test/api-response.test.js b/test/api-response.test.js new file mode 100644 index 0000000..6571bb8 --- /dev/null +++ b/test/api-response.test.js @@ -0,0 +1,20 @@ +/* eslint-env mocha */ +'use strict'; +const {assert} = require('chai'); +const psi = require('..'); + +describe('API', function () { + this.timeout(50000); + + it('should get data from PageSpeed Insights', () => { + return psi('addyosmani.com/').then(data => { + assert.include(data.data.id, 'addyosmani.com'); + }); + }); + + it('should support options', () => { + return psi('addyosmani.com/', {locale: 'no'}).then(data => { + assert.strictEqual(data.data.lighthouseResult.configSettings.locale, 'no'); + }); + }); +}); From 6ed67cb67d216c9045b86cc39eaca7e5e675eb7d Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Thu, 21 Nov 2019 19:30:52 +0100 Subject: [PATCH 10/24] Reverted googleapis npm dependency to previous verison --- .gitignore | 2 -- package.json | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index c7e268f..239ecff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ node_modules yarn.lock -.nyc_output/ -coverage/ diff --git a/package.json b/package.json index baad5d6..1c9b0ec 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "node": ">=6" }, "scripts": { - "test": "mocha" + "test": "xo && mocha" }, "files": [ "cli.js", @@ -34,7 +34,7 @@ "dependencies": { "chalk": "^2.4.2", "download": "^7.0.0", - "googleapis": "^45.0.0", + "googleapis": "^38.0.0", "humanize-url": "^2.1.0", "lodash": "^4.17.11", "meow": "^5.0.0", From 94fe5362a797885695ce361a3d054819bf803aa5 Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Mon, 25 Nov 2019 19:50:39 +0100 Subject: [PATCH 11/24] Added proposed change of test definition --- test/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.test.js b/test/index.test.js index e968c41..5448c98 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -21,7 +21,7 @@ describe('Index file', () => { url: 'http://addyosmani.com' }; - it('should return strategy "mobile" if no strategy is passed', () => { + it('should respect passed strategy options', () => { const expectedOutput = { ...defaultConfig, strategy: 'mobile' From 8e8ab8158d89101aa202f7b76566bfe28f26e075 Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Mon, 25 Nov 2019 19:52:09 +0100 Subject: [PATCH 12/24] Revert unnecessary change --- test/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.test.js b/test/index.test.js index 5448c98..e968c41 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -21,7 +21,7 @@ describe('Index file', () => { url: 'http://addyosmani.com' }; - it('should respect passed strategy options', () => { + it('should return strategy "mobile" if no strategy is passed', () => { const expectedOutput = { ...defaultConfig, strategy: 'mobile' From 22c9e7719544898082fc8e9465a8543bd689f3b5 Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Tue, 26 Nov 2019 23:38:44 +0100 Subject: [PATCH 13/24] Moved optionsHandler and getTreshold to options-handler. Removed rewire dependency --- index.js | 13 +++--------- lib/options-handler.js | 17 ++++++++++++++++ lib/output.js | 5 +---- package.json | 1 - test/index.test.js | 25 ------------------------ test/options-handler.test.js | 38 ++++++++++++++++++++++++++++++++++++ test/output.test.js | 17 ---------------- 7 files changed, 59 insertions(+), 57 deletions(-) create mode 100644 lib/options-handler.js create mode 100644 test/options-handler.test.js delete mode 100644 test/output.test.js diff --git a/index.js b/index.js index ed6cc56..0030f33 100755 --- a/index.js +++ b/index.js @@ -1,26 +1,19 @@ 'use strict'; const {google} = require('googleapis'); -const prependHttp = require('prepend-http'); const pify = require('pify'); const output = require('./lib/output'); +const {getOptions} = require('./lib/options-handler'); const {runpagespeed} = pify(google.pagespeedonline('v5').pagespeedapi); -function handleOpts(url, options) { - options = Object.assign({strategy: 'mobile'}, options); - options.nokey = options.key === undefined; - options.url = prependHttp(url); - return options; -} - const psi = (url, options) => Promise.resolve().then(() => { if (!url) { throw new Error('URL required'); } - return runpagespeed(handleOpts(url, options)); + return runpagespeed(getOptions(url, options)); }); module.exports = psi; -module.exports.output = (url, options) => psi(url, options).then(data => output(handleOpts(url, options), data.data)); +module.exports.output = (url, options) => psi(url, options).then(data => output(getOptions(url, options), data.data)); diff --git a/lib/options-handler.js b/lib/options-handler.js new file mode 100644 index 0000000..ed3ad5b --- /dev/null +++ b/lib/options-handler.js @@ -0,0 +1,17 @@ +const prependHttp = require('prepend-http'); + +const THRESHOLD = 70; + +const getOptions = (url, options) => { + options = Object.assign({strategy: 'mobile'}, options); + options.nokey = options.key === undefined; + options.url = prependHttp(url); + return options; +}; + +const getThreshold = threshold => (typeof threshold === 'number' && threshold && threshold < 100) ? threshold : THRESHOLD; + +module.exports = { + getOptions, + getThreshold +}; diff --git a/lib/output.js b/lib/output.js index 184c156..b532aac 100644 --- a/lib/output.js +++ b/lib/output.js @@ -2,8 +2,7 @@ const sortOn = require('sort-on'); const humanizeUrl = require('humanize-url'); const prettyMs = require('pretty-ms'); - -const THRESHOLD = 70; +const {getThreshold} = require('./../lib/options-handler'); function overview(url, strategy, scores) { const ret = []; @@ -91,8 +90,6 @@ function getReporter(format) { const convertToPercentum = num => num * 100; -const getThreshold = threshold => (typeof threshold === 'number' && threshold && threshold < 100) ? threshold : THRESHOLD; - module.exports = (parameters, response) => { return Promise.resolve().then(() => { const renderer = getReporter(parameters.format); diff --git a/package.json b/package.json index 1c9b0ec..b77610d 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,6 @@ "devDependencies": { "chai": "^4.2.0", "mocha": "^6.0.2", - "rewire": "^4.0.1", "xo": "^0.25.3" }, "xo": { diff --git a/test/index.test.js b/test/index.test.js index e968c41..807f393 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,9 +1,5 @@ /* eslint-env mocha */ const {expect} = require('chai'); -const rewire = require('rewire'); - -const psiWired = rewire('..'); -const handleOptions = psiWired.__get__('handleOpts'); const psi = require('..'); @@ -15,25 +11,4 @@ describe('Index file', () => { expect(error.message).to.eql('URL required'); }); }); - describe('handleOpts method', async () => { - const defaultConfig = { - nokey: true, - url: 'http://addyosmani.com' - }; - - it('should return strategy "mobile" if no strategy is passed', () => { - const expectedOutput = { - ...defaultConfig, - strategy: 'mobile' - }; - expect(handleOptions('http://addyosmani.com')).to.eql(expectedOutput); - }); - it('should respect passed strategy options', () => { - const expectedOutput = { - ...defaultConfig, - strategy: 'desktop' - }; - expect(handleOptions('http://addyosmani.com', {strategy: 'desktop'})).to.eql(expectedOutput); - }); - }); }); diff --git a/test/options-handler.test.js b/test/options-handler.test.js new file mode 100644 index 0000000..b94a84c --- /dev/null +++ b/test/options-handler.test.js @@ -0,0 +1,38 @@ +/* eslint-env mocha */ +const {expect} = require('chai'); + +const {getOptions, getThreshold} = require('../lib/options-handler'); + +describe('Options handler method', () => { + describe('getOptions method', () => { + const defaultConfig = { + nokey: true, + url: 'http://addyosmani.com' + }; + it('should return strategy "mobile" if no strategy is passed', () => { + const expectedOutput = { + ...defaultConfig, + strategy: 'mobile' + }; + expect(getOptions('http://addyosmani.com')).to.eql(expectedOutput); + }); + it('should respect passed strategy options', () => { + const expectedOutput = { + ...defaultConfig, + strategy: 'desktop' + }; + expect(getOptions('http://addyosmani.com', {strategy: 'desktop'})).to.eql(expectedOutput); + }); + }); + + describe('getThreshold method', () => { + it('should return "70" if no valid value is passed', () => { + expect(getThreshold('string')).to.equal(70); + expect(getThreshold(false)).to.equal(70); + expect(getThreshold(101)).to.equal(70); + }); + it('should respect passed threshold values', () => { + expect(getThreshold(80)).to.equal(80); + }); + }); +}); diff --git a/test/output.test.js b/test/output.test.js deleted file mode 100644 index d834983..0000000 --- a/test/output.test.js +++ /dev/null @@ -1,17 +0,0 @@ -/* eslint-env mocha */ -const {expect} = require('chai'); -const rewire = require('rewire'); - -const outputWired = rewire('./../lib/output.js'); -const getThreshold = outputWired.__get__('getThreshold'); - -describe('getThreshold method', () => { - it('should return "70" if no valid value is passed', () => { - expect(getThreshold('string')).to.equal(70); - expect(getThreshold(false)).to.equal(70); - expect(getThreshold(101)).to.equal(70); - }); - it('should respect passed threshold values', () => { - expect(getThreshold(80)).to.equal(80); - }); -}); From 3b56a1a25bbe797f996b0d57321e4b1aee64894d Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Wed, 27 Nov 2019 17:34:43 +0100 Subject: [PATCH 14/24] Moved getReporter to options-handler --- lib/options-handler.js | 5 ++++- lib/output.js | 9 ++------- test/options-handler.test.js | 13 ++++++++++++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/options-handler.js b/lib/options-handler.js index ed3ad5b..8454b8e 100644 --- a/lib/options-handler.js +++ b/lib/options-handler.js @@ -11,7 +11,10 @@ const getOptions = (url, options) => { const getThreshold = threshold => (typeof threshold === 'number' && threshold && threshold < 100) ? threshold : THRESHOLD; +const getReporter = format => ['cli', 'json', 'tap'].includes(format) ? format : 'cli'; + module.exports = { getOptions, - getThreshold + getThreshold, + getReporter }; diff --git a/lib/output.js b/lib/output.js index b532aac..fcc55cc 100644 --- a/lib/output.js +++ b/lib/output.js @@ -2,7 +2,7 @@ const sortOn = require('sort-on'); const humanizeUrl = require('humanize-url'); const prettyMs = require('pretty-ms'); -const {getThreshold} = require('./../lib/options-handler'); +const {getThreshold, getReporter} = require('./../lib/options-handler'); function overview(url, strategy, scores) { const ret = []; @@ -83,16 +83,11 @@ const opportunities = lighthouseResult => { return sortOn(ret, 'label'); }; -function getReporter(format) { - const outputFormat = ['cli', 'json', 'tap'].includes(format) ? format : 'cli'; - return require(`./formats/${outputFormat}`); -} - const convertToPercentum = num => num * 100; module.exports = (parameters, response) => { return Promise.resolve().then(() => { - const renderer = getReporter(parameters.format); + const renderer = require(`./formats/${getReporter(parameters.format)}`); const threshold = getThreshold(parameters.threshold); const {lighthouseResult, loadingExperience, id} = response; diff --git a/test/options-handler.test.js b/test/options-handler.test.js index b94a84c..08e7350 100644 --- a/test/options-handler.test.js +++ b/test/options-handler.test.js @@ -1,7 +1,7 @@ /* eslint-env mocha */ const {expect} = require('chai'); -const {getOptions, getThreshold} = require('../lib/options-handler'); +const {getOptions, getThreshold, getReporter} = require('../lib/options-handler'); describe('Options handler method', () => { describe('getOptions method', () => { @@ -35,4 +35,15 @@ describe('Options handler method', () => { expect(getThreshold(80)).to.equal(80); }); }); + + describe('getReporter method', () => { + it('should return "cli" if no valid format is passed', () => { + expect(getReporter('foo')).to.equal('cli'); + }); + it('should respect passed format if valid', () => { + expect(getReporter('cli')).to.equal('cli'); + expect(getReporter('tap')).to.equal('tap'); + expect(getReporter('json')).to.equal('json'); + }); + }); }); From 4c65857cfae4df68a3de73a1489863c695d2bce3 Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Wed, 11 Mar 2020 00:18:00 +0100 Subject: [PATCH 15/24] Update googlepais to v40.0.0 * Update index file to use new api * Update googleapis dependency --- index.js | 16 +++++++++++----- package.json | 3 +-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 0030f33..b091860 100755 --- a/index.js +++ b/index.js @@ -1,17 +1,23 @@ 'use strict'; -const {google} = require('googleapis'); -const pify = require('pify'); +const google = require('googleapis'); const output = require('./lib/output'); const {getOptions} = require('./lib/options-handler'); - -const {runpagespeed} = pify(google.pagespeedonline('v5').pagespeedapi); +const pagespeedonline = new google.pagespeedonline_v5.Pagespeedonline({ + version: 'v5', + auth: false +}); const psi = (url, options) => Promise.resolve().then(() => { if (!url) { throw new Error('URL required'); } - return runpagespeed(getOptions(url, options)); + const opt = getOptions(url, options); + + return pagespeedonline.pagespeedapi.runpagespeed({ + ...opt, + google: opt.nokey + }); }); module.exports = psi; diff --git a/package.json b/package.json index ca1d11f..bd71202 100644 --- a/package.json +++ b/package.json @@ -34,10 +34,9 @@ ], "dependencies": { "chalk": "^2.4.2", - "googleapis": "^38.0.0", + "googleapis": "^40.0.0", "humanize-url": "^2.1.0", "meow": "^5.0.0", - "pify": "^4.0.0", "prepend-http": "^2.0.0", "pretty-ms": "^4.0.0", "sort-on": "^3.0.0", From 085a3a26fa50df90f7b43c232411724d4e22baf0 Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Wed, 11 Mar 2020 17:27:39 +0100 Subject: [PATCH 16/24] Clean no necessary variables --- index.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index b091860..156afdd 100755 --- a/index.js +++ b/index.js @@ -2,22 +2,14 @@ const google = require('googleapis'); const output = require('./lib/output'); const {getOptions} = require('./lib/options-handler'); -const pagespeedonline = new google.pagespeedonline_v5.Pagespeedonline({ - version: 'v5', - auth: false -}); +const pagespeedonline = new google.pagespeedonline_v5.Pagespeedonline(); const psi = (url, options) => Promise.resolve().then(() => { if (!url) { throw new Error('URL required'); } - const opt = getOptions(url, options); - - return pagespeedonline.pagespeedapi.runpagespeed({ - ...opt, - google: opt.nokey - }); + return pagespeedonline.pagespeedapi.runpagespeed(getOptions(url, options)); }); module.exports = psi; From abf59c6706533142aab799721fde51e5cfede15f Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Wed, 11 Mar 2020 20:21:34 +0100 Subject: [PATCH 17/24] Update googleapis to v47.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bd71202..1e702b0 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ ], "dependencies": { "chalk": "^2.4.2", - "googleapis": "^40.0.0", + "googleapis": "^47.0.0", "humanize-url": "^2.1.0", "meow": "^5.0.0", "prepend-http": "^2.0.0", From 98294d337c89ba48b3ad0d809c528a590f7397bd Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Wed, 11 Mar 2020 20:39:07 +0100 Subject: [PATCH 18/24] Update project dependencies --- package.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 1e702b0..0e79f5c 100644 --- a/package.json +++ b/package.json @@ -33,20 +33,20 @@ "size" ], "dependencies": { - "chalk": "^2.4.2", + "chalk": "^3.0.0", "googleapis": "^47.0.0", "humanize-url": "^2.1.0", - "meow": "^5.0.0", - "prepend-http": "^2.0.0", - "pretty-ms": "^4.0.0", - "sort-on": "^3.0.0", - "update-notifier": "^2.5.0" + "meow": "^6.0.1", + "prepend-http": "^3.0.1", + "pretty-ms": "^6.0.1", + "sort-on": "^4.1.0", + "update-notifier": "^4.1.0" }, "devDependencies": { "chai": "^4.2.0", - "mocha": "^6.0.2", - "strip-ansi": "^5.1.0", - "nyc": "^14.1.1", + "mocha": "^7.1.0", + "nyc": "^15.0.0", + "strip-ansi": "^6.0.0", "xo": "^0.25.3" }, "xo": { From a2566eb5ff86969684fde15cf07ba7b950304c00 Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Wed, 11 Mar 2020 20:53:39 +0100 Subject: [PATCH 19/24] Revert index and googleapis version to master --- index.js | 8 +++++--- package.json | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 156afdd..0030f33 100755 --- a/index.js +++ b/index.js @@ -1,15 +1,17 @@ 'use strict'; -const google = require('googleapis'); +const {google} = require('googleapis'); +const pify = require('pify'); const output = require('./lib/output'); const {getOptions} = require('./lib/options-handler'); -const pagespeedonline = new google.pagespeedonline_v5.Pagespeedonline(); + +const {runpagespeed} = pify(google.pagespeedonline('v5').pagespeedapi); const psi = (url, options) => Promise.resolve().then(() => { if (!url) { throw new Error('URL required'); } - return pagespeedonline.pagespeedapi.runpagespeed(getOptions(url, options)); + return runpagespeed(getOptions(url, options)); }); module.exports = psi; diff --git a/package.json b/package.json index 0e79f5c..1818530 100644 --- a/package.json +++ b/package.json @@ -34,9 +34,10 @@ ], "dependencies": { "chalk": "^3.0.0", - "googleapis": "^47.0.0", + "googleapis": "^38.0.0", "humanize-url": "^2.1.0", "meow": "^6.0.1", + "pify": "^4.0.0", "prepend-http": "^3.0.1", "pretty-ms": "^6.0.1", "sort-on": "^4.1.0", From 8fb6e42464fbc4aaab63ac4dbd9db2efb7bced0d Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Wed, 11 Mar 2020 00:18:00 +0100 Subject: [PATCH 20/24] Update googlepais to v40.0.0 * Update index file to use new api * Update googleapis dependency --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index b214034..573a8bd 100755 --- a/index.js +++ b/index.js @@ -1,9 +1,9 @@ 'use strict'; -const {google} = require('googleapis'); +const { google } = require('googleapis'); const pify = require('pify'); const output = require('./lib/output'); -const {getOptions} = require('./lib/options-handler'); -const {pagespeedapi} = google.pagespeedonline('v5'); +const { getOptions } = require('./lib/options-handler'); +const { pagespeedapi } = google.pagespeedonline('v5'); const runpagespeed = pify(pagespeedapi.runpagespeed).bind(pagespeedapi); From 74c316d53fe1f980bcf90a551052c33164ac91ac Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Wed, 11 Mar 2020 17:27:39 +0100 Subject: [PATCH 21/24] Clean no necessary variables --- index.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 573a8bd..3456f0c 100755 --- a/index.js +++ b/index.js @@ -2,17 +2,15 @@ const { google } = require('googleapis'); const pify = require('pify'); const output = require('./lib/output'); -const { getOptions } = require('./lib/options-handler'); -const { pagespeedapi } = google.pagespeedonline('v5'); - -const runpagespeed = pify(pagespeedapi.runpagespeed).bind(pagespeedapi); +const {getOptions} = require('./lib/options-handler'); +const pagespeedonline = new google.pagespeedonline_v5.Pagespeedonline(); const psi = (url, options) => Promise.resolve().then(() => { if (!url) { throw new Error('URL required'); } - return runpagespeed(getOptions(url, options)); + return pagespeedonline.pagespeedapi.runpagespeed(getOptions(url, options)); }); module.exports = psi; From e923eda038838b90399adc1e5d010e6194281dd4 Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Wed, 11 Mar 2020 20:39:07 +0100 Subject: [PATCH 22/24] Update project dependencies --- package.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index c1b6544..c72d817 100644 --- a/package.json +++ b/package.json @@ -33,21 +33,21 @@ "size" ], "dependencies": { - "chalk": "^2.4.2", + "chalk": "^3.0.0", "googleapis": "^47.0.0", "humanize-url": "^2.1.0", - "meow": "^5.0.0", + "meow": "^6.0.1", "pify": "^4.0.0", - "prepend-http": "^2.0.0", - "pretty-ms": "^4.0.0", - "sort-on": "^3.0.0", - "update-notifier": "^2.5.0" + "prepend-http": "^3.0.1", + "pretty-ms": "^6.0.1", + "sort-on": "^4.1.0", + "update-notifier": "^4.1.0" }, "devDependencies": { "chai": "^4.2.0", - "mocha": "^6.0.2", - "strip-ansi": "^5.1.0", - "nyc": "^14.1.1", + "mocha": "^7.1.0", + "nyc": "^15.0.0", + "strip-ansi": "^6.0.0", "xo": "^0.25.3" }, "xo": { From 640d927b1ce3b19b8046dfccd529858f8fc74ab7 Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Wed, 11 Mar 2020 20:53:39 +0100 Subject: [PATCH 23/24] Revert index and googleapis version to master --- index.js | 7 ++++--- package.json | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 3456f0c..0030f33 100755 --- a/index.js +++ b/index.js @@ -1,16 +1,17 @@ 'use strict'; -const { google } = require('googleapis'); +const {google} = require('googleapis'); const pify = require('pify'); const output = require('./lib/output'); const {getOptions} = require('./lib/options-handler'); -const pagespeedonline = new google.pagespeedonline_v5.Pagespeedonline(); + +const {runpagespeed} = pify(google.pagespeedonline('v5').pagespeedapi); const psi = (url, options) => Promise.resolve().then(() => { if (!url) { throw new Error('URL required'); } - return pagespeedonline.pagespeedapi.runpagespeed(getOptions(url, options)); + return runpagespeed(getOptions(url, options)); }); module.exports = psi; diff --git a/package.json b/package.json index c72d817..1818530 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ ], "dependencies": { "chalk": "^3.0.0", - "googleapis": "^47.0.0", + "googleapis": "^38.0.0", "humanize-url": "^2.1.0", "meow": "^6.0.1", "pify": "^4.0.0", From a96aa7c85087f174f30fea049ccae5e85b703372 Mon Sep 17 00:00:00 2001 From: JuanMa Ruiz Date: Sun, 15 Mar 2020 13:56:02 +0100 Subject: [PATCH 24/24] Update dependencies --- index.js | 3 ++- package.json | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 0030f33..b214034 100755 --- a/index.js +++ b/index.js @@ -3,8 +3,9 @@ const {google} = require('googleapis'); const pify = require('pify'); const output = require('./lib/output'); const {getOptions} = require('./lib/options-handler'); +const {pagespeedapi} = google.pagespeedonline('v5'); -const {runpagespeed} = pify(google.pagespeedonline('v5').pagespeedapi); +const runpagespeed = pify(pagespeedapi.runpagespeed).bind(pagespeedapi); const psi = (url, options) => Promise.resolve().then(() => { if (!url) { diff --git a/package.json b/package.json index 1818530..8df1ef2 100644 --- a/package.json +++ b/package.json @@ -34,10 +34,10 @@ ], "dependencies": { "chalk": "^3.0.0", - "googleapis": "^38.0.0", + "googleapis": "^47.0.0", "humanize-url": "^2.1.0", "meow": "^6.0.1", - "pify": "^4.0.0", + "pify": "^5.0.0", "prepend-http": "^3.0.1", "pretty-ms": "^6.0.1", "sort-on": "^4.1.0",