test(core): Update transplanted views benchpress test to support VE (#36058)

Remove uses of render3 internal `detectChanges` calls to allow test to
be run against VE code as well as Ivy.

PR Close #36058
This commit is contained in:
Andrew Scott 2020-03-13 07:31:11 -07:00 committed by Andrew Kushnir
parent 6b4c5289b3
commit 05d0586223
6 changed files with 88 additions and 59 deletions

View File

@ -19,11 +19,12 @@ describe('change detection benchmark', () => {
ignoreBrowserSynchronization: true,
params: [{name: 'viewCount', value: 1}],
});
await $('#destroyDom').click();
expect(await $('#root').getText()).toEqual('');
await $('#createDom').click();
expect($('#root').getText()).toContain('1');
await $('#detectChanges').click();
expect($('#root').getText()).toContain('2');
await $('#detectChanges').click();
expect($('#root').getText()).toContain('3');
await $('#destroyDom').click();
expect(await $('#root').getText()).toEqual('');
});

View File

@ -1,29 +1,26 @@
package(default_visibility = ["//visibility:public"])
load("//tools:defaults.bzl", "ng_module", "ng_rollup_bundle", "ts_devserver")
load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test")
load("//modules/benchmarks:e2e_test.bzl", "e2e_test")
package(default_visibility = ["//modules/benchmarks:__subpackages__"])
ng_module(
name = "transplanted_views_lib",
srcs = [
"index_aot.ts",
"transplanted_views.ts",
],
tags = ["ivy-only"],
srcs = glob(["*.ts"]),
generate_ve_shims = True,
tsconfig = "//modules/benchmarks:tsconfig-build.json",
deps = [
"//modules/benchmarks/src:util_lib",
"//modules/benchmarks/src/change_detection:util_lib",
"//packages:types",
"//packages/common",
"//packages/core",
"//packages/platform-browser",
"//packages/platform-browser-dynamic",
],
)
ng_rollup_bundle(
name = "bundle",
entry_point = ":index_aot.ts",
tags = ["ivy-only"],
deps = [
":transplanted_views_lib",
"@npm//rxjs",
@ -31,25 +28,21 @@ ng_rollup_bundle(
)
ts_devserver(
name = "devserver",
name = "prodserver",
bootstrap = ["//packages/zone.js/dist:zone.js"],
port = 4200,
static_files = ["index.html"],
tags = ["ivy-only"],
deps = [
":bundle.min_debug.js",
],
deps = [":bundle.min_debug.es2015.js"],
)
benchmark_test(
name = "perf",
server = ":devserver",
tags = ["ivy-only"],
server = ":prodserver",
deps = ["//modules/benchmarks/src/change_detection:perf_tests_lib"],
)
e2e_test(
name = "e2e",
server = ":devserver",
tags = ["ivy-only"],
server = ":prodserver",
deps = ["//modules/benchmarks/src/change_detection:e2e_tests_lib"],
)

View File

@ -0,0 +1,16 @@
/**
* @license
* Copyright Google Inc. 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 {enableProdMode} from '@angular/core';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {init} from './init';
import {TransplantedViewsModule} from './transplanted_views';
enableProdMode();
platformBrowserDynamic().bootstrapModule(TransplantedViewsModule).then(init);

View File

@ -5,24 +5,12 @@
* 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 {ɵrenderComponent as renderComponent} from '@angular/core';
import {bindAction, profile} from '../../util';
import {enableProdMode} from '@angular/core';
import {platformBrowser} from '@angular/platform-browser';
import {DeclarationComponent, createDom, destroyDom, detectChanges} from './transplanted_views';
import {init} from './init';
import {TransplantedViewsModuleNgFactory} from './transplanted_views.ngfactory';
function noop() {}
export function main() {
let component: DeclarationComponent;
if (typeof window !== 'undefined') {
component = renderComponent<DeclarationComponent>(DeclarationComponent);
bindAction('#destroyDom', () => destroyDom(component));
bindAction('#createDom', () => createDom(component));
bindAction('#detectChanges', () => detectChanges(component));
bindAction(
'#detectChangesProfile', profile(() => detectChanges(component), noop, 'detect_changes'));
}
}
main();
enableProdMode();
platformBrowser().bootstrapModuleFactory(TransplantedViewsModuleNgFactory).then(init);

View File

@ -0,0 +1,41 @@
/**
* @license
* Copyright Google Inc. 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 {ApplicationRef, NgModuleRef} from '@angular/core';
import {bindAction, profile} from '../../util';
import {numViews} from '../util';
import {DeclarationComponent, TransplantedViewsModule} from './transplanted_views';
export function init(moduleRef: NgModuleRef<TransplantedViewsModule>) {
const appRef: ApplicationRef = moduleRef.injector.get(ApplicationRef);
const declaration: DeclarationComponent = appRef.components[0].instance;
bindAction('#destroyDom', destroyDom);
bindAction('#createDom', createDom);
bindAction('#detectChanges', detectChanges);
bindAction('#detectChangesProfile', profile(detectChanges, noop, 'detectChanges'));
// helpers
function destroyDom() {
declaration.viewCount = 0;
appRef.tick();
declaration.templateRefreshCount = 0;
appRef.tick();
}
function createDom() {
declaration.viewCount = numViews;
appRef.tick();
}
function detectChanges() { appRef.tick(); }
function noop() {}
}

View File

@ -6,9 +6,10 @@
* found in the LICENSE file at https://angular.io/license
*/
import {CommonModule} from '@angular/common';
import {ChangeDetectionStrategy, Component, Input, NgModule, TemplateRef, ɵdetectChanges} from '@angular/core';
import {newArray, numViews} from '../util';
import {ChangeDetectionStrategy, Component, Input, NgModule, TemplateRef} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {newArray} from '../util';
@Component({
selector: 'declaration-component',
@ -45,21 +46,10 @@ export class InsertionComponent {
trackByIndex(index: number, item: any) { return index; }
}
@NgModule({declarations: [DeclarationComponent, InsertionComponent], imports: [CommonModule]})
export class TransplantedViewModule {
}
export function destroyDom(component: DeclarationComponent) {
component.templateRefreshCount = 0;
component.viewCount = 0;
ɵdetectChanges(component);
}
export function createDom(component: DeclarationComponent) {
component.viewCount = numViews;
ɵdetectChanges(component);
}
export function detectChanges(component: DeclarationComponent) {
ɵdetectChanges(component);
@NgModule({
declarations: [DeclarationComponent, InsertionComponent],
bootstrap: [DeclarationComponent],
imports: [BrowserModule]
})
export class TransplantedViewsModule {
}