X Tutup
Skip to content

Commit 33593cf

Browse files
committed
fix(build): Use Angular's testability API to wait for end of e2e tests
Closes #3911
1 parent 00a4b2e commit 33593cf

File tree

19 files changed

+102
-41
lines changed

19 files changed

+102
-41
lines changed

modules/angular2/src/core/testability/browser_testability.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ class PublicTestability implements _JsObjectProxyable {
6363
this._testability = testability;
6464
}
6565

66+
bool isStable() {
67+
return this._testability.isStable();
68+
}
69+
6670
whenStable(Function callback) {
6771
return this._testability.whenStable(callback);
6872
}
@@ -75,7 +79,8 @@ class PublicTestability implements _JsObjectProxyable {
7579
return _jsify({
7680
'findBindings': (bindingString, [exactMatch, allowNonElementNodes]) =>
7781
findBindings(bindingString, exactMatch, allowNonElementNodes),
78-
'whenStable': (callback) => whenStable(() => callback.apply([])),
82+
'isStable': () => isStable(),
83+
'whenStable': (callback) => whenStable(() => callback.apply([]))
7984
})..['_dart_'] = this;
8085
}
8186
}

modules/angular2/src/core/testability/browser_testability.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class PublicTestability {
1111

1212
constructor(testability: Testability) { this._testability = testability; }
1313

14+
isStable(): boolean { return this._testability.isStable(); }
15+
1416
whenStable(callback: Function) { this._testability.whenStable(callback); }
1517

1618
findBindings(using: any, binding: string, exactMatch: boolean): any[] {

modules/angular2/src/core/testability/testability.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ export class Testability {
4242
return this._pendingCount;
4343
}
4444

45+
isStable(): boolean { return this._pendingCount == 0 && !this._isAngularEventPending; }
46+
4547
_runCallbacksIfReady(): void {
46-
if (this._pendingCount != 0 || this._isAngularEventPending) {
48+
if (!this.isStable()) {
4749
return; // Not ready
4850
}
4951

modules/angular2/src/test_lib/perf_util.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ export function runBenchmark(config) {
2424
});
2525
}
2626
var url = encodeURI(config.url + '?' + urlParams.join('&'));
27-
return browser.get(url).then(function() {
27+
var getter = config.waitForAngular2 !== false ? browser.get(url) :
28+
browser.driver.get(browser.baseUrl + url);
29+
return getter.then(function() {
2830
return global['benchpressRunner'].sample({
2931
id: config.id,
3032
execute: config.work,

modules/benchmarks/e2e_test/change_detection_perf.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ describe('ng2 change detection benchmark', function() {
1515
{name: 'numberOfChecks', value: 900000},
1616
{name: 'iterations', value: 20, scale: 'linear'}
1717
],
18-
microMetrics: {'detectChangesAvg': 'avg time to detect changes (ms)'}
18+
microMetrics: {'detectChangesAvg': 'avg time to detect changes (ms)'},
19+
waitForAngular2: false
1920
}).then(done, done.fail);
2021
});
2122

@@ -28,7 +29,8 @@ describe('ng2 change detection benchmark', function() {
2829
{name: 'numberOfChecks', value: 900000},
2930
{name: 'iterations', value: 20, scale: 'linear'}
3031
],
31-
microMetrics: {'detectChangesAvg': 'avg time to detect changes (ms)'}
32+
microMetrics: {'detectChangesAvg': 'avg time to detect changes (ms)'},
33+
waitForAngular2: false
3234
}).then(done, done.fail);
3335
});
3436

@@ -41,7 +43,8 @@ describe('ng2 change detection benchmark', function() {
4143
{name: 'numberOfChecks', value: 900000},
4244
{name: 'iterations', value: 20, scale: 'linear'}
4345
],
44-
microMetrics: {'detectChangesAvg': 'avg time to detect changes (ms)'}
46+
microMetrics: {'detectChangesAvg': 'avg time to detect changes (ms)'},
47+
waitForAngular2: false
4548
}).then(done, done.fail);
4649
});
4750

