Skip to content

Commit c086f7c

Browse files
committed
Add restartTest command
1 parent 6bac270 commit c086f7c

File tree

11 files changed

+80
-4
lines changed

11 files changed

+80
-4
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ $ webpagetest --help
5757
* **locations** _[options]_: list locations and the number of pending tests
5858
* **testers** _[options]_: list testers status and details
5959
* **test** _[options] \<url_or_script\>_: run test, _\<url_or_script\>_ can also be a path to a script file
60+
* **restart** _\<id\>_: restart test
6061
* **cancel** _\<id\>_: cancel running/pending test
6162
* **har** _\<id\>_: get the HTTP Archive (HAR) from test
6263
* **pagespeed** _[options] \<id\>_: get the Google Page Speed results (if available) from test
@@ -147,7 +148,7 @@ _The default WPT server can also be specified via environment variable `WEBPAGET
147148
* **--timeout** _\<seconds\>_: timeout for polling and waiting results [no timeout]
148149
* **--lighthouse**: perform lighthouse test (Chrome only, Linux agent only)
149150

150-
#### API Key (works for **test** and **cancel** commands)
151+
#### API Key (works for **test**, **restart** and **cancel** commands)
151152
* **-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)
152153

153154
#### Request (works for **status**, **results**, **locations**, **testers** and **test** commands)
@@ -351,6 +352,7 @@ Methods and options (including the one letter shorthands) are the same when usin
351352
* `getLocations(options, callback)`
352353
* `getTesters(options, callback)`
353354
* `runTest(url_or_script, options, callback)`
355+
* `restartTest(id, options, callback)`
354356
* `cancelTest(id, options, callback)`
355357
* `getHARData(id, options, callback)`
356358
* `getPageSpeedData(id, options, callback)`
@@ -475,7 +477,7 @@ wpt.runTest(script, (err, data) => {
475477
* **timeout**: _String_, timeout for polling and waiting results [no timeout]
476478
* **lighthouse**: _Boolean_, perform lighthouse test (Chrome only, Linux agent only)
477479

478-
#### API Key (works for `runTest` and `cancelTest` methods)
480+
#### API Key (works for `runTest`, `restartTest` and `cancelTest` methods)
479481
* **key**: _String_, API key (if assigned). Contact the WebPageTest server administrator for a key if required
480482

481483
#### Request (works for `getTestStatus` `getResults` `getLocations` `getTesters` and `runTest` methods)

lib/mapping.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,12 @@ var commands = {
709709
info: 'run test',
710710
nokey: [options.results]
711711
},
712+
'restart': {
713+
name: 'restartTest',
714+
param: 'id',
715+
options: [options.apikey],
716+
info: 'restart test'
717+
},
712718
'cancel': {
713719
name: 'cancelTest',
714720
param: 'id',

lib/webpagetest.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function get(config, pathname, proxy, agent, callback, encoding) {
9393
if (encoding !== 'binary') {
9494
options.headers['accept-encoding'] = 'gzip,deflate';
9595
}
96-
96+
9797
if (agent) {
9898
options.agent = agent;
9999
}
@@ -472,6 +472,17 @@ function runTest(what, options, callback) {
472472
return api.call(this, paths.test, callback, query, options);
473473
}
474474

475+
function restartTest(id, options, callback) {
476+
var query = {resubmit: id};
477+
478+
callback = callback || options;
479+
options = options === callback ? undefined : options;
480+
481+
helper.setQuery(mapping.commands.restart, options, query);
482+
483+
return api.call(this, paths.test, callback, query, options);
484+
}
485+
475486
function cancelTest(id, options, callback) {
476487
var query = {test: id};
477488

@@ -759,6 +770,7 @@ WebPageTest.prototype = {
759770
getLocations: getLocations,
760771
getTesters: getTesters,
761772
runTest: runTest,
773+
restartTest: restartTest,
762774
cancelTest: cancelTest,
763775
getPageSpeedData: getPageSpeedData,
764776
getHARData: getHARData,

test/command-line-test.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,24 @@ describe('WebPageTest Command Line', function() {
142142
});
143143
});
144144

145+
it('gets a restart test input returns the API url', function(done) {
146+
exec(mock('restart 120816_V2_2'), function(err, data) {
147+
if (err) return done(err);
148+
data = JSON.parse(data);
149+
assert.equal(data.url, wptServer + 'runtest.php?resubmit=120816_V2_2');
150+
done();
151+
});
152+
});
153+
154+
it('gets a restart test with api key input returns the API url', function(done) {
155+
exec(mock('restart -k 12345 120816_V2_2'), function(err, data) {
156+
if (err) return done(err);
157+
data = JSON.parse(data);
158+
assert.equal(data.url, wptServer + 'runtest.php?resubmit=120816_V2_2&k=12345');
159+
done();
160+
});
161+
});
162+
145163
it('gets a cancel test input returns the API url', function(done) {
146164
exec(mock('cancel 120816_V2_2'), function(err, data) {
147165
if (err) return done(err);
@@ -306,7 +324,7 @@ describe('WebPageTest Command Line', function() {
306324

307325
// loop all commands help
308326
[
309-
'', 'status', 'results', 'locations', 'testers', 'test', 'cancel', 'har',
327+
'', 'status', 'results', 'locations', 'testers', 'test', 'restart', 'cancel', 'har',
310328
'pagespeed', 'utilization', 'request', 'timeline', 'netlog', 'chrometrace',
311329
'console', 'testinfo', 'history', 'googlecsi', 'response', 'waterfall',
312330
'screenshot', 'video', 'player', 'listen', 'batch'

test/dryrun-test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,22 @@ describe('Dry Run', function() {
156156
});
157157
});
158158

159+
it('gets a restart test request', function(done) {
160+
wpt.restartTest('120816_V2_2', {dryRun: true}, function (err, data) {
161+
if (err) return done(err);
162+
assert.equal(data.url, wptServer + 'runtest.php?resubmit=120816_V2_2');
163+
done();
164+
});
165+
});
166+
167+
it('gets a restart test with api key request', function(done) {
168+
wpt.restartTest('120816_V2_2', {key: '12345', dryRun: true}, function (err, data) {
169+
if (err) return done(err);
170+
assert.equal(data.url, wptServer + 'runtest.php?resubmit=120816_V2_2&k=12345');
171+
done();
172+
});
173+
});
174+
159175
it('gets a cancel test request', function(done) {
160176
wpt.cancelTest('120816_V2_2', {dryRun: true}, function (err, data) {
161177
if (err) return done(err);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
Usage: restart [options] <id>
3+
4+
restart test
5+
6+
Options:
7+
8+
-h, --help output usage information
9+
-k, --key <api_key> API key (if assigned). Contact the WebPageTest server administrator for a key if required
10+

test/fixtures/command-line/help.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
locations [options] list locations and the number of pending tests
1010
testers [options] list testers status and details
1111
test [options] <url_or_script> run test
12+
restart [options] <id> restart test
1213
cancel [options] <id> cancel running/pending test
1314
har <id> get the HTTP Archive (HAR) from test
1415
pagespeed [options] <id> get the Google Page Speed results (if available) from test

test/fixtures/objects/restart.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"testId":"120817_V2_2"}

test/fixtures/responses/restart.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"testId":"120817_V2_2"}

test/helpers/nock-server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var reqResMap = {
3232
'/getgzip.php?test=120816_V2_2&file=1_screen.jpg': 'screenshot.jpg',
3333
'/thumbnail.php?test=120816_V2_2&file=1_screen.jpg&run=1&cached=0': 'screenshotThumbnail.jpg',
3434
'/getgzip.php?test=120816_V2_2&file=1_screen.png': 'screenshotFullResolution.png',
35+
'/runtest.php?resubmit=120816_V2_2': 'restart.json',
3536
'/cancelTest.php?test=120816_V2_2': 'cancel.html',
3637
'/cancelTest.php?test=120816_V2_3': 'cancelNotCancelled.html',
3738
'/video/create.php?tests=130416_YS_KD4-r%3A3-c%3A1%2C130416_W6_KEE-r%3A8-c%3A1&f=json&end=visual': 'createVideo.json',

0 commit comments

Comments
 (0)