feat(tests): add a test injector

fixes #614

Asynchronous test should inject an AsyncTestCompleter:

Before:

  it("async test", (done) => {
    // ...
    done();
  });

After:

  it("async test", inject([AsyncTestCompleter], (async) => {
    // ...
    async.done();
  }));

Note: inject() is currently a function and the first parameter is the
array of DI tokens to inject as the test function parameters. This
construct is linked to Traceur limitations. The planned syntax is:

  it("async test", @Inject (async: AsyncTestCompleter) => {
    // ...
    async.done();
  });
This commit is contained in:
Victor Berchet
2015-03-13 11:10:11 +01:00
parent 5926d2e2f7
commit 33b5ba863e
29 changed files with 1241 additions and 640 deletions

View File

@ -1,4 +1,15 @@
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/test_lib';
import {
afterEach,
AsyncTestCompleter,
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xit,
} from 'angular2/test_lib';
import { List, ListWrapper, StringMap } from 'angular2/src/facade/collection';
import { PromiseWrapper, Promise } from 'angular2/src/facade/async';
@ -15,28 +26,28 @@ export function main() {
describe('multi metric', () => {
it('should merge descriptions', (done) => {
it('should merge descriptions', inject([AsyncTestCompleter], (async) => {
createMetric(['m1', 'm2']).then( (m) => {
expect(m.describe()).toEqual({
'm1': 'describe', 'm2': 'describe'
});
done();
async.done();
});
});
}));
it('should merge all beginMeasure calls', (done) => {
it('should merge all beginMeasure calls', inject([AsyncTestCompleter], (async) => {
createMetric(['m1', 'm2'])
.then( (m) => m.beginMeasure() )
.then( (values) => {
expect(values).toEqual([
'm1_beginMeasure', 'm2_beginMeasure'
]);
done();
async.done();
});
});
}));
[false, true].forEach( (restartFlag) => {
it(`should merge all endMeasure calls for restart=${restartFlag}`, (done) => {
it(`should merge all endMeasure calls for restart=${restartFlag}`, inject([AsyncTestCompleter], (async) => {
createMetric(['m1', 'm2'])
.then( (m) => m.endMeasure(restartFlag) )
.then( (values) => {
@ -44,9 +55,9 @@ export function main() {
'm1': { 'restart': restartFlag },
'm2': { 'restart': restartFlag }
});
done();
async.done();
});
});
}));
});
});

View File

