Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

webpagetest

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpagetest - npm Package Compare versions

Comparing version 0.1.3 to 0.2.0

70

lib/helper.js
/**
* Copyright (c) 2013, Twitter Inc. and other contributors
* Copyright (c) 2013, Twitter Inc.
* Copyright (c) 2013, Marcel Duran and other contributors
* Released under the MIT License
*/
var jsonml = require('jsonml'),
var xml2js = require('xml2js'),
url = require('url'),
os = require('os');
var parser = new xml2js.Parser({explicitArray: false, mergeAttrs: true});
var reNumber = /^[\.\+\-]?[\d\.]+$/,

@@ -29,44 +32,29 @@ reInvalidDec = /(?:\.\d*){2,}/,

function xmlToObj(xml) {
var obj = {},
function normalizeObj(root) {
if (typeof root === 'object') {
Object.keys(root).forEach(function(key) {
var value = root[key];
if (typeof value === 'string') {
if (value.length === 0 || value === '\n') {
delete root[key];
} else {
root[key] = parseNumber(value);
}
} else {
normalizeObj(value);
}
});
}
}
rec = function xmlToObjRecursion(a, o) {
var val, newObj, i,
len = a.length;
function xmlToObj(xml, callback) {
if (len === 2 && !o[a[0]]) {
if (typeof a[1] !== 'object') {
o[a[0]] = parseNumber(a[1]);
} else {
o[a[0]] = {};
rec(a[1], o[a[0]]);
}
} else if (len >= 2) {
if (o[a[0]]) {
if (!(o[a[0]] instanceof Array)) {
val = o[a[0]];
o[a[0]] = [val];
}
if (len === 2) {
return rec([o[a[0]].length, a[1]], o[a[0]]);
} else {
newObj = {};
o[a[0]].push(newObj);
}
} else {
o[a[0]] = {};
}
for (i = 1, len = a.length; i < len; i += 1) {
rec(a[i], newObj || o[a[0]]);
}
} else if (len === undefined && typeof a === 'object') {
Object.keys(a).forEach(function(key) {
o[key] = a[key];
});
}
};
parser.parseString(xml, function (err, obj) {
if (err) {
callback(err);
}
rec(jsonml.parse(xml), obj);
return obj;
normalizeObj(obj);
callback(undefined, obj);
});
}

@@ -73,0 +61,0 @@

/**
* Copyright (c) 2013, Twitter Inc. and other contributors
* Copyright (c) 2013, Twitter Inc.
* Copyright (c) 2013, Marcel Duran and other contributors
* Released under the MIT License

@@ -24,9 +25,2 @@ */

test: {
'key': {
name: 'key',
key: 'k',
api: 'k',
param: 'api_key',
info: 'API key (if assigned). Contact the WebPageTest server administrator for a key if required'
},
'location': {

@@ -341,2 +335,8 @@ name: 'location',

},
'htmlbody': {
name: 'htmlBody',
api: 'htmlbody',
bool: true,
info: 'save the content of only the base HTML response'
},
'poll': {

@@ -535,2 +535,11 @@ name: 'pollResults',

}
},
'apikey': {
'key': {
name: 'key',
key: 'k',
api: 'k',
param: 'api_key',
info: 'API key (if assigned). Contact the WebPageTest server administrator for a key if required'
}
}

@@ -565,3 +574,3 @@ };

param: 'url_or_script',
options: [options.test, options.request, options.results],
options: [options.apikey, options.test, options.request, options.results],
info: 'run test',

@@ -573,2 +582,3 @@ nokey: [options.results]

param: 'id',
options: [options.apikey],
info: 'cancel running/pending test'

@@ -575,0 +585,0 @@ },

/**
* Copyright (c) 2013, Twitter Inc. and other contributors
* Copyright (c) 2013, Twitter Inc.
* Copyright (c) 2013, Marcel Duran and other contributors
* Released under the MIT License

@@ -90,2 +91,4 @@ */

