1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | 'use strict';
|
14 |
|
15 | const { getOrCreateLogger } = require('./log-common.js');
|
16 |
|
17 | module.exports = function perf() {
|
18 | let executor;
|
19 |
|
20 | return {
|
21 | set executor(value) {
|
22 | executor = value;
|
23 | },
|
24 | command: 'perf',
|
25 | desc: 'Test performance',
|
26 | builder: (yargs) => {
|
27 | yargs
|
28 | .option('fastly-namespace', {
|
29 | alias: 'fastlyNamespace',
|
30 | describe: 'CDN Namespace (e.g. Fastly Service ID)',
|
31 | type: 'string',
|
32 |
|
33 | })
|
34 | .option('fastly-auth', {
|
35 | alias: 'fastlyAuth',
|
36 | describe: 'API Key for Fastly API ($HLX_FASTLY_AUTH)',
|
37 | type: 'string',
|
38 | })
|
39 | .option('junit', {
|
40 | describe: 'Create JUnit report in this file',
|
41 | type: 'string',
|
42 | default: '',
|
43 | })
|
44 | .option('device', {
|
45 | describe: 'Device to test from',
|
46 | type: 'string',
|
47 | default: 'MotorolaMotoG4',
|
48 | choices: ['MotorolaMotoG4',
|
49 | 'iPhone5',
|
50 | 'iPhone6',
|
51 | 'iPhone6Plus',
|
52 | 'iPhone7',
|
53 | 'iPhone8',
|
54 | 'Nexus5X',
|
55 | 'Nexus6P',
|
56 | 'GalaxyS5',
|
57 | 'iPad',
|
58 | 'iPadPro'],
|
59 | })
|
60 | .option('connection', {
|
61 | describe: 'Throttle connection speed to',
|
62 | default: 'regular3G',
|
63 | type: 'string',
|
64 | choices: ['regular2G',
|
65 | 'good2G',
|
66 | 'slow3G',
|
67 | 'regular3G',
|
68 | 'good3G',
|
69 | 'emergingMarkets',
|
70 | 'regular4G',
|
71 | 'LTE',
|
72 | 'dsl',
|
73 | 'wifi',
|
74 | 'cable'],
|
75 | })
|
76 | .option('location', {
|
77 | describe: 'Run the test from this location',
|
78 | type: 'string',
|
79 | default: 'London',
|
80 | choices: ['NorthVirginia',
|
81 | 'Frankfurt',
|
82 | 'Sydney',
|
83 | 'Ohio',
|
84 | 'California',
|
85 | 'Oregon',
|
86 | 'Canada',
|
87 | 'Ireland',
|
88 | 'Tokyo',
|
89 | 'Seoul',
|
90 | 'Singapore',
|
91 | 'Mumbai',
|
92 | 'SaoPaulo',
|
93 | 'London'],
|
94 | })
|
95 | .demandOption(
|
96 | 'fastly-auth',
|
97 | 'Authentication is required. You can pass the key via the HLX_FASTLY_AUTH environment variable, too',
|
98 | )
|
99 | .demandOption(
|
100 | 'fastly-namespace',
|
101 | 'Fastly Service ID is required',
|
102 | )
|
103 | .help();
|
104 | },
|
105 | handler: async (argv) => {
|
106 | if (!executor) {
|
107 |
|
108 | const PerfCommand = require('./perf.cmd');
|
109 | executor = new PerfCommand(getOrCreateLogger(argv));
|
110 | }
|
111 |
|
112 | await executor
|
113 | .withFastlyNamespace(argv.fastlyNamespace)
|
114 | .withFastlyAuth(argv.fastlyAuth)
|
115 | .withDevice(argv.device)
|
116 | .withConnection(argv.connection)
|
117 | .withLocation(argv.location)
|
118 | .withJunit(argv.junit)
|
119 | .run();
|
120 | },
|
121 | };
|
122 | };
|