UNPKG

3.56 kBJavaScriptView Raw
1/*
2 * Copyright 2018 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12
13'use strict';
14
15const { getOrCreateLogger } = require('./log-common.js');
16
17module.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 // eslint-disable-next-line global-require
108 const PerfCommand = require('./perf.cmd'); // lazy load the handler to speed up execution time
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};