@ -1,4 +1,15 @@
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/test_lib';
import {
afterEach,
AsyncTestCompleter,
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xit,
} from 'angular2/test_lib';
import { List, ListWrapper } from 'angular2/src/facade/collection';
import { PromiseWrapper, Promise } from 'angular2/src/facade/async';
@ -34,20 +45,20 @@ export function main() {
describe('beginMeasure', () => {
it('should mark the timeline', (done) => {
it('should mark the timeline', inject([AsyncTestCompleter], (async) => {
var metric = createMetric([[]]);
metric.beginMeasure().then((_) => {
expect(commandLog).toEqual([['timeBegin', 'benchpress0']]);
done();
async.done();
});
});
}));
});
describe('endMeasure', () => {
it('should mark and aggregate events in between the marks', (done) => {
it('should mark and aggregate events in between the marks', inject([AsyncTestCompleter], (async) => {
var events = [
[
eventFactory.markStart('benchpress0', 0),
@ -67,11 +78,11 @@ export function main() {
]);
expect(data['script']).toBe(2);
done();
async.done();
});
});
}));
it('should restart timing', (done) => {
it('should restart timing', inject([AsyncTestCompleter], (async) => {
var events = [
[
eventFactory.markStart('benchpress0', 0),
@ -94,11 +105,11 @@ export function main() {
'readPerfLog'
]);
done();
async.done();
});
});
}));
it('should loop and aggregate until the end mark is present', (done) => {
it('should loop and aggregate until the end mark is present', inject([AsyncTestCompleter], (async) => {
var events = [
[ eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 1) ],
[ eventFactory.end('script', 2) ],
@ -119,11 +130,11 @@ export function main() {
]);
expect(data['script']).toBe(3);
done();
async.done();
});
});
}));
it('should store events after the end mark for the next call', (done) => {
it('should store events after the end mark for the next call', inject([AsyncTestCompleter], (async) => {
var events = [
[ eventFactory.markStart('benchpress0', 0), eventFactory.markEnd('benchpress0', 1), eventFactory.markStart('benchpress1', 1),
eventFactory.start('script', 1), eventFactory.end('script', 2) ],
@ -146,9 +157,9 @@ export function main() {
]);
expect(data['script']).toBe(3);
done();
async.done();
});
});
}));
});
@ -163,17 +174,17 @@ export function main() {
}
it('should report a single interval', (done) => {
it('should report a single interval', inject([AsyncTestCompleter], (async) => {
aggregate([
eventFactory.start('script', 0),
eventFactory.end('script', 5)
]).then((data) => {
expect(data['script']).toBe(5);
done();
async.done();
});
});
}));
it('should sum up multiple intervals', (done) => {
it('should sum up multiple intervals', inject([AsyncTestCompleter], (async) => {
aggregate([
eventFactory.start('script', 0),
eventFactory.end('script', 5),
@ -181,29 +192,29 @@ export function main() {
eventFactory.end('script', 17)
]).then((data) => {
expect(data['script']).toBe(12);
done();
async.done();
});
});
}));
it('should ignore not started intervals', (done) => {
it('should ignore not started intervals', inject([AsyncTestCompleter], (async) => {
aggregate([
eventFactory.end('script', 10)
]).then((data) => {
expect(data['script']).toBe(0);
done();
async.done();
});
});
}));
it('should ignore not ended intervals', (done) => {
it('should ignore not ended intervals', inject([AsyncTestCompleter], (async) => {
aggregate([
eventFactory.start('script', 10)
]).then((data) => {
expect(data['script']).toBe(0);
done();
async.done();
});
});
}));
it('should ignore events from different processed as the start mark', (done) => {
it('should ignore events from different processed as the start mark', inject([AsyncTestCompleter], (async) => {
var otherProcessEventFactory = new TraceEventFactory('timeline', 'pid1');
var metric = createMetric([[
eventFactory.markStart('benchpress0', 0),
@ -217,23 +228,23 @@ export function main() {
.then( (_) => metric.endMeasure(false) )
.then((data) => {
expect(data['script']).toBe(5);
done();
async.done();
});
});
}));
['script', 'render'].forEach( (metricName) => {
it(`should support ${metricName} metric`, (done) => {
it(`should support ${metricName} metric`, inject([AsyncTestCompleter], (async) => {
aggregate([
eventFactory.start(metricName, 0),
eventFactory.end(metricName, 5)
]).then((data) => {
expect(data[metricName]).toBe(5);
done();
async.done();
});
});
}));
});
it('should support gcTime/gcAmount metric', (done) => {
it('should support gcTime/gcAmount metric', inject([AsyncTestCompleter], (async) => {
aggregate([
eventFactory.start('gc', 0, {'usedHeapSize': 2500}),
eventFactory.end('gc', 5, {'usedHeapSize': 1000})
@ -242,11 +253,11 @@ export function main() {
expect(data['gcAmount']).toBe(1.5);
expect(data['majorGcTime']).toBe(0);
expect(data['majorGcAmount']).toBe(0);
done();
async.done();
});
});
}));
it('should support majorGcTime/majorGcAmount metric', (done) => {
it('should support majorGcTime/majorGcAmount metric', inject([AsyncTestCompleter], (async) => {
aggregate([
eventFactory.start('gc', 0, {'usedHeapSize': 2500}),
eventFactory.end('gc', 5, {'usedHeapSize': 1000, 'majorGc': true})
@ -255,11 +266,11 @@ export function main() {
expect(data['gcAmount']).toBe(1.5);
expect(data['majorGcTime']).toBe(5);
expect(data['majorGcAmount']).toBe(1.5);
done();
async.done();
});
});
}));
it('should subtract gcTime in script from script time', (done) => {
it('should subtract gcTime in script from script time', inject([AsyncTestCompleter], (async) => {
aggregate([
eventFactory.start('script', 0),
eventFactory.start('gc', 1, {'usedHeapSize': 1000}),
@ -267,32 +278,32 @@ export function main() {
eventFactory.end('script', 5)
]).then((data) => {
expect(data['script']).toBe(2);
done();
async.done();
});
});
}));
describe('microIterations', () => {
it('should not report scriptMicroAvg if microIterations = 0', (done) => {
it('should not report scriptMicroAvg if microIterations = 0', inject([AsyncTestCompleter], (async) => {
aggregate([
eventFactory.start('script', 0),
eventFactory.end('script', 5)
], 0).then((data) => {
expect(isPresent(data['scriptMicroAvg'])).toBe(false);
done();
async.done();
});
});
}));
it('should report scriptMicroAvg', (done) => {
it('should report scriptMicroAvg', inject([AsyncTestCompleter], (async) => {
aggregate([
eventFactory.start('script', 0),
eventFactory.end('script', 5)
], 4).then((data) => {
expect(data['script']).toBe(5);
expect(data['scriptMicroAvg']).toBe(5/4);
done();
async.done();
});
});
}));
});

View File

@ -1,4 +1,15 @@
import {describe, ddescribe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/test_lib';
import {
afterEach,
AsyncTestCompleter,
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xit,
} from 'angular2/test_lib';
import { DateWrapper, Json, RegExpWrapper, isPresent } from 'angular2/src/facade/lang';
import { PromiseWrapper } from 'angular2/src/facade/async';
@ -32,7 +43,7 @@ export function main() {
return new Injector(bindings).get(JsonFileReporter);
}
it('should write all data into a file', (done) => {
it('should write all data into a file', inject([AsyncTestCompleter], (async) => {
createReporter({
sampleId: 'someId',
descriptions: [{ 'a': 2 }],
@ -85,8 +96,8 @@ export function main() {
}
]
});
done();
});
async.done();
}));
});
}

View File

@ -1,4 +1,15 @@
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/test_lib';
import {
afterEach,
AsyncTestCompleter,
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xit,
} from 'angular2/test_lib';
import { List, ListWrapper, StringMap } from 'angular2/src/facade/collection';
import { PromiseWrapper, Promise } from 'angular2/src/facade/async';
@ -16,7 +27,7 @@ export function main() {
describe('multi reporter', () => {
it('should reportMeasureValues to all', (done) => {
it('should reportMeasureValues to all', inject([AsyncTestCompleter], (async) => {
var mv = new MeasureValues(0, DateWrapper.now(), {});
createReporters(['m1', 'm2'])
.then( (r) => r.reportMeasureValues(mv) )
@ -26,11 +37,11 @@ export function main() {
{'id': 'm1', 'values': mv},
{'id': 'm2', 'values': mv}
]);
done();
async.done();
});
});
}));
it('should reportSample to call', (done) => {
it('should reportSample to call', inject([AsyncTestCompleter], (async) => {
var completeSample = [
new MeasureValues(0, DateWrapper.now(), {}),
new MeasureValues(1, DateWrapper.now(), {})
@ -45,9 +56,9 @@ export function main() {
{'id': 'm1', 'completeSample': completeSample, 'validSample': validSample},
{'id': 'm2', 'completeSample': completeSample, 'validSample': validSample}
]);
done();
async.done();
})
});
}));
});
}

