From aadc332be2a169191c9a5d6c37e32c62d9a8fb70 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Wed, 6 Feb 2019 18:03:58 +0100 Subject: [PATCH] build: run tree benchmark tests with bazel (#28568) PR Close #28568 --- modules/benchmarks/benchmark_test.bzl | 24 +++++ modules/benchmarks/e2e_test/tree_data.ts | 79 ---------------- modules/benchmarks/e2e_test/tree_perf.ts | 93 ------------------- modules/benchmarks/e2e_test/tree_spec.ts | 63 ------------- modules/benchmarks/src/BUILD.bazel | 8 +- modules/benchmarks/src/tree/BUILD.bazel | 33 ++++--- .../benchmarks/src/tree/baseline/BUILD.bazel | 7 ++ .../src/tree/incremental_dom/BUILD.bazel | 7 ++ modules/benchmarks/src/tree/iv/BUILD.bazel | 10 ++ modules/benchmarks/src/tree/ng1/BUILD.bazel | 10 ++ modules/benchmarks/src/tree/ng2/BUILD.bazel | 10 ++ .../benchmarks/src/tree/ng2_next/BUILD.bazel | 10 ++ .../src/tree/ng2_static/BUILD.bazel | 7 ++ .../src/tree/ng2_switch/BUILD.bazel | 7 ++ .../benchmarks/src/tree/render3/BUILD.bazel | 18 +--- .../src/tree/render3_function/BUILD.bazel | 8 ++ modules/benchmarks/src/tree/tree_perf.spec.ts | 51 ++-------- .../src/tree/tree_perf_detect_changes.spec.ts | 28 ++++++ .../src/tree/tree_perf_test_utils.ts | 36 +++++++ modules/benchmarks/start-server.js | 18 ++++ modules/e2e_util/BUILD.bazel | 1 + modules/tsconfig.json | 6 +- 22 files changed, 221 insertions(+), 313 deletions(-) create mode 100644 modules/benchmarks/benchmark_test.bzl delete mode 100644 modules/benchmarks/e2e_test/tree_data.ts delete mode 100644 modules/benchmarks/e2e_test/tree_perf.ts delete mode 100644 modules/benchmarks/e2e_test/tree_spec.ts create mode 100644 modules/benchmarks/src/tree/tree_perf_detect_changes.spec.ts create mode 100644 modules/benchmarks/src/tree/tree_perf_test_utils.ts create mode 100644 modules/benchmarks/start-server.js diff --git a/modules/benchmarks/benchmark_test.bzl b/modules/benchmarks/benchmark_test.bzl new file mode 100644 index 0000000000..2f068d8f2a --- /dev/null +++ b/modules/benchmarks/benchmark_test.bzl @@ -0,0 +1,24 @@ +load("//packages/bazel:index.bzl", "protractor_web_test_suite") + +""" + Macro that can be used to define a benchmark test. This differentiates from + a normal Protractor test suite because we specify a custom "perf" configuration + that sets up "@angular/benchpress". +""" + +def benchmark_test(name, server, deps, tags = []): + protractor_web_test_suite( + name = name, + configuration = "//:protractor-perf.conf.js", + data = [ + "//packages/bazel/src/protractor/utils", + "//packages/benchpress", + ], + on_prepare = "//modules/benchmarks:start-server.js", + server = server, + tags = tags, + deps = [ + "@ngdeps//protractor", + "@ngdeps//yargs", + ] + deps, + ) diff --git a/modules/benchmarks/e2e_test/tree_data.ts b/modules/benchmarks/e2e_test/tree_data.ts deleted file mode 100644 index 21628eeeeb..0000000000 --- a/modules/benchmarks/e2e_test/tree_data.ts +++ /dev/null @@ -1,79 +0,0 @@ -/** - * @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 {$} from 'protractor'; - -export const CreateBtn = '#createDom'; -export const DestroyBtn = '#destroyDom'; -export const DetectChangesBtn = '#detectChanges'; -export const RootEl = '#root'; -export const NumberOfChecksEl = '#numberOfChecks'; - -export interface Benchmark { - id: string; - url: string; - buttons: string[]; - ignoreBrowserSynchronization?: boolean; - extraParams?: {name: string, value: any}[]; -} - -const CreateDestroyButtons: string[] = [CreateBtn, DestroyBtn]; -const CreateDestroyDetectChangesButtons: string[] = [...CreateDestroyButtons, DetectChangesBtn]; - -export const Benchmarks: Benchmark[] = [ - { - id: `deepTree.ng2`, - url: 'all/benchmarks/src/tree/ng2/index.html', - buttons: CreateDestroyDetectChangesButtons, - }, - { - id: `deepTree.ng2.next`, - url: 'all/benchmarks/src/tree/ng2_next/index.html', - buttons: CreateDestroyDetectChangesButtons, - ignoreBrowserSynchronization: true, - }, - { - id: `deepTree.ng2.static`, - url: 'all/benchmarks/src/tree/ng2_static/index.html', - buttons: CreateDestroyButtons, - }, - { - id: `deepTree.ng2_switch`, - url: 'all/benchmarks/src/tree/ng2_switch/index.html', - buttons: CreateDestroyButtons, - }, - { - id: `deepTree.ng2.render3_function`, - url: 'all/benchmarks/src/tree/render3_function/index.html', - buttons: CreateDestroyDetectChangesButtons, - ignoreBrowserSynchronization: true, - }, - { - id: `deepTree.iv`, - url: 'all/benchmarks/src/tree/iv/index.html', - buttons: CreateDestroyDetectChangesButtons, - ignoreBrowserSynchronization: true, - }, - { - id: `deepTree.baseline`, - url: 'all/benchmarks/src/tree/baseline/index.html', - buttons: CreateDestroyButtons, - ignoreBrowserSynchronization: true, - }, - { - id: `deepTree.incremental_dom`, - url: 'all/benchmarks/src/tree/incremental_dom/index.html', - buttons: CreateDestroyButtons, - ignoreBrowserSynchronization: true, - }, - { - id: `deepTree.ng1`, - url: 'all/benchmarks/src/tree/ng1/index.html', - buttons: CreateDestroyDetectChangesButtons, - } -]; diff --git a/modules/benchmarks/e2e_test/tree_perf.ts b/modules/benchmarks/e2e_test/tree_perf.ts deleted file mode 100644 index 12034c7e07..0000000000 --- a/modules/benchmarks/e2e_test/tree_perf.ts +++ /dev/null @@ -1,93 +0,0 @@ -/** - * @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 {runBenchmark, verifyNoBrowserErrors} from 'e2e_util/perf_util'; -import {$, browser} from 'protractor'; - -import {Benchmark, Benchmarks, CreateBtn, DestroyBtn, DetectChangesBtn, RootEl} from './tree_data'; - -describe('tree benchmark perf', () => { - - let _oldRootEl: any; - beforeEach(() => _oldRootEl = browser.rootEl); - - afterEach(() => { - browser.rootEl = _oldRootEl; - verifyNoBrowserErrors(); - }); - - Benchmarks.forEach(benchmark => { - describe(benchmark.id, () => { - // This is actually a destroyOnly benchmark - it('should work for createOnly', done => { - runTreeBenchmark({ - id: 'createOnly', - benchmark, - prepare: () => $(CreateBtn).click(), - work: () => $(DestroyBtn).click() - }).then(done, done.fail); - }); - - it('should work for createOnlyForReal', done => { - runTreeBenchmark({ - id: 'createOnlyForReal', - benchmark, - prepare: () => $(DestroyBtn).click(), - work: () => $(CreateBtn).click() - }).then(done, done.fail); - }); - - it('should work for createDestroy', done => { - runTreeBenchmark({ - id: 'createDestroy', - benchmark, - work: () => { - $(DestroyBtn).click(); - $(CreateBtn).click(); - } - }).then(done, done.fail); - }); - - it('should work for update', done => { - runTreeBenchmark({id: 'update', benchmark, work: () => $(CreateBtn).click()}) - .then(done, done.fail); - }); - - if (benchmark.buttons.indexOf(DetectChangesBtn) !== -1) { - it('should work for detectChanges', done => { - runTreeBenchmark({ - id: 'detectChanges', - benchmark, - work: () => $(DetectChangesBtn).click(), - setup: () => $(DestroyBtn).click() - }).then(done, done.fail); - }); - } - - }); - }); -}); - -function runTreeBenchmark({id, benchmark, prepare, setup, work}: { - id: string; benchmark: Benchmark, prepare ? () : void; setup ? () : void; work(): void; -}) { - let params = [{name: 'depth', value: 11}]; - if (benchmark.extraParams) { - params = params.concat(benchmark.extraParams); - } - browser.rootEl = RootEl; - return runBenchmark({ - id: `${benchmark.id}.${id}`, - url: benchmark.url, - ignoreBrowserSynchronization: benchmark.ignoreBrowserSynchronization, - params: params, - work: work, - prepare: prepare, - setup: setup - }); -} diff --git a/modules/benchmarks/e2e_test/tree_spec.ts b/modules/benchmarks/e2e_test/tree_spec.ts deleted file mode 100644 index 6c58fd4b84..0000000000 --- a/modules/benchmarks/e2e_test/tree_spec.ts +++ /dev/null @@ -1,63 +0,0 @@ -/** - * @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 {openBrowser, verifyNoBrowserErrors} from 'e2e_util/e2e_util'; -import {$, browser} from 'protractor'; - -import {Benchmark, Benchmarks, CreateBtn, DestroyBtn, DetectChangesBtn, NumberOfChecksEl, RootEl} from './tree_data'; - -describe('tree benchmark spec', () => { - - let _oldRootEl: any; - beforeEach(() => _oldRootEl = browser.rootEl); - - afterEach(() => { - browser.rootEl = _oldRootEl; - verifyNoBrowserErrors(); - }); - - Benchmarks.forEach(benchmark => { - describe(benchmark.id, () => { - it('should work for createDestroy', () => { - openTreeBenchmark(benchmark); - $(CreateBtn).click(); - expect($(RootEl).getText()).toContain('0'); - $(DestroyBtn).click(); - expect($(RootEl).getText()).toEqual(''); - }); - - it('should work for update', () => { - openTreeBenchmark(benchmark); - $(CreateBtn).click(); - $(CreateBtn).click(); - expect($(RootEl).getText()).toContain('A'); - }); - - if (benchmark.buttons.indexOf(DetectChangesBtn) !== -1) { - it('should work for detectChanges', () => { - openTreeBenchmark(benchmark); - $(DetectChangesBtn).click(); - expect($(NumberOfChecksEl).getText()).toContain('10'); - }); - } - }); - }); - - function openTreeBenchmark(benchmark: Benchmark) { - let params = [{name: 'depth', value: 4}]; - if (benchmark.extraParams) { - params = params.concat(benchmark.extraParams); - } - browser.rootEl = RootEl; - openBrowser({ - url: benchmark.url, - ignoreBrowserSynchronization: benchmark.ignoreBrowserSynchronization, - params: params, - }); - } -}); diff --git a/modules/benchmarks/src/BUILD.bazel b/modules/benchmarks/src/BUILD.bazel index 45901bd2fa..fd7fb9848a 100644 --- a/modules/benchmarks/src/BUILD.bazel +++ b/modules/benchmarks/src/BUILD.bazel @@ -4,13 +4,7 @@ load("//tools:defaults.bzl", "ts_library") ts_library( name = "util_lib", - srcs = [ - "util.ts", - ], - deps = [ - "//packages:types", - "//packages/core", - ], + srcs = ["util.ts"], ) ts_library( diff --git a/modules/benchmarks/src/tree/BUILD.bazel b/modules/benchmarks/src/tree/BUILD.bazel index 9dea8fba76..05d485954b 100644 --- a/modules/benchmarks/src/tree/BUILD.bazel +++ b/modules/benchmarks/src/tree/BUILD.bazel @@ -4,25 +4,36 @@ load("//tools:defaults.bzl", "ts_library") ts_library( name = "util_lib", - srcs = [ - "util.ts", - ], + srcs = ["util.ts"], + deps = ["//modules/benchmarks/src:util_lib"], +) + +ts_library( + name = "test_utils_lib", + testonly = 1, + srcs = ["tree_perf_test_utils.ts"], deps = [ - "//modules/benchmarks/src:util_lib", - "//packages:types", - "//packages/core", + "//modules/e2e_util", + "@ngdeps//protractor", ], ) ts_library( name = "perf_lib", testonly = 1, - srcs = [ - "tree_perf.spec.ts", - ], + srcs = ["tree_perf.spec.ts"], deps = [ - "//modules/e2e_util", - "//packages:types", + ":test_utils_lib", + "@ngdeps//protractor", + ], +) + +ts_library( + name = "perf_detect_changes_lib", + testonly = 1, + srcs = ["tree_perf_detect_changes.spec.ts"], + deps = [ + ":test_utils_lib", "@ngdeps//protractor", ], ) diff --git a/modules/benchmarks/src/tree/baseline/BUILD.bazel b/modules/benchmarks/src/tree/baseline/BUILD.bazel index 692ad22e76..9450d53c15 100644 --- a/modules/benchmarks/src/tree/baseline/BUILD.bazel +++ b/modules/benchmarks/src/tree/baseline/BUILD.bazel @@ -1,5 +1,6 @@ load("//tools:defaults.bzl", "ts_library") load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver") +load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) @@ -20,3 +21,9 @@ ts_devserver( port = 4200, deps = [":baseline"], ) + +benchmark_test( + name = "perf", + server = ":devserver", + deps = ["//modules/benchmarks/src/tree:perf_lib"], +) diff --git a/modules/benchmarks/src/tree/incremental_dom/BUILD.bazel b/modules/benchmarks/src/tree/incremental_dom/BUILD.bazel index d0ff842a5b..da172f9d6e 100644 --- a/modules/benchmarks/src/tree/incremental_dom/BUILD.bazel +++ b/modules/benchmarks/src/tree/incremental_dom/BUILD.bazel @@ -1,5 +1,6 @@ load("//tools:defaults.bzl", "ts_library") load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver") +load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) @@ -24,3 +25,9 @@ ts_devserver( ], deps = [":incremental_dom"], ) + +benchmark_test( + name = "perf", + server = ":devserver", + deps = ["//modules/benchmarks/src/tree:perf_lib"], +) diff --git a/modules/benchmarks/src/tree/iv/BUILD.bazel b/modules/benchmarks/src/tree/iv/BUILD.bazel index 7cebf516b7..b6c88e036a 100644 --- a/modules/benchmarks/src/tree/iv/BUILD.bazel +++ b/modules/benchmarks/src/tree/iv/BUILD.bazel @@ -1,4 +1,5 @@ load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver") +load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) @@ -8,3 +9,12 @@ ts_devserver( port = 4200, static_files = ["tree.js"], ) + +benchmark_test( + name = "perf", + server = ":devserver", + deps = [ + "//modules/benchmarks/src/tree:perf_detect_changes_lib", + "//modules/benchmarks/src/tree:perf_lib", + ], +) diff --git a/modules/benchmarks/src/tree/ng1/BUILD.bazel b/modules/benchmarks/src/tree/ng1/BUILD.bazel index 796cf5a681..6bdc2c4ce8 100644 --- a/modules/benchmarks/src/tree/ng1/BUILD.bazel +++ b/modules/benchmarks/src/tree/ng1/BUILD.bazel @@ -1,5 +1,6 @@ load("//tools:defaults.bzl", "ts_library") load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver") +load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) @@ -23,3 +24,12 @@ ts_devserver( ], deps = [":ng1"], ) + +benchmark_test( + name = "perf", + server = ":devserver", + deps = [ + "//modules/benchmarks/src/tree:perf_detect_changes_lib", + "//modules/benchmarks/src/tree:perf_lib", + ], +) diff --git a/modules/benchmarks/src/tree/ng2/BUILD.bazel b/modules/benchmarks/src/tree/ng2/BUILD.bazel index 5069a15710..12e9fd83f2 100644 --- a/modules/benchmarks/src/tree/ng2/BUILD.bazel +++ b/modules/benchmarks/src/tree/ng2/BUILD.bazel @@ -1,5 +1,6 @@ load("//tools:defaults.bzl", "ng_module") load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver") +load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) @@ -30,3 +31,12 @@ ts_devserver( ], deps = [":ng2"], ) + +benchmark_test( + name = "perf", + server = ":devserver", + deps = [ + "//modules/benchmarks/src/tree:perf_detect_changes_lib", + "//modules/benchmarks/src/tree:perf_lib", + ], +) diff --git a/modules/benchmarks/src/tree/ng2_next/BUILD.bazel b/modules/benchmarks/src/tree/ng2_next/BUILD.bazel index 59fe333d45..585674c2cc 100644 --- a/modules/benchmarks/src/tree/ng2_next/BUILD.bazel +++ b/modules/benchmarks/src/tree/ng2_next/BUILD.bazel @@ -1,5 +1,6 @@ load("//tools:defaults.bzl", "ts_library") load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver") +load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) @@ -24,3 +25,12 @@ ts_devserver( scripts = ["@ngdeps//node_modules/tslib:tslib.js"], deps = [":ng2_next"], ) + +benchmark_test( + name = "perf", + server = ":devserver", + deps = [ + "//modules/benchmarks/src/tree:perf_detect_changes_lib", + "//modules/benchmarks/src/tree:perf_lib", + ], +) diff --git a/modules/benchmarks/src/tree/ng2_static/BUILD.bazel b/modules/benchmarks/src/tree/ng2_static/BUILD.bazel index 44efe74ffc..4bed4314a6 100644 --- a/modules/benchmarks/src/tree/ng2_static/BUILD.bazel +++ b/modules/benchmarks/src/tree/ng2_static/BUILD.bazel @@ -1,5 +1,6 @@ load("//tools:defaults.bzl", "ts_library") load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver") +load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) @@ -28,3 +29,9 @@ ts_devserver( ], deps = [":ng2_static"], ) + +benchmark_test( + name = "perf", + server = ":devserver", + deps = ["//modules/benchmarks/src/tree:perf_lib"], +) diff --git a/modules/benchmarks/src/tree/ng2_switch/BUILD.bazel b/modules/benchmarks/src/tree/ng2_switch/BUILD.bazel index 738ed3f030..bfbe8565da 100644 --- a/modules/benchmarks/src/tree/ng2_switch/BUILD.bazel +++ b/modules/benchmarks/src/tree/ng2_switch/BUILD.bazel @@ -1,5 +1,6 @@ load("//tools:defaults.bzl", "ng_module") load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver") +load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) @@ -30,3 +31,9 @@ ts_devserver( ], deps = [":ng2_switch"], ) + +benchmark_test( + name = "perf", + server = ":devserver", + deps = ["//modules/benchmarks/src/tree:perf_lib"], +) diff --git a/modules/benchmarks/src/tree/render3/BUILD.bazel b/modules/benchmarks/src/tree/render3/BUILD.bazel index 9e7e7af73b..7e6564a6c6 100644 --- a/modules/benchmarks/src/tree/render3/BUILD.bazel +++ b/modules/benchmarks/src/tree/render3/BUILD.bazel @@ -1,8 +1,8 @@ package(default_visibility = ["//modules/benchmarks:__subpackages__"]) load("//tools:defaults.bzl", "ng_module", "ng_rollup_bundle") -load("//packages/bazel:index.bzl", "protractor_web_test_suite") load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver") +load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test") ng_module( name = "tree_lib", @@ -36,22 +36,12 @@ ts_devserver( tags = ["ivy-only"], ) -protractor_web_test_suite( +benchmark_test( name = "perf", - configuration = "//:protractor-perf.conf.js", - data = [ - "//packages/bazel/src/protractor/utils", - "//packages/benchpress", - ], - on_prepare = ":protractor.on_prepare.js", server = ":devserver", - tags = [ - "ivy-only", - ], + tags = ["ivy-only"], deps = [ + "//modules/benchmarks/src/tree:perf_detect_changes_lib", "//modules/benchmarks/src/tree:perf_lib", - "@ngdeps//node-uuid", - "@ngdeps//protractor", - "@ngdeps//yargs", ], ) diff --git a/modules/benchmarks/src/tree/render3_function/BUILD.bazel b/modules/benchmarks/src/tree/render3_function/BUILD.bazel index 48f531cbaa..69760e79ea 100644 --- a/modules/benchmarks/src/tree/render3_function/BUILD.bazel +++ b/modules/benchmarks/src/tree/render3_function/BUILD.bazel @@ -1,5 +1,6 @@ load("@build_bazel_rules_typescript//:defs.bzl", "ts_devserver") load("//tools:defaults.bzl", "ts_library") +load("//modules/benchmarks:benchmark_test.bzl", "benchmark_test") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) @@ -22,5 +23,12 @@ ts_devserver( scripts = ["@ngdeps//node_modules/tslib:tslib.js"], deps = [":render3_function_lib"], ) + +benchmark_test( + name = "perf", + server = ":devserver", + deps = [ + "//modules/benchmarks/src/tree:perf_detect_changes_lib", + "//modules/benchmarks/src/tree:perf_lib", ], ) diff --git a/modules/benchmarks/src/tree/tree_perf.spec.ts b/modules/benchmarks/src/tree/tree_perf.spec.ts index 25df3f8632..1b4881c5e3 100644 --- a/modules/benchmarks/src/tree/tree_perf.spec.ts +++ b/modules/benchmarks/src/tree/tree_perf.spec.ts @@ -6,10 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ -import {$, browser} from 'protractor'; - -import {openBrowser} from '../../../e2e_util/e2e_util'; -import {runBenchmark} from '../../../e2e_util/perf_util'; +import {$} from 'protractor'; +import {openTreeBenchmark, runTreeBenchmark} from './tree_perf_test_utils'; describe('benchmark render', () => { it('should work for createDestroy', () => { @@ -26,20 +24,15 @@ describe('benchmark render', () => { $('#createDom').click(); expect($('#root').getText()).toContain('A'); }); - - it('should work for detectChanges', () => { - openTreeBenchmark(); - $('#detectChanges').click(); - expect($('#numberOfChecks').getText()).toContain('10'); - }); - }); describe('benchmarks', () => { it('should work for createOnly', done => { runTreeBenchmark({ - id: 'createOnly', + // This cannot be called "createOnly" because the actual destroy benchmark + // has the "createOnly" id already. See: https://github.com/angular/angular/pull/21503 + id: 'createOnlyForReal', prepare: () => $('#destroyDom').click(), work: () => $('#createDom').click() }).then(done, done.fail); @@ -47,6 +40,8 @@ describe('benchmarks', () => { it('should work for destroy', done => { runTreeBenchmark({ + // This is actually a benchmark for destroying the dom, but it has been accidentally + // named "createOnly". See https://github.com/angular/angular/pull/21503. id: 'createOnly', prepare: () => $('#createDom').click(), work: () => $('#destroyDom').click() @@ -66,36 +61,4 @@ describe('benchmarks', () => { it('should work for update', done => { runTreeBenchmark({id: 'update', work: () => $('#createDom').click()}).then(done, done.fail); }); - - it('should work for detectChanges', done => { - runTreeBenchmark({ - id: 'detectChanges', - work: () => $('#detectChanges').click(), - setup: () => $('#destroyDom').click() - }).then(done, done.fail); - }); - }); - -function runTreeBenchmark({id, prepare, setup, work}: - {id: string; prepare ? () : void; setup ? () : void; work(): void;}) { - browser.rootEl = '#root'; - return runBenchmark({ - id: id, - url: '', - ignoreBrowserSynchronization: true, - params: [{name: 'depth', value: 11}], - work: work, - prepare: prepare, - setup: setup - }); -} - -function openTreeBenchmark() { - browser.rootEl = '#root'; - openBrowser({ - url: '', - ignoreBrowserSynchronization: true, - params: [{name: 'depth', value: 4}], - }); -} diff --git a/modules/benchmarks/src/tree/tree_perf_detect_changes.spec.ts b/modules/benchmarks/src/tree/tree_perf_detect_changes.spec.ts new file mode 100644 index 0000000000..9b744d2bac --- /dev/null +++ b/modules/benchmarks/src/tree/tree_perf_detect_changes.spec.ts @@ -0,0 +1,28 @@ +/** + * @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 {$} from 'protractor'; +import {openTreeBenchmark, runTreeBenchmark} from './tree_perf_test_utils'; + +describe('benchmark render', () => { + it('should work for detectChanges', () => { + openTreeBenchmark(); + $('#detectChanges').click(); + expect($('#numberOfChecks').getText()).toContain('10'); + }); +}); + +describe('benchmarks', () => { + it('should work for detectChanges', async() => { + await runTreeBenchmark({ + id: 'detectChanges', + work: () => $('#detectChanges').click(), + setup: () => $('#destroyDom').click() + }); + }); +}); diff --git a/modules/benchmarks/src/tree/tree_perf_test_utils.ts b/modules/benchmarks/src/tree/tree_perf_test_utils.ts new file mode 100644 index 0000000000..b2fa21b138 --- /dev/null +++ b/modules/benchmarks/src/tree/tree_perf_test_utils.ts @@ -0,0 +1,36 @@ +/** + * @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 {browser} from 'protractor'; + +import {openBrowser} from '../../../e2e_util/e2e_util'; +import {runBenchmark} from '../../../e2e_util/perf_util'; + +export function runTreeBenchmark({id, prepare, setup, work}: { + id: string; prepare ? () : void; setup ? () : void; work(): void; +}) { + browser.rootEl = '#root'; + return runBenchmark({ + id: id, + url: '', + ignoreBrowserSynchronization: true, + params: [{name: 'depth', value: 11}], + work: work, + prepare: prepare, + setup: setup + }); +} + +export function openTreeBenchmark() { + browser.rootEl = '#root'; + openBrowser({ + url: '', + ignoreBrowserSynchronization: true, + params: [{name: 'depth', value: 4}], + }); +} diff --git a/modules/benchmarks/start-server.js b/modules/benchmarks/start-server.js new file mode 100644 index 0000000000..98fbaf25f8 --- /dev/null +++ b/modules/benchmarks/start-server.js @@ -0,0 +1,18 @@ +/** + * @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 + */ + +const protractorUtils = require('@angular/bazel/protractor-utils'); +const protractor = require('protractor'); + +module.exports = async function(config) { + const {port} = await protractorUtils.runServer(config.workspace, config.server, '-port', []); + const processedConfig = await protractor.browser.getProcessedConfig(); + const serverUrl = `http://localhost:${port}`; + + return processedConfig.baseUrl = protractor.browser.baseUrl = serverUrl; +}; diff --git a/modules/e2e_util/BUILD.bazel b/modules/e2e_util/BUILD.bazel index a39c6ac905..647b53205e 100644 --- a/modules/e2e_util/BUILD.bazel +++ b/modules/e2e_util/BUILD.bazel @@ -12,6 +12,7 @@ ts_library( "@ngdeps//@types/fs-extra", "@ngdeps//@types/selenium-webdriver", "@ngdeps//fs-extra", + "@ngdeps//node-uuid", "@ngdeps//protractor", "@ngdeps//selenium-webdriver", ], diff --git a/modules/tsconfig.json b/modules/tsconfig.json index 868a537327..783949bb5e 100644 --- a/modules/tsconfig.json +++ b/modules/tsconfig.json @@ -28,8 +28,10 @@ "benchmarks/src/old", "benchmarks/src/**/index_aot.ts", "benchmarks_external", - "playground", - "payload_tests" + "payload_tests", + // Tests which are already migrated to Bazel: + "playground/", + "benchmarks/src/tree" ], "angularCompilerOptions": { "skipTemplateCodegen": true