forked from catchpoint/WebPageTest.api-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapping.js
More file actions
986 lines (962 loc) · 24.4 KB
/
mapping.js
File metadata and controls
986 lines (962 loc) · 24.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
/**
* Copyright (c) 2013, Twitter Inc.
* Copyright (c) 2020, Google Inc.
* Copyright (c) 2020, Marcel Duran and other contributors
* Released under the MIT License
*/
var reBool = /^0|false|no|off$/i;
var options = {
common: {
server: {
name: "server",
key: "s",
param: "server",
info: "the WPT server URL [%s]",
},
dryrun: {
name: "dryRun",
key: "d",
bool: true,
info: "just return the RESTful API URL",
},
},
test: {
location: {
name: "location",
key: "l",
api: "location",
param: "location",
info: "location to test from",
},
// Test Setting tab
connectivity: {
name: "connectivity",
key: "y",
api: "connectivity",
param: "profile",
info: "connectivity profile (Cable|DSL|3GSlow|3G|3GFast|4G|LTE|Edge|2G|Dial|FIOS|Native|custom) [Cable]",
},
runs: {
name: "runs",
key: "r",
api: "runs",
param: "number",
info: "number of test runs [1]",
},
first: {
name: "firstViewOnly",
key: "f",
api: "fvonly",
bool: true,
info: "skip the Repeat View test",
},
video: {
name: "video",
key: "v",
api: "video",
bool: true,
info: "capture video",
},
private: {
name: "private",
key: "p",
api: "private",
bool: true,
info: "keep the test hidden from the test log",
},
label: {
name: "label",
key: "L",
api: "label",
param: "label",
info: "label for the test",
},
// Advanced tab
onload: {
name: "stopAtDocumentComplete",
key: "i",
api: "web10",
bool: true,
info: "stop test at document complete. typically, tests run until all activity stops",
},
noscript: {
name: "disableJavaScript",
key: "S",
api: "noscript",
bool: true,
info: "disable JavaScript (IE, Chrome, Firefox)",
},
clearcerts: {
name: "clearCerts",
key: "C",
api: "clearcerts",
bool: true,
info: "clear SSL certificate caches",
},
ignoressl: {
name: "ignoreSSL",
key: "R",
api: "ignoreSSL",
bool: true,
info: "ignore SSL certificate errors, e.g. name mismatch, self-signed certificates, etc",
},
standards: {
name: "disableCompatibilityView",
key: "T",
api: "standards",
bool: true,
info: "forces all pages to load in standards mode (IE only)",
},
tcpdump: {
name: "tcpDump",
key: "u",
api: "tcpdump",
bool: true,
info: "capture network packet trace (tcpdump)",
},
bodies: {
name: "saveResponseBodies",
key: "O",
api: "bodies",
bool: true,
info: "save response bodies for text resources",
},
keepua: {
name: "keepOriginalUserAgent",
key: "K",
api: "keepua",
bool: true,
info: "do not add PTST to the original browser User Agent string",
},
dom: {
name: "domElement",
key: "m",
api: "domelement",
param: "element",
info: "DOM element to record for sub-measurement",
},
duration: {
name: "minimumDuration",
key: "N",
api: "time",
param: "seconds",
info: "minimum test duration in seconds",
},
tester: {
name: "tester",
key: "E",
api: "tester",
param: "name",
info: "run the test on a specific PC (name must match exactly or the test will not run)",
},
injectScript: {
name: "injectScript",
api: "injectScript",
param: "injectScript",
info: "JavaScript to run after the document has started loading",
},
// Chrome tab
mobile: {
name: "emulateMobile",
key: "W",
api: "mobile",
bool: true,
info: "(experimental) emulate mobile browser: Chrome mobile user agent, 640x960 screen, 2x scaling and fixed viewport (Chrome only)",
},
device: {
name: "device",
api: "mobileDevice",
param: "string",
info: "device name from mobile_devices.ini to use for mobile emulation (only when mobile=1 is specified to enable emulation and only for Chrome)",
},
timeline: {
name: "timeline",
key: "M",
api: "timeline",
bool: true,
info: "capture Developer Tools Timeline (Chrome only)",
},
callstack: {
name: "timelineCallStack",
key: "J",
api: "timelineStack",
bool: true,
info: "set between 1-5 to include the JS call stack. must be used in conjunction with timeline (increases overhead) (Chrome only)",
valid: /[1-5]/,
},
chrometrace: {
name: "chromeTrace",
key: "q",
api: "trace",
bool: true,
info: "capture chrome trace (about://tracing) (Chrome only)",
},
tracecategories: {
name: "traceCategories",
api: "traceCategories",
param: "categories",
info: "trace categories (when chrometrace enabled) (Chrome only)",
},
netlog: {
name: "netLog",
key: "G",
api: "netlog",
bool: true,
info: "capture Network Log (Chrome only)",
},
datareduction: {
name: "dataReduction",
key: "Q",
api: "dataReduction",
bool: true,
info: "enable data reduction on Chrome 34+ Android (Chrome only)",
},
useragent: {
name: "userAgent",
key: "x",
api: "uastring",
param: "string",
info: "custom user agent string (Chrome only)",
},
cmdline: {
name: "commandLine",
key: "X",
api: "cmdline",
param: "switches",
info: "use a list of custom command line switches (Chrome only)",
},
lighthouse: {
name: "lighthouse",
api: "lighthouse",
bool: true,
info: "perform lighthouse test (Chrome only, Linux agent only)",
},
//throttle_cpu param
throttleCPU: {
name: "throttleCPU",
key: "thc",
api: "throttle_cpu",
param: "number",
info: "custom cpu throttling",
},
// Auth tab
login: {
name: "login",
key: "g",
api: "login",
param: "username",
info: "username for authenticating tests (http authentication)",
},
password: {
name: "password",
key: "w",
api: "password",
param: "password",
info: "password for authenticating tests (http authentication)",
},
// Script tab
sensitive: {
name: "sensitive",
key: "t",
api: "sensitive",
bool: true,
info: "discard script and http headers in the result",
},
noheaders: {
name: "disableHTTPHeaders",
key: "H",
api: "noheaders",
bool: true,
info: "disable saving of the http headers (as well as browser status messages and CPU utilization)",
},
// Block tab
block: {
name: "block",
key: "b",
api: "block",
param: "urls",
array: true,
info: "space-delimited list of urls to block (substring match)",
},
// SPOF tab
spof: {
name: "spof",
key: "Z",
api: "spof",
param: "domains",
array: true,
info: "space-delimited list of domains to simulate failure by re-routing to blackhole.webpagetest.org to silently drop all requests",
},
// Custom tab
custom: {
name: "customMetrics",
key: "c",
api: "custom",
param: "script",
info: "execute arbitrary JavaScript at the end of a test to collect custom metrics",
},
// API only settings
authtype: {
name: "authenticationType",
key: "a",
api: "authType",
param: "type",
info: "type of authentication: 0 = Basic, 1 = SNS [0]",
},
notify: {
name: "notifyEmail",
key: "n",
api: "notify",
param: "e-mail",
info: "e-mail address to notify with the test results",
},
pingback: {
name: "pingback",
key: "B",
api: "pingback",
param: "url",
info: 'URL to ping when the test is complete (the test ID will be passed as an "id" parameter)',
},
bwdown: {
name: "bandwidthDown",
key: "D",
api: "bwDown",
param: "bandwidth",
info: "download bandwidth in Kbps (used when specifying a custom connectivity profile)",
},
bwup: {
name: "bandwidthUp",
key: "U",
api: "bwUp",
param: "bandwidth",
info: "upload bandwidth in Kbps (used when specifying a custom connectivity profile)",
},
browserwidth: {
name: "browserwidth",
key: "bw",
api: "browser_width",
param: "pixels",
info: "Browser window width (in display pixels)",
},
browserheight: {
name: "browserheight",
key: "bh",
api: "browser_height",
param: "pixels",
info: "Browser window height (in display pixels)",
},
viewportheight: {
name: "viewportheight",
key: "vh",
api: "height",
param: "pixels",
info: "Viewport Height in css pixels",
},
viewportwidth: {
name: "viewportwidth",
key: "vw",
api: "width",
param: "pixels",
info: "Viewport Width in css pixels",
},
devicetopixelratio: {
name: "devicetopixelratio",
key: "dpr",
api: "dpr",
param: "ratio",
info: "Device To Pixel Ratio",
},
appendua: {
name: "appendua",
key: "au",
api: "appendua",
param: "string",
info: "String to append to the user agent string. This is in addition to the default PTST/ver string",
},
testtype: {
name: "testtype",
key: "tt",
api: "type",
param: "string",
info: "For running alternative test types, can specify traceroute or lighthouse",
},
profiler: {
name: "profiler",
key: "pr",
api: "profiler",
param: "number",
info: "Set to 1 to enable the V8 sampling profiler (Chromium only)",
},
disableAVIF: {
name: "disableAVIF",
key: "avif",
api: "disableAVIF",
param: "number",
info: "Set to 1 to disable AVIF support (Chromium 88+)",
},
disableWEBP: {
name: "disableWEBP",
key: "webp",
api: "disableWEBP",
param: "number",
info: "Set to 1 to disable WEBP support (Chromium 88+)",
},
disableJXL: {
name: "disableJXL",
key: "jxl",
api: "disableJXL",
param: "number",
info: "Set to 1 to disable JpegXL support (Chromium 88+)",
},
dtShaper: {
name: "dtShaper",
key: "dts",
api: "dtShaper",
param: "number",
info: "Set to 1 to use Chrome's built-in traffic-shaping instead of the packet-level netem shaping usually used by the test agents",
},
latency: {
name: "latency",
key: "Y",
api: "latency",
param: "time",
info: "first-hop Round Trip Time in ms (used when specifying a custom connectivity profile)",
},
plr: {
name: "packetLossRate",
key: "P",
api: "plr",
param: "percentage",
info: "packet loss rate - percent of packets to drop (used when specifying a custom connectivity profile)",
},
noopt: {
name: "disableOptimization",
key: "z",
api: "noopt",
bool: true,
info: "disable optimization checks (for faster testing)",
},
noimages: {
name: "disableScreenshot",
key: "I",
api: "noimages",
bool: true,
info: "disable screen shot capturing",
},
full: {
name: "fullResolutionScreenshot",
key: "F",
api: "pngss",
bool: true,
info: "save a full-resolution version of the fully loaded screen shot as a PNG",
},
jpeg: {
name: "jpegQuality",
key: "j",
api: "iq",
param: "level",
info: "jpeg compression level (30-100) for the screen shots and video capture",
},
medianvideo: {
name: "medianVideo",
key: "A",
api: "mv",
bool: true,
info: "store the video from the median run when capturing video is enabled",
},
htmlbody: {
name: "htmlBody",
api: "htmlbody",
bool: true,
info: "save the content of only the base HTML response",
},
tsview: {
name: "tsView",
api: "tsview_id",
param: "id",
info: "test name to use when submitting results to tsviewdb (for private instances that have integrated with tsviewdb)",
},
tsviewconfigs: {
name: "tsViewConfigs",
api: "tsview_configs",
param: "string",
info: "configs to use when submitting results to tsviewdb (for private instances that have integrated with tsviewdb)",
},
affinity: {
name: "affinity",
api: "affinity",
param: "string",
info: "string to hash test to a specific test agent. tester will be picked by index among available testers",
},
priority: {
name: "priority",
api: "priority",
param: "number",
info: "change test priority (0-9) [enforced by API key, otherwise 5]",
valid: /^\d$/,
},
// Undocumented/experimental/transitent/deprecated
noads: {
name: "blockAds",
api: "blockads",
bool: true,
info: "block ads defined by adblockrules.org",
},
continuous: {
name: "continuousVideoCapture",
api: "continuousVideo",
bool: true,
info: "capture video continuously (unstable/experimental, may cause tests to fail)",
},
spdy3: {
name: "forceSpdy3",
api: "spdy3",
bool: true,
info: "force SPDY version 3 (Chrome only)",
},
swrender: {
name: "forceSoftwareRendering",
api: "swrender",
bool: true,
info: "force software rendering, disable GPU acceleration (Chrome only)",
},
// Synchonous tests + results
poll: {
name: "pollResults",
param: "interval",
optional: true,
info: "poll for results after test is scheduled at every <interval> seconds [5]",
},
wait: {
name: "waitResults",
param: "hostname:port",
optional: true,
info: "wait for test results informed by agent once complete listening on <hostname>:<port> [hostname:first port available above 8000]",
},
timeout: {
name: "timeout",
param: "seconds",
info: "timeout for polling and waiting results [no timeout]",
},
},
request: {
request: {
name: "requestId",
key: "e",
api: "r",
param: "id",
info: "echo request ID, useful to track asynchronous requests",
},
},
run: {
run: {
name: "run",
key: "r",
param: "number",
info: "which run number on a multiple runs test [1]",
},
cached: {
name: "repeatView",
key: "c",
bool: true,
info: "get the Repeat View (cached view) instead of default First View (primed cache)",
},
},
image: {
thumbnail: {
name: "thumbnail",
key: "t",
bool: true,
info: "get the thumbnail of actual image",
},
uri: {
name: "dataURI",
key: "u",
bool: true,
info: "return the base64 string representation (inline) of actual image",
},
},
screenshot: {
full: {
name: "fullResolution",
key: "f",
bool: true,
info: "get full resolution screenshot in PNG format if available",
},
render: {
name: "startRender",
key: "n",
bool: true,
info: "get the page screenshot at the Start Render point (i.e.: when something was first displayed on screen)",
},
complete: {
name: "documentComplete",
key: "p",
bool: true,
info: "get the page screenshot at the Document Complete point (i.e.: when window.onload was fired)",
},
},
results: {
breakdown: {
name: "breakDown",
key: "b",
api: "breakdown",
bool: true,
info: "include the breakdown of requests and bytes by mime type",
},
domains: {
name: "domains",
key: "D",
api: "domains",
bool: true,
info: "include the breakdown of requests and bytes by domain",
},
pagespeed: {
name: "pageSpeed",
key: "p",
api: "pagespeed",
bool: true,
info: "include the PageSpeed score in the response (may be slower)",
},
requests: {
name: "requests",
key: "R",
api: "requests",
bool: true,
info: "include the request data in the response (slower and results in much larger responses)",
},
median: {
name: "medianMetric",
key: "m",
api: "medianMetric",
param: "metric",
info: "set the metric used to calculate median for multiple runs tests [loadTime]",
},
medianrun: {
name: "medianRun",
api: "medianRun",
param: "metric",
info: "set the run used for median for multiple runs tests [median]",
},
specs: {
name: "specs",
key: "S",
param: "json_or_file",
info: "set the specs for performance test suite",
},
reporter: {
name: "reporter",
key: "r",
param: "name",
info: "set performance test suite reporter output: [dot]|spec|tap|xunit|list|progress|min|nyan|landing|json|doc|markdown|teamcity",
valid:
/^(?:dot|spec|tap|xunit|list|progress|min|nyan|landing|json|doc|markdown|teamcity)$/,
},
proxy: {
name: "proxy",
info: "set the proxy used to fetch results",
},
},
waterfall: {
type: {
name: "chartType",
api: "type",
key: "T",
param: "chart",
info: "set the chart type: waterfall or connection [waterfall]",
},
mime: {
name: "colorByMime",
api: "mime",
key: "M",
bool: true,
info: "set chart coloring by MIME type [false]",
},
width: {
name: "chartWidth",
api: "width",
key: "w",
param: "px",
info: "chart image width in px (300-2000) [930]",
},
max: {
name: "maxTime",
api: "max",
key: "m",
param: "seconds",
info: "set maximum time in seconds [automatic]",
},
requests: {
name: "requests",
api: "requests",
key: "R",
param: "items",
info: "filter requests (e.g.:1,2,3,4-9,8) [all]",
},
nocpu: {
name: "noCPU",
api: "cpu",
key: "C",
bool: true,
invert: true,
info: "hide CPU utilization [false]",
},
nobandwidth: {
name: "noBandwidth",
api: "bw",
key: "b",
bool: true,
invert: true,
info: "hide bandwidth utilization [false]",
},
noellipsis: {
name: "noEllipsis",
api: "dots",
key: "i",
bool: true,
invert: true,
info: "hide ellipsis (...) for missing items [false]",
},
nolabels: {
name: "noLabels",
api: "labels",
key: "l",
bool: true,
invert: true,
info: "hide labels for requests (URL) [false]",
},
},
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",
},
},
video: {
end: {
name: "comparisonEndPoint",
key: "e",
api: "end",
param: "end_point",
info: "frame comparison end point: [visual]=visually complete | all=last change | doc=document complete | full=fully loaded",
valid: /^(?:visual|all|doc|full)$/,
},
},
response: {
request: {
name: "request",
api: "request",
key: "R",
param: "number",
info: "the request number [1]",
},
},
listen: {
key: {
name: "key",
key: "k",
param: "file",
info: "private key file to use for SSL",
},
cert: {
name: "cert",
key: "c",
param: "file",
info: "public x509 certificate file to use for SSL",
},
},
};
var commands = {
status: {
name: "getTestStatus",
param: "id",
options: [options.request],
info: "check test status",
},
results: {
name: "getTestResults",
param: "id",
options: [options.results, options.request],
info: "get test results",
},
locations: {
name: "getLocations",
options: [options.request, options.apikey],
info: "list locations and the number of pending tests",
},
testBalance: {
name: "getTestBalance",
options: [options.apikey],
info: "get remaining tests for the account",
},
testers: {
name: "getTesters",
options: [options.request],
info: "list testers status and details",
},
test: {
name: "runTest",
param: "url_or_script",
options: [options.apikey, options.test, options.request, options.results],
info: "run test",
nokey: [options.results],
},
restart: {
name: "restartTest",
param: "id",
options: [options.apikey],
info: "restart test",
},
cancel: {
name: "cancelTest",
param: "id",
options: [options.apikey],
info: "cancel running/pending test",
},
har: {
name: "getHARData",
param: "id",
info: "get the HTTP Archive (HAR) from test",
},
pagespeed: {
name: "getPageSpeedData",
param: "id",
options: [options.run],
info: "get the Google Page Speed results (if available) from test",
},
utilization: {
name: "getUtilizationData",
param: "id",
options: [options.run],
info: "get the CPU, bandwidth and memory utilization data from test",
},
request: {
name: "getRequestData",
param: "id",
options: [options.run],
info: "get the request data from test",
},
timeline: {
name: "getTimelineData",
param: "id",
options: [options.run],
info: "get the Chrome Developer Tools Timeline data (if available) from test",
},
netlog: {
name: "getNetLogData",
param: "id",
options: [options.run],
info: "get the Chrome Developer Tools Net log data (if available) from test",
},
chrometrace: {
name: "getChromeTraceData",
param: "id",
options: [options.run],
info: "get the Chrome Trace data (if available) from test",
},
console: {
name: "getConsoleLogData",
param: "id",
options: [options.run],
info: "get the browser console log data (if available) from test",
},
testinfo: {
name: "getTestInfo",
param: "id",
info: "get test request info/details",
},
history: {
name: "getHistory",
param: "days",
optional: true,
info: "get history of previously run tests",
},
googlecsi: {
name: "getGoogleCsiData",
param: "id",
options: [options.run],
info: "get Google CSI data (Client Side Instrumentation)",
},
response: {
name: "getResponseBody",
param: "id",
options: [options.run, options.response],
info: "get response body for text resources",
},
waterfall: {
name: "getWaterfallImage",
param: "id",
options: [options.run, options.image, options.waterfall],
info: "get the waterfall PNG image",
},
screenshot: {
name: "getScreenshotImage",
param: "id",
options: [options.run, options.image, options.screenshot],
info: "get the fully loaded page screenshot in JPG format (PNG if in full resolution)",
},
video: {
name: "createVideo",
param: "tests",
options: [options.video],
info: "create a video from <tests> (comma separated test ids)",
},
player: {
name: "getEmbedVideoPlayer",
param: "id",
info: "get a html5 player for a video <id>",
},
listen: {
name: "listen",
param: "hostname:port",
optional: true,
options: [options.listen],
info: "start webpagetest-api proxy server on <hostname>:<port> [hostname:%s]",
},
};
// add options shorthands by referrencing flag through key
Object.keys(options).forEach(function eachType(type) {
Object.keys(options[type]).forEach(function eachOption(option) {
var obj = options[type][option];
if (obj.key) {
options[type][obj.key] = obj;
}
});
});
// set valid options only per command
function setOptions(command, query) {
var count, opts;
command = commands[command];
if (!command) {
return;
}
opts = {};
count = Object.keys(query).length;
[options.common].concat(command.options).some(function someTypes(options) {
if (!options) {
return;
}
Object.keys(options).some(function someOptions(key) {
var valid = options[key].valid;
if (key in query) {
if (options[key].bool) {
opts[options[key].name] = !reBool.test(query[key]);
} else if (!valid || (valid && valid.test(query[key]))) {
opts[options[key].name] = decodeURIComponent(query[key]);
}
count -= 1;
}
return count === 0;
});
return count === 0;
});
return opts;
}
module.exports = {
setOptions: setOptions,
commands: commands,
options: options,
};