|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google LLC All Rights Reserved. |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style license that can be |
| 6 | + * found in the LICENSE file at https://angular.io/license |
| 7 | + */ |
| 8 | + |
| 9 | +import {runBenchmark, verifyNoBrowserErrors} from '@angular/build-tooling/bazel/benchmark/driver-utilities'; |
| 10 | +import {$} from 'protractor'; |
| 11 | + |
| 12 | +interface Worker { |
| 13 | + id: string; |
| 14 | + prepare?(): void; |
| 15 | + work(): void; |
| 16 | +} |
| 17 | + |
| 18 | +const CreateWorker: Worker = { |
| 19 | + id: 'create', |
| 20 | + prepare: () => $('#destroyDom').click(), |
| 21 | + work: () => $('#createDom').click() |
| 22 | +}; |
| 23 | + |
| 24 | +const UpdateWorker: Worker = { |
| 25 | + id: 'update', |
| 26 | + prepare: () => { |
| 27 | + $('#createDom').click(); |
| 28 | + }, |
| 29 | + work: () => $('#createDom').click() |
| 30 | +}; |
| 31 | + |
| 32 | +// In order to make sure that we don't change the ids of the benchmarks, we need to |
| 33 | +// determine the current test package name from the Bazel target. This is necessary |
| 34 | +// because previous to the Bazel conversion, the benchmark test ids contained the test |
| 35 | +// name. e.g. "largeTable.ng2_switch.createDestroy". We determine the name of the |
| 36 | +// Bazel package where this test runs from the current test target. The Bazel target |
| 37 | +// looks like: "//modules/benchmarks/src/largetable/{pkg_name}:{target_name}". |
| 38 | +const testPackageName = process.env['BAZEL_TARGET']!.split(':')[0].split('/').pop(); |
| 39 | + |
| 40 | +describe('defer benchmark perf', () => { |
| 41 | + afterEach(verifyNoBrowserErrors); |
| 42 | + |
| 43 | + [CreateWorker, UpdateWorker].forEach((worker) => { |
| 44 | + describe(worker.id, () => { |
| 45 | + it(`should run benchmark for ${testPackageName}`, async () => { |
| 46 | + await runTableBenchmark({ |
| 47 | + id: `defer.${testPackageName}.${worker.id}`, |
| 48 | + url: '/', |
| 49 | + ignoreBrowserSynchronization: true, |
| 50 | + worker, |
| 51 | + }); |
| 52 | + }); |
| 53 | + }); |
| 54 | + }); |
| 55 | +}); |
| 56 | + |
| 57 | +function runTableBenchmark( |
| 58 | + config: {id: string, url: string, ignoreBrowserSynchronization?: boolean, worker: Worker}) { |
| 59 | + return runBenchmark({ |
| 60 | + id: config.id, |
| 61 | + url: config.url, |
| 62 | + ignoreBrowserSynchronization: config.ignoreBrowserSynchronization, |
| 63 | + params: [{name: 'cols', value: 40}, {name: 'rows', value: 200}], |
| 64 | + prepare: config.worker.prepare, |
| 65 | + work: config.worker.work |
| 66 | + }); |
| 67 | +} |
0 commit comments