11## WebPageTest API Wrapper for NodeJS
22
3- [ ![ Build Status] ( https://secure.travis-ci.org/marcelduran/webpagetest-api.png ?branch=master )] ( https://travis-ci.org/marcelduran/webpagetest-api )
3+ [ ![ Build Status] ( https://secure.travis-ci.org/marcelduran/webpagetest-api.svg ?branch=master )] ( https://travis-ci.org/marcelduran/webpagetest-api )
44[ ![ NPM Version] ( https://img.shields.io/npm/v/webpagetest.svg?style=flat )] ( https://www.npmjs.org/package/webpagetest )
55[ ![ NPM Downloads] ( https://img.shields.io/npm/dm/webpagetest.svg?style=flat )] ( https://www.npmjs.org/package/webpagetest )
6- [ ![ Dependencies Status] ( https://david-dm.org/marcelduran/webpagetest-api.png )] ( https://david-dm.org/marcelduran/webpagetest-api )
6+ [ ![ Dependencies Status] ( https://david-dm.org/marcelduran/webpagetest-api.svg )] ( https://david-dm.org/marcelduran/webpagetest-api )
77
88[ WebPageTest API Wrapper] ( https://marcelduran.com/webpagetest-api ) is a [ NPM] ( https://npmjs.org ) package that wraps [ WebPageTest] ( https://github.com/WPO-Foundation/webpagetest ) API for [ NodeJS] ( https://nodejs.org ) as a module and a command-line tool.
99
@@ -22,10 +22,10 @@ $ webpagetest test https://twitter.com/marcelduran
2222
2323### Module
2424``` javascript
25- var WebPageTest = require (' webpagetest' );
26- var wpt = new WebPageTest (' www.webpagetest.org' );
25+ const WebPageTest = require (' webpagetest' );
26+ const wpt = new WebPageTest (' www.webpagetest.org' );
2727
28- wpt .runTest (' https://twitter.com/marcelduran' , function (err , data ) {
28+ wpt .runTest (' https://twitter.com/marcelduran' , (err , data ) => {
2929 console .log (err || data);
3030});
3131```
@@ -362,7 +362,7 @@ Methods and options (including the one letter shorthands) are the same when usin
362362### Parameters
363363* ** id** : test ID string _ required_
364364* ** options** : parameters object _ optional_ , see below
365- * ** callback** : the callback ` function (error, data)` _ optional _
365+ * ** callback** : the callback ` (error, data) ` _ optional=> _
366366* ** url_or_script** : decoded url or script string _ required_
367367* ** port** : port number _ optional_ \[ default: 7791\]
368368* ** script** : script array in the format:
@@ -383,7 +383,7 @@ Methods and options (including the one letter shorthands) are the same when usin
383383* ` scriptToString ` script array values 1-N are optional. e.g:
384384
385385``` javascript
386- var script = wpt .scriptToString ([
386+ const script = wpt .scriptToString ([
387387 {logData: 0 },
388388 {navigate: ' http://foo.com/login' },
389389 {logData: 1 },
@@ -392,7 +392,8 @@ var script = wpt.scriptToString([
392392 {submitForm: ' action=http://foo.com/main' },
393393 ' waitForComplete'
394394]);
395- wpt .runTest (script, function (err , data ) {
395+
396+ wpt .runTest (script, (err , data ) => {
396397 console .log (err || data);
397398});
398399```
@@ -514,36 +515,36 @@ wpt.runTest(script, function(err, data) {
514515
515516#### 1. Instantiating
516517``` javascript
517- var WebPageTest = require (' webpagetest' );
518+ const WebPageTest = require (' webpagetest' );
518519
519- var wpt = new WebPageTest (' my-wpt.foo.com' ); // default: www.webpagetest.org
520- var wptPublic = new WebPageTest (' www.webpagetest.org' , ' MY_API_KEY' );
520+ const wpt = new WebPageTest (' my-wpt.foo.com' ); // default: www.webpagetest.org
521+ const wptPublic = new WebPageTest (' www.webpagetest.org' , ' MY_API_KEY' );
521522```
522523
523524#### 2. Get available locations
524525``` javascript
525- wpt .getLocations (function (err , data ) {
526+ wpt .getLocations ((err , data ) => {
526527 console .log (err || data);
527528});
528529```
529530
530531#### 3. Run test on https://twitter.com/marcelduran from San Jose on IE9
531532``` javascript
532- wpt .runTest (' https://twitter.com/marcelduran' , {location: ' SanJose_IE9' }, function (err , data ) {
533+ wpt .runTest (' https://twitter.com/marcelduran' , {location: ' SanJose_IE9' }, (err , data ) => {
533534 console .log (err || data);
534535});
535536```
536537
537538#### 4. Check current test status
538539``` javascript
539- wpt .getTestStatus (' 121025_PT_N8K' , function (err , data ) {
540+ wpt .getTestStatus (' 121025_PT_N8K' , (err , data ) => {
540541 console .log (err || data);
541542});
542543```
543544
544545#### 5. Get test results
545546``` javascript
546- wpt .getTestResults (' 121025_PT_N8K' , function (err , data ) {
547+ wpt .getTestResults (' 121025_PT_N8K' , (err , data ) => {
547548 console .log (err || data);
548549});
549550```
@@ -554,21 +555,21 @@ wpt.getWaterfallImage('121025_PT_N8K', {
554555 thumbnail: true ,
555556 repeatView: true ,
556557 dataURI: true
557- }, function (err , data , info ) {
558+ }, (err , data , info ) => {
558559 console .log (err || data, info);
559560});
560561```
561562
562563#### Run test on https://twitter.com/marcelduran and poll results every 5 seconds timing out in 60 seconds
563564``` javascript
564- wpt .runTest (' https://twitter.com/marcelduran' , {pollResults: 5 , timeout: 60 }, function (err , data ) {
565+ wpt .runTest (' https://twitter.com/marcelduran' , {pollResults: 5 , timeout: 60 }, (err , data ) => {
565566 console .log (err || data);
566567});
567568```
568569
569570#### Or run test on https://twitter.com/marcelduran and wait results listening on localhost\* port 8000\*\*
570571``` javascript
571- wpt .runTest (' https://twitter.com/marcelduran' , {waitResults: ' localhost:8000' }, function (err , data ) {
572+ wpt .runTest (' https://twitter.com/marcelduran' , {waitResults: ' localhost:8000' }, (err , data ) => {
572573 console .log (err || data);
573574});
574575```
@@ -606,13 +607,13 @@ https://localhost:8443
606607
607608### Module
608609``` javascript
609- var server = wpt .listen (8080 , function (err , data ) {
610+ const server = wpt .listen (8080 , (err , data ) => {
610611 if (err) throw err;
611612 console .log (' listening on ' + data .url );
612613}); // listen on port 8080 (optional), default port is 7791
613614
614- setTimeout (function () {
615- server .close (function () {
615+ setTimeout (() => {
616+ server .close (() => {
616617 console .log (' server closed' );
617618 });
618619}, 10000 ); // wait for 10s before stop listening
0 commit comments