@@ -54,7 +57,8 @@ describe('ng2 change detection benchmark', function() {
5457
{name: 'numberOfChecks', value: 900000},
5558
{name: 'iterations', value: 20, scale: 'linear'}
5659
],
57-
microMetrics: {'detectChangesAvg': 'avg time to detect changes (ms)'}
60+
microMetrics: {'detectChangesAvg': 'avg time to detect changes (ms)'},
61+
waitForAngular2: false
5862
}).then(done, done.fail);
5963
});
6064

@@ -67,7 +71,8 @@ describe('ng2 change detection benchmark', function() {
6771
{name: 'numberOfChecks', value: 900000},
6872
{name: 'iterations', value: 20, scale: 'linear'}
6973
],
70-
microMetrics: {'detectChangesAvg': 'avg time to detect changes (ms)'}
74+
microMetrics: {'detectChangesAvg': 'avg time to detect changes (ms)'},
75+
waitForAngular2: false
7176
}).then(done, done.fail);
7277
});
7378

@@ -80,7 +85,8 @@ describe('ng2 change detection benchmark', function() {
8085
{name: 'numberOfChecks', value: 900000},
8186
{name: 'iterations', value: 20, scale: 'linear'}
8287
],
83-
microMetrics: {'detectChangesAvg': 'avg time to detect changes (ms)'}
88+
microMetrics: {'detectChangesAvg': 'avg time to detect changes (ms)'},
89+
waitForAngular2: false
8490
}).then(done, done.fail);
8591
});
8692

modules/benchmarks/e2e_test/di_perf.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ describe('ng2 di benchmark', function() {
1212
buttons: ['#getByToken'],
1313
id: 'ng2.di.getByToken',
1414
params: [{name: 'iterations', value: 20000, scale: 'linear'}],
15-
microMetrics: {'injectAvg': 'avg time for injection (in ms)'}
15+
microMetrics: {'injectAvg': 'avg time for injection (in ms)'},
16+
waitForAngular2: false
1617
}).then(done, done.fail);
1718
});
1819

@@ -22,7 +23,8 @@ describe('ng2 di benchmark', function() {
2223
buttons: ['#getByKey'],
2324
id: 'ng2.di.getByKey',
2425
params: [{name: 'iterations', value: 20000, scale: 'linear'}],
25-
microMetrics: {'injectAvg': 'avg time for injection (in ms)'}
26+
microMetrics: {'injectAvg': 'avg time for injection (in ms)'},
27+
waitForAngular2: false
2628
}).then(done, done.fail);
2729
});
2830

@@ -32,7 +34,8 @@ describe('ng2 di benchmark', function() {
3234
buttons: ['#getChild'],
3335
id: 'ng2.di.getChild',
3436
params: [{name: 'iterations', value: 20000, scale: 'linear'}],
35-
microMetrics: {'injectAvg': 'avg time for getChild (in ms)'}
37+
microMetrics: {'injectAvg': 'avg time for getChild (in ms)'},
38+
waitForAngular2: false
3639
}).then(done, done.fail);
3740
});
3841

@@ -42,7 +45,8 @@ describe('ng2 di benchmark', function() {
4245
buttons: ['#instantiate'],
4346
id: 'ng2.di.instantiate',
4447
params: [{name: 'iterations', value: 10000, scale: 'linear'}],
45-
microMetrics: {'injectAvg': 'avg time for instantiate (in ms)'}
48+
microMetrics: {'injectAvg': 'avg time for instantiate (in ms)'},
49+
waitForAngular2: false
4650
}).then(done, done.fail);
4751
});
4852

@@ -56,7 +60,8 @@ describe('ng2 di benchmark', function() {
5660
buttons: ['#createVariety'],
5761
id: 'ng2.di.createVariety',
5862
params: [{name: 'iterations', value: 10000, scale: 'linear'}],
59-
microMetrics: {'injectAvg': 'avg time for createVariety (in ms)'}
63+
microMetrics: {'injectAvg': 'avg time for createVariety (in ms)'},
64+
waitForAngular2: false
6065
}).then(done, done.fail);
6166
});
6267

