({
id,
url = '',
params = [],
ignoreBrowserSynchronization = true,
microMetrics,
work,
prepare,
setup,
}: {
id: string;
url?: string;
params?: {name: string; value: any}[];
ignoreBrowserSynchronization?: boolean;
microMetrics?: {[key: string]: string};
work?: (() => void) | (() => Promise<unknown>);
prepare?: (() => void) | (() => Promise<unknown>);
setup?: (() => void) | (() => Promise<unknown>);
})
| 28 | let _cachedBenchpressSetup: Promise<BenchpressSetup> | null = null; |
| 29 | |
| 30 | export async function runBenchmark({ |
| 31 | id, |
| 32 | url = '', |
| 33 | params = [], |
| 34 | ignoreBrowserSynchronization = true, |
| 35 | microMetrics, |
| 36 | work, |
| 37 | prepare, |
| 38 | setup, |
| 39 | }: { |
| 40 | id: string; |
| 41 | url?: string; |
| 42 | params?: {name: string; value: any}[]; |
| 43 | ignoreBrowserSynchronization?: boolean; |
| 44 | microMetrics?: {[key: string]: string}; |
| 45 | work?: (() => void) | (() => Promise<unknown>); |
| 46 | prepare?: (() => void) | (() => Promise<unknown>); |
| 47 | setup?: (() => void) | (() => Promise<unknown>); |
| 48 | }): Promise<any> { |
| 49 | if (_cachedBenchpressSetup === null) { |
| 50 | _cachedBenchpressSetup = _prepareBenchpressSetup(); |
| 51 | } |
| 52 | |
| 53 | // Wait for the benchpress setup to complete initialization. |
| 54 | // The benchpress setup is loaded asynchronously due to it relying on ESM. |
| 55 | // TODO: This can be removed when benchmark tests/e2e tests can run with ESM. |
| 56 | const {module, runner} = await _cachedBenchpressSetup; |
| 57 | |
| 58 | openBrowser({url, params, ignoreBrowserSynchronization}); |
| 59 | if (setup) { |
| 60 | await setup(); |
| 61 | } |
| 62 | return runner.sample({ |
| 63 | id, |
| 64 | execute: work, |
| 65 | prepare, |
| 66 | microMetrics, |
| 67 | providers: [{provide: module.Options.SAMPLE_DESCRIPTION, useValue: {}}], |
| 68 | }); |
| 69 | } |
| 70 | |
| 71 | async function _prepareBenchpressSetup(): Promise<BenchpressSetup> { |
| 72 | const module = await loadBenchpressModule(); |
searching dependent graphs…