Skip to content
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

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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('');
});
Expand Down
@@ -1,55 +1,48 @@
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",
],
)

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"],
)
@@ -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);
Expand Up @@ -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);
41 changes: 41 additions & 0 deletions modules/benchmarks/src/change_detection/transplanted_views/init.ts
@@ -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();
atscott marked this conversation as resolved.
Show resolved Hide resolved
declaration.templateRefreshCount = 0;
appRef.tick();
}

function createDom() {
declaration.viewCount = numViews;
appRef.tick();
}

function detectChanges() { appRef.tick(); }

function noop() {}
}
atscott marked this conversation as resolved.
Show resolved Hide resolved
Expand Up @@ -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',
Expand Down Expand Up @@ -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 {
}