Skip to content

Commit 1b6c221

Browse files
authored
Merge pull request #141 from abdulsuhail/issue-137-fix
issue 237 fixed, fetching locations based on API availability.
2 parents 4ed3807 + 1ebcec4 commit 1b6c221

File tree

4 files changed

+44
-8
lines changed

4 files changed

+44
-8
lines changed

README.md

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ _The default WPT server can also be specified via environment variable `WEBPAGET
148148
* **--timeout** _\<seconds\>_: timeout for polling and waiting results [no timeout]
149149
* **--lighthouse**: perform lighthouse test (Chrome only, Linux agent only)
150150

151-
#### API Key (works for **test**, **restart** and **cancel** commands)
151+
#### API Key (works for **test**, **restart**,**locations** and **cancel** commands)
152152
* **-k, --key** _\<api_key\>_:API key (if assigned). Contact the WebPageTest server administrator for a key if required or request an API key for limited testing at [webpagetest.org/getkey.php](https://www.webpagetest.org/getkey.php)
153153

154154
#### Request (works for **status**, **results**, **locations**, **testers** and **test** commands)
@@ -200,7 +200,7 @@ _The default WPT server can also be specified via environment variable `WEBPAGET
200200

201201

202202
### Examples
203-
#### 1. Get available locations
203+
#### 1. Get all available locations
204204
```bash
205205
$ webpagetest locations
206206
```
@@ -228,8 +228,36 @@ $ webpagetest locations
228228
}
229229
}
230230
```
231+
#### 2. Get API available locations
232+
```bash
233+
$ webpagetest locations --key 1F2A3K4E5
234+
```
235+
```javascript
236+
{
237+
"response": {
238+
"statusCode": 200, "statusText": "Ok",
239+
"data": {
240+
"location": [
241+
...
242+
{
243+
"id": "SanJose_IE9",
244+
"Label": "San Jose, CA USA (IE 9,Chrome,Firefox)",
245+
"location": "SanJose_IE9",
246+
"Browser": "IE 9",
247+
"PendingTests": {
248+
"p1": 0, "p2": 0, "p3": 0, "p4": 0, "p5": 2, "p6": 2, "p7": 0,
249+
"p8": 0, "p9": 0, "Total": 7, "HighPriority": 2, "LowPriority": 4,
250+
"Testing": 1, "Idle": 0
251+
}
252+
},
253+
...
254+
]
255+
}
256+
}
257+
}
258+
```
231259

232-
#### 2. Run test on http://marcelduran.com/webpagetest-api from San Jose on IE9
260+
#### 3. Run test on http://marcelduran.com/webpagetest-api from San Jose on IE9
233261
```bash
234262
$ webpagetest test http://marcelduran.com/webpagetest-api --key 1F2A3K4E5 --location SanJose_IE9
235263
```
@@ -249,7 +277,7 @@ $ webpagetest test http://marcelduran.com/webpagetest-api --key 1F2A3K4E5 --loca
249277
}
250278
```
251279

252-
#### 3. Check current test status
280+
#### 4. Check current test status
253281
```bash
254282
$ webpagetest status 121025_PT_N8K
255283
```
@@ -268,7 +296,7 @@ $ webpagetest status 121025_PT_N8K
268296
}
269297
```
270298

271-
#### 4. Get test results
299+
#### 5. Get test results
272300
```bash
273301
$ webpagetest results 121025_PT_N8K
274302
```
@@ -301,7 +329,7 @@ $ webpagetest results 121025_PT_N8K
301329
}
302330
```
303331

304-
#### 5. Get test waterfall thumbnail from repeat view as data URI
332+
#### 6. Get test waterfall thumbnail from repeat view as data URI
305333
```bash
306334
$ webpagetest waterfall 121025_PT_N8K --thumbnail --cached --uri
307335
```
@@ -526,6 +554,9 @@ wpt.runTest(script, (err, data) => {
526554
* **key** _String_: private key file path to use for SSL
527555
* **cert** _String_: public x509 certificate file path to use for SSL
528556

557+
#### Location (works for `getLocations` method only)
558+
* **allLocations** _Boolean_: if true, returns all available locations irrespective of API availability
559+
529560
### Examples
530561

531562
#### 1. Instantiating

lib/mapping.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ var commands = {
694694
},
695695
'locations': {
696696
name: 'getLocations',
697-
options: [options.request],
697+
options: [options.request,options.apikey],
698698
info: 'list locations and the number of pending tests'
699699
},
700700
'testers': {

lib/webpagetest.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,9 @@ function getLocations(options, callback) {
300300
options = options === callback ? undefined : options;
301301

302302
var query = helper.setQuery(mapping.commands.locations, options);
303-
303+
if (!query.k && this.config.key && !options.allLocations) {
304+
query.k = this.config.key;
305+
}
304306
return api.call(this, paths.locations, callback, query, options);
305307
}
306308

test/fixtures/command-line/help-locations.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ list locations and the number of pending tests
44

55
Options:
66
-e, --request <id> echo request ID, useful to track asynchronous requests
7+
-k, --key <api_key> API key (if assigned). Contact the
8+
WebPageTest server administrator for a
9+
key if required
710
-h, --help display help for command

0 commit comments

Comments
 (0)