opts.forEach(function eachOptions(option) {
var nokey = method.nokey && method.nokey.indexOf(option) > -1;
Object.keys(option).forEach(function eachOption(optKey) {

@@ -100,4 +103,3 @@ var opt = option[optKey];

options[[
opt.key,
', ',
opt.key && !nokey ? opt.key + ', ' : '',
optKey

@@ -104,0 +106,0 @@ ].join('')] = optKey === 'server' ?

@@ -0,1 +1,7 @@

/**
* Copyright (c) 2013, Twitter Inc.
* Copyright (c) 2013, Marcel Duran and other contributors
* Released under the MIT License
*/
var fs = require('fs'),

@@ -2,0 +8,0 @@ Mocha = require('mocha'),

/**
* Copyright (c) 2013, Twitter Inc. and other contributors
* Copyright (c) 2013, Twitter Inc.
* Copyright (c) 2013, Marcel Duran and other contributors
* Released under the MIT License

@@ -18,3 +19,3 @@ */

reConnectivity = /^(?:DSL|FIOS|Dial|custom)$/,
reHTMLOtput = /<h\d[^<]*>([^<]+)<\/h\d>/; // for H3 on cancelTest.php
reHTMLOutput = /<h\d[^<]*>([^<]+)<\/h\d>/; // for H3 on cancelTest.php

@@ -159,5 +160,10 @@ var paths = {

} else if (info.type === 'text/xml') {
data = helper.xmlToObj(data);
helper.xmlToObj(data, function(err, obj) {
if (typeof callback === 'function') {
callback.apply(this, [err, obj].concat(options.args));
}
});
return;
} else if (info.type === 'text/html') {
data = {result: (reHTMLOtput.exec(data) || [])[1]};
data = {result: (reHTMLOutput.exec(data) || [])[1]};
}

@@ -404,6 +410,10 @@ }

function cancelTest(id, options, callback) {
var query = {test: id};
callback = callback || options;
options = options === callback ? undefined : options;
return api.call(this, paths.cancel, callback, {test: id}, options);
helper.setQuery(mapping.commands.cancel, options, query);
return api.call(this, paths.cancel, callback, query, options);
}

@@ -410,0 +420,0 @@

{
"name": "webpagetest",
"version": "0.1.3",
"version": "0.2.0",
"description": "WebPageTest API wrapper for NodeJS",

@@ -36,9 +36,9 @@ "author": "Marcel Duran <github@marcelduran.com> (http://github.com/marcelduran)",

"dependencies": {
"jsonml": "~0.0.4",
"commander": "~1.3.2",
"mocha": "~1.12.0"
"commander": "~2.0.0",
"mocha": "~1.13.0",
"xml2js": "~0.2.8"
},
"devDependencies": {
"nock": "~0.19.0"
"nock": "~0.22.1"
}
}

@@ -69,3 +69,2 @@ ## WebPageTest API Wrapper for NodeJS [![Build Status](https://secure.travis-ci.org/marcelduran/webpagetest-api.png?branch=master)](http://travis-ci.org/marcelduran/webpagetest-api) [![Dependencies Status](https://david-dm.org/marcelduran/webpagetest-api.png)](https://david-dm.org/marcelduran/webpagetest-api)

#### Test (works for **test** command only)
* **-k, --key** _\<api_key\>_:API key (if assigned). Contact the WebPageTest server administrator for a key if required
* **-l, --location** _\<location\>_: location to test from

@@ -119,2 +118,5 @@ * **-r, --runs** _\<number\>_: number of test runs [1]

#### API Key (works for **test** and **cancel** commands)
* **-k, --key** _\<api_key\>_:API key (if assigned). Contact the WebPageTest server administrator for a key if required
#### Request (works for **status**, **results**, **locations**, **testers** and **test** commands)

@@ -367,3 +369,2 @@ * **-e, --request** _\<id\>_: echo request ID, useful to track asynchronous requests

#### Test (works for `runTest` method only)
* **key**: _String_, API key (if assigned). Contact the WebPageTest server administrator for a key if required
* **location**: _String_, location to test from

@@ -417,2 +418,5 @@ * **runs**: _Number_, number of test runs [1]

#### API Key (works for **runTest** and **cancelTest** methods)
* **key**: _String_, API key (if assigned). Contact the WebPageTest server administrator for a key if required
#### Request (works for **getTestStatus**, **getResults**, **getLocations**, **getTesters** and **runTest** methods)

@@ -612,2 +616,3 @@ * **requestId**: _String_, echo request ID, useful to track asynchronous requests

* 0.2.0: Replaced jsonml by xml2js dependency
* 0.1.3: Test results extra data (breakdown, domains, requests, pagespeed)

@@ -634,4 +639,5 @@ * 0.1.0: Specs (CI); Run in batch; Node methods/options as command aliases; new Chrome test options

Copyright 2013 Twitter, Inc. and other contributors
Copyright 2013 Twitter, Inc.
Copyright 2013 Marcel Duran and other contributors
Licensed under the [MIT License](http://github.com/marcelduran/webpagetest-api/raw/master/LICENSE)
/**
* Copyright (c) 2013, Twitter Inc. and other contributors
* Copyright (c) 2013, Twitter Inc.
* Copyright (c) 2013, Marcel Duran and other contributors
* Released under the MIT License

@@ -152,2 +153,11 @@ */

it('gets a cancel test with api key input returns the API url', function(done) {
exec(mock('cancel -k 12345 120816_V2_2'), function(err, data) {
if (err) return done(err);
data = JSON.parse(data);
assert.equal(data.url, wptServer + 'cancelTest.php?test=120816_V2_2&k=12345');
done();
});
});
it('gets a page speed data input returns the API url', function(done) {

@@ -154,0 +164,0 @@ exec(mock('pagespeed 120816_V2_2'), function(err, data) {

/**
* Copyright (c) 2013, Twitter Inc. and other contributors
* Copyright (c) 2013, Twitter Inc.
* Copyright (c) 2013, Marcel Duran and other contributors
* Released under the MIT License

@@ -165,2 +166,10 @@ */

it('gets a cancel test with api key request', function(done) {
wpt.cancelTest('120816_V2_2', {key: '12345', dryRun: true}, function (err, data) {
if (err) return done(err);
assert.equal(data.url, wptServer + 'cancelTest.php?test=120816_V2_2&k=12345');
done();
});
});
it('gets page speed data request', function(done) {

@@ -167,0 +176,0 @@ wpt.getPageSpeedData('120816_V2_2', {dryRun: true}, function (err, data) {

/**
* Copyright (c) 2013, Twitter Inc. and other contributors
* Copyright (c) 2013, Twitter Inc.
* Copyright (c) 2013, Marcel Duran and other contributors
* Released under the MIT License

@@ -4,0 +5,0 @@ */

@@ -6,3 +6,4 @@

-h, --help output usage information
-h, --help output usage information
-k, --key <api_key> API key (if assigned). Contact the WebPageTest server administrator for a key if required

@@ -52,2 +52,3 @@

--cmdline <switches> use a list of custom command line switches (Chrome only)
--htmlbody save the content of only the base HTML response
--poll [interval] poll for results after test is scheduled at every <interval> seconds [5]

@@ -54,0 +55,0 @@ --wait [hostname:port] wait for test results informed by agent once complete listening on <hostname>:<port> [hostname:first port available above 8000]

@@ -11,3 +11,3 @@

test [options] <url_or_script> run test
cancel <id> cancel running/pending test
cancel [options] <id> cancel running/pending test
har <id> get the HTTPS Archive (HAR) from test

@@ -14,0 +14,0 @@ pagespeed [options] <id> get the Google Page Speed results (if available) from test

/**
* Copyright (c) 2013, Twitter Inc. and other contributors
* Copyright (c) 2013, Twitter Inc.
* Copyright (c) 2013, Marcel Duran and other contributors
* Released under the MIT License

@@ -51,8 +52,8 @@ */

'/runtest.php?script=&f=json': 'runTestInvalid.json',
'/getgzip.php?test=120816_V2_3&file=1_pagespeed.txt': undefined,
'/getgzip.php?test=120816_V2_3&file=1_pagespeed.txt': '',
'/export.php?test=120816_V2_3': 'harNotFound.json',
'/waterfall.php?test=120816_V2_3&run=1&cached=0': 'waterfallNotFound.png',
'/thumbnail.php?test=120816_V2_3&run=1&cached=0&file=1_waterfall.png': 'waterfallThumbnailNotFound.png',
'/thumbnail.php?test=120816_V2_3&file=1_screen.jpg&run=1&cached=0': undefined,
'/cancelTest.php?test=120816_V2_4': undefined,
'/thumbnail.php?test=120816_V2_3&file=1_screen.jpg&run=1&cached=0': '',
'/cancelTest.php?test=120816_V2_4': '',
'/runtest.php?url=http%3A%2F%2Fapikey.com&f=json': 'runTestNoAPIKey.json',

@@ -59,0 +60,0 @@ '/runtest.php?url=http%3A%2F%2Fapikey.com&k=12345&f=json': 'runTestInvalidAPIKey.json'

/**
* Copyright (c) 2013, Twitter Inc. and other contributors
* Copyright (c) 2013, Twitter Inc.
* Copyright (c) 2013, Marcel Duran and other contributors
* Released under the MIT License

@@ -4,0 +5,0 @@ */

/**
* Copyright (c) 2013, Twitter Inc. and other contributors
* Copyright (c) 2013, Twitter Inc.
* Copyright (c) 2013, Marcel Duran and other contributors
* Released under the MIT License

@@ -4,0 +5,0 @@ */

/**
* Copyright (c) 2013, Twitter Inc. and other contributors
* Copyright (c) 2013, Twitter Inc.
* Copyright (c) 2013, Marcel Duran and other contributors
* Released under the MIT License

@@ -4,0 +5,0 @@ */

/**
* Copyright (c) 2013, Twitter Inc. and other contributors
* Copyright (c) 2013, Twitter Inc.
* Copyright (c) 2013, Marcel Duran and other contributors
* Released under the MIT License

@@ -4,0 +5,0 @@ */

/**
* Copyright (c) 2013, Twitter Inc. and other contributors
* Copyright (c) 2013, Twitter Inc.
* Copyright (c) 2013, Marcel Duran and other contributors
* Released under the MIT License

@@ -4,0 +5,0 @@ */

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc