Skip to content

Commit b087a12

Browse files
Merge branch 'master' into gentle-mite
2 parents 39f95a9 + 7be9af9 commit b087a12

File tree

5 files changed

+38
-80
lines changed

5 files changed

+38
-80
lines changed

README.md

Lines changed: 12 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# WebPageTest API Wrapper for NodeJS
55

6-
[![Build Status](https://travis-ci.com/WebPageTest/webpagetest-api.svg?branch=master)](https://travis-ci.com/WebPageTest/webpagetest-api)
6+
<!-- [![Build Status](https://travis-ci.com/WebPageTest/webpagetest-api.svg?branch=master)](https://travis-ci.com/WebPageTest/webpagetest-api) -->
77
[![NPM Version](https://img.shields.io/npm/v/webpagetest.svg?style=flat)](https://www.npmjs.org/package/webpagetest)
88
[![NPM Downloads](https://img.shields.io/npm/dm/webpagetest.svg?style=flat)](https://www.npmjs.org/package/webpagetest)
99

@@ -22,7 +22,7 @@ npm install webpagetest -g
2222
### Command line
2323

2424
```bash
25-
webpagetest test https://docs.webpagetest.org/api/integrations/
25+
webpagetest test https://docs.webpagetest.org/api/integrations/ -k YOURAPIKEY
2626
```
2727

2828
### Docker
@@ -240,10 +240,10 @@ _The default WPT server can also be specified via environment variable `WEBPAGET
240240

241241
### Examples
242242

243-
#### 1. Get all available locations
243+
#### 1. Get API available locations
244244

245245
```bash
246-
$ webpagetest locations
246+
$ webpagetest locations -k YOURAPIKEY
247247
```
248248

249249
```javascript
@@ -271,41 +271,10 @@ $ webpagetest locations
271271
}
272272
```
273273

274-
#### 2. Get API available locations
274+
#### 2. Run test on https://docs.webpagetest.org/api/integrations/ from San Jose on IE9
275275

276276
```bash
277-
webpagetest locations --key 1F2A3K4E5
278-
```
279-
280-
```javascript
281-
{
282-
"response": {
283-
"statusCode": 200, "statusText": "Ok",
284-
"data": {
285-
"location": [
286-
...
287-
{
288-
"id": "SanJose_IE9",
289-
"Label": "San Jose, CA USA (IE 9,Chrome,Firefox)",
290-
"location": "SanJose_IE9",
291-
"Browser": "IE 9",
292-
"PendingTests": {
293-
"p1": 0, "p2": 0, "p3": 0, "p4": 0, "p5": 2, "p6": 2, "p7": 0,
294-
"p8": 0, "p9": 0, "Total": 7, "HighPriority": 2, "LowPriority": 4,
295-
"Testing": 1, "Idle": 0
296-
}
297-
},
298-
...
299-
]
300-
}
301-
}
302-
}
303-
```
304-
305-
#### 3. Run test on https://docs.webpagetest.org/api/integrations/ from San Jose on IE9
306-
307-
```bash
308-
webpagetest test https://docs.webpagetest.org/api/integrations/ --key 1F2A3K4E5 --location SanJose_IE9
277+
webpagetest test https://docs.webpagetest.org/api/integrations/ -k YOURAPIKEY --location SanJose_IE9
309278
```
310279

311280
```javascript
@@ -324,10 +293,10 @@ webpagetest test https://docs.webpagetest.org/api/integrations/ --key 1F2A3K4E5
324293
}
325294
```
326295

327-
#### 4. Check current test status
296+
#### 3. Check current test status
328297

329298
```bash
330-
webpagetest status 121025_PT_N8K
299+
webpagetest status 121025_PT_N8K -k YOURAPIKEY
331300
```
332301

333302
```javascript
@@ -345,10 +314,10 @@ webpagetest status 121025_PT_N8K
345314
}
346315
```
347316

348-
#### 5. Get test results
317+
#### 4. Get test results
349318

350319
```bash
351-
webpagetest results 121025_PT_N8K
320+
webpagetest results 121025_PT_N8K -k YOURAPIKEY
352321
```
353322

354323
```javascript
@@ -380,23 +349,12 @@ webpagetest results 121025_PT_N8K
380349
}
381350
```
382351

383-
#### 6. Get test waterfall thumbnail from repeat view as data URI
384-
385-
```bash
386-
webpagetest waterfall 121025_PT_N8K --thumbnail --cached --uri
387-
```
388352

389-
```javascript
390-
{
391-
"type": "image/png",
392-
"data": "iVBORw0KGgoAAAANSUhEUgA...RK5CYII="
393-
}
394-
```
395353

396-
#### 7. Get remaining tests count for the account
354+
#### 5. Get remaining tests count for the account
397355

398356
```bash
399-
webpagetest testBalance --key 1F2A3K4E5
357+
webpagetest testBalance -k YOURAPIKEY
400358
```
401359

402360
```javascript

bin/webpagetest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ function cleanupProgram() {
273273
}
274274

275275
function execCommand() {
276-
var wpt = new WebPageTest(program.server || defaultServer);
276+
var wpt = new WebPageTest(program.server || defaultServer, options.key);
277277

278278
// options
279279
if (options) {

lib/mapping.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ var commands = {
13321332
},
13331333
testers: {
13341334
name: "getTesters",
1335-
options: [options.request],
1335+
options: [options.request, options.apikey],
13361336
info: "list testers status and details",
13371337
},
13381338
test: {
@@ -1369,101 +1369,105 @@ var commands = {
13691369
har: {
13701370
name: "getHARData",
13711371
param: "id",
1372+
options: [options.apikey],
13721373
info: "get the HTTP Archive (HAR) from test",
13731374
},
13741375
pagespeed: {
13751376
name: "getPageSpeedData",
13761377
param: "id",
1377-
options: [options.run],
1378+
options: [options.run, options.apikey],
13781379
info: "get the Google Page Speed results (if available) from test",
13791380
},
13801381
utilization: {
13811382
name: "getUtilizationData",
13821383
param: "id",
1383-
options: [options.run],
1384+
options: [options.run, options.apikey],
13841385
info: "get the CPU, bandwidth and memory utilization data from test",
13851386
},
13861387
request: {
13871388
name: "getRequestData",
13881389
param: "id",
1389-
options: [options.run],
1390+
options: [options.run, options.apikey],
13901391
info: "get the request data from test",
13911392
},
13921393
timeline: {
13931394
name: "getTimelineData",
13941395
param: "id",
1395-
options: [options.run],
1396+
options: [options.run, options.apikey],
13961397
info: "get the Chrome Developer Tools Timeline data (if available) from test",
13971398
},
13981399
netlog: {
13991400
name: "getNetLogData",
14001401
param: "id",
1401-
options: [options.run],
1402+
options: [options.run, options.apikey],
14021403
info: "get the Chrome Developer Tools Net log data (if available) from test",
14031404
},
14041405
chrometrace: {
14051406
name: "getChromeTraceData",
14061407
param: "id",
1407-
options: [options.run],
1408+
options: [options.run, options.apikey],
14081409
info: "get the Chrome Trace data (if available) from test",
14091410
},
14101411
console: {
14111412
name: "getConsoleLogData",
14121413
param: "id",
1413-
options: [options.run],
1414+
options: [options.run, options.apikey],
14141415
info: "get the browser console log data (if available) from test",
14151416
},
14161417
testinfo: {
14171418
name: "getTestInfo",
14181419
param: "id",
1420+
options: [options.apikey],
14191421
info: "get test request info/details",
14201422
},
14211423
history: {
14221424
name: "getHistory",
14231425
param: "days",
14241426
optional: true,
1427+
options: [options.apikey],
14251428
info: "get history of previously run tests",
14261429
},
14271430
googlecsi: {
14281431
name: "getGoogleCsiData",
14291432
param: "id",
1430-
options: [options.run],
1433+
options: [options.run, options.apikey],
14311434
info: "get Google CSI data (Client Side Instrumentation)",
14321435
},
14331436
response: {
14341437
name: "getResponseBody",
14351438
param: "id",
1436-
options: [options.run, options.response],
1439+
options: [options.run, options.response, options.apikey],
14371440
info: "get response body for text resources",
14381441
},
14391442
waterfall: {
14401443
name: "getWaterfallImage",
14411444
param: "id",
1442-
options: [options.run, options.image, options.waterfall],
1445+
options: [options.run, options.image, options.waterfall, options.apikey],
14431446
info: "get the waterfall PNG image",
14441447
},
14451448
screenshot: {
14461449
name: "getScreenshotImage",
14471450
param: "id",
1448-
options: [options.run, options.image, options.screenshot],
1451+
options: [options.run, options.image, options.screenshot, options.apikey],
14491452
info: "get the fully loaded page screenshot in JPG format (PNG if in full resolution)",
14501453
},
14511454
video: {
14521455
name: "createVideo",
14531456
param: "tests",
1454-
options: [options.video],
1457+
options: [options.video, options.apikey],
14551458
info: "create a video from <tests> (comma separated test ids)",
14561459
},
14571460
player: {
14581461
name: "getEmbedVideoPlayer",
14591462
param: "id",
1463+
options: [options.apikey],
14601464
info: "get a html5 player for a video <id>",
14611465
},
14621466
listen: {
14631467
name: "listen",
14641468
param: "hostname:port",
14651469
optional: true,
1466-
options: [options.listen],
1470+
options: [options.listen,options.apikey],
14671471
info: "start webpagetest-api proxy server on <hostname>:<port> [hostname:%s]",
14681472
},
14691473
};

lib/webpagetest.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,10 @@ function get(config, pathname, data, proxy, agent, callback, encoding) {
9999
options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
100100
}
101101

102-
if (encoding !== "binary") {
103-
options.headers["X-WPT-API-KEY"] = this.config.key;
104-
options.headers["accept-encoding"] = "gzip,deflate";
105-
options.headers["User-Agent"] = "WebpagetestNodeWrapper/v0.6.0";
106-
}
102+
// api key always required
103+
options.headers["X-WPT-API-KEY"] = this.config.key;
104+
options.headers["accept-encoding"] = "gzip,deflate";
105+
options.headers["User-Agent"] = "WebpagetestNodeWrapper/v0.7.4";
107106

108107
if (agent) {
109108
options.agent = agent;
@@ -347,9 +346,6 @@ function getLocations(options, callback) {
347346
options = options === callback ? undefined : options;
348347

349348
var query = helper.setQuery(mapping.commands.locations, options);
350-
if (!query.k && this.config.key && !options.allLocations) {
351-
query.k = this.config.key;
352-
}
353349
return api.call(this, paths.locations, callback, query, options);
354350
}
355351

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpagetest",
3-
"version": "0.7.1",
3+
"version": "0.7.4",
44
"description": "WebPageTest API wrapper for NodeJS",
55
"author": "WebPageTest <[email protected]> (http://github.com/WebPageTest)",
66
"homepage": "http://github.com/WebPageTest/webpagetest-api",
@@ -34,9 +34,9 @@
3434
"csv": "^6.2.2",
3535
"entities": "^4.4.0",
3636
"mocha": "^10.1.0",
37-
"xml2js": "^0.4.23"
37+
"xml2js": "^0.6.2"
3838
},
3939
"devDependencies": {
4040
"nock": "^13.2.9"
4141
}
42-
}
42+
}

0 commit comments

Comments
 (0)