From 8035fc31e1b431a15f9ac8a9b39b00b8ee8a7add Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 16 Nov 2014 16:19:27 +0700 Subject: [PATCH] support humanized URLs --- bin/cli.js | 4 +--- index.js | 7 +++++++ package.json | 1 + test/test.js | 7 +++---- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 90cc009..73da9d3 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -30,9 +30,7 @@ if (process.argv.indexOf('-v') !== -1 || process.argv.indexOf('--version') !== - return; } -if (query.indexOf('http') !== -1) { - opts.url = argv._[0]; -} +opts.url = argv._[0]; if(!opts.url){ printHelp(); diff --git a/index.js b/index.js index 8bbd908..1492eb9 100755 --- a/index.js +++ b/index.js @@ -8,13 +8,20 @@ 'use strict'; var pagespeed = require('gpagespeed'); +var prependHttp = require('prepend-http'); var output = require('./output').init(); module.exports = function (opts, cb) { opts = opts || {}; cb = cb || function () {}; + + if (!opts.url) { + throw new Error('URL required'); + } + opts.strategy = opts.strategy || 'desktop'; opts.nokey = opts.key === undefined; + opts.url = prependHttp(opts.url); pagespeed(opts, function (err, data) { if (err) { diff --git a/package.json b/package.json index e49d2e8..926a0d7 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "chalk": "^0.5.1", "gpagespeed": "0.0.8", "minimist": "^1.1.0", + "prepend-http": "^1.0.0", "pretty-bytes": "^1.0.1" }, "devDependencies": { diff --git a/test/test.js b/test/test.js index ae0953a..dae337e 100644 --- a/test/test.js +++ b/test/test.js @@ -34,10 +34,9 @@ describe('PSI formatting', function () { }); describe('CLI Error handling', function() { - it('should throw if no valid URL is provided', function (done) { - insights({}, function(err) { - assert.equal(err.message, 'Missing required param: url'); - done(); + it('should throw if no valid URL is provided', function () { + assert.throws(function () { + insights({}, function() {}); }); }); });