1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
13 | if (k2 === undefined) k2 = k;
|
14 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
15 | }) : (function(o, m, k, k2) {
|
16 | if (k2 === undefined) k2 = k;
|
17 | o[k2] = m[k];
|
18 | }));
|
19 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
20 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
21 | }) : function(o, v) {
|
22 | o["default"] = v;
|
23 | });
|
24 | var __importStar = (this && this.__importStar) || function (mod) {
|
25 | if (mod && mod.__esModule) return mod;
|
26 | var result = {};
|
27 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
28 | __setModuleDefault(result, mod);
|
29 | return result;
|
30 | };
|
31 | Object.defineProperty(exports, "__esModule", { value: true });
|
32 | exports.specUrl = exports.specsFromOpts = void 0;
|
33 | const path = __importStar(require("path"));
|
34 | const browser_1 = require("./browser");
|
35 | const config_1 = require("./config");
|
36 | const defaults = __importStar(require("./defaults"));
|
37 | const util_1 = require("./util");
|
38 | const versions_1 = require("./versions");
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | async function specsFromOpts(opts) {
|
45 | let windowSize;
|
46 | if (opts['window-size']) {
|
47 | const match = opts['window-size'].match(/^(\d+),(\d+)$/);
|
48 | if (match === null) {
|
49 | throw new Error(`Invalid --window-size flag, must match "width,height, " ` +
|
50 | `but was "${opts['window-size']}"`);
|
51 | }
|
52 | windowSize = {
|
53 | width: Number(match[1]),
|
54 | height: Number(match[2]),
|
55 | };
|
56 | }
|
57 | else {
|
58 | windowSize = {
|
59 | width: defaults.windowWidth,
|
60 | height: defaults.windowHeight,
|
61 | };
|
62 | }
|
63 | const browserStrings = new Set((opts.browser || defaults.browserName)
|
64 | .replace(/\s+/, '')
|
65 | .split(',')
|
66 | .filter((b) => b !== ''));
|
67 | if (browserStrings.size === 0) {
|
68 | throw new Error('At least one --browser must be specified');
|
69 | }
|
70 | const browsers = [...browserStrings].map((str) => {
|
71 | const config = Object.assign(Object.assign({}, browser_1.parseBrowserConfigString(str)), { windowSize });
|
72 | browser_1.validateBrowserConfig(config);
|
73 | return config;
|
74 | });
|
75 | const specs = [];
|
76 | const versions = versions_1.parsePackageVersions(opts['package-version']);
|
77 | if (versions.length === 0) {
|
78 | versions.push(undefined);
|
79 | }
|
80 | let measurement;
|
81 | if (opts.measure === 'callback') {
|
82 | measurement = {
|
83 | mode: 'callback',
|
84 | };
|
85 | }
|
86 | else if (opts.measure === 'fcp') {
|
87 | measurement = {
|
88 | mode: 'performance',
|
89 | entryName: 'first-contentful-paint',
|
90 | };
|
91 | }
|
92 | else if (opts.measure === 'global') {
|
93 | measurement = {
|
94 | mode: 'expression',
|
95 | expression: opts['measurement-expression'] || defaults.measurementExpression,
|
96 | };
|
97 | }
|
98 | else if (opts.measure !== undefined) {
|
99 | util_1.throwUnreachable(opts.measure, `Internal error: unknown measure ${JSON.stringify(opts.measure)}`);
|
100 | }
|
101 |
|
102 |
|
103 | for (const argStr of opts._unknown || []) {
|
104 | const arg = parseBenchmarkArgument(argStr);
|
105 | if (arg.kind === 'remote') {
|
106 | const url = {
|
107 | kind: 'remote',
|
108 | url: arg.url,
|
109 | };
|
110 | for (const browser of browsers) {
|
111 | const spec = {
|
112 | name: arg.alias || arg.url,
|
113 | browser,
|
114 | measurement: [measurement === undefined ? defaults.measurement(url) :
|
115 | measurement],
|
116 | url,
|
117 | };
|
118 | specs.push(spec);
|
119 | }
|
120 | }
|
121 | else {
|
122 | const root = opts.root || defaults.root;
|
123 | const urlPath = await config_1.urlFromLocalPath(root, arg.diskPath);
|
124 | let name = arg.alias;
|
125 | if (name === undefined) {
|
126 | const serverRelativePath = path.relative(root, arg.diskPath);
|
127 | name = serverRelativePath.replace(/\\/g, '/');
|
128 | }
|
129 | for (const browser of browsers) {
|
130 | for (const version of versions) {
|
131 | const url = {
|
132 | kind: 'local',
|
133 | urlPath,
|
134 | queryString: arg.queryString,
|
135 | version,
|
136 | };
|
137 | const spec = {
|
138 | name,
|
139 | browser,
|
140 | measurement: [measurement === undefined ? defaults.measurement(url) :
|
141 | measurement],
|
142 | url,
|
143 | };
|
144 | specs.push(spec);
|
145 | }
|
146 | }
|
147 | }
|
148 | }
|
149 | return specs;
|
150 | }
|
151 | exports.specsFromOpts = specsFromOpts;
|
152 | function parseBenchmarkArgument(str) {
|
153 | if (util_1.isHttpUrl(str)) {
|
154 |
|
155 | return {
|
156 | kind: 'remote',
|
157 | url: str,
|
158 | };
|
159 | }
|
160 | if (str.includes('=')) {
|
161 | const eq = str.indexOf('=');
|
162 | const maybeUrl = str.substring(eq + 1);
|
163 | if (util_1.isHttpUrl(maybeUrl)) {
|
164 |
|
165 | return {
|
166 | kind: 'remote',
|
167 | url: maybeUrl,
|
168 | alias: str.substring(0, eq),
|
169 | };
|
170 | }
|
171 | }
|
172 | let queryString = '';
|
173 | if (str.includes('?')) {
|
174 |
|
175 |
|
176 | const q = str.indexOf('?');
|
177 | queryString = str.substring(q);
|
178 | str = str.substring(0, q);
|
179 | }
|
180 | let alias = undefined;
|
181 | if (str.includes('=')) {
|
182 |
|
183 |
|
184 | const eq = str.indexOf('=');
|
185 | alias = str.substring(0, eq);
|
186 | str = str.substring(eq + 1);
|
187 | }
|
188 |
|
189 |
|
190 |
|
191 |
|
192 | return {
|
193 | kind: 'local',
|
194 | alias,
|
195 | diskPath: str,
|
196 | queryString: queryString,
|
197 | };
|
198 | }
|
199 | function specUrl(spec, servers, config) {
|
200 | if (spec.url.kind === 'remote') {
|
201 | return spec.url.url;
|
202 | }
|
203 | const server = servers.get(spec);
|
204 | if (server === undefined) {
|
205 | throw new Error('Internal error: no server for spec');
|
206 | }
|
207 | if (config.remoteAccessibleHost !== '' &&
|
208 | spec.browser.remoteUrl !== undefined) {
|
209 | return 'http://' + config.remoteAccessibleHost + ':' + server.port +
|
210 | spec.url.urlPath + spec.url.queryString;
|
211 | }
|
212 | return server.url + spec.url.urlPath + spec.url.queryString;
|
213 | }
|
214 | exports.specUrl = specUrl;
|
215 |
|
\ | No newline at end of file |