View File

@ -1,4 +1,15 @@
import {describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/test_lib';
import {
afterEach,
AsyncTestCompleter,
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xit,
} from 'angular2/test_lib';
import {
Runner, Sampler, SampleDescription,
Validator, bind, Injector, Metric,
@ -31,16 +42,16 @@ export function main() {
return runner;
}
it('should set SampleDescription.id', (done) => {
it('should set SampleDescription.id', inject([AsyncTestCompleter], (async) => {
createRunner().sample({id: 'someId'})
.then( (_) => injector.asyncGet(SampleDescription) )
.then( (desc) => {
expect(desc.id).toBe('someId');
done();
async.done();
});
});
}));
it('should merge SampleDescription.description', (done) => {
it('should merge SampleDescription.description', inject([AsyncTestCompleter], (async) => {
createRunner([
bind(Options.DEFAULT_DESCRIPTION).toValue({'a': 1})
]).sample({id: 'someId', bindings: [
@ -55,44 +66,44 @@ export function main() {
'b': 2,
'v': 11
});
done();
async.done();
});
});
}));
it('should fill SampleDescription.metrics from the Metric', (done) => {
it('should fill SampleDescription.metrics from the Metric', inject([AsyncTestCompleter], (async) => {
createRunner().sample({id: 'someId'})
.then( (_) => injector.asyncGet(SampleDescription) )
.then( (desc) => {
expect(desc.metrics).toEqual({ 'm1': 'some metric' });
done();
async.done();
});
});
}));
it('should bind Options.EXECUTE', (done) => {
it('should bind Options.EXECUTE', inject([AsyncTestCompleter], (async) => {
var execute = () => {};
createRunner().sample({id: 'someId', execute: execute}).then( (_) => {
expect(injector.get(Options.EXECUTE)).toEqual(execute);
done();
async.done();
});
});
}));
it('should bind Options.PREPARE', (done) => {
it('should bind Options.PREPARE', inject([AsyncTestCompleter], (async) => {
var prepare = () => {};
createRunner().sample({id: 'someId', prepare: prepare}).then( (_) => {
expect(injector.get(Options.PREPARE)).toEqual(prepare);
done();
async.done();
});
});
}));
it('should bind Options.MICRO_ITERATIONS', (done) => {
it('should bind Options.MICRO_ITERATIONS', inject([AsyncTestCompleter], (async) => {
createRunner().sample({id: 'someId', microIterations: 23}).then( (_) => {
expect(injector.get(Options.MICRO_ITERATIONS)).toEqual(23);
done();
async.done();
});
});
}));
it('should overwrite bindings per sample call', (done) => {
it('should overwrite bindings per sample call', inject([AsyncTestCompleter], (async) => {
createRunner([
bind(Options.DEFAULT_DESCRIPTION).toValue({'a': 1}),
]).sample({id: 'someId', bindings: [
@ -101,10 +112,10 @@ export function main() {
.then( (desc) => {
expect(injector.get(SampleDescription).description['a']).toBe(2);
done();
async.done();
});
});
}));
});
}

View File

@ -1,4 +1,15 @@
import {describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/test_lib';
import {
afterEach,
AsyncTestCompleter,
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xit,
} from 'angular2/test_lib';
import { isBlank, isPresent, BaseException, stringify, Date, DateWrapper } from 'angular2/src/facade/lang';
import { ListWrapper, List } from 'angular2/src/facade/collection';
@ -58,7 +69,7 @@ export function main() {
sampler = new Injector(bindings).get(Sampler);
}
it('should call the prepare and execute callbacks using WebDriverAdapter.waitFor', (done) => {
it('should call the prepare and execute callbacks using WebDriverAdapter.waitFor', inject([AsyncTestCompleter], (async) => {
var log = [];
var count = 0;
var driver = new MockDriverAdapter([], (callback) => {
@ -79,12 +90,12 @@ export function main() {
sampler.sample().then( (_) => {
expect(count).toBe(4);
expect(log).toEqual([0,1,2,3]);
done();
async.done();
});
});
}));
it('should call prepare, gc, beginMeasure, execute, gc, endMeasure for every iteration', (done) => {
it('should call prepare, gc, beginMeasure, execute, gc, endMeasure for every iteration', inject([AsyncTestCompleter], (async) => {
var workCount = 0;
var log = [];
createSampler({
@ -115,11 +126,11 @@ export function main() {
['gc'],
['endMeasure', false, {'script': 1}],
]);
done();
async.done();
});
});
}));
it('should call execute, gc, endMeasure for every iteration if there is no prepare callback', (done) => {
it('should call execute, gc, endMeasure for every iteration if there is no prepare callback', inject([AsyncTestCompleter], (async) => {
var log = [];
var workCount = 0;
createSampler({
@ -143,11 +154,11 @@ export function main() {
['gc'],
['endMeasure', true, {'script': 1}],
]);
done();
async.done();
});
});
}));
it('should not gc if the flag is not set', (done) => {
it('should not gc if the flag is not set', inject([AsyncTestCompleter], (async) => {
var log = [];
createSampler({
metric: createCountingMetric(),
@ -158,11 +169,11 @@ export function main() {
});
sampler.sample().then( (_) => {
expect(log).toEqual([]);
done();
async.done();
});
});
}));
it('should only collect metrics for execute and ignore metrics from prepare', (done) => {
it('should only collect metrics for execute and ignore metrics from prepare', inject([AsyncTestCompleter], (async) => {
var scriptTime = 0;
var iterationCount = 1;
createSampler({
@ -184,11 +195,11 @@ export function main() {
expect(state.completeSample.length).toBe(2);
expect(state.completeSample[0]).toEqual(mv(0, 1000, {'script': 10}));
expect(state.completeSample[1]).toEqual(mv(1, 1001, {'script': 20}));
done();
async.done();
});
});
}));
it('should call the validator for every execution and store the valid sample', (done) => {
it('should call the validator for every execution and store the valid sample', inject([AsyncTestCompleter], (async) => {
var log = [];
var validSample = [{}];
@ -213,11 +224,11 @@ export function main() {
['validate', [mv(0, 1000, {'script': 0}), mv(1, 1001, {'script': 1})], validSample]
);
done();
async.done();
});
});
}));
it('should report the metric values', (done) => {
it('should report the metric values', inject([AsyncTestCompleter], (async) => {
var log = [];
var validSample = [{}];
createSampler({
@ -244,9 +255,9 @@ export function main() {
['reportSample', [mv(0, 1000, {'script': 0}), mv(1, 1001, {'script': 1})], validSample]
);
done();
async.done();
});
});
}));
});
}
@ -366,4 +377,4 @@ class MockReporter extends Reporter {
ListWrapper.push(this._log, ['reportSample', completeSample, validSample]);
return PromiseWrapper.resolve(null);
}
}
}

