1 | /**
|
2 | * @license
|
3 | * Copyright (c) 2019 The Polymer Project Authors. All rights reserved.
|
4 | * This code may only be used under the BSD style license found at
|
5 | * http://polymer.github.io/LICENSE.txt The complete set of authors may be found
|
6 | * at http://polymer.github.io/AUTHORS.txt The complete set of contributors may
|
7 | * be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by
|
8 | * Google as part of the polymer project is also subject to an additional IP
|
9 | * rights grant found at http://polymer.github.io/PATENTS.txt
|
10 | */
|
11 | import { BrowserName } from './browser';
|
12 | import { Config } from './config';
|
13 | import { ExtendedPackageDependencyMap, Measurement } from './types';
|
14 | /**
|
15 | * Expected format of the top-level JSON config file. Note this interface is
|
16 | * used to generate the JSON schema for validation.
|
17 | */
|
18 | export interface ConfigFile {
|
19 | /**
|
20 | * Root directory to serve benchmarks from (default current directory).
|
21 | */
|
22 | root?: string;
|
23 | /**
|
24 | * Minimum number of times to run each benchmark (default 50).
|
25 | * @TJS-type integer
|
26 | * @TJS-minimum 2
|
27 | */
|
28 | sampleSize?: number;
|
29 | /**
|
30 | * The maximum number of minutes to spend auto-sampling (default 3).
|
31 | * @TJS-minimum 0
|
32 | */
|
33 | timeout?: number;
|
34 | /**
|
35 | * The degrees of difference to try and resolve when auto-sampling
|
36 | * (e.g. 0ms, +1ms, -1ms, 0%, +1%, -1%, default 0%).
|
37 | */
|
38 | horizons?: string[];
|
39 | /**
|
40 | * Benchmarks to run.
|
41 | * @TJS-minItems 1
|
42 | */
|
43 | benchmarks: ConfigFileBenchmark[];
|
44 | /**
|
45 | * Whether to automatically convert ES module imports with bare module
|
46 | * specifiers to paths.
|
47 | */
|
48 | resolveBareModules?: boolean;
|
49 | /**
|
50 | * An optional reference to the JSON Schema for this file.
|
51 | *
|
52 | * If none is given, and the file is a valid tachometer config file,
|
53 | * tachometer will write back to the config file to give this a value.
|
54 | */
|
55 | $schema?: string;
|
56 | }
|
57 | /**
|
58 | * Expected format of a benchmark in a JSON config file.
|
59 | */
|
60 | interface ConfigFileBenchmark {
|
61 | /**
|
62 | * A fully qualified URL, or a local path to an HTML file or directory. If a
|
63 | * directory, must contain an index.html. Query parameters are permitted on
|
64 | * local paths (e.g. 'my/benchmark.html?foo=bar').
|
65 | */
|
66 | url?: string;
|
67 | /**
|
68 | * An optional label for this benchmark. Defaults to the URL.
|
69 | */
|
70 | name?: string;
|
71 | /**
|
72 | * Which browser to run the benchmark in.
|
73 | *
|
74 | * Options:
|
75 | * - chrome (default)
|
76 | * - chrome-headless
|
77 | * - firefox
|
78 | * - firefox-headless
|
79 | * - safari
|
80 | * - edge
|
81 | * - ie
|
82 | */
|
83 | browser?: string | BrowserConfigs;
|
84 | /**
|
85 | * Which time interval to measure.
|
86 | *
|
87 | * Options:
|
88 | * - callback: bench.start() to bench.stop() (default for local paths)
|
89 | * - fcp: first contentful paint (default for fully qualified URLs)
|
90 | * - global: result returned from window.tachometerResult (or custom
|
91 | * expression set via measurementExpression)
|
92 | * - {
|
93 | * performanceEntry: {
|
94 | * //
|
95 | * https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry/name
|
96 | * name: string;
|
97 | * }
|
98 | * }
|
99 | */
|
100 | measurement?: ConfigFileMeasurement;
|
101 | /**
|
102 | * Expression to use to retrieve global result. Defaults to
|
103 | * `window.tachometerResult`.
|
104 | */
|
105 | measurementExpression?: string;
|
106 | /**
|
107 | * Optional NPM dependency overrides to apply and install. Only supported with
|
108 | * local paths.
|
109 | */
|
110 | packageVersions?: ConfigFilePackageVersion;
|
111 | /**
|
112 | * Recursively expand this benchmark configuration with any number of
|
113 | * variations. Useful for testing the same base configuration with e.g.
|
114 | * multiple browers or package versions.
|
115 | */
|
116 | expand?: ConfigFileBenchmark[];
|
117 | }
|
118 | declare type ConfigFileMeasurement = 'callback' | 'fcp' | 'global' | Measurement | Array<Measurement>;
|
119 | declare type BrowserConfigs = ChromeConfig | FirefoxConfig | SafariConfig | EdgeConfig | IEConfig;
|
120 | interface BrowserConfigBase {
|
121 | /**
|
122 | * Name of the browser:
|
123 | *
|
124 | * Options:
|
125 | * - chrome
|
126 | * - firefox
|
127 | * - safari
|
128 | * - edge
|
129 | * - ie
|
130 | */
|
131 | name: BrowserName;
|
132 | /**
|
133 | * A remote WebDriver server HTTP address to launch the browser from.
|
134 | */
|
135 | remoteUrl?: string;
|
136 | /**
|
137 | * The size of new windows created from this browser. Defaults to 1024x768.
|
138 | */
|
139 | windowSize?: WindowSize;
|
140 | }
|
141 | interface WindowSize {
|
142 | /**
|
143 | * Width of the browser window in pixels. Defaults to 1024.
|
144 | *
|
145 | * @TJS-type integer
|
146 | * @TJS-minimum 0
|
147 | */
|
148 | width: number;
|
149 | /**
|
150 | * Height of the browser window in pixels. Defaults to 768.
|
151 | *
|
152 | * @TJS-type integer
|
153 | * @TJS-minimum 0
|
154 | */
|
155 | height: number;
|
156 | }
|
157 | interface ChromeConfig extends BrowserConfigBase {
|
158 | name: 'chrome';
|
159 | /**
|
160 | * Whether to launch the headless (no GUI) version of this browser.
|
161 | */
|
162 | headless?: boolean;
|
163 | /**
|
164 | * Path to the binary to use when launching this browser, instead of the
|
165 | * default one.
|
166 | */
|
167 | binary?: string;
|
168 | /**
|
169 | * Additional command-line arguments to pass when launching the browser.
|
170 | */
|
171 | addArguments?: string[];
|
172 | /**
|
173 | * Command-line arguments that WebDriver normally adds by default when
|
174 | * launching the browser, which you would like to omit.
|
175 | */
|
176 | removeArguments?: string[];
|
177 | /**
|
178 | * Optional CPU Throttling rate. (1 is no throttle, 2 is 2x slowdown,
|
179 | * etc). This is currently only supported in headless mode.
|
180 | * @TJS-minimum 1
|
181 | */
|
182 | cpuThrottlingRate?: number;
|
183 | }
|
184 | interface FirefoxConfig extends BrowserConfigBase {
|
185 | name: 'firefox';
|
186 | /**
|
187 | * Whether to launch the headless (no GUI) version of this browser.
|
188 | */
|
189 | headless?: boolean;
|
190 | /**
|
191 | * Path to the binary to use when launching this browser, instead of the
|
192 | * default one.
|
193 | */
|
194 | binary?: string;
|
195 | /**
|
196 | * Additional command-line arguments to pass when launching the browser.
|
197 | */
|
198 | addArguments?: string[];
|
199 | /**
|
200 | * Advanced preferences that are usually set from the about:config page
|
201 | * in Firefox (see
|
202 | * https://support.mozilla.org/en-US/kb/about-config-editor-firefox).
|
203 | */
|
204 | preferences?: {
|
205 | [name: string]: string | number | boolean;
|
206 | };
|
207 | }
|
208 | interface SafariConfig extends BrowserConfigBase {
|
209 | name: 'safari';
|
210 | }
|
211 | interface EdgeConfig extends BrowserConfigBase {
|
212 | name: 'edge';
|
213 | }
|
214 | interface IEConfig extends BrowserConfigBase {
|
215 | name: 'ie';
|
216 | }
|
217 | interface ConfigFilePackageVersion {
|
218 | /**
|
219 | * Required label to identify this version map.
|
220 | */
|
221 | label: string;
|
222 | /**
|
223 | * Map from NPM package to version. Any version syntax supported by NPM is
|
224 | * supported here.
|
225 | */
|
226 | dependencies: ExtendedPackageDependencyMap;
|
227 | }
|
228 | /**
|
229 | * Validate the given JSON object parsed from a config file, and expand it into
|
230 | * a fully specified configuration.
|
231 | */
|
232 | export declare function parseConfigFile(parsedJson: unknown): Promise<Partial<Config>>;
|
233 | export declare function writeBackSchemaIfNeeded(rawConfigObj: Partial<ConfigFile>, configFile: string): Promise<void>;
|
234 | export {};
|