@@ -69,7 +74,8 @@ describe('ng2 di benchmark', function() {
6974
buttons: ['#createVarietyResolved'],
7075
id: 'ng2.di.createVarietyResolved',
7176
params: [{name: 'iterations', value: 10000, scale: 'linear'}],
72-
microMetrics: {'injectAvg': 'avg time for createVarietyResolved (in ms)'}
77+
microMetrics: {'injectAvg': 'avg time for createVarietyResolved (in ms)'},
78+
waitForAngular2: false
7379
}).then(done, done.fail);
7480
});
7581

modules/benchmarks/e2e_test/element_injector_perf.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ describe('ng2 element injector benchmark', function() {
1212
buttons: ['#instantiate'],
1313
id: 'ng2.elementInjector.instantiate',
1414
params: [{name: 'iterations', value: 20000, scale: 'linear'}],
15-
microMetrics: {'instantiateAvg': 'avg time for injection (in ms)'}
15+
microMetrics: {'instantiateAvg': 'avg time for injection (in ms)'},
16+
waitForAngular2: false
1617
}).then(done, done.fail);
1718
});
1819

@@ -22,7 +23,8 @@ describe('ng2 element injector benchmark', function() {
2223
buttons: ['#hydrate'],
2324
id: 'ng2.elementInjector.hydrate',
2425
params: [{name: 'iterations', value: 20000, scale: 'linear'}],
25-
microMetrics: {'instantiateAvg': 'avg time for injection (in ms)'}
26+
microMetrics: {'instantiateAvg': 'avg time for injection (in ms)'},
27+
waitForAngular2: false
2628
}).then(done, done.fail);
2729
});
2830

modules/benchmarks/e2e_test/selector_perf.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ describe('ng2 selector benchmark', function() {
1111
url: URL,
1212
buttons: ['#parse'],
1313
id: 'ng2.selector.parse',
14-
params: [{name: 'selectors', value: 10000, scale: 'linear'}]
14+
params: [{name: 'selectors', value: 10000, scale: 'linear'}],
15+
waitForAngular2: false
1516
}).then(done, done.fail);
1617
});
1718

@@ -20,7 +21,8 @@ describe('ng2 selector benchmark', function() {
2021
url: URL,
2122
buttons: ['#addSelectable'],
2223
id: 'ng2.selector.addSelectable',
23-
params: [{name: 'selectors', value: 10000, scale: 'linear'}]
24+
params: [{name: 'selectors', value: 10000, scale: 'linear'}],
25+
waitForAngular2: false
2426
}).then(done, done.fail);
2527
});
2628

@@ -29,7 +31,8 @@ describe('ng2 selector benchmark', function() {
2931
url: URL,
3032
buttons: ['#match'],
3133
id: 'ng2.selector.match',
32-
params: [{name: 'selectors', value: 10000, scale: 'linear'}]
34+
params: [{name: 'selectors', value: 10000, scale: 'linear'}],
35+
waitForAngular2: false
3336
}).then(done, done.fail);
3437
});
3538

modules/benchmarks_external/e2e_test/compiler_perf.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ describe('ng1.x compiler benchmark', function() {
1111
url: URL,
1212
buttons: ['#compileWithBindings'],
1313
id: 'ng1.compile.withBindings',
14-
params: [{name: 'elements', value: 150, scale: 'linear'}]
14+
params: [{name: 'elements', value: 150, scale: 'linear'}],
15+
waitForAngular2: false
1516
}).then(done, done.fail);
1617
});
1718

@@ -20,7 +21,8 @@ describe('ng1.x compiler benchmark', function() {
2021
url: URL,
2122
buttons: ['#compileNoBindings'],
2223
id: 'ng1.compile.noBindings',
23-
params: [{name: 'elements', value: 150, scale: 'linear'}]
24+
params: [{name: 'elements', value: 150, scale: 'linear'}],
25+
waitForAngular2: false
2426
}).then(done, done.fail);
2527
});
2628

modules/benchmarks_external/e2e_test/largetable_perf.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ describe('ng1.x largetable benchmark', function() {
1717
{name: 'columns', value: 100, scale: 'sqrt'},
1818
{name: 'rows', value: 20, scale: 'sqrt'},
1919
{name: 'benchmarkType', value: benchmarkType}
20-
]
20+
],
21+
waitForAngular2: false
2122
}).then(done, done.fail);
2223
});
2324
});

0 commit comments

Comments
 (0)
X Tutup