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, ignoreBrowserSynchronization: true,
params: [{name: 'viewCount', value: 1}], params: [{name: 'viewCount', value: 1}],
}); });
await $('#destroyDom').click();
expect(await $('#root').getText()).toEqual('');
await $('#createDom').click();
expect($('#root').getText()).toContain('1'); expect($('#root').getText()).toContain('1');
await $('#detectChanges').click(); await $('#detectChanges').click();
expect($('#root').getText()).toContain('2'); expect($('#root').getText()).toContain('2');
await $('#detectChanges').click();
expect($('#root').getText()).toContain('3');
await $('#destroyDom').click(); await $('#destroyDom').click();
expect(await $('#root').getText()).toEqual(''); 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("//tools:defaults.bzl", "ng_module", "ng_rollup_bundle", "ts_devserver")
load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test") load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test")
load("//modules/benchmarks:e2e_test.bzl", "e2e_test") load("//modules/benchmarks:e2e_test.bzl", "e2e_test")
package(default_visibility = ["//modules/benchmarks:__subpackages__"])
ng_module( ng_module(
name = "transplanted_views_lib", name = "transplanted_views_lib",
srcs = [ srcs = glob(["*.ts"]),
"index_aot.ts", generate_ve_shims = True,
"transplanted_views.ts", tsconfig = "//modules/benchmarks:tsconfig-build.json",
],
tags = ["ivy-only"],
deps = [ deps = [
"//modules/benchmarks/src:util_lib", "//modules/benchmarks/src:util_lib",
"//modules/benchmarks/src/change_detection:util_lib", "//modules/benchmarks/src/change_detection:util_lib",
"//packages:types",
"//packages/common",
"//packages/core", "//packages/core",
"//packages/platform-browser",
"//packages/platform-browser-dynamic",
], ],
) )
ng_rollup_bundle( ng_rollup_bundle(
name = "bundle", name = "bundle",
entry_point = ":index_aot.ts", entry_point = ":index_aot.ts",
tags = ["ivy-only"],
deps = [ deps = [
":transplanted_views_lib", ":transplanted_views_lib",
"@npm//rxjs", "@npm//rxjs",
@ -31,25 +28,21 @@ ng_rollup_bundle(
) )
ts_devserver( ts_devserver(
name = "devserver", name = "prodserver",
bootstrap = ["//packages/zone.js/dist:zone.js"],
port = 4200, port = 4200,
static_files = ["index.html"], static_files = ["index.html"],
tags = ["ivy-only"], deps = [":bundle.min_debug.es2015.js"],
deps = [
":bundle.min_debug.js",
],
) )
benchmark_test( benchmark_test(
name = "perf", name = "perf",
server = ":devserver", server = ":prodserver",
tags = ["ivy-only"],
deps = ["//modules/benchmarks/src/change_detection:perf_tests_lib"], deps = ["//modules/benchmarks/src/change_detection:perf_tests_lib"],
) )
e2e_test( e2e_test(
name = "e2e", name = "e2e",
server = ":devserver", server = ":prodserver",
tags = ["ivy-only"],
deps = ["//modules/benchmarks/src/change_detection:e2e_tests_lib"], 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 * 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 * 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() {} enableProdMode();
platformBrowser().bootstrapModuleFactory(TransplantedViewsModuleNgFactory).then(init);
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();

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