-
Notifications
You must be signed in to change notification settings - Fork 6.8k
test(menu): add performance tests for mat-menu #20151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
b1162a7
0245220
de8e7eb
5854b0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
load("@npm_angular_dev_infra_private//benchmark/component_benchmark:component_benchmark.bzl", "component_benchmark") | ||
|
||
# TODO(wagnermaciel): Update this target to provide indigo-pink in a way that doesn't require having to import it with | ||
# stylesUrls inside the components once `component_benchmark` supports asset injection. | ||
|
||
component_benchmark( | ||
name = "benchmark", | ||
driver = ":menu.perf-spec.ts", | ||
driver_deps = [ | ||
"@npm//@angular/dev-infra-private", | ||
"@npm//protractor", | ||
"@npm//@types/jasmine", | ||
"//src/cdk/testing", | ||
"//src/cdk/testing/protractor", | ||
"//src/material/menu/testing", | ||
], | ||
ng_deps = [ | ||
"@npm//@angular/core", | ||
"@npm//@angular/platform-browser", | ||
"//src/material/menu", | ||
"//src/cdk/a11y", | ||
], | ||
ng_srcs = [":app.module.ts"], | ||
prefix = "", | ||
styles = ["//src/material/prebuilt-themes:indigo-pink"], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {A11yModule} from '@angular/cdk/a11y'; | ||
import {Component, NgModule, ViewEncapsulation} from '@angular/core'; | ||
import {BrowserModule} from '@angular/platform-browser'; | ||
import {MatMenuModule} from '@angular/material/menu'; | ||
|
||
/** component: mat-menu */ | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
template: ` | ||
<button mat-button [matMenuTriggerFor]="menu">Menu</button> | ||
<mat-menu #menu="matMenu"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We support multi-level menus too. Should we have a test that captures it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm I ran into a bit of an issue with this. The main things I wanted to test out for nested menus is 1. is there any slowdown with opening the root menu if there are a couple of nested menus, and 2. how long it takes to open a menu fully. The problem (which I left a comment for) is that calling getHarness seems to be an expensive operation which makes figuring out how expensive opening up submenus are. I am wondering if I should change the test from opening a nested menu fully to just opening a single nested menu like
@crisbeto Lmk what are your thoughts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Harnesses trigger change detection and wait for it to finish before every action so I'm not sure whether we should be basing our performance tests on them. @mmalerba do you think that we should use Protractor directly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using protractor has it's own issues with cdk-overlay-container There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the harnesses explicitly run change detection in e2e tests (though I'm sure they cause it by clicking). I think using the harness to open/close pretty much boils down to the same thing you would be doing via protractor directly anyways. The part where the harnesses might add some overhead is in searching for submenus, e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't they also wait for animations for finish? @wagnermaciel it might be worth trying to import the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was under the impression that we actually wanted to wait for animations to finish There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I think I figured out the correct solution here. The MatMenuHarness uses |
||
<button mat-menu-item>Item 1</button> | ||
<button mat-menu-item>Item 2</button> | ||
<button mat-menu-item>Item 3</button> | ||
<button mat-menu-item>Item 4</button> | ||
<button mat-menu-item>Item 5</button> | ||
<button mat-menu-item>Item 6</button> | ||
<button mat-menu-item>Item 7</button> | ||
<button mat-menu-item>Item 8</button> | ||
<button mat-menu-item>Item 9</button> | ||
<button mat-menu-item>Item 10</button> | ||
</mat-menu> | ||
`, | ||
encapsulation: ViewEncapsulation.None, | ||
styleUrls: ['//src/material/core/theming/prebuilt/indigo-pink.css'], | ||
}) | ||
export class MenuBenchmarkApp { | ||
} | ||
|
||
|
||
@NgModule({ | ||
declarations: [MenuBenchmarkApp], | ||
imports: [ | ||
A11yModule, | ||
wagnermaciel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
BrowserModule, | ||
MatMenuModule, | ||
], | ||
providers: [], | ||
wagnermaciel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bootstrap: [MenuBenchmarkApp] | ||
}) | ||
export class AppModule {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {runBenchmark} from '@angular/dev-infra-private/benchmark/driver-utilities'; | ||
|
||
import {HarnessLoader} from '@angular/cdk/testing'; | ||
import {ProtractorHarnessEnvironment} from '@angular/cdk/testing/protractor'; | ||
import {MatMenuHarness} from '@angular/material/menu/testing/menu-harness'; | ||
|
||
let loader: HarnessLoader; | ||
|
||
describe('menu performance benchmarks', () => { | ||
beforeEach(() => { | ||
loader = ProtractorHarnessEnvironment.loader(); | ||
}); | ||
|
||
it('opens a menu with 10 items', async () => { | ||
let menu: MatMenuHarness; | ||
await runBenchmark({ | ||
id: 'menu-open', | ||
url: '', | ||
ignoreBrowserSynchronization: true, | ||
params: [], | ||
setup: async () => menu = await loader.getHarness(MatMenuHarness), | ||
prepare: async () => await menu.close(), | ||
work: async () => await menu.open(), | ||
}); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.