View File

@ -1,4 +1,15 @@
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/test_lib';
import {
afterEach,
AsyncTestCompleter,
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xit,
} from 'angular2/test_lib';
import { StringMap, ListWrapper } from 'angular2/src/facade/collection';
import { isPresent, StringWrapper } from 'angular2/src/facade/lang';
@ -17,22 +28,22 @@ export function main() {
describe('WebDriverExtension.bindTo', () => {
it('should bind the extension that matches the capabilities', (done) => {
it('should bind the extension that matches the capabilities', inject([AsyncTestCompleter], (async) => {
createExtension(['m1', 'm2', 'm3'], {'browser': 'm2'}).then( (m) => {
expect(m.id).toEqual('m2');
done();
async.done();
});
});
}));
it('should throw if there is no match', (done) => {
it('should throw if there is no match', inject([AsyncTestCompleter], (async) => {
PromiseWrapper.catchError(
createExtension(['m1'], {'browser': 'm2'}),
(err) => {
expect(isPresent(err)).toBe(true);
done();
async.done();
}
);
});
}));
});
}

View File

@ -1,4 +1,15 @@
import {describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/test_lib';
import {
afterEach,
AsyncTestCompleter,
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xit,
} from 'angular2/test_lib';
import { ListWrapper } from 'angular2/src/facade/collection';
import { PromiseWrapper } from 'angular2/src/facade/async';
@ -34,111 +45,111 @@ export function main() {
return extension;
}
it('should force gc via window.gc()', (done) => {
it('should force gc via window.gc()', inject([AsyncTestCompleter], (async) => {
createExtension().gc().then( (_) => {
expect(log).toEqual([['executeScript', 'window.gc()']]);
done();
async.done();
});
});
}));
it('should mark the timeline via console.time()', (done) => {
it('should mark the timeline via console.time()', inject([AsyncTestCompleter], (async) => {
createExtension().timeBegin('someName').then( (_) => {
expect(log).toEqual([['executeScript', `console.time('someName');`]]);
done();
async.done();
});
});
}));
it('should mark the timeline via console.timeEnd()', (done) => {
it('should mark the timeline via console.timeEnd()', inject([AsyncTestCompleter], (async) => {
createExtension().timeEnd('someName').then( (_) => {
expect(log).toEqual([['executeScript', `console.timeEnd('someName');`]]);
done();
async.done();
});
});
}));
it('should mark the timeline via console.time() and console.timeEnd()', (done) => {
it('should mark the timeline via console.time() and console.timeEnd()', inject([AsyncTestCompleter], (async) => {
createExtension().timeEnd('name1', 'name2').then( (_) => {
expect(log).toEqual([['executeScript', `console.timeEnd('name1');console.time('name2');`]]);
done();
async.done();
});
});
}));
describe('readPerfLog', () => {
it('should execute a dummy script before reading them', (done) => {
it('should execute a dummy script before reading them', inject([AsyncTestCompleter], (async) => {
// TODO(tbosch): This seems to be a bug in ChromeDriver:
// Sometimes it does not report the newest events of the performance log
// to the WebDriver client unless a script is executed...
createExtension([]).readPerfLog().then( (_) => {
expect(log).toEqual([ [ 'executeScript', '1+1' ], [ 'logs', 'performance' ] ]);
done();
async.done();
});
});
}));
it('should normalize times to ms and forward ph and pid event properties', (done) => {
it('should normalize times to ms and forward ph and pid event properties', inject([AsyncTestCompleter], (async) => {
createExtension([
chromeTimelineEvents.complete('FunctionCall', 1100, 5500, null)
]).readPerfLog().then( (events) => {
expect(events).toEqual([
normEvents.complete('script', 1.1, 5.5, null),
]);
done();
async.done();
});
});
}));
it('should normalize "tdur" to "dur"', (done) => {
it('should normalize "tdur" to "dur"', inject([AsyncTestCompleter], (async) => {
var event = chromeTimelineEvents.create('X', 'FunctionCall', 1100, null);
event['tdur'] = 5500;
createExtension([event]).readPerfLog().then( (events) => {
expect(events).toEqual([
normEvents.complete('script', 1.1, 5.5, null),
]);
done();
async.done();
});
});
}));
it('should report FunctionCall events as "script"', (done) => {
it('should report FunctionCall events as "script"', inject([AsyncTestCompleter], (async) => {
createExtension([
chromeTimelineEvents.start('FunctionCall', 0)
]).readPerfLog().then( (events) => {
expect(events).toEqual([
normEvents.start('script', 0),
]);
done();
async.done();
});
});
}));
it('should ignore FunctionCalls from webdriver', (done) => {
it('should ignore FunctionCalls from webdriver', inject([AsyncTestCompleter], (async) => {
createExtension([
chromeTimelineEvents.start('FunctionCall', 0, {'data': {'scriptName': 'InjectedScript'}})
]).readPerfLog().then( (events) => {
expect(events).toEqual([]);
done();
async.done();
});
});
}));
it('should report begin timestamps', (done) => {
it('should report begin timestamps', inject([AsyncTestCompleter], (async) => {
createExtension([
blinkEvents.create('S', 'someName', 1000)
]).readPerfLog().then( (events) => {
expect(events).toEqual([
normEvents.markStart('someName', 1.0)
]);
done();
async.done();
});
});
}));
it('should report end timestamps', (done) => {
it('should report end timestamps', inject([AsyncTestCompleter], (async) => {
createExtension([
blinkEvents.create('F', 'someName', 1000)
]).readPerfLog().then( (events) => {
expect(events).toEqual([
normEvents.markEnd('someName', 1.0)
]);
done();
async.done();
});
});
}));
it('should report gc', (done) => {
it('should report gc', inject([AsyncTestCompleter], (async) => {
createExtension([
chromeTimelineEvents.start('GCEvent', 1000, {'usedHeapSizeBefore': 1000}),
chromeTimelineEvents.end('GCEvent', 2000, {'usedHeapSizeAfter': 0}),
@ -147,11 +158,11 @@ export function main() {
normEvents.start('gc', 1.0, {'usedHeapSize': 1000}),
normEvents.end('gc', 2.0, {'usedHeapSize': 0, 'majorGc': false}),
]);
done();
async.done();
});
});
}));
it('should report major gc', (done) => {
it('should report major gc', inject([AsyncTestCompleter], (async) => {
createExtension([
chromeTimelineEvents.start('GCEvent', 1000, {'usedHeapSizeBefore': 1000}),
v8EventsOtherProcess.start('majorGC', 1100, null),
@ -162,11 +173,11 @@ export function main() {
normEvents.start('gc', 1.0, {'usedHeapSize': 1000}),
normEvents.end('gc', 2.0, {'usedHeapSize': 0, 'majorGc': false}),
]);
done();
async.done();
});
});
}));
it('should ignore major gc from different processes', (done) => {
it('should ignore major gc from different processes', inject([AsyncTestCompleter], (async) => {
createExtension([
chromeTimelineEvents.start('GCEvent', 1000, {'usedHeapSizeBefore': 1000}),
v8Events.start('majorGC', 1100, null),
@ -177,12 +188,12 @@ export function main() {
normEvents.start('gc', 1.0, {'usedHeapSize': 1000}),
normEvents.end('gc', 2.0, {'usedHeapSize': 0, 'majorGc': true}),
]);
done();
async.done();
});
});
}));
['RecalculateStyles', 'Layout', 'UpdateLayerTree', 'Paint', 'Rasterize', 'CompositeLayers'].forEach( (recordType) => {
it(`should report ${recordType} as "render"`, (done) => {
it(`should report ${recordType} as "render"`, inject([AsyncTestCompleter], (async) => {
createExtension([
chromeTimelineEvents.start(recordType, 1234),
chromeTimelineEvents.end(recordType, 2345)
@ -191,21 +202,21 @@ export function main() {
normEvents.start('render', 1.234),
normEvents.end('render', 2.345),
]);
done();
async.done();
});
});
}));
});
it('should throw an error on buffer overflow', (done) => {
it('should throw an error on buffer overflow', inject([AsyncTestCompleter], (async) => {
PromiseWrapper.catchError(createExtension([
chromeTimelineEvents.start('FunctionCall', 1234),
], 'Tracing.bufferUsage').readPerfLog(), (err) => {
expect( () => {
throw err;
}).toThrowError('The DevTools trace buffer filled during the test!');
done();
async.done();
});
});
}));
it('should match chrome browsers', () => {
expect(createExtension().supports({

View File

@ -1,4 +1,15 @@
import {describe, ddescribe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/test_lib';
import {
afterEach,
AsyncTestCompleter,
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xit,
} from 'angular2/test_lib';
import { ListWrapper } from 'angular2/src/facade/collection';
import { PromiseWrapper } from 'angular2/src/facade/async';
@ -30,47 +41,47 @@ export function main() {
return extension;
}
it('should force gc via window.gc()', (done) => {
it('should force gc via window.gc()', inject([AsyncTestCompleter], (async) => {
createExtension().gc().then( (_) => {
expect(log).toEqual([['executeScript', 'window.gc()']]);
done();
async.done();
});
});
}));
it('should mark the timeline via console.time()', (done) => {
it('should mark the timeline via console.time()', inject([AsyncTestCompleter], (async) => {
createExtension().timeBegin('someName').then( (_) => {
expect(log).toEqual([['executeScript', `console.time('someName');`]]);
done();
async.done();
});
});
}));
it('should mark the timeline via console.timeEnd()', (done) => {
it('should mark the timeline via console.timeEnd()', inject([AsyncTestCompleter], (async) => {
createExtension().timeEnd('someName').then( (_) => {
expect(log).toEqual([['executeScript', `console.timeEnd('someName');`]]);
done();
async.done();
});
});
}));
it('should mark the timeline via console.time() and console.timeEnd()', (done) => {
it('should mark the timeline via console.time() and console.timeEnd()', inject([AsyncTestCompleter], (async) => {
createExtension().timeEnd('name1', 'name2').then( (_) => {
expect(log).toEqual([['executeScript', `console.timeEnd('name1');console.time('name2');`]]);
done();
async.done();
});
});
}));
describe('readPerfLog', () => {
it('should execute a dummy script before reading them', (done) => {
it('should execute a dummy script before reading them', inject([AsyncTestCompleter], (async) => {
// TODO(tbosch): This seems to be a bug in ChromeDriver:
// Sometimes it does not report the newest events of the performance log
// to the WebDriver client unless a script is executed...
createExtension([]).readPerfLog().then( (_) => {
expect(log).toEqual([ [ 'executeScript', '1+1' ], [ 'logs', 'performance' ] ]);
done();
async.done();
});
});
}));
it('should report FunctionCall records as "script"', (done) => {
it('should report FunctionCall records as "script"', inject([AsyncTestCompleter], (async) => {
createExtension([
durationRecord('FunctionCall', 1, 5)
]).readPerfLog().then( (events) => {
@ -78,42 +89,42 @@ export function main() {
normEvents.start('script', 1),
normEvents.end('script', 5)
]);
done();
async.done();
});
});
}));
it('should ignore FunctionCalls from webdriver', (done) => {
it('should ignore FunctionCalls from webdriver', inject([AsyncTestCompleter], (async) => {
createExtension([
internalScriptRecord(1, 5)
]).readPerfLog().then( (events) => {
expect(events).toEqual([]);
done();
async.done();
});
});
}));
it('should report begin time', (done) => {
it('should report begin time', inject([AsyncTestCompleter], (async) => {
createExtension([
timeBeginRecord('someName', 12)
]).readPerfLog().then( (events) => {
expect(events).toEqual([
normEvents.markStart('someName', 12)
]);
done();
async.done();
});
});
}));
it('should report end timestamps', (done) => {
it('should report end timestamps', inject([AsyncTestCompleter], (async) => {
createExtension([
timeEndRecord('someName', 12)
]).readPerfLog().then( (events) => {
expect(events).toEqual([
normEvents.markEnd('someName', 12)
]);
done();
async.done();
});
});
}));
it('should report gc', (done) => {
it('should report gc', inject([AsyncTestCompleter], (async) => {
createExtension([
gcRecord(1, 3, 21)
]).readPerfLog().then( (events) => {
@ -121,12 +132,12 @@ export function main() {
normEvents.start('gc', 1, {'usedHeapSize': 0}),
normEvents.end('gc', 3, {'usedHeapSize': -21}),
]);
done();
async.done();
});
});
}));
['RecalculateStyles', 'Layout', 'UpdateLayerTree', 'Paint', 'Rasterize', 'CompositeLayers'].forEach( (recordType) => {
it(`should report ${recordType}`, (done) => {
it(`should report ${recordType}`, inject([AsyncTestCompleter], (async) => {
createExtension([
durationRecord(recordType, 0, 1)
]).readPerfLog().then( (events) => {
@ -134,13 +145,13 @@ export function main() {
normEvents.start('render', 0),
normEvents.end('render', 1),
]);
done();
async.done();
});
});
}));
});
it('should walk children', (done) => {
it('should walk children', inject([AsyncTestCompleter], (async) => {
createExtension([
durationRecord('FunctionCall', 1, 5, [
timeBeginRecord('someName', 2)
@ -151,9 +162,9 @@ export function main() {
normEvents.markStart('someName', 2),
normEvents.end('script', 5)
]);
done();
async.done();
});
});
}));
it('should match safari browsers', () => {
expect(createExtension().supports({