Skip to content

Commit

Permalink
Merge pull request #38 from sindresorhus/support-humanized-urls
Browse files Browse the repository at this point in the history
support humanized URLs
  • Loading branch information
addyosmani committed Nov 21, 2014
2 parents 6a568cb + 8035fc3 commit 1206a07
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
4 changes: 1 addition & 3 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 3 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {});
});
});
});

0 comments on commit 1206a07

Please sign in to comment.