Skip to content

Commit 956f9de

Browse files
committed
test(button-harness): add performance tests for buttons using the protractor harness env
* The main thing we are looking at here is not the button's performance. Instead we are looking at the performance overhead of using the protractor and testbed harness env. * We are running tests with & without the ProtractorHarnessEnvironment and with & without the TestbedHarnessEnvironment. * We are benchmarking 5 operations with a varying number of buttons: 1. Get the first button 2. Click the first button 3. Click the middle button 4. Click the last button 5. Click every button
1 parent 4f1238f commit 956f9de

File tree

3 files changed

+131
-0
lines changed

3 files changed

+131
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
load("@npm_angular_dev_infra_private//benchmark/component_benchmark:component_benchmark.bzl", "component_benchmark")
2+
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_test_library", "ng_web_test_suite", "ts_library")
3+
4+
# TODO(wagnermaciel): Update this target to provide indigo-pink in a way that doesn't require having to import it with
5+
# stylesUrls inside the components once `component_benchmark` supports asset injection.
6+
7+
component_benchmark(
8+
name = "benchmark",
9+
driver = ":protractor.perf-spec.ts",
10+
driver_deps = [
11+
"@npm//@angular/dev-infra-private",
12+
"@npm//protractor",
13+
"@npm//@types/jasmine",
14+
"//src/cdk/testing",
15+
"//src/material/button/testing",
16+
"//src/cdk/testing/protractor",
17+
],
18+
ng_deps = [
19+
"@npm//@angular/core",
20+
"@npm//@angular/platform-browser",
21+
"//src/material/button",
22+
],
23+
ng_srcs = [":app.module.ts"],
24+
prefix = "",
25+
styles = ["//src/material/prebuilt-themes:indigo-pink"],
26+
)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 {Component, NgModule, ViewEncapsulation} from '@angular/core';
10+
import {BrowserModule} from '@angular/platform-browser';
11+
import {MatButtonModule} from '@angular/material/button';
12+
13+
/** component: mat-raised-button-harness-test */
14+
15+
@Component({
16+
selector: 'app-root',
17+
template: `
18+
<button *ngFor="let val of vals" mat-button> {{ val }} </button>
19+
`,
20+
encapsulation: ViewEncapsulation.None,
21+
styleUrls: ['//src/material/core/theming/prebuilt/indigo-pink.css'],
22+
})
23+
export class ButtonHarnessTest {
24+
vals = Array.from({ length: 100 }, (_, i) => i);
25+
}
26+
27+
@NgModule({
28+
declarations: [ButtonHarnessTest],
29+
imports: [
30+
BrowserModule,
31+
MatButtonModule,
32+
],
33+
bootstrap: [ButtonHarnessTest],
34+
})
35+
export class AppModule {}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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 {HarnessLoader} from '@angular/cdk/testing';
10+
import {MatButtonHarness} from '@angular/material/button/testing/button-harness';
11+
import {runBenchmark} from '@angular/dev-infra-private/benchmark/driver-utilities';
12+
import {ProtractorHarnessEnvironment} from '@angular/cdk/testing/protractor';
13+
14+
let loader: HarnessLoader;
15+
16+
describe('perf test for basic protractor harness', () => {
17+
it('should load the protractor harness environment', async () => {
18+
await runBenchmark({
19+
id: 'initial-harness-load',
20+
url: '',
21+
ignoreBrowserSynchronization: true,
22+
params: [],
23+
work: () => { loader = ProtractorHarnessEnvironment.loader(); },
24+
});
25+
});
26+
27+
it('should retrieve all of the buttons', async () => {
28+
await runBenchmark({
29+
id: 'get-first-button',
30+
url: '',
31+
ignoreBrowserSynchronization: true,
32+
params: [],
33+
setup: () => { loader = ProtractorHarnessEnvironment.loader(); },
34+
work: async () => await loader.getAllHarnesses(MatButtonHarness),
35+
});
36+
});
37+
38+
it('should retrieve the first button', async () => {
39+
await runBenchmark({
40+
id: 'get-first-button',
41+
url: '',
42+
ignoreBrowserSynchronization: true,
43+
params: [],
44+
setup: () => { loader = ProtractorHarnessEnvironment.loader(); },
45+
work: async () => await (await loader.getHarness(MatButtonHarness.with({text: '0'}))).click(),
46+
});
47+
});
48+
49+
it('should retrieve the middle button', async () => {
50+
await runBenchmark({
51+
id: 'get-middle-button',
52+
url: '',
53+
ignoreBrowserSynchronization: true,
54+
params: [],
55+
setup: () => { loader = ProtractorHarnessEnvironment.loader(); },
56+
work: async () => await (await loader.getHarness(MatButtonHarness.with({text: '49'}))).click(),
57+
});
58+
});
59+
60+
it('should retrieve the last button', async () => {
61+
await runBenchmark({
62+
id: 'get-last-button',
63+
url: '',
64+
ignoreBrowserSynchronization: true,
65+
params: [],
66+
setup: () => { loader = ProtractorHarnessEnvironment.loader(); },
67+
work: async () => await (await loader.getHarness(MatButtonHarness.with({text: '99'}))).click(),
68+
});
69+
});
70+
});

0 commit comments

Comments
 (0)