test: clean up internal testing utilities (#42177)
We have some internal proxies for all of the Jasmine functions, as well as some other helpers. This code hasn't been touched in more than 5 years, it can lead to confusion and it isn't really necessary since the same can be achieved using Jasmine. These changes remove most of the code and clean up our existing unit tests. PR Close #42177
This commit is contained in:
parent
bd51762d6e
commit
a787f78074
|
@ -6,8 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
import {Injector, Metric, MultiMetric} from '../../index';
|
import {Injector, Metric, MultiMetric} from '../../index';
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
@ -22,29 +20,27 @@ function createMetric(ids: any[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('multi metric', () => {
|
describe('multi metric', () => {
|
||||||
it('should merge descriptions', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
it('should merge descriptions', done => {
|
||||||
createMetric(['m1', 'm2']).then((m) => {
|
createMetric(['m1', 'm2']).then((m) => {
|
||||||
expect(m.describe()).toEqual({'m1': 'describe', 'm2': 'describe'});
|
expect(m.describe()).toEqual({'m1': 'describe', 'm2': 'describe'});
|
||||||
async.done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should merge all beginMeasure calls',
|
it('should merge all beginMeasure calls', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createMetric(['m1', 'm2']).then((m) => m.beginMeasure()).then((values) => {
|
||||||
createMetric(['m1', 'm2']).then((m) => m.beginMeasure()).then((values) => {
|
expect(values).toEqual(['m1_beginMeasure', 'm2_beginMeasure']);
|
||||||
expect(values).toEqual(['m1_beginMeasure', 'm2_beginMeasure']);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
[false, true].forEach((restartFlag) => {
|
[false, true].forEach((restartFlag) => {
|
||||||
it(`should merge all endMeasure calls for restart=${restartFlag}`,
|
it(`should merge all endMeasure calls for restart=${restartFlag}`, done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createMetric(['m1', 'm2']).then((m) => m.endMeasure(restartFlag)).then((values) => {
|
||||||
createMetric(['m1', 'm2']).then((m) => m.endMeasure(restartFlag)).then((values) => {
|
expect(values).toEqual({'m1': {'restart': restartFlag}, 'm2': {'restart': restartFlag}});
|
||||||
expect(values).toEqual({'m1': {'restart': restartFlag}, 'm2': {'restart': restartFlag}});
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {StaticProvider} from '@angular/core';
|
import {StaticProvider} from '@angular/core';
|
||||||
import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
import {Injector, Metric, Options, PerfLogEvent, PerfLogFeatures, PerflogMetric, WebDriverExtension} from '../../index';
|
import {Injector, Metric, Options, PerfLogEvent, PerfLogFeatures, PerflogMetric, WebDriverExtension} from '../../index';
|
||||||
import {TraceEventFactory} from '../trace_event_factory';
|
import {TraceEventFactory} from '../trace_event_factory';
|
||||||
|
@ -130,152 +129,145 @@ describe('perflog metric', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('beginMeasure', () => {
|
describe('beginMeasure', () => {
|
||||||
it('should not force gc and mark the timeline',
|
it('should not force gc and mark the timeline', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const metric = createMetric([[]], null!);
|
||||||
const metric = createMetric([[]], null!);
|
metric.beginMeasure().then((_) => {
|
||||||
metric.beginMeasure().then((_) => {
|
expect(commandLog).toEqual([['timeBegin', 'benchpress0']]);
|
||||||
expect(commandLog).toEqual([['timeBegin', 'benchpress0']]);
|
|
||||||
|
|
||||||
async.done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should force gc and mark the timeline',
|
it('should force gc and mark the timeline', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const metric = createMetric([[]], null!, {forceGc: true});
|
||||||
const metric = createMetric([[]], null!, {forceGc: true});
|
metric.beginMeasure().then((_) => {
|
||||||
metric.beginMeasure().then((_) => {
|
expect(commandLog).toEqual([['gc'], ['timeBegin', 'benchpress0']]);
|
||||||
expect(commandLog).toEqual([['gc'], ['timeBegin', 'benchpress0']]);
|
|
||||||
|
|
||||||
async.done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('endMeasure', () => {
|
describe('endMeasure', () => {
|
||||||
it('should mark and aggregate events in between the marks',
|
it('should mark and aggregate events in between the marks', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const events = [[
|
||||||
const events = [[
|
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 4),
|
||||||
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 4),
|
eventFactory.end('script', 6), eventFactory.markEnd('benchpress0', 10)
|
||||||
eventFactory.end('script', 6), eventFactory.markEnd('benchpress0', 10)
|
]];
|
||||||
]];
|
const metric = createMetric(events, null!);
|
||||||
const metric = createMetric(events, null!);
|
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
expect(commandLog).toEqual([
|
||||||
expect(commandLog).toEqual([
|
['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', null], 'readPerfLog'
|
||||||
['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', null], 'readPerfLog'
|
]);
|
||||||
]);
|
expect(data['scriptTime']).toBe(2);
|
||||||
expect(data['scriptTime']).toBe(2);
|
|
||||||
|
|
||||||
async.done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should mark and aggregate events since navigationStart',
|
it('should mark and aggregate events since navigationStart', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const events = [[
|
||||||
const events = [[
|
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 4),
|
||||||
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 4),
|
eventFactory.end('script', 6), eventFactory.instant('navigationStart', 7),
|
||||||
eventFactory.end('script', 6), eventFactory.instant('navigationStart', 7),
|
eventFactory.start('script', 8), eventFactory.end('script', 9),
|
||||||
eventFactory.start('script', 8), eventFactory.end('script', 9),
|
eventFactory.markEnd('benchpress0', 10)
|
||||||
eventFactory.markEnd('benchpress0', 10)
|
]];
|
||||||
]];
|
const metric = createMetric(events, null!);
|
||||||
const metric = createMetric(events, null!);
|
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
expect(data['scriptTime']).toBe(1);
|
||||||
expect(data['scriptTime']).toBe(1);
|
|
||||||
|
|
||||||
async.done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should ignore navigationStart if ignoreNavigation is set',
|
it('should ignore navigationStart if ignoreNavigation is set', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const events = [[
|
||||||
const events = [[
|
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 4),
|
||||||
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 4),
|
eventFactory.end('script', 6), eventFactory.instant('navigationStart', 7),
|
||||||
eventFactory.end('script', 6), eventFactory.instant('navigationStart', 7),
|
eventFactory.start('script', 8), eventFactory.end('script', 9),
|
||||||
eventFactory.start('script', 8), eventFactory.end('script', 9),
|
eventFactory.markEnd('benchpress0', 10)
|
||||||
eventFactory.markEnd('benchpress0', 10)
|
]];
|
||||||
]];
|
const metric = createMetric(events, null!, {ignoreNavigation: true});
|
||||||
const metric = createMetric(events, null!, {ignoreNavigation: true});
|
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
expect(data['scriptTime']).toBe(3);
|
||||||
expect(data['scriptTime']).toBe(3);
|
|
||||||
|
|
||||||
async.done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should restart timing', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
it('should restart timing', done => {
|
||||||
const events = [
|
const events = [
|
||||||
[
|
[
|
||||||
eventFactory.markStart('benchpress0', 0),
|
eventFactory.markStart('benchpress0', 0),
|
||||||
eventFactory.markEnd('benchpress0', 1),
|
eventFactory.markEnd('benchpress0', 1),
|
||||||
eventFactory.markStart('benchpress1', 2),
|
eventFactory.markStart('benchpress1', 2),
|
||||||
],
|
],
|
||||||
[eventFactory.markEnd('benchpress1', 3)]
|
[eventFactory.markEnd('benchpress1', 3)]
|
||||||
];
|
];
|
||||||
const metric = createMetric(events, null!);
|
const metric = createMetric(events, null!);
|
||||||
metric.beginMeasure()
|
metric.beginMeasure()
|
||||||
.then((_) => metric.endMeasure(true))
|
.then((_) => metric.endMeasure(true))
|
||||||
.then((_) => metric.endMeasure(true))
|
.then((_) => metric.endMeasure(true))
|
||||||
.then((_) => {
|
.then((_) => {
|
||||||
expect(commandLog).toEqual([
|
expect(commandLog).toEqual([
|
||||||
['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', 'benchpress1'],
|
['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', 'benchpress1'],
|
||||||
'readPerfLog', ['timeEnd', 'benchpress1', 'benchpress2'], 'readPerfLog'
|
'readPerfLog', ['timeEnd', 'benchpress1', 'benchpress2'], 'readPerfLog'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
async.done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should loop and aggregate until the end mark is present',
|
it('should loop and aggregate until the end mark is present', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const events = [
|
||||||
const events = [
|
[eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 1)],
|
||||||
[eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 1)],
|
[eventFactory.end('script', 2)],
|
||||||
[eventFactory.end('script', 2)],
|
[
|
||||||
[
|
eventFactory.start('script', 3), eventFactory.end('script', 5),
|
||||||
eventFactory.start('script', 3), eventFactory.end('script', 5),
|
eventFactory.markEnd('benchpress0', 10)
|
||||||
eventFactory.markEnd('benchpress0', 10)
|
]
|
||||||
]
|
];
|
||||||
];
|
const metric = createMetric(events, null!);
|
||||||
const metric = createMetric(events, null!);
|
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
expect(commandLog).toEqual([
|
||||||
expect(commandLog).toEqual([
|
['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', null], 'readPerfLog',
|
||||||
['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', null], 'readPerfLog',
|
['setTimeout', 100], 'readPerfLog', ['setTimeout', 100], 'readPerfLog'
|
||||||
['setTimeout', 100], 'readPerfLog', ['setTimeout', 100], 'readPerfLog'
|
]);
|
||||||
]);
|
expect(data['scriptTime']).toBe(3);
|
||||||
expect(data['scriptTime']).toBe(3);
|
|
||||||
|
|
||||||
async.done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should store events after the end mark for the next call',
|
it('should store events after the end mark for the next call', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const events = [
|
||||||
const events = [
|
[
|
||||||
[
|
eventFactory.markStart('benchpress0', 0), eventFactory.markEnd('benchpress0', 1),
|
||||||
eventFactory.markStart('benchpress0', 0), eventFactory.markEnd('benchpress0', 1),
|
eventFactory.markStart('benchpress1', 1), eventFactory.start('script', 1),
|
||||||
eventFactory.markStart('benchpress1', 1), eventFactory.start('script', 1),
|
eventFactory.end('script', 2)
|
||||||
eventFactory.end('script', 2)
|
],
|
||||||
],
|
[
|
||||||
[
|
eventFactory.start('script', 3), eventFactory.end('script', 5),
|
||||||
eventFactory.start('script', 3), eventFactory.end('script', 5),
|
eventFactory.markEnd('benchpress1', 6)
|
||||||
eventFactory.markEnd('benchpress1', 6)
|
]
|
||||||
]
|
];
|
||||||
];
|
const metric = createMetric(events, null!);
|
||||||
const metric = createMetric(events, null!);
|
metric.beginMeasure()
|
||||||
metric.beginMeasure()
|
.then((_) => metric.endMeasure(true))
|
||||||
.then((_) => metric.endMeasure(true))
|
.then((data) => {
|
||||||
.then((data) => {
|
expect(data['scriptTime']).toBe(0);
|
||||||
expect(data['scriptTime']).toBe(0);
|
return metric.endMeasure(true);
|
||||||
return metric.endMeasure(true);
|
})
|
||||||
})
|
.then((data) => {
|
||||||
.then((data) => {
|
expect(commandLog).toEqual([
|
||||||
expect(commandLog).toEqual([
|
['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', 'benchpress1'],
|
||||||
['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', 'benchpress1'],
|
'readPerfLog', ['timeEnd', 'benchpress1', 'benchpress2'], 'readPerfLog'
|
||||||
'readPerfLog', ['timeEnd', 'benchpress1', 'benchpress2'], 'readPerfLog'
|
]);
|
||||||
]);
|
expect(data['scriptTime']).toBe(3);
|
||||||
expect(data['scriptTime']).toBe(3);
|
|
||||||
|
|
||||||
async.done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
|
||||||
describe('with forced gc', () => {
|
describe('with forced gc', () => {
|
||||||
let events: PerfLogEvent[][];
|
let events: PerfLogEvent[][];
|
||||||
|
@ -290,29 +282,28 @@ describe('perflog metric', () => {
|
||||||
]];
|
]];
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should measure forced gc', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
it('should measure forced gc', done => {
|
||||||
const metric = createMetric(events, null!, {forceGc: true});
|
const metric = createMetric(events, null!, {forceGc: true});
|
||||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||||
expect(commandLog).toEqual([
|
expect(commandLog).toEqual([
|
||||||
['gc'], ['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', 'benchpress1'],
|
['gc'], ['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', 'benchpress1'],
|
||||||
'readPerfLog', ['gc'], ['timeEnd', 'benchpress1', null], 'readPerfLog'
|
'readPerfLog', ['gc'], ['timeEnd', 'benchpress1', null], 'readPerfLog'
|
||||||
]);
|
]);
|
||||||
expect(data['forcedGcTime']).toBe(3);
|
expect(data['forcedGcTime']).toBe(3);
|
||||||
expect(data['forcedGcAmount']).toBe(1.5);
|
expect(data['forcedGcAmount']).toBe(1.5);
|
||||||
|
|
||||||
async.done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should restart after the forced gc if needed',
|
it('should restart after the forced gc if needed', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const metric = createMetric(events, null!, {forceGc: true});
|
||||||
const metric = createMetric(events, null!, {forceGc: true});
|
metric.beginMeasure().then((_) => metric.endMeasure(true)).then((data) => {
|
||||||
metric.beginMeasure().then((_) => metric.endMeasure(true)).then((data) => {
|
expect(commandLog[5]).toEqual(['timeEnd', 'benchpress1', 'benchpress2']);
|
||||||
expect(commandLog[5]).toEqual(['timeEnd', 'benchpress1', 'benchpress2']);
|
|
||||||
|
|
||||||
async.done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -335,352 +326,314 @@ describe('perflog metric', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('frame metrics', () => {
|
describe('frame metrics', () => {
|
||||||
it('should calculate mean frame time',
|
it('should calculate mean frame time', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate(
|
||||||
aggregate(
|
[
|
||||||
[
|
eventFactory.markStart('frameCapture', 0), eventFactory.instant('frame', 1),
|
||||||
eventFactory.markStart('frameCapture', 0), eventFactory.instant('frame', 1),
|
eventFactory.instant('frame', 3), eventFactory.instant('frame', 4),
|
||||||
eventFactory.instant('frame', 3), eventFactory.instant('frame', 4),
|
eventFactory.markEnd('frameCapture', 5)
|
||||||
eventFactory.markEnd('frameCapture', 5)
|
],
|
||||||
],
|
{captureFrames: true})
|
||||||
{captureFrames: true})
|
.then((data) => {
|
||||||
.then((data) => {
|
expect(data['frameTime.mean']).toBe(((3 - 1) + (4 - 3)) / 2);
|
||||||
expect(data['frameTime.mean']).toBe(((3 - 1) + (4 - 3)) / 2);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should throw if no start event',
|
it('should throw if no start event', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate([eventFactory.instant('frame', 4), eventFactory.markEnd('frameCapture', 5)], {
|
||||||
aggregate([eventFactory.instant('frame', 4), eventFactory.markEnd('frameCapture', 5)], {
|
captureFrames: true
|
||||||
captureFrames: true
|
}).catch((err): any => {
|
||||||
}).catch((err): any => {
|
expect(() => {
|
||||||
expect(() => {
|
throw err;
|
||||||
throw err;
|
}).toThrowError('missing start event for frame capture');
|
||||||
}).toThrowError('missing start event for frame capture');
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should throw if no end event',
|
it('should throw if no end event', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate([eventFactory.markStart('frameCapture', 3), eventFactory.instant('frame', 4)], {
|
||||||
aggregate(
|
captureFrames: true
|
||||||
[eventFactory.markStart('frameCapture', 3), eventFactory.instant('frame', 4)],
|
}).catch((err): any => {
|
||||||
{captureFrames: true})
|
expect(() => {
|
||||||
.catch((err): any => {
|
throw err;
|
||||||
expect(() => {
|
}).toThrowError('missing end event for frame capture');
|
||||||
throw err;
|
done();
|
||||||
}).toThrowError('missing end event for frame capture');
|
});
|
||||||
async.done();
|
});
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should throw if trying to capture twice',
|
it('should throw if trying to capture twice', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate(
|
||||||
aggregate(
|
[eventFactory.markStart('frameCapture', 3), eventFactory.markStart('frameCapture', 4)],
|
||||||
[
|
{captureFrames: true})
|
||||||
eventFactory.markStart('frameCapture', 3),
|
.catch((err): any => {
|
||||||
eventFactory.markStart('frameCapture', 4)
|
expect(() => {
|
||||||
],
|
throw err;
|
||||||
{captureFrames: true})
|
}).toThrowError('can capture frames only once per benchmark run');
|
||||||
.catch((err): any => {
|
done();
|
||||||
expect(() => {
|
});
|
||||||
throw err;
|
});
|
||||||
}).toThrowError('can capture frames only once per benchmark run');
|
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should throw if trying to capture when frame capture is disabled',
|
it('should throw if trying to capture when frame capture is disabled', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate([eventFactory.markStart('frameCapture', 3)]).catch((err) => {
|
||||||
aggregate([eventFactory.markStart('frameCapture', 3)]).catch((err) => {
|
expect(() => {
|
||||||
expect(() => {
|
throw err;
|
||||||
throw err;
|
})
|
||||||
})
|
.toThrowError(
|
||||||
.toThrowError(
|
'found start event for frame capture, but frame capture was not requested in benchpress');
|
||||||
'found start event for frame capture, but frame capture was not requested in benchpress');
|
done();
|
||||||
async.done();
|
return null;
|
||||||
return null;
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should throw if frame capture is enabled, but nothing is captured',
|
it('should throw if frame capture is enabled, but nothing is captured', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate([], {captureFrames: true}).catch((err): any => {
|
||||||
aggregate([], {captureFrames: true}).catch((err): any => {
|
expect(() => {
|
||||||
expect(() => {
|
throw err;
|
||||||
throw err;
|
}).toThrowError('frame capture requested in benchpress, but no start event was found');
|
||||||
}).toThrowError('frame capture requested in benchpress, but no start event was found');
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should calculate best and worst frame time',
|
it('should calculate best and worst frame time', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate(
|
||||||
aggregate(
|
[
|
||||||
[
|
eventFactory.markStart('frameCapture', 0), eventFactory.instant('frame', 1),
|
||||||
eventFactory.markStart('frameCapture', 0), eventFactory.instant('frame', 1),
|
eventFactory.instant('frame', 9), eventFactory.instant('frame', 15),
|
||||||
eventFactory.instant('frame', 9), eventFactory.instant('frame', 15),
|
eventFactory.instant('frame', 18), eventFactory.instant('frame', 28),
|
||||||
eventFactory.instant('frame', 18), eventFactory.instant('frame', 28),
|
eventFactory.instant('frame', 32), eventFactory.markEnd('frameCapture', 10)
|
||||||
eventFactory.instant('frame', 32), eventFactory.markEnd('frameCapture', 10)
|
],
|
||||||
],
|
{captureFrames: true})
|
||||||
{captureFrames: true})
|
.then((data) => {
|
||||||
.then((data) => {
|
expect(data['frameTime.worst']).toBe(10);
|
||||||
expect(data['frameTime.worst']).toBe(10);
|
expect(data['frameTime.best']).toBe(3);
|
||||||
expect(data['frameTime.best']).toBe(3);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should calculate percentage of smoothness to be good',
|
it('should calculate percentage of smoothness to be good', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate(
|
||||||
aggregate(
|
[
|
||||||
[
|
eventFactory.markStart('frameCapture', 0), eventFactory.instant('frame', 1),
|
||||||
eventFactory.markStart('frameCapture', 0), eventFactory.instant('frame', 1),
|
eventFactory.instant('frame', 2), eventFactory.instant('frame', 3),
|
||||||
eventFactory.instant('frame', 2), eventFactory.instant('frame', 3),
|
eventFactory.markEnd('frameCapture', 4)
|
||||||
eventFactory.markEnd('frameCapture', 4)
|
],
|
||||||
],
|
{captureFrames: true})
|
||||||
{captureFrames: true})
|
.then((data) => {
|
||||||
.then((data) => {
|
expect(data['frameTime.smooth']).toBe(1.0);
|
||||||
expect(data['frameTime.smooth']).toBe(1.0);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should calculate percentage of smoothness to be bad',
|
it('should calculate percentage of smoothness to be bad', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate(
|
||||||
aggregate(
|
[
|
||||||
[
|
eventFactory.markStart('frameCapture', 0), eventFactory.instant('frame', 1),
|
||||||
eventFactory.markStart('frameCapture', 0), eventFactory.instant('frame', 1),
|
eventFactory.instant('frame', 2), eventFactory.instant('frame', 22),
|
||||||
eventFactory.instant('frame', 2), eventFactory.instant('frame', 22),
|
eventFactory.instant('frame', 23), eventFactory.instant('frame', 24),
|
||||||
eventFactory.instant('frame', 23), eventFactory.instant('frame', 24),
|
eventFactory.markEnd('frameCapture', 4)
|
||||||
eventFactory.markEnd('frameCapture', 4)
|
],
|
||||||
],
|
{captureFrames: true})
|
||||||
{captureFrames: true})
|
.then((data) => {
|
||||||
.then((data) => {
|
expect(data['frameTime.smooth']).toBe(0.75);
|
||||||
expect(data['frameTime.smooth']).toBe(0.75);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should report a single interval',
|
it('should report a single interval', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate([eventFactory.start('script', 0), eventFactory.end('script', 5)]).then((data) => {
|
||||||
aggregate([
|
expect(data['scriptTime']).toBe(5);
|
||||||
eventFactory.start('script', 0), eventFactory.end('script', 5)
|
done();
|
||||||
]).then((data) => {
|
});
|
||||||
expect(data['scriptTime']).toBe(5);
|
});
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should sum up multiple intervals',
|
it('should sum up multiple intervals', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate([
|
||||||
aggregate([
|
eventFactory.start('script', 0), eventFactory.end('script', 5),
|
||||||
eventFactory.start('script', 0), eventFactory.end('script', 5),
|
eventFactory.start('script', 10), eventFactory.end('script', 17)
|
||||||
eventFactory.start('script', 10), eventFactory.end('script', 17)
|
]).then((data) => {
|
||||||
]).then((data) => {
|
expect(data['scriptTime']).toBe(12);
|
||||||
expect(data['scriptTime']).toBe(12);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should ignore not started intervals',
|
it('should ignore not started intervals', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate([eventFactory.end('script', 10)]).then((data) => {
|
||||||
aggregate([eventFactory.end('script', 10)]).then((data) => {
|
expect(data['scriptTime']).toBe(0);
|
||||||
expect(data['scriptTime']).toBe(0);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should ignore not ended intervals',
|
it('should ignore not ended intervals', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate([eventFactory.start('script', 10)]).then((data) => {
|
||||||
aggregate([eventFactory.start('script', 10)]).then((data) => {
|
expect(data['scriptTime']).toBe(0);
|
||||||
expect(data['scriptTime']).toBe(0);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should ignore nested intervals',
|
it('should ignore nested intervals', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate([
|
||||||
aggregate([
|
eventFactory.start('script', 0), eventFactory.start('script', 5),
|
||||||
eventFactory.start('script', 0), eventFactory.start('script', 5),
|
eventFactory.end('script', 10), eventFactory.end('script', 17)
|
||||||
eventFactory.end('script', 10), eventFactory.end('script', 17)
|
]).then((data) => {
|
||||||
]).then((data) => {
|
expect(data['scriptTime']).toBe(17);
|
||||||
expect(data['scriptTime']).toBe(17);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should ignore events from different processed as the start mark',
|
it('should ignore events from different processed as the start mark', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const otherProcessEventFactory = new TraceEventFactory('timeline', 'pid1');
|
||||||
const otherProcessEventFactory = new TraceEventFactory('timeline', 'pid1');
|
const metric = createMetric(
|
||||||
const metric = createMetric(
|
[[
|
||||||
[[
|
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 0, null),
|
||||||
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 0, null),
|
eventFactory.end('script', 5, null), otherProcessEventFactory.start('script', 10, null),
|
||||||
eventFactory.end('script', 5, null),
|
otherProcessEventFactory.end('script', 17, null),
|
||||||
otherProcessEventFactory.start('script', 10, null),
|
eventFactory.markEnd('benchpress0', 20)
|
||||||
otherProcessEventFactory.end('script', 17, null),
|
]],
|
||||||
eventFactory.markEnd('benchpress0', 20)
|
null!);
|
||||||
]],
|
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||||
null!);
|
expect(data['scriptTime']).toBe(5);
|
||||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
done();
|
||||||
expect(data['scriptTime']).toBe(5);
|
});
|
||||||
async.done();
|
});
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should mark a run as invalid if the start and end marks are different',
|
it('should mark a run as invalid if the start and end marks are different', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const otherProcessEventFactory = new TraceEventFactory('timeline', 'pid1');
|
||||||
const otherProcessEventFactory = new TraceEventFactory('timeline', 'pid1');
|
const metric = createMetric(
|
||||||
const metric = createMetric(
|
[[
|
||||||
[[
|
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 0, null),
|
||||||
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 0, null),
|
eventFactory.end('script', 5, null), otherProcessEventFactory.start('script', 10, null),
|
||||||
eventFactory.end('script', 5, null),
|
otherProcessEventFactory.end('script', 17, null),
|
||||||
otherProcessEventFactory.start('script', 10, null),
|
otherProcessEventFactory.markEnd('benchpress0', 20)
|
||||||
otherProcessEventFactory.end('script', 17, null),
|
]],
|
||||||
otherProcessEventFactory.markEnd('benchpress0', 20)
|
null!);
|
||||||
]],
|
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||||
null!);
|
expect(data['invalid']).toBe(1);
|
||||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
done();
|
||||||
expect(data['invalid']).toBe(1);
|
});
|
||||||
async.done();
|
});
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should support scriptTime metric',
|
it('should support scriptTime metric', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate([eventFactory.start('script', 0), eventFactory.end('script', 5)]).then((data) => {
|
||||||
aggregate([
|
expect(data['scriptTime']).toBe(5);
|
||||||
eventFactory.start('script', 0), eventFactory.end('script', 5)
|
done();
|
||||||
]).then((data) => {
|
});
|
||||||
expect(data['scriptTime']).toBe(5);
|
});
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should support renderTime metric',
|
it('should support renderTime metric', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate([eventFactory.start('render', 0), eventFactory.end('render', 5)]).then((data) => {
|
||||||
aggregate([
|
expect(data['renderTime']).toBe(5);
|
||||||
eventFactory.start('render', 0), eventFactory.end('render', 5)
|
done();
|
||||||
]).then((data) => {
|
});
|
||||||
expect(data['renderTime']).toBe(5);
|
});
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should support gcTime/gcAmount metric',
|
it('should support gcTime/gcAmount metric', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate([
|
||||||
aggregate([
|
eventFactory.start('gc', 0, {'usedHeapSize': 2500}),
|
||||||
eventFactory.start('gc', 0, {'usedHeapSize': 2500}),
|
eventFactory.end('gc', 5, {'usedHeapSize': 1000})
|
||||||
eventFactory.end('gc', 5, {'usedHeapSize': 1000})
|
]).then((data) => {
|
||||||
]).then((data) => {
|
expect(data['gcTime']).toBe(5);
|
||||||
expect(data['gcTime']).toBe(5);
|
expect(data['gcAmount']).toBe(1.5);
|
||||||
expect(data['gcAmount']).toBe(1.5);
|
expect(data['majorGcTime']).toBe(0);
|
||||||
expect(data['majorGcTime']).toBe(0);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should support majorGcTime metric',
|
it('should support majorGcTime metric', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate([
|
||||||
aggregate([
|
eventFactory.start('gc', 0, {'usedHeapSize': 2500}),
|
||||||
eventFactory.start('gc', 0, {'usedHeapSize': 2500}),
|
eventFactory.end('gc', 5, {'usedHeapSize': 1000, 'majorGc': true})
|
||||||
eventFactory.end('gc', 5, {'usedHeapSize': 1000, 'majorGc': true})
|
]).then((data) => {
|
||||||
]).then((data) => {
|
expect(data['gcTime']).toBe(5);
|
||||||
expect(data['gcTime']).toBe(5);
|
expect(data['majorGcTime']).toBe(5);
|
||||||
expect(data['majorGcTime']).toBe(5);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should support pureScriptTime = scriptTime-gcTime-renderTime',
|
it('should support pureScriptTime = scriptTime-gcTime-renderTime', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate([
|
||||||
aggregate([
|
eventFactory.start('script', 0), eventFactory.start('gc', 1, {'usedHeapSize': 1000}),
|
||||||
eventFactory.start('script', 0), eventFactory.start('gc', 1, {'usedHeapSize': 1000}),
|
eventFactory.end('gc', 4, {'usedHeapSize': 0}), eventFactory.start('render', 4),
|
||||||
eventFactory.end('gc', 4, {'usedHeapSize': 0}), eventFactory.start('render', 4),
|
eventFactory.end('render', 5), eventFactory.end('script', 6)
|
||||||
eventFactory.end('render', 5), eventFactory.end('script', 6)
|
]).then((data) => {
|
||||||
]).then((data) => {
|
expect(data['scriptTime']).toBe(6);
|
||||||
expect(data['scriptTime']).toBe(6);
|
expect(data['pureScriptTime']).toBe(2);
|
||||||
expect(data['pureScriptTime']).toBe(2);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
describe('receivedData', () => {
|
describe('receivedData', () => {
|
||||||
it('should report received data since last navigationStart',
|
it('should report received data since last navigationStart', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate(
|
||||||
aggregate(
|
[
|
||||||
[
|
eventFactory.instant('receivedData', 0, {'encodedDataLength': 1}),
|
||||||
eventFactory.instant('receivedData', 0, {'encodedDataLength': 1}),
|
eventFactory.instant('navigationStart', 1),
|
||||||
eventFactory.instant('navigationStart', 1),
|
eventFactory.instant('receivedData', 2, {'encodedDataLength': 2}),
|
||||||
eventFactory.instant('receivedData', 2, {'encodedDataLength': 2}),
|
eventFactory.instant('navigationStart', 3),
|
||||||
eventFactory.instant('navigationStart', 3),
|
eventFactory.instant('receivedData', 4, {'encodedDataLength': 4}),
|
||||||
eventFactory.instant('receivedData', 4, {'encodedDataLength': 4}),
|
eventFactory.instant('receivedData', 5, {'encodedDataLength': 8})
|
||||||
eventFactory.instant('receivedData', 5, {'encodedDataLength': 8})
|
],
|
||||||
],
|
{receivedData: true})
|
||||||
{receivedData: true})
|
.then((data) => {
|
||||||
.then((data) => {
|
expect(data['receivedData']).toBe(12);
|
||||||
expect(data['receivedData']).toBe(12);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('requestCount', () => {
|
describe('requestCount', () => {
|
||||||
it('should report count of requests sent since last navigationStart',
|
it('should report count of requests sent since last navigationStart', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate(
|
||||||
aggregate(
|
[
|
||||||
[
|
eventFactory.instant('sendRequest', 0), eventFactory.instant('navigationStart', 1),
|
||||||
eventFactory.instant('sendRequest', 0), eventFactory.instant('navigationStart', 1),
|
eventFactory.instant('sendRequest', 2), eventFactory.instant('navigationStart', 3),
|
||||||
eventFactory.instant('sendRequest', 2), eventFactory.instant('navigationStart', 3),
|
eventFactory.instant('sendRequest', 4), eventFactory.instant('sendRequest', 5)
|
||||||
eventFactory.instant('sendRequest', 4), eventFactory.instant('sendRequest', 5)
|
],
|
||||||
],
|
{requestCount: true})
|
||||||
{requestCount: true})
|
.then((data) => {
|
||||||
.then((data) => {
|
expect(data['requestCount']).toBe(2);
|
||||||
expect(data['requestCount']).toBe(2);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('microMetrics', () => {
|
describe('microMetrics', () => {
|
||||||
it('should report micro metrics',
|
it('should report micro metrics', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate(
|
||||||
aggregate(
|
[
|
||||||
[
|
eventFactory.markStart('mm1', 0),
|
||||||
eventFactory.markStart('mm1', 0),
|
eventFactory.markEnd('mm1', 5),
|
||||||
eventFactory.markEnd('mm1', 5),
|
],
|
||||||
],
|
{microMetrics: {'mm1': 'micro metric 1'}})
|
||||||
{microMetrics: {'mm1': 'micro metric 1'}})
|
.then((data) => {
|
||||||
.then((data) => {
|
expect(data['mm1']).toBe(5.0);
|
||||||
expect(data['mm1']).toBe(5.0);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should ignore micro metrics that were not specified',
|
it('should ignore micro metrics that were not specified', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate([
|
||||||
aggregate([
|
eventFactory.markStart('mm1', 0),
|
||||||
eventFactory.markStart('mm1', 0),
|
eventFactory.markEnd('mm1', 5),
|
||||||
eventFactory.markEnd('mm1', 5),
|
]).then((data) => {
|
||||||
]).then((data) => {
|
expect(data['mm1']).toBeFalsy();
|
||||||
expect(data['mm1']).toBeFalsy();
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should report micro metric averages',
|
it('should report micro metric averages', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
aggregate(
|
||||||
aggregate(
|
[
|
||||||
[
|
eventFactory.markStart('mm1*20', 0),
|
||||||
eventFactory.markStart('mm1*20', 0),
|
eventFactory.markEnd('mm1*20', 5),
|
||||||
eventFactory.markEnd('mm1*20', 5),
|
],
|
||||||
],
|
{microMetrics: {'mm1': 'micro metric 1'}})
|
||||||
{microMetrics: {'mm1': 'micro metric 1'}})
|
.then((data) => {
|
||||||
.then((data) => {
|
expect(data['mm1']).toBe(5 / 20);
|
||||||
expect(data['mm1']).toBe(5 / 20);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Injector, StaticProvider} from '@angular/core';
|
import {Injector, StaticProvider} from '@angular/core';
|
||||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
import {Options, PerfLogEvent, PerfLogFeatures, UserMetric, WebDriverAdapter} from '../../index';
|
import {Options, PerfLogEvent, PerfLogFeatures, UserMetric, WebDriverAdapter} from '../../index';
|
||||||
|
|
||||||
|
@ -42,23 +41,22 @@ describe('user metric', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('endMeasure', () => {
|
describe('endMeasure', () => {
|
||||||
it('should stop measuring when all properties have numeric values',
|
it('should stop measuring when all properties have numeric values', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const metric = createMetric(
|
||||||
const metric = createMetric(
|
[[]], new PerfLogFeatures(),
|
||||||
[[]], new PerfLogFeatures(),
|
{userMetrics: {'loadTime': 'time to load', 'content': 'time to see content'}});
|
||||||
{userMetrics: {'loadTime': 'time to load', 'content': 'time to see content'}});
|
metric.beginMeasure().then(() => metric.endMeasure(true)).then(values => {
|
||||||
metric.beginMeasure().then(() => metric.endMeasure(true)).then(values => {
|
expect(values['loadTime']).toBe(25);
|
||||||
expect(values['loadTime']).toBe(25);
|
expect(values['content']).toBe(250);
|
||||||
expect(values['content']).toBe(250);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
|
||||||
|
|
||||||
wdAdapter.data['loadTime'] = 25;
|
wdAdapter.data['loadTime'] = 25;
|
||||||
// Wait before setting 2nd property.
|
// Wait before setting 2nd property.
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
wdAdapter.data['content'] = 250;
|
wdAdapter.data['content'] = 250;
|
||||||
}, 50);
|
}, 50);
|
||||||
}), 600);
|
}, 600);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {StaticProvider} from '@angular/core';
|
import {StaticProvider} from '@angular/core';
|
||||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
import {ConsoleReporter, Injector, MeasureValues, SampleDescription} from '../../index';
|
import {ConsoleReporter, Injector, MeasureValues, SampleDescription} from '../../index';
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
import {Injector, JsonFileReporter, MeasureValues, Options, SampleDescription} from '../../index';
|
import {Injector, JsonFileReporter, MeasureValues, Options, SampleDescription} from '../../index';
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -37,37 +35,35 @@ import {Injector, JsonFileReporter, MeasureValues, Options, SampleDescription} f
|
||||||
return Injector.create(providers).get<JsonFileReporter>(JsonFileReporter);
|
return Injector.create(providers).get<JsonFileReporter>(JsonFileReporter);
|
||||||
}
|
}
|
||||||
|
|
||||||
it('should write all data into a file',
|
it('should write all data into a file', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createReporter({
|
||||||
createReporter({
|
sampleId: 'someId',
|
||||||
sampleId: 'someId',
|
descriptions: [{'a': 2}],
|
||||||
descriptions: [{'a': 2}],
|
path: 'somePath',
|
||||||
path: 'somePath',
|
metrics: {'a': 'script time', 'b': 'render time'}
|
||||||
metrics: {'a': 'script time', 'b': 'render time'}
|
})
|
||||||
})
|
.reportSample(
|
||||||
.reportSample(
|
[mv(0, 0, {'a': 3, 'b': 6})],
|
||||||
[mv(0, 0, {'a': 3, 'b': 6})],
|
[mv(0, 0, {'a': 3, 'b': 6}), mv(1, 1, {'a': 5, 'b': 9})]);
|
||||||
[mv(0, 0, {'a': 3, 'b': 6}), mv(1, 1, {'a': 5, 'b': 9})]);
|
const regExp = /somePath\/someId_\d+\.json/;
|
||||||
const regExp = /somePath\/someId_\d+\.json/;
|
expect(loggedFile['filename'].match(regExp) != null).toBe(true);
|
||||||
expect(loggedFile['filename'].match(regExp) != null).toBe(true);
|
const parsedContent = JSON.parse(loggedFile['content']) as {[key: string]: any};
|
||||||
const parsedContent = JSON.parse(loggedFile['content']) as {[key: string]: any};
|
expect(parsedContent).toEqual({
|
||||||
expect(parsedContent).toEqual({
|
'description': {
|
||||||
'description': {
|
'id': 'someId',
|
||||||
'id': 'someId',
|
'description': {'a': 2},
|
||||||
'description': {'a': 2},
|
'metrics': {'a': 'script time', 'b': 'render time'}
|
||||||
'metrics': {'a': 'script time', 'b': 'render time'}
|
},
|
||||||
},
|
'stats': {'a': '4.00+-25%', 'b': '7.50+-20%'},
|
||||||
'stats': {'a': '4.00+-25%', 'b': '7.50+-20%'},
|
'completeSample':
|
||||||
'completeSample': [
|
[{'timeStamp': '1970-01-01T00:00:00.000Z', 'runIndex': 0, 'values': {'a': 3, 'b': 6}}],
|
||||||
{'timeStamp': '1970-01-01T00:00:00.000Z', 'runIndex': 0, 'values': {'a': 3, 'b': 6}}
|
'validSample': [
|
||||||
],
|
{'timeStamp': '1970-01-01T00:00:00.000Z', 'runIndex': 0, 'values': {'a': 3, 'b': 6}},
|
||||||
'validSample': [
|
{'timeStamp': '1970-01-01T00:00:00.001Z', 'runIndex': 1, 'values': {'a': 5, 'b': 9}}
|
||||||
{'timeStamp': '1970-01-01T00:00:00.000Z', 'runIndex': 0, 'values': {'a': 3, 'b': 6}},
|
]
|
||||||
{'timeStamp': '1970-01-01T00:00:00.001Z', 'runIndex': 1, 'values': {'a': 5, 'b': 9}}
|
});
|
||||||
]
|
done();
|
||||||
});
|
});
|
||||||
async.done();
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
import {Injector, MeasureValues, MultiReporter, Reporter} from '../../index';
|
import {Injector, MeasureValues, MultiReporter, Reporter} from '../../index';
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
@ -22,30 +20,29 @@ function createReporters(ids: any[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('multi reporter', () => {
|
describe('multi reporter', () => {
|
||||||
it('should reportMeasureValues to all',
|
it('should reportMeasureValues to all', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const mv = new MeasureValues(0, new Date(), {});
|
||||||
const mv = new MeasureValues(0, new Date(), {});
|
createReporters(['m1', 'm2']).then((r) => r.reportMeasureValues(mv)).then((values) => {
|
||||||
createReporters(['m1', 'm2']).then((r) => r.reportMeasureValues(mv)).then((values) => {
|
expect(values).toEqual([{'id': 'm1', 'values': mv}, {'id': 'm2', 'values': mv}]);
|
||||||
expect(values).toEqual([{'id': 'm1', 'values': mv}, {'id': 'm2', 'values': mv}]);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should reportSample to call', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
it('should reportSample to call', done => {
|
||||||
const completeSample =
|
const completeSample =
|
||||||
[new MeasureValues(0, new Date(), {}), new MeasureValues(1, new Date(), {})];
|
[new MeasureValues(0, new Date(), {}), new MeasureValues(1, new Date(), {})];
|
||||||
const validSample = [completeSample[1]];
|
const validSample = [completeSample[1]];
|
||||||
|
|
||||||
createReporters(['m1', 'm2'])
|
createReporters(['m1', 'm2'])
|
||||||
.then((r) => r.reportSample(completeSample, validSample))
|
.then((r) => r.reportSample(completeSample, validSample))
|
||||||
.then((values) => {
|
.then((values) => {
|
||||||
expect(values).toEqual([
|
expect(values).toEqual([
|
||||||
{'id': 'm1', 'completeSample': completeSample, 'validSample': validSample},
|
{'id': 'm1', 'completeSample': completeSample, 'validSample': validSample},
|
||||||
{'id': 'm2', 'completeSample': completeSample, 'validSample': validSample}
|
{'id': 'm2', 'completeSample': completeSample, 'validSample': validSample}
|
||||||
]);
|
]);
|
||||||
async.done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
import {Injector, Metric, Options, Runner, SampleDescription, Sampler, SampleState, Validator, WebDriverAdapter} from '../index';
|
import {Injector, Metric, Options, Runner, SampleDescription, Sampler, SampleState, Validator, WebDriverAdapter} from '../index';
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -35,83 +33,75 @@ import {Injector, Metric, Options, Runner, SampleDescription, Sampler, SampleSta
|
||||||
return runner;
|
return runner;
|
||||||
}
|
}
|
||||||
|
|
||||||
it('should set SampleDescription.id',
|
it('should set SampleDescription.id', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createRunner()
|
||||||
createRunner()
|
.sample({id: 'someId'})
|
||||||
.sample({id: 'someId'})
|
.then((_) => injector.get(SampleDescription))
|
||||||
.then((_) => injector.get(SampleDescription))
|
.then((desc) => {
|
||||||
.then((desc) => {
|
expect(desc.id).toBe('someId');
|
||||||
expect(desc.id).toBe('someId');
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should merge SampleDescription.description',
|
it('should merge SampleDescription.description', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createRunner([{provide: Options.DEFAULT_DESCRIPTION, useValue: {'a': 1}}])
|
||||||
createRunner([{provide: Options.DEFAULT_DESCRIPTION, useValue: {'a': 1}}])
|
.sample({
|
||||||
.sample({
|
id: 'someId',
|
||||||
id: 'someId',
|
providers: [{provide: Options.SAMPLE_DESCRIPTION, useValue: {'b': 2}}]
|
||||||
providers: [{provide: Options.SAMPLE_DESCRIPTION, useValue: {'b': 2}}]
|
})
|
||||||
})
|
.then((_) => injector.get(SampleDescription))
|
||||||
.then((_) => injector.get(SampleDescription))
|
.then((desc) => {
|
||||||
.then((desc) => {
|
expect(desc.description)
|
||||||
expect(desc.description)
|
.toEqual({'forceGc': false, 'userAgent': 'someUserAgent', 'a': 1, 'b': 2, 'v': 11});
|
||||||
.toEqual(
|
done();
|
||||||
{'forceGc': false, 'userAgent': 'someUserAgent', 'a': 1, 'b': 2, 'v': 11});
|
});
|
||||||
async.done();
|
});
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should fill SampleDescription.metrics from the Metric',
|
it('should fill SampleDescription.metrics from the Metric', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createRunner()
|
||||||
createRunner()
|
.sample({id: 'someId'})
|
||||||
.sample({id: 'someId'})
|
.then((_) => injector.get(SampleDescription))
|
||||||
.then((_) => injector.get(SampleDescription))
|
.then((desc) => {
|
||||||
.then((desc) => {
|
expect(desc.metrics).toEqual({'m1': 'some metric'});
|
||||||
expect(desc.metrics).toEqual({'m1': 'some metric'});
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should provide Options.EXECUTE',
|
it('should provide Options.EXECUTE', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const execute = () => {};
|
||||||
const execute = () => {};
|
createRunner().sample({id: 'someId', execute: execute}).then((_) => {
|
||||||
createRunner().sample({id: 'someId', execute: execute}).then((_) => {
|
expect(injector.get(Options.EXECUTE)).toEqual(execute);
|
||||||
expect(injector.get(Options.EXECUTE)).toEqual(execute);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should provide Options.PREPARE',
|
it('should provide Options.PREPARE', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const prepare = () => {};
|
||||||
const prepare = () => {};
|
createRunner().sample({id: 'someId', prepare: prepare}).then((_) => {
|
||||||
createRunner().sample({id: 'someId', prepare: prepare}).then((_) => {
|
expect(injector.get(Options.PREPARE)).toEqual(prepare);
|
||||||
expect(injector.get(Options.PREPARE)).toEqual(prepare);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should provide Options.MICRO_METRICS',
|
it('should provide Options.MICRO_METRICS', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createRunner().sample({id: 'someId', microMetrics: {'a': 'b'}}).then((_) => {
|
||||||
createRunner().sample({id: 'someId', microMetrics: {'a': 'b'}}).then((_) => {
|
expect(injector.get(Options.MICRO_METRICS)).toEqual({'a': 'b'});
|
||||||
expect(injector.get(Options.MICRO_METRICS)).toEqual({'a': 'b'});
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should overwrite providers per sample call',
|
it('should overwrite providers per sample call', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createRunner([{provide: Options.DEFAULT_DESCRIPTION, useValue: {'a': 1}}])
|
||||||
createRunner([{provide: Options.DEFAULT_DESCRIPTION, useValue: {'a': 1}}])
|
.sample({
|
||||||
.sample({
|
id: 'someId',
|
||||||
id: 'someId',
|
providers: [{provide: Options.DEFAULT_DESCRIPTION, useValue: {'a': 2}}]
|
||||||
providers: [{provide: Options.DEFAULT_DESCRIPTION, useValue: {'a': 2}}]
|
})
|
||||||
})
|
.then((_) => injector.get(SampleDescription))
|
||||||
.then((_) => injector.get(SampleDescription))
|
.then((desc) => {
|
||||||
.then((desc) => {
|
expect(desc.description['a']).toBe(2);
|
||||||
expect(desc.description['a']).toBe(2);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
import {Injector, MeasureValues, Metric, Options, Reporter, Sampler, Validator, WebDriverAdapter} from '../index';
|
import {Injector, MeasureValues, Metric, Options, Reporter, Sampler, Validator, WebDriverAdapter} from '../index';
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -47,59 +45,57 @@ import {Injector, MeasureValues, Metric, Options, Reporter, Sampler, Validator,
|
||||||
sampler = Injector.create(providers).get(Sampler);
|
sampler = Injector.create(providers).get(Sampler);
|
||||||
}
|
}
|
||||||
|
|
||||||
it('should call the prepare and execute callbacks using WebDriverAdapter.waitFor',
|
it('should call the prepare and execute callbacks using WebDriverAdapter.waitFor', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const log: any[] = [];
|
||||||
const log: any[] = [];
|
let count = 0;
|
||||||
let count = 0;
|
const driver = new MockDriverAdapter([], (callback: Function) => {
|
||||||
const driver = new MockDriverAdapter([], (callback: Function) => {
|
const result = callback();
|
||||||
const result = callback();
|
log.push(result);
|
||||||
log.push(result);
|
return Promise.resolve(result);
|
||||||
return Promise.resolve(result);
|
});
|
||||||
});
|
createSampler({
|
||||||
createSampler({
|
driver: driver,
|
||||||
driver: driver,
|
validator: createCountingValidator(2),
|
||||||
validator: createCountingValidator(2),
|
prepare: () => count++,
|
||||||
prepare: () => count++,
|
execute: () => count++,
|
||||||
execute: () => count++,
|
});
|
||||||
});
|
sampler.sample().then((_) => {
|
||||||
sampler.sample().then((_) => {
|
expect(count).toBe(4);
|
||||||
expect(count).toBe(4);
|
expect(log).toEqual([0, 1, 2, 3]);
|
||||||
expect(log).toEqual([0, 1, 2, 3]);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should call prepare, beginMeasure, execute, endMeasure for every iteration',
|
it('should call prepare, beginMeasure, execute, endMeasure for every iteration', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
let workCount = 0;
|
||||||
let workCount = 0;
|
const log: any[] = [];
|
||||||
const log: any[] = [];
|
createSampler({
|
||||||
createSampler({
|
metric: createCountingMetric(log),
|
||||||
metric: createCountingMetric(log),
|
validator: createCountingValidator(2),
|
||||||
validator: createCountingValidator(2),
|
prepare: () => {
|
||||||
prepare: () => {
|
log.push(`p${workCount++}`);
|
||||||
log.push(`p${workCount++}`);
|
},
|
||||||
},
|
execute: () => {
|
||||||
execute: () => {
|
log.push(`w${workCount++}`);
|
||||||
log.push(`w${workCount++}`);
|
}
|
||||||
}
|
});
|
||||||
});
|
sampler.sample().then((_) => {
|
||||||
sampler.sample().then((_) => {
|
expect(log).toEqual([
|
||||||
expect(log).toEqual([
|
'p0',
|
||||||
'p0',
|
['beginMeasure'],
|
||||||
['beginMeasure'],
|
'w1',
|
||||||
'w1',
|
['endMeasure', false, {'script': 0}],
|
||||||
['endMeasure', false, {'script': 0}],
|
'p2',
|
||||||
'p2',
|
['beginMeasure'],
|
||||||
['beginMeasure'],
|
'w3',
|
||||||
'w3',
|
['endMeasure', false, {'script': 1}],
|
||||||
['endMeasure', false, {'script': 1}],
|
]);
|
||||||
]);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should call execute, endMeasure for every iteration if there is no prepare callback',
|
it('should call execute, endMeasure for every iteration if there is no prepare callback',
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
done => {
|
||||||
const log: any[] = [];
|
const log: any[] = [];
|
||||||
let workCount = 0;
|
let workCount = 0;
|
||||||
createSampler({
|
createSampler({
|
||||||
|
@ -118,93 +114,90 @@ import {Injector, MeasureValues, Metric, Options, Reporter, Sampler, Validator,
|
||||||
'w1',
|
'w1',
|
||||||
['endMeasure', true, {'script': 1}],
|
['endMeasure', true, {'script': 1}],
|
||||||
]);
|
]);
|
||||||
async.done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should only collect metrics for execute and ignore metrics from prepare',
|
it('should only collect metrics for execute and ignore metrics from prepare', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
let scriptTime = 0;
|
||||||
let scriptTime = 0;
|
let iterationCount = 1;
|
||||||
let iterationCount = 1;
|
createSampler({
|
||||||
createSampler({
|
validator: createCountingValidator(2),
|
||||||
validator: createCountingValidator(2),
|
metric: new MockMetric(
|
||||||
metric: new MockMetric(
|
[],
|
||||||
[],
|
() => {
|
||||||
() => {
|
const result = Promise.resolve({'script': scriptTime});
|
||||||
const result = Promise.resolve({'script': scriptTime});
|
scriptTime = 0;
|
||||||
scriptTime = 0;
|
return result;
|
||||||
return result;
|
}),
|
||||||
}),
|
prepare: () => {
|
||||||
prepare: () => {
|
scriptTime = 1 * iterationCount;
|
||||||
scriptTime = 1 * iterationCount;
|
},
|
||||||
},
|
execute: () => {
|
||||||
execute: () => {
|
scriptTime = 10 * iterationCount;
|
||||||
scriptTime = 10 * iterationCount;
|
iterationCount++;
|
||||||
iterationCount++;
|
}
|
||||||
}
|
});
|
||||||
});
|
sampler.sample().then((state) => {
|
||||||
sampler.sample().then((state) => {
|
expect(state.completeSample.length).toBe(2);
|
||||||
expect(state.completeSample.length).toBe(2);
|
expect(state.completeSample[0]).toEqual(mv(0, 1000, {'script': 10}));
|
||||||
expect(state.completeSample[0]).toEqual(mv(0, 1000, {'script': 10}));
|
expect(state.completeSample[1]).toEqual(mv(1, 1001, {'script': 20}));
|
||||||
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',
|
it('should call the validator for every execution and store the valid sample', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const log: any[] = [];
|
||||||
const log: any[] = [];
|
const validSample = [mv(null!, null!, {})];
|
||||||
const validSample = [mv(null!, null!, {})];
|
|
||||||
|
|
||||||
createSampler({
|
createSampler({
|
||||||
metric: createCountingMetric(),
|
metric: createCountingMetric(),
|
||||||
validator: createCountingValidator(2, validSample, log),
|
validator: createCountingValidator(2, validSample, log),
|
||||||
execute: EMPTY_EXECUTE
|
execute: EMPTY_EXECUTE
|
||||||
});
|
});
|
||||||
sampler.sample().then((state) => {
|
sampler.sample().then((state) => {
|
||||||
expect(state.validSample).toBe(validSample);
|
expect(state.validSample).toBe(validSample);
|
||||||
// TODO(tbosch): Why does this fail??
|
// TODO(tbosch): Why does this fail??
|
||||||
// expect(log).toEqual([
|
// expect(log).toEqual([
|
||||||
// ['validate', [{'script': 0}], null],
|
// ['validate', [{'script': 0}], null],
|
||||||
// ['validate', [{'script': 0}, {'script': 1}], validSample]
|
// ['validate', [{'script': 0}, {'script': 1}], validSample]
|
||||||
// ]);
|
// ]);
|
||||||
|
|
||||||
expect(log.length).toBe(2);
|
expect(log.length).toBe(2);
|
||||||
expect(log[0]).toEqual(['validate', [mv(0, 1000, {'script': 0})], null]);
|
expect(log[0]).toEqual(['validate', [mv(0, 1000, {'script': 0})], null]);
|
||||||
expect(log[1]).toEqual(
|
expect(log[1]).toEqual(
|
||||||
['validate', [mv(0, 1000, {'script': 0}), mv(1, 1001, {'script': 1})], validSample]);
|
['validate', [mv(0, 1000, {'script': 0}), mv(1, 1001, {'script': 1})], validSample]);
|
||||||
|
|
||||||
async.done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should report the metric values',
|
it('should report the metric values', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const log: any[] = [];
|
||||||
const log: any[] = [];
|
const validSample = [mv(null!, null!, {})];
|
||||||
const validSample = [mv(null!, null!, {})];
|
createSampler({
|
||||||
createSampler({
|
validator: createCountingValidator(2, validSample),
|
||||||
validator: createCountingValidator(2, validSample),
|
metric: createCountingMetric(),
|
||||||
metric: createCountingMetric(),
|
reporter: new MockReporter(log),
|
||||||
reporter: new MockReporter(log),
|
execute: EMPTY_EXECUTE
|
||||||
execute: EMPTY_EXECUTE
|
});
|
||||||
});
|
sampler.sample().then((_) => {
|
||||||
sampler.sample().then((_) => {
|
// TODO(tbosch): Why does this fail??
|
||||||
// TODO(tbosch): Why does this fail??
|
// expect(log).toEqual([
|
||||||
// expect(log).toEqual([
|
// ['reportMeasureValues', 0, {'script': 0}],
|
||||||
// ['reportMeasureValues', 0, {'script': 0}],
|
// ['reportMeasureValues', 1, {'script': 1}],
|
||||||
// ['reportMeasureValues', 1, {'script': 1}],
|
// ['reportSample', [{'script': 0}, {'script': 1}], validSample]
|
||||||
// ['reportSample', [{'script': 0}, {'script': 1}], validSample]
|
// ]);
|
||||||
// ]);
|
expect(log.length).toBe(3);
|
||||||
expect(log.length).toBe(3);
|
expect(log[0]).toEqual(['reportMeasureValues', mv(0, 1000, {'script': 0})]);
|
||||||
expect(log[0]).toEqual(['reportMeasureValues', mv(0, 1000, {'script': 0})]);
|
expect(log[1]).toEqual(['reportMeasureValues', mv(1, 1001, {'script': 1})]);
|
||||||
expect(log[1]).toEqual(['reportMeasureValues', mv(1, 1001, {'script': 1})]);
|
expect(log[2]).toEqual([
|
||||||
expect(log[2]).toEqual([
|
'reportSample', [mv(0, 1000, {'script': 0}), mv(1, 1001, {'script': 1})], validSample
|
||||||
'reportSample', [mv(0, 1000, {'script': 0}), mv(1, 1001, {'script': 1})], validSample
|
]);
|
||||||
]);
|
|
||||||
|
|
||||||
async.done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {Statistic} from '../src/statistic';
|
import {Statistic} from '../src/statistic';
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
import {Injector, MeasureValues, RegressionSlopeValidator} from '../../index';
|
import {Injector, MeasureValues, RegressionSlopeValidator} from '../../index';
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
import {Injector, MeasureValues, SizeValidator} from '../../index';
|
import {Injector, MeasureValues, SizeValidator} from '../../index';
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
import {Injector, Options, WebDriverExtension} from '../index';
|
import {Injector, Options, WebDriverExtension} from '../index';
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
@ -28,21 +26,19 @@ function createExtension(ids: any[], caps: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('WebDriverExtension.provideFirstSupported', () => {
|
describe('WebDriverExtension.provideFirstSupported', () => {
|
||||||
it('should provide the extension that matches the capabilities',
|
it('should provide the extension that matches the capabilities', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createExtension(['m1', 'm2', 'm3'], {'browser': 'm2'}).then((m) => {
|
||||||
createExtension(['m1', 'm2', 'm3'], {'browser': 'm2'}).then((m) => {
|
expect(m.id).toEqual('m2');
|
||||||
expect(m.id).toEqual('m2');
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should throw if there is no match',
|
it('should throw if there is no match', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createExtension(['m1'], {'browser': 'm2'}).catch((err) => {
|
||||||
createExtension(['m1'], {'browser': 'm2'}).catch((err) => {
|
expect(err != null).toBe(true);
|
||||||
expect(err != null).toBe(true);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {AsyncTestCompleter, describe, expect, fit, inject, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
import {ChromeDriverExtension, Injector, Options, WebDriverAdapter, WebDriverExtension} from '../../index';
|
import {ChromeDriverExtension, Injector, Options, WebDriverAdapter, WebDriverExtension} from '../../index';
|
||||||
import {TraceEventFactory} from '../trace_event_factory';
|
import {TraceEventFactory} from '../trace_event_factory';
|
||||||
|
|
||||||
|
@ -54,344 +52,323 @@ import {TraceEventFactory} from '../trace_event_factory';
|
||||||
return extension;
|
return extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
it('should force gc via window.gc()',
|
it('should force gc via window.gc()', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createExtension().gc().then((_) => {
|
||||||
createExtension().gc().then((_) => {
|
expect(log).toEqual([['executeScript', 'window.gc()']]);
|
||||||
expect(log).toEqual([['executeScript', 'window.gc()']]);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should clear the perf logs and mark the timeline via performance.mark() on the first call',
|
it('should clear the perf logs and mark the timeline via performance.mark() on the first call',
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
done => {
|
||||||
createExtension().timeBegin('someName').then(() => {
|
createExtension().timeBegin('someName').then(() => {
|
||||||
expect(log).toEqual([
|
expect(log).toEqual([
|
||||||
['logs', 'performance'], ['executeScript', `performance.mark('someName-bpstart');`]
|
['logs', 'performance'], ['executeScript', `performance.mark('someName-bpstart');`]
|
||||||
]);
|
]);
|
||||||
async.done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should mark the timeline via performance.mark() on the second call',
|
it('should mark the timeline via performance.mark() on the second call', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const ext = createExtension();
|
||||||
const ext = createExtension();
|
ext.timeBegin('someName')
|
||||||
ext.timeBegin('someName')
|
.then((_) => {
|
||||||
.then((_) => {
|
log.splice(0, log.length);
|
||||||
log.splice(0, log.length);
|
ext.timeBegin('someName');
|
||||||
ext.timeBegin('someName');
|
})
|
||||||
})
|
.then(() => {
|
||||||
.then(() => {
|
expect(log).toEqual([['executeScript', `performance.mark('someName-bpstart');`]]);
|
||||||
expect(log).toEqual([['executeScript', `performance.mark('someName-bpstart');`]]);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should mark the timeline via performance.mark()',
|
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
|
||||||
createExtension().timeEnd('someName', null).then((_) => {
|
|
||||||
expect(log).toEqual([['executeScript', `performance.mark('someName-bpend');`]]);
|
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should mark the timeline via performance.mark() with start and end of a test',
|
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
|
||||||
createExtension().timeEnd('name1', 'name2').then((_) => {
|
|
||||||
expect(log).toEqual([
|
|
||||||
['executeScript', `performance.mark('name1-bpend');performance.mark('name2-bpstart');`]
|
|
||||||
]);
|
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should normalize times to ms and forward ph and pid event properties',
|
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
|
||||||
createExtension([chromeTimelineV8Events.complete('FunctionCall', 1100, 5500, null)])
|
|
||||||
.readPerfLog()
|
|
||||||
.then((events) => {
|
|
||||||
expect(events).toEqual([
|
|
||||||
normEvents.complete('script', 1.1, 5.5, null),
|
|
||||||
]);
|
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should normalize "tdur" to "dur"',
|
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
|
||||||
const event: any = chromeTimelineV8Events.create('X', 'FunctionCall', 1100, null);
|
|
||||||
event['tdur'] = 5500;
|
|
||||||
createExtension([event]).readPerfLog().then((events) => {
|
|
||||||
expect(events).toEqual([
|
|
||||||
normEvents.complete('script', 1.1, 5.5, null),
|
|
||||||
]);
|
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should report FunctionCall events as "script"',
|
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
|
||||||
createExtension([chromeTimelineV8Events.start('FunctionCall', 0)])
|
|
||||||
.readPerfLog()
|
|
||||||
.then((events) => {
|
|
||||||
expect(events).toEqual([
|
|
||||||
normEvents.start('script', 0),
|
|
||||||
]);
|
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should report EvaluateScript events as "script"',
|
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
|
||||||
createExtension([chromeTimelineV8Events.start('EvaluateScript', 0)])
|
|
||||||
.readPerfLog()
|
|
||||||
.then((events) => {
|
|
||||||
expect(events).toEqual([
|
|
||||||
normEvents.start('script', 0),
|
|
||||||
]);
|
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should report minor gc', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
|
||||||
createExtension([
|
|
||||||
chromeTimelineV8Events.start('MinorGC', 1000, {'usedHeapSizeBefore': 1000}),
|
|
||||||
chromeTimelineV8Events.end('MinorGC', 2000, {'usedHeapSizeAfter': 0}),
|
|
||||||
])
|
|
||||||
.readPerfLog()
|
|
||||||
.then((events) => {
|
|
||||||
expect(events.length).toEqual(2);
|
|
||||||
expect(events[0]).toEqual(
|
|
||||||
normEvents.start('gc', 1.0, {'usedHeapSize': 1000, 'majorGc': false}));
|
|
||||||
expect(events[1]).toEqual(
|
|
||||||
normEvents.end('gc', 2.0, {'usedHeapSize': 0, 'majorGc': false}));
|
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should report major gc', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
|
||||||
createExtension(
|
|
||||||
[
|
|
||||||
chromeTimelineV8Events.start('MajorGC', 1000, {'usedHeapSizeBefore': 1000}),
|
|
||||||
chromeTimelineV8Events.end('MajorGC', 2000, {'usedHeapSizeAfter': 0}),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
.readPerfLog()
|
|
||||||
.then((events) => {
|
|
||||||
expect(events.length).toEqual(2);
|
|
||||||
expect(events[0]).toEqual(
|
|
||||||
normEvents.start('gc', 1.0, {'usedHeapSize': 1000, 'majorGc': true}));
|
|
||||||
expect(events[1]).toEqual(
|
|
||||||
normEvents.end('gc', 2.0, {'usedHeapSize': 0, 'majorGc': true}));
|
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
['Layout', 'UpdateLayerTree', 'Paint'].forEach((recordType) => {
|
|
||||||
it(`should report ${recordType} as "render"`,
|
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
|
||||||
createExtension(
|
|
||||||
[
|
|
||||||
chrome45TimelineEvents.start(recordType, 1234),
|
|
||||||
chrome45TimelineEvents.end(recordType, 2345)
|
|
||||||
],
|
|
||||||
)
|
|
||||||
.readPerfLog()
|
|
||||||
.then((events) => {
|
|
||||||
expect(events).toEqual([
|
|
||||||
normEvents.start('render', 1.234),
|
|
||||||
normEvents.end('render', 2.345),
|
|
||||||
]);
|
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should report UpdateLayoutTree as "render"`,
|
it('should mark the timeline via performance.mark()', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createExtension().timeEnd('someName', null).then((_) => {
|
||||||
createExtension(
|
expect(log).toEqual([['executeScript', `performance.mark('someName-bpend');`]]);
|
||||||
[
|
done();
|
||||||
chromeBlinkTimelineEvents.start('UpdateLayoutTree', 1234),
|
});
|
||||||
chromeBlinkTimelineEvents.end('UpdateLayoutTree', 2345)
|
});
|
||||||
],
|
|
||||||
)
|
|
||||||
.readPerfLog()
|
|
||||||
.then((events) => {
|
|
||||||
expect(events).toEqual([
|
|
||||||
normEvents.start('render', 1.234),
|
|
||||||
normEvents.end('render', 2.345),
|
|
||||||
]);
|
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should ignore FunctionCalls from webdriver',
|
it('should mark the timeline via performance.mark() with start and end of a test', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createExtension().timeEnd('name1', 'name2').then((_) => {
|
||||||
createExtension([chromeTimelineV8Events.start(
|
expect(log).toEqual([
|
||||||
'FunctionCall', 0, {'data': {'scriptName': 'InjectedScript'}})])
|
['executeScript', `performance.mark('name1-bpend');performance.mark('name2-bpstart');`]
|
||||||
.readPerfLog()
|
]);
|
||||||
.then((events) => {
|
done();
|
||||||
expect(events).toEqual([]);
|
});
|
||||||
async.done();
|
});
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should ignore FunctionCalls with empty scriptName',
|
it('should normalize times to ms and forward ph and pid event properties', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createExtension([chromeTimelineV8Events.complete('FunctionCall', 1100, 5500, null)])
|
||||||
createExtension(
|
.readPerfLog()
|
||||||
[chromeTimelineV8Events.start('FunctionCall', 0, {'data': {'scriptName': ''}})])
|
.then((events) => {
|
||||||
.readPerfLog()
|
expect(events).toEqual([
|
||||||
.then((events) => {
|
normEvents.complete('script', 1.1, 5.5, null),
|
||||||
expect(events).toEqual([]);
|
]);
|
||||||
async.done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should report navigationStart',
|
it('should normalize "tdur" to "dur"', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const event: any = chromeTimelineV8Events.create('X', 'FunctionCall', 1100, null);
|
||||||
createExtension([chromeBlinkUserTimingEvents.instant('navigationStart', 1234)])
|
event['tdur'] = 5500;
|
||||||
.readPerfLog()
|
createExtension([event]).readPerfLog().then((events) => {
|
||||||
.then((events) => {
|
expect(events).toEqual([
|
||||||
expect(events).toEqual([normEvents.instant('navigationStart', 1.234)]);
|
normEvents.complete('script', 1.1, 5.5, null),
|
||||||
async.done();
|
]);
|
||||||
});
|
done();
|
||||||
}));
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should report receivedData', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
it('should report FunctionCall events as "script"', done => {
|
||||||
createExtension(
|
createExtension([chromeTimelineV8Events.start('FunctionCall', 0)])
|
||||||
[chrome45TimelineEvents.instant(
|
.readPerfLog()
|
||||||
'ResourceReceivedData', 1234, {'data': {'encodedDataLength': 987}})],
|
.then((events) => {
|
||||||
)
|
expect(events).toEqual([
|
||||||
.readPerfLog()
|
normEvents.start('script', 0),
|
||||||
.then((events) => {
|
]);
|
||||||
expect(events).toEqual(
|
done();
|
||||||
[normEvents.instant('receivedData', 1.234, {'encodedDataLength': 987})]);
|
});
|
||||||
async.done();
|
});
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should report sendRequest', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
it('should report EvaluateScript events as "script"', done => {
|
||||||
createExtension(
|
createExtension([chromeTimelineV8Events.start('EvaluateScript', 0)])
|
||||||
[chrome45TimelineEvents.instant(
|
.readPerfLog()
|
||||||
'ResourceSendRequest', 1234,
|
.then((events) => {
|
||||||
{'data': {'url': 'http://here', 'requestMethod': 'GET'}})],
|
expect(events).toEqual([
|
||||||
)
|
normEvents.start('script', 0),
|
||||||
.readPerfLog()
|
]);
|
||||||
.then((events) => {
|
done();
|
||||||
expect(events).toEqual([normEvents.instant(
|
});
|
||||||
'sendRequest', 1.234, {'url': 'http://here', 'method': 'GET'})]);
|
});
|
||||||
async.done();
|
|
||||||
});
|
it('should report minor gc', done => {
|
||||||
}));
|
createExtension([
|
||||||
|
chromeTimelineV8Events.start('MinorGC', 1000, {'usedHeapSizeBefore': 1000}),
|
||||||
|
chromeTimelineV8Events.end('MinorGC', 2000, {'usedHeapSizeAfter': 0}),
|
||||||
|
])
|
||||||
|
.readPerfLog()
|
||||||
|
.then((events) => {
|
||||||
|
expect(events.length).toEqual(2);
|
||||||
|
expect(events[0]).toEqual(
|
||||||
|
normEvents.start('gc', 1.0, {'usedHeapSize': 1000, 'majorGc': false}));
|
||||||
|
expect(events[1]).toEqual(
|
||||||
|
normEvents.end('gc', 2.0, {'usedHeapSize': 0, 'majorGc': false}));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should report major gc', done => {
|
||||||
|
createExtension(
|
||||||
|
[
|
||||||
|
chromeTimelineV8Events.start('MajorGC', 1000, {'usedHeapSizeBefore': 1000}),
|
||||||
|
chromeTimelineV8Events.end('MajorGC', 2000, {'usedHeapSizeAfter': 0}),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
.readPerfLog()
|
||||||
|
.then((events) => {
|
||||||
|
expect(events.length).toEqual(2);
|
||||||
|
expect(events[0]).toEqual(
|
||||||
|
normEvents.start('gc', 1.0, {'usedHeapSize': 1000, 'majorGc': true}));
|
||||||
|
expect(events[1]).toEqual(
|
||||||
|
normEvents.end('gc', 2.0, {'usedHeapSize': 0, 'majorGc': true}));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
['Layout', 'UpdateLayerTree', 'Paint'].forEach((recordType) => {
|
||||||
|
it(`should report ${recordType} as "render"`, done => {
|
||||||
|
createExtension(
|
||||||
|
[
|
||||||
|
chrome45TimelineEvents.start(recordType, 1234),
|
||||||
|
chrome45TimelineEvents.end(recordType, 2345)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
.readPerfLog()
|
||||||
|
.then((events) => {
|
||||||
|
expect(events).toEqual([
|
||||||
|
normEvents.start('render', 1.234),
|
||||||
|
normEvents.end('render', 2.345),
|
||||||
|
]);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should report UpdateLayoutTree as "render"`, done => {
|
||||||
|
createExtension(
|
||||||
|
[
|
||||||
|
chromeBlinkTimelineEvents.start('UpdateLayoutTree', 1234),
|
||||||
|
chromeBlinkTimelineEvents.end('UpdateLayoutTree', 2345)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
.readPerfLog()
|
||||||
|
.then((events) => {
|
||||||
|
expect(events).toEqual([
|
||||||
|
normEvents.start('render', 1.234),
|
||||||
|
normEvents.end('render', 2.345),
|
||||||
|
]);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should ignore FunctionCalls from webdriver', done => {
|
||||||
|
createExtension([chromeTimelineV8Events.start(
|
||||||
|
'FunctionCall', 0, {'data': {'scriptName': 'InjectedScript'}})])
|
||||||
|
.readPerfLog()
|
||||||
|
.then((events) => {
|
||||||
|
expect(events).toEqual([]);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should ignore FunctionCalls with empty scriptName', done => {
|
||||||
|
createExtension(
|
||||||
|
[chromeTimelineV8Events.start('FunctionCall', 0, {'data': {'scriptName': ''}})])
|
||||||
|
.readPerfLog()
|
||||||
|
.then((events) => {
|
||||||
|
expect(events).toEqual([]);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should report navigationStart', done => {
|
||||||
|
createExtension([chromeBlinkUserTimingEvents.instant('navigationStart', 1234)])
|
||||||
|
.readPerfLog()
|
||||||
|
.then((events) => {
|
||||||
|
expect(events).toEqual([normEvents.instant('navigationStart', 1.234)]);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should report receivedData', done => {
|
||||||
|
createExtension(
|
||||||
|
[chrome45TimelineEvents.instant(
|
||||||
|
'ResourceReceivedData', 1234, {'data': {'encodedDataLength': 987}})],
|
||||||
|
)
|
||||||
|
.readPerfLog()
|
||||||
|
.then((events) => {
|
||||||
|
expect(events).toEqual(
|
||||||
|
[normEvents.instant('receivedData', 1.234, {'encodedDataLength': 987})]);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should report sendRequest', done => {
|
||||||
|
createExtension(
|
||||||
|
[chrome45TimelineEvents.instant(
|
||||||
|
'ResourceSendRequest', 1234,
|
||||||
|
{'data': {'url': 'http://here', 'requestMethod': 'GET'}})],
|
||||||
|
)
|
||||||
|
.readPerfLog()
|
||||||
|
.then((events) => {
|
||||||
|
expect(events).toEqual([normEvents.instant(
|
||||||
|
'sendRequest', 1.234, {'url': 'http://here', 'method': 'GET'})]);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('readPerfLog (common)', () => {
|
describe('readPerfLog (common)', () => {
|
||||||
it('should execute a dummy script before reading them',
|
it('should execute a dummy script before reading them', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
// TODO(tbosch): This seems to be a bug in ChromeDriver:
|
||||||
// TODO(tbosch): This seems to be a bug in ChromeDriver:
|
// Sometimes it does not report the newest events of the performance log
|
||||||
// Sometimes it does not report the newest events of the performance log
|
// to the WebDriver client unless a script is executed...
|
||||||
// to the WebDriver client unless a script is executed...
|
createExtension([]).readPerfLog().then((_) => {
|
||||||
createExtension([]).readPerfLog().then((_) => {
|
expect(log).toEqual([['executeScript', '1+1'], ['logs', 'performance']]);
|
||||||
expect(log).toEqual([['executeScript', '1+1'], ['logs', 'performance']]);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
['Rasterize', 'CompositeLayers'].forEach((recordType) => {
|
['Rasterize', 'CompositeLayers'].forEach((recordType) => {
|
||||||
it(`should report ${recordType} as "render"`,
|
it(`should report ${recordType} as "render"`, done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createExtension(
|
||||||
createExtension(
|
[
|
||||||
[
|
chromeTimelineEvents.start(recordType, 1234),
|
||||||
chromeTimelineEvents.start(recordType, 1234),
|
chromeTimelineEvents.end(recordType, 2345)
|
||||||
chromeTimelineEvents.end(recordType, 2345)
|
],
|
||||||
],
|
)
|
||||||
)
|
.readPerfLog()
|
||||||
.readPerfLog()
|
.then((events) => {
|
||||||
.then((events) => {
|
expect(events).toEqual([
|
||||||
expect(events).toEqual([
|
normEvents.start('render', 1.234),
|
||||||
normEvents.start('render', 1.234),
|
normEvents.end('render', 2.345),
|
||||||
normEvents.end('render', 2.345),
|
]);
|
||||||
]);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('frame metrics', () => {
|
describe('frame metrics', () => {
|
||||||
it('should report ImplThreadRenderingStats as frame event',
|
it('should report ImplThreadRenderingStats as frame event', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createExtension([benchmarkEvents.instant(
|
||||||
createExtension([benchmarkEvents.instant(
|
'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
|
||||||
'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
|
{'data': {'frame_count': 1}})])
|
||||||
{'data': {'frame_count': 1}})])
|
.readPerfLog()
|
||||||
.readPerfLog()
|
.then((events) => {
|
||||||
.then((events) => {
|
expect(events).toEqual([
|
||||||
expect(events).toEqual([
|
normEvents.instant('frame', 1.1),
|
||||||
normEvents.instant('frame', 1.1),
|
]);
|
||||||
]);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should not report ImplThreadRenderingStats with zero frames',
|
it('should not report ImplThreadRenderingStats with zero frames', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createExtension([benchmarkEvents.instant(
|
||||||
createExtension([benchmarkEvents.instant(
|
'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
|
||||||
'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
|
{'data': {'frame_count': 0}})])
|
||||||
{'data': {'frame_count': 0}})])
|
.readPerfLog()
|
||||||
.readPerfLog()
|
.then((events) => {
|
||||||
.then((events) => {
|
expect(events).toEqual([]);
|
||||||
expect(events).toEqual([]);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should throw when ImplThreadRenderingStats contains more than one frame',
|
it('should throw when ImplThreadRenderingStats contains more than one frame', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createExtension([benchmarkEvents.instant(
|
||||||
createExtension([benchmarkEvents.instant(
|
'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
|
||||||
'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
|
{'data': {'frame_count': 2}})])
|
||||||
{'data': {'frame_count': 2}})])
|
.readPerfLog()
|
||||||
.readPerfLog()
|
.catch((err): any => {
|
||||||
.catch((err): any => {
|
expect(() => {
|
||||||
expect(() => {
|
throw err;
|
||||||
throw err;
|
}).toThrowError('multi-frame render stats not supported');
|
||||||
}).toThrowError('multi-frame render stats not supported');
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should report begin timestamps',
|
it('should report begin timestamps', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createExtension([blinkEvents.create('S', 'someName', 1000)])
|
||||||
createExtension([blinkEvents.create('S', 'someName', 1000)])
|
.readPerfLog()
|
||||||
.readPerfLog()
|
.then((events) => {
|
||||||
.then((events) => {
|
expect(events).toEqual([normEvents.markStart('someName', 1.0)]);
|
||||||
expect(events).toEqual([normEvents.markStart('someName', 1.0)]);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should report end timestamps',
|
it('should report end timestamps', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createExtension([blinkEvents.create('F', 'someName', 1000)])
|
||||||
createExtension([blinkEvents.create('F', 'someName', 1000)])
|
.readPerfLog()
|
||||||
.readPerfLog()
|
.then((events) => {
|
||||||
.then((events) => {
|
expect(events).toEqual([normEvents.markEnd('someName', 1.0)]);
|
||||||
expect(events).toEqual([normEvents.markEnd('someName', 1.0)]);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should throw an error on buffer overflow',
|
it('should throw an error on buffer overflow', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createExtension(
|
||||||
createExtension(
|
[
|
||||||
[
|
chromeTimelineEvents.start('FunctionCall', 1234),
|
||||||
chromeTimelineEvents.start('FunctionCall', 1234),
|
],
|
||||||
],
|
CHROME45_USER_AGENT, 'Tracing.bufferUsage')
|
||||||
CHROME45_USER_AGENT, 'Tracing.bufferUsage')
|
.readPerfLog()
|
||||||
.readPerfLog()
|
.catch((err): any => {
|
||||||
.catch((err): any => {
|
expect(() => {
|
||||||
expect(() => {
|
throw err;
|
||||||
throw err;
|
}).toThrowError('The DevTools trace buffer filled during the test!');
|
||||||
}).toThrowError('The DevTools trace buffer filled during the test!');
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should match chrome browsers', () => {
|
it('should match chrome browsers', () => {
|
||||||
expect(createExtension().supports({'browserName': 'chrome'})).toBe(true);
|
expect(createExtension().supports({'browserName': 'chrome'})).toBe(true);
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
import {Injector, IOsDriverExtension, WebDriverAdapter, WebDriverExtension} from '../../index';
|
import {Injector, IOsDriverExtension, WebDriverAdapter, WebDriverExtension} from '../../index';
|
||||||
import {TraceEventFactory} from '../trace_event_factory';
|
import {TraceEventFactory} from '../trace_event_factory';
|
||||||
|
|
||||||
|
@ -37,102 +35,91 @@ import {TraceEventFactory} from '../trace_event_factory';
|
||||||
expect(() => createExtension().gc()).toThrowError('Force GC is not supported on iOS');
|
expect(() => createExtension().gc()).toThrowError('Force GC is not supported on iOS');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should mark the timeline via console.time()',
|
it('should mark the timeline via console.time()', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createExtension().timeBegin('someName').then((_) => {
|
||||||
createExtension().timeBegin('someName').then((_) => {
|
expect(log).toEqual([['executeScript', `console.time('someName');`]]);
|
||||||
expect(log).toEqual([['executeScript', `console.time('someName');`]]);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should mark the timeline via console.timeEnd()',
|
it('should mark the timeline via console.timeEnd()', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createExtension().timeEnd('someName', null).then((_) => {
|
||||||
createExtension().timeEnd('someName', null).then((_) => {
|
expect(log).toEqual([['executeScript', `console.timeEnd('someName');`]]);
|
||||||
expect(log).toEqual([['executeScript', `console.timeEnd('someName');`]]);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should mark the timeline via console.time() and console.timeEnd()',
|
it('should mark the timeline via console.time() and console.timeEnd()', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createExtension().timeEnd('name1', 'name2').then((_) => {
|
||||||
createExtension().timeEnd('name1', 'name2').then((_) => {
|
expect(log).toEqual([['executeScript', `console.timeEnd('name1');console.time('name2');`]]);
|
||||||
expect(log).toEqual(
|
done();
|
||||||
[['executeScript', `console.timeEnd('name1');console.time('name2');`]]);
|
});
|
||||||
async.done();
|
});
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe('readPerfLog', () => {
|
describe('readPerfLog', () => {
|
||||||
it('should execute a dummy script before reading them',
|
it('should execute a dummy script before reading them', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
// TODO(tbosch): This seems to be a bug in ChromeDriver:
|
||||||
// TODO(tbosch): This seems to be a bug in ChromeDriver:
|
// Sometimes it does not report the newest events of the performance log
|
||||||
// Sometimes it does not report the newest events of the performance log
|
// to the WebDriver client unless a script is executed...
|
||||||
// to the WebDriver client unless a script is executed...
|
createExtension([]).readPerfLog().then((_) => {
|
||||||
createExtension([]).readPerfLog().then((_) => {
|
expect(log).toEqual([['executeScript', '1+1'], ['logs', 'performance']]);
|
||||||
expect(log).toEqual([['executeScript', '1+1'], ['logs', 'performance']]);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should report FunctionCall records as "script"',
|
it('should report FunctionCall records as "script"', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createExtension([durationRecord('FunctionCall', 1, 5)]).readPerfLog().then((events) => {
|
||||||
createExtension([durationRecord('FunctionCall', 1, 5)]).readPerfLog().then((events) => {
|
expect(events).toEqual([normEvents.start('script', 1), normEvents.end('script', 5)]);
|
||||||
expect(events).toEqual([normEvents.start('script', 1), normEvents.end('script', 5)]);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should ignore FunctionCalls from webdriver',
|
it('should ignore FunctionCalls from webdriver', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createExtension([internalScriptRecord(1, 5)]).readPerfLog().then((events) => {
|
||||||
createExtension([internalScriptRecord(1, 5)]).readPerfLog().then((events) => {
|
expect(events).toEqual([]);
|
||||||
expect(events).toEqual([]);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should report begin time', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
it('should report begin time', done => {
|
||||||
createExtension([timeBeginRecord('someName', 12)]).readPerfLog().then((events) => {
|
createExtension([timeBeginRecord('someName', 12)]).readPerfLog().then((events) => {
|
||||||
expect(events).toEqual([normEvents.markStart('someName', 12)]);
|
expect(events).toEqual([normEvents.markStart('someName', 12)]);
|
||||||
async.done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should report end timestamps',
|
it('should report end timestamps', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createExtension([timeEndRecord('someName', 12)]).readPerfLog().then((events) => {
|
||||||
createExtension([timeEndRecord('someName', 12)]).readPerfLog().then((events) => {
|
expect(events).toEqual([normEvents.markEnd('someName', 12)]);
|
||||||
expect(events).toEqual([normEvents.markEnd('someName', 12)]);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
['RecalculateStyles', 'Layout', 'UpdateLayerTree', 'Paint', 'Rasterize', 'CompositeLayers']
|
['RecalculateStyles', 'Layout', 'UpdateLayerTree', 'Paint', 'Rasterize', 'CompositeLayers']
|
||||||
.forEach((recordType) => {
|
.forEach((recordType) => {
|
||||||
it(`should report ${recordType}`,
|
it(`should report ${recordType}`, done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
createExtension([durationRecord(recordType, 0, 1)]).readPerfLog().then((events) => {
|
||||||
createExtension([durationRecord(recordType, 0, 1)])
|
expect(events).toEqual([
|
||||||
.readPerfLog()
|
normEvents.start('render', 0),
|
||||||
.then((events) => {
|
normEvents.end('render', 1),
|
||||||
expect(events).toEqual([
|
]);
|
||||||
normEvents.start('render', 0),
|
done();
|
||||||
normEvents.end('render', 1),
|
});
|
||||||
]);
|
});
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should walk children', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
it('should walk children', done => {
|
||||||
createExtension([durationRecord('FunctionCall', 1, 5, [timeBeginRecord('someName', 2)])])
|
createExtension([durationRecord('FunctionCall', 1, 5, [timeBeginRecord('someName', 2)])])
|
||||||
.readPerfLog()
|
.readPerfLog()
|
||||||
.then((events) => {
|
.then((events) => {
|
||||||
expect(events).toEqual([
|
expect(events).toEqual([
|
||||||
normEvents.start('script', 1), normEvents.markStart('someName', 2),
|
normEvents.start('script', 1), normEvents.markStart('someName', 2),
|
||||||
normEvents.end('script', 5)
|
normEvents.end('script', 5)
|
||||||
]);
|
]);
|
||||||
async.done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should match safari browsers', () => {
|
it('should match safari browsers', () => {
|
||||||
expect(createExtension().supports({'browserName': 'safari'})).toBe(true);
|
expect(createExtension().supports({'browserName': 'safari'})).toBe(true);
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
import {HttpClient} from '@angular/common/http/src/client';
|
import {HttpClient} from '@angular/common/http/src/client';
|
||||||
import {HttpErrorResponse, HttpEventType, HttpResponse, HttpStatusCode} from '@angular/common/http/src/response';
|
import {HttpErrorResponse, HttpEventType, HttpResponse, HttpStatusCode} from '@angular/common/http/src/response';
|
||||||
import {HttpClientTestingBackend} from '@angular/common/http/testing/src/backend';
|
import {HttpClientTestingBackend} from '@angular/common/http/testing/src/backend';
|
||||||
import {ddescribe, describe, fit, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {toArray} from 'rxjs/operators';
|
import {toArray} from 'rxjs/operators';
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
import {JSONP_ERR_NO_CALLBACK, JSONP_ERR_WRONG_METHOD, JSONP_ERR_WRONG_RESPONSE_TYPE, JsonpClientBackend} from '@angular/common/http/src/jsonp';
|
import {JSONP_ERR_NO_CALLBACK, JSONP_ERR_WRONG_METHOD, JSONP_ERR_WRONG_RESPONSE_TYPE, JsonpClientBackend} from '@angular/common/http/src/jsonp';
|
||||||
import {HttpRequest} from '@angular/common/http/src/request';
|
import {HttpRequest} from '@angular/common/http/src/request';
|
||||||
import {HttpErrorResponse, HttpEventType} from '@angular/common/http/src/response';
|
import {HttpErrorResponse, HttpEventType} from '@angular/common/http/src/response';
|
||||||
import {ddescribe, describe, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {toArray} from 'rxjs/operators';
|
import {toArray} from 'rxjs/operators';
|
||||||
|
|
||||||
import {MockDocument} from './jsonp_mock';
|
import {MockDocument} from './jsonp_mock';
|
||||||
|
|
|
@ -10,7 +10,6 @@ import {HttpContext} from '@angular/common/http/src/context';
|
||||||
import {HttpHeaders} from '@angular/common/http/src/headers';
|
import {HttpHeaders} from '@angular/common/http/src/headers';
|
||||||
import {HttpParams} from '@angular/common/http/src/params';
|
import {HttpParams} from '@angular/common/http/src/params';
|
||||||
import {HttpRequest} from '@angular/common/http/src/request';
|
import {HttpRequest} from '@angular/common/http/src/request';
|
||||||
import {ddescribe, describe, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
const TEST_URL = 'https://angular.io/';
|
const TEST_URL = 'https://angular.io/';
|
||||||
const TEST_STRING = `I'm a body!`;
|
const TEST_STRING = `I'm a body!`;
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
import {HttpHeaders} from '@angular/common/http/src/headers';
|
import {HttpHeaders} from '@angular/common/http/src/headers';
|
||||||
import {HttpResponse, HttpStatusCode} from '@angular/common/http/src/response';
|
import {HttpResponse, HttpStatusCode} from '@angular/common/http/src/response';
|
||||||
import {describe, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
{
|
{
|
||||||
describe('HttpResponse', () => {
|
describe('HttpResponse', () => {
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
import {HttpRequest} from '@angular/common/http/src/request';
|
import {HttpRequest} from '@angular/common/http/src/request';
|
||||||
import {HttpDownloadProgressEvent, HttpErrorResponse, HttpEvent, HttpEventType, HttpHeaderResponse, HttpResponse, HttpResponseBase, HttpStatusCode, HttpUploadProgressEvent} from '@angular/common/http/src/response';
|
import {HttpDownloadProgressEvent, HttpErrorResponse, HttpEvent, HttpEventType, HttpHeaderResponse, HttpResponse, HttpResponseBase, HttpStatusCode, HttpUploadProgressEvent} from '@angular/common/http/src/response';
|
||||||
import {HttpXhrBackend} from '@angular/common/http/src/xhr';
|
import {HttpXhrBackend} from '@angular/common/http/src/xhr';
|
||||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {Observable} from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
import {toArray} from 'rxjs/operators';
|
import {toArray} from 'rxjs/operators';
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {parseCookieValue} from '@angular/common/src/cookie';
|
import {parseCookieValue} from '@angular/common/src/cookie';
|
||||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
{
|
{
|
||||||
describe('cookies', () => {
|
describe('cookies', () => {
|
||||||
|
|
|
@ -12,7 +12,6 @@ import localeEn from '@angular/common/locales/en';
|
||||||
import localeEsUS from '@angular/common/locales/es-US';
|
import localeEsUS from '@angular/common/locales/es-US';
|
||||||
import localeFr from '@angular/common/locales/fr';
|
import localeFr from '@angular/common/locales/fr';
|
||||||
import {ɵDEFAULT_LOCALE_ID, ɵregisterLocaleData, ɵunregisterLocaleData} from '@angular/core';
|
import {ɵDEFAULT_LOCALE_ID, ɵregisterLocaleData, ɵunregisterLocaleData} from '@angular/core';
|
||||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
describe('Format number', () => {
|
describe('Format number', () => {
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
|
|
|
@ -7,15 +7,16 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {AsyncPipe, ɵgetDOM as getDOM} from '@angular/common';
|
import {AsyncPipe, ɵgetDOM as getDOM} from '@angular/common';
|
||||||
import {EventEmitter} from '@angular/core';
|
import {ChangeDetectorRef, EventEmitter} from '@angular/core';
|
||||||
import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {browserDetection} from '@angular/platform-browser/testing/src/browser_util';
|
import {browserDetection} from '@angular/platform-browser/testing/src/browser_util';
|
||||||
import {Subscribable, Unsubscribable} from 'rxjs';
|
import {Subscribable, Unsubscribable} from 'rxjs';
|
||||||
|
|
||||||
import {SpyChangeDetectorRef} from '../spies';
|
|
||||||
|
|
||||||
{
|
{
|
||||||
describe('AsyncPipe', () => {
|
describe('AsyncPipe', () => {
|
||||||
|
function getChangeDetectorRefSpy() {
|
||||||
|
return jasmine.createSpyObj('ChangeDetectorRef', ['markForCheck', 'detectChanges']);
|
||||||
|
}
|
||||||
|
|
||||||
describe('Observable', () => {
|
describe('Observable', () => {
|
||||||
// only expose methods from the Subscribable interface, to ensure that
|
// only expose methods from the Subscribable interface, to ensure that
|
||||||
// the implementation does not rely on other methods:
|
// the implementation does not rely on other methods:
|
||||||
|
@ -33,13 +34,13 @@ import {SpyChangeDetectorRef} from '../spies';
|
||||||
let emitter: EventEmitter<any>;
|
let emitter: EventEmitter<any>;
|
||||||
let subscribable: Subscribable<any>;
|
let subscribable: Subscribable<any>;
|
||||||
let pipe: AsyncPipe;
|
let pipe: AsyncPipe;
|
||||||
let ref: any;
|
let ref: ChangeDetectorRef&jasmine.SpyObj<ChangeDetectorRef>;
|
||||||
const message = {};
|
const message = {};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
emitter = new EventEmitter();
|
emitter = new EventEmitter();
|
||||||
subscribable = wrapSubscribable(emitter);
|
subscribable = wrapSubscribable(emitter);
|
||||||
ref = new SpyChangeDetectorRef();
|
ref = getChangeDetectorRefSpy();
|
||||||
pipe = new AsyncPipe(ref);
|
pipe = new AsyncPipe(ref);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -48,32 +49,30 @@ import {SpyChangeDetectorRef} from '../spies';
|
||||||
expect(pipe.transform(subscribable)).toBe(null);
|
expect(pipe.transform(subscribable)).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the latest available value',
|
it('should return the latest available value', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
pipe.transform(subscribable);
|
||||||
pipe.transform(subscribable);
|
emitter.emit(message);
|
||||||
emitter.emit(message);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(pipe.transform(subscribable)).toEqual(message);
|
expect(pipe.transform(subscribable)).toEqual(message);
|
||||||
async.done();
|
done();
|
||||||
}, 0);
|
}, 0);
|
||||||
}));
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should return same value when nothing has changed since the last call',
|
it('should return same value when nothing has changed since the last call', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
pipe.transform(subscribable);
|
||||||
pipe.transform(subscribable);
|
emitter.emit(message);
|
||||||
emitter.emit(message);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
pipe.transform(subscribable);
|
pipe.transform(subscribable);
|
||||||
expect(pipe.transform(subscribable)).toBe(message);
|
expect(pipe.transform(subscribable)).toBe(message);
|
||||||
async.done();
|
done();
|
||||||
}, 0);
|
}, 0);
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should dispose of the existing subscription when subscribing to a new observable',
|
it('should dispose of the existing subscription when subscribing to a new observable',
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
done => {
|
||||||
pipe.transform(subscribable);
|
pipe.transform(subscribable);
|
||||||
|
|
||||||
const newEmitter = new EventEmitter();
|
const newEmitter = new EventEmitter();
|
||||||
|
@ -84,20 +83,19 @@ import {SpyChangeDetectorRef} from '../spies';
|
||||||
// this should not affect the pipe
|
// this should not affect the pipe
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(pipe.transform(newSubscribable)).toBe(null);
|
expect(pipe.transform(newSubscribable)).toBe(null);
|
||||||
async.done();
|
done();
|
||||||
}, 0);
|
}, 0);
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should request a change detection check upon receiving a new value',
|
it('should request a change detection check upon receiving a new value', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
pipe.transform(subscribable);
|
||||||
pipe.transform(subscribable);
|
emitter.emit(message);
|
||||||
emitter.emit(message);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(ref.spy('markForCheck')).toHaveBeenCalled();
|
expect(ref.markForCheck).toHaveBeenCalled();
|
||||||
async.done();
|
done();
|
||||||
}, 10);
|
}, 10);
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should return value for unchanged NaN', () => {
|
it('should return value for unchanged NaN', () => {
|
||||||
emitter.emit(null);
|
emitter.emit(null);
|
||||||
|
@ -115,23 +113,22 @@ import {SpyChangeDetectorRef} from '../spies';
|
||||||
expect(() => pipe.ngOnDestroy()).not.toThrow();
|
expect(() => pipe.ngOnDestroy()).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should dispose of the existing subscription',
|
it('should dispose of the existing subscription', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
pipe.transform(subscribable);
|
||||||
pipe.transform(subscribable);
|
pipe.ngOnDestroy();
|
||||||
pipe.ngOnDestroy();
|
emitter.emit(message);
|
||||||
emitter.emit(message);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(pipe.transform(subscribable)).toBe(null);
|
expect(pipe.transform(subscribable)).toBe(null);
|
||||||
async.done();
|
done();
|
||||||
}, 0);
|
}, 0);
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Subscribable', () => {
|
describe('Subscribable', () => {
|
||||||
it('should infer the type from the subscribable', () => {
|
it('should infer the type from the subscribable', () => {
|
||||||
const ref = new SpyChangeDetectorRef() as any;
|
const ref = getChangeDetectorRefSpy();
|
||||||
const pipe = new AsyncPipe(ref);
|
const pipe = new AsyncPipe(ref);
|
||||||
const emitter = new EventEmitter<{name: 'T'}>();
|
const emitter = new EventEmitter<{name: 'T'}>();
|
||||||
// The following line will fail to compile if the type cannot be inferred.
|
// The following line will fail to compile if the type cannot be inferred.
|
||||||
|
@ -145,7 +142,7 @@ import {SpyChangeDetectorRef} from '../spies';
|
||||||
let resolve: (result: any) => void;
|
let resolve: (result: any) => void;
|
||||||
let reject: (error: any) => void;
|
let reject: (error: any) => void;
|
||||||
let promise: Promise<any>;
|
let promise: Promise<any>;
|
||||||
let ref: SpyChangeDetectorRef;
|
let ref: any;
|
||||||
// adds longer timers for passing tests in IE
|
// adds longer timers for passing tests in IE
|
||||||
const timer = (getDOM() && browserDetection.isIE) ? 50 : 10;
|
const timer = (getDOM() && browserDetection.isIE) ? 50 : 10;
|
||||||
|
|
||||||
|
@ -154,8 +151,8 @@ import {SpyChangeDetectorRef} from '../spies';
|
||||||
resolve = res;
|
resolve = res;
|
||||||
reject = rej;
|
reject = rej;
|
||||||
});
|
});
|
||||||
ref = new SpyChangeDetectorRef();
|
ref = getChangeDetectorRefSpy();
|
||||||
pipe = new AsyncPipe(ref as any);
|
pipe = new AsyncPipe(ref);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('transform', () => {
|
describe('transform', () => {
|
||||||
|
@ -163,32 +160,30 @@ import {SpyChangeDetectorRef} from '../spies';
|
||||||
expect(pipe.transform(promise)).toBe(null);
|
expect(pipe.transform(promise)).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the latest available value',
|
it('should return the latest available value', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
pipe.transform(promise);
|
||||||
pipe.transform(promise);
|
|
||||||
|
|
||||||
resolve(message);
|
resolve(message);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(pipe.transform(promise)).toEqual(message);
|
expect(pipe.transform(promise)).toEqual(message);
|
||||||
async.done();
|
done();
|
||||||
}, timer);
|
}, timer);
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should return value when nothing has changed since the last call',
|
it('should return value when nothing has changed since the last call', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
pipe.transform(promise);
|
||||||
pipe.transform(promise);
|
resolve(message);
|
||||||
resolve(message);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
pipe.transform(promise);
|
pipe.transform(promise);
|
||||||
expect(pipe.transform(promise)).toBe(message);
|
expect(pipe.transform(promise)).toBe(message);
|
||||||
async.done();
|
done();
|
||||||
}, timer);
|
}, timer);
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should dispose of the existing subscription when subscribing to a new promise',
|
it('should dispose of the existing subscription when subscribing to a new promise',
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
done => {
|
||||||
pipe.transform(promise);
|
pipe.transform(promise);
|
||||||
|
|
||||||
promise = new Promise<any>(() => {});
|
promise = new Promise<any>(() => {});
|
||||||
|
@ -198,41 +193,38 @@ import {SpyChangeDetectorRef} from '../spies';
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(pipe.transform(promise)).toBe(null);
|
expect(pipe.transform(promise)).toBe(null);
|
||||||
async.done();
|
done();
|
||||||
}, timer);
|
}, timer);
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should request a change detection check upon receiving a new value',
|
it('should request a change detection check upon receiving a new value', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
pipe.transform(promise);
|
||||||
const markForCheck = ref.spy('markForCheck');
|
resolve(message);
|
||||||
pipe.transform(promise);
|
|
||||||
resolve(message);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(markForCheck).toHaveBeenCalled();
|
expect(ref.markForCheck).toHaveBeenCalled();
|
||||||
async.done();
|
done();
|
||||||
}, timer);
|
}, timer);
|
||||||
}));
|
});
|
||||||
|
|
||||||
describe('ngOnDestroy', () => {
|
describe('ngOnDestroy', () => {
|
||||||
it('should do nothing when no source', () => {
|
it('should do nothing when no source', () => {
|
||||||
expect(() => pipe.ngOnDestroy()).not.toThrow();
|
expect(() => pipe.ngOnDestroy()).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should dispose of the existing source',
|
it('should dispose of the existing source', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
pipe.transform(promise);
|
||||||
pipe.transform(promise);
|
expect(pipe.transform(promise)).toBe(null);
|
||||||
expect(pipe.transform(promise)).toBe(null);
|
resolve(message);
|
||||||
resolve(message);
|
|
||||||
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(pipe.transform(promise)).toEqual(message);
|
expect(pipe.transform(promise)).toEqual(message);
|
||||||
pipe.ngOnDestroy();
|
pipe.ngOnDestroy();
|
||||||
expect(pipe.transform(promise)).toBe(null);
|
expect(pipe.transform(promise)).toBe(null);
|
||||||
async.done();
|
done();
|
||||||
}, timer);
|
}, timer);
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
import {I18nPluralPipe, NgLocalization} from '@angular/common';
|
import {I18nPluralPipe, NgLocalization} from '@angular/common';
|
||||||
import {PipeResolver} from '@angular/compiler/src/pipe_resolver';
|
import {PipeResolver} from '@angular/compiler/src/pipe_resolver';
|
||||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {JitReflector} from '@angular/platform-browser-dynamic/src/compiler_reflector';
|
import {JitReflector} from '@angular/platform-browser-dynamic/src/compiler_reflector';
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,7 +14,6 @@ import localeEn from '@angular/common/locales/en';
|
||||||
import localeEsUS from '@angular/common/locales/es-US';
|
import localeEsUS from '@angular/common/locales/es-US';
|
||||||
import localeFr from '@angular/common/locales/fr';
|
import localeFr from '@angular/common/locales/fr';
|
||||||
import {ɵregisterLocaleData, ɵunregisterLocaleData} from '@angular/core';
|
import {ɵregisterLocaleData, ɵunregisterLocaleData} from '@angular/core';
|
||||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
{
|
{
|
||||||
describe('Number pipes', () => {
|
describe('Number pipes', () => {
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
/**
|
|
||||||
* @license
|
|
||||||
* Copyright Google LLC 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 {ChangeDetectorRef} from '@angular/core/src/change_detection/change_detector_ref';
|
|
||||||
import {SpyObject} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
export class SpyChangeDetectorRef extends SpyObject {
|
|
||||||
constructor() {
|
|
||||||
super(ChangeDetectorRef);
|
|
||||||
this.spy('markForCheck');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class SpyNgControl extends SpyObject {}
|
|
||||||
|
|
||||||
export class SpyValueAccessor extends SpyObject {
|
|
||||||
writeValue: any;
|
|
||||||
}
|
|
|
@ -6,7 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {browserDetection} from '@angular/platform-browser/testing/src/browser_util';
|
import {browserDetection} from '@angular/platform-browser/testing/src/browser_util';
|
||||||
import {BrowserViewportScroller, ViewportScroller} from '../src/viewport_scroller';
|
import {BrowserViewportScroller, ViewportScroller} from '../src/viewport_scroller';
|
||||||
|
|
||||||
|
|
|
@ -11,14 +11,13 @@ import {Serializer} from '@angular/compiler/src/i18n';
|
||||||
import {MessageBundle} from '@angular/compiler/src/i18n/message_bundle';
|
import {MessageBundle} from '@angular/compiler/src/i18n/message_bundle';
|
||||||
import {HtmlParser} from '@angular/compiler/src/ml_parser/html_parser';
|
import {HtmlParser} from '@angular/compiler/src/ml_parser/html_parser';
|
||||||
import {DEFAULT_INTERPOLATION_CONFIG} from '@angular/compiler/src/ml_parser/interpolation_config';
|
import {DEFAULT_INTERPOLATION_CONFIG} from '@angular/compiler/src/ml_parser/interpolation_config';
|
||||||
|
import {ResourceLoader} from '@angular/compiler/src/resource_loader';
|
||||||
import {Component, DebugElement, TRANSLATIONS, TRANSLATIONS_FORMAT} from '@angular/core';
|
import {Component, DebugElement, TRANSLATIONS, TRANSLATIONS_FORMAT} from '@angular/core';
|
||||||
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||||
import {By} from '@angular/platform-browser/src/dom/debug/by';
|
import {By} from '@angular/platform-browser/src/dom/debug/by';
|
||||||
import {stringifyElement} from '@angular/platform-browser/testing/src/browser_util';
|
import {stringifyElement} from '@angular/platform-browser/testing/src/browser_util';
|
||||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||||
|
|
||||||
import {SpyResourceLoader} from '../spies';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'i18n-cmp',
|
selector: 'i18n-cmp',
|
||||||
template: '',
|
template: '',
|
||||||
|
@ -180,7 +179,7 @@ export const HTML = `
|
||||||
export async function configureCompiler(translationsToMerge: string, format: string) {
|
export async function configureCompiler(translationsToMerge: string, format: string) {
|
||||||
TestBed.configureCompiler({
|
TestBed.configureCompiler({
|
||||||
providers: [
|
providers: [
|
||||||
SpyResourceLoader.PROVIDE,
|
{provide: ResourceLoader, useValue: jasmine.createSpyObj('ResourceLoader', ['get'])},
|
||||||
FrLocalization.PROVIDE,
|
FrLocalization.PROVIDE,
|
||||||
{provide: TRANSLATIONS, useValue: translationsToMerge},
|
{provide: TRANSLATIONS, useValue: translationsToMerge},
|
||||||
{provide: TRANSLATIONS_FORMAT, useValue: format},
|
{provide: TRANSLATIONS_FORMAT, useValue: format},
|
||||||
|
|
|
@ -6,8 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Injector, NgModule} from '@angular/core';
|
import {NgModule} from '@angular/core';
|
||||||
import {beforeEach, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {JitReflector} from '@angular/platform-browser-dynamic/src/compiler_reflector';
|
import {JitReflector} from '@angular/platform-browser-dynamic/src/compiler_reflector';
|
||||||
|
|
||||||
import {MockNgModuleResolver} from '../testing';
|
import {MockNgModuleResolver} from '../testing';
|
||||||
|
@ -16,9 +15,9 @@ import {MockNgModuleResolver} from '../testing';
|
||||||
describe('MockNgModuleResolver', () => {
|
describe('MockNgModuleResolver', () => {
|
||||||
let ngModuleResolver: MockNgModuleResolver;
|
let ngModuleResolver: MockNgModuleResolver;
|
||||||
|
|
||||||
beforeEach(inject([Injector], (injector: Injector) => {
|
beforeEach(() => {
|
||||||
ngModuleResolver = new MockNgModuleResolver(new JitReflector());
|
ngModuleResolver = new MockNgModuleResolver(new JitReflector());
|
||||||
}));
|
});
|
||||||
|
|
||||||
describe('NgModule overriding', () => {
|
describe('NgModule overriding', () => {
|
||||||
it('should fallback to the default NgModuleResolver when templates are not overridden',
|
it('should fallback to the default NgModuleResolver when templates are not overridden',
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {MockResourceLoader} from '@angular/compiler/testing/src/resource_loader_mock';
|
import {MockResourceLoader} from '@angular/compiler/testing/src/resource_loader_mock';
|
||||||
import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
{
|
{
|
||||||
describe('MockResourceLoader', () => {
|
describe('MockResourceLoader', () => {
|
||||||
|
@ -42,41 +41,37 @@ import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@ang
|
||||||
request.then(onResponse, onError);
|
request.then(onResponse, onError);
|
||||||
}
|
}
|
||||||
|
|
||||||
it('should return a response from the definitions',
|
it('should return a response from the definitions', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const url = '/foo';
|
||||||
const url = '/foo';
|
const response = 'bar';
|
||||||
const response = 'bar';
|
resourceLoader.when(url, response);
|
||||||
resourceLoader.when(url, response);
|
expectResponse(resourceLoader.get(url), url, response, () => done());
|
||||||
expectResponse(resourceLoader.get(url), url, response, () => async.done());
|
resourceLoader.flush();
|
||||||
resourceLoader.flush();
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should return an error from the definitions',
|
it('should return an error from the definitions', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const url = '/foo';
|
||||||
const url = '/foo';
|
const response: string = null!;
|
||||||
const response: string = null!;
|
resourceLoader.when(url, response);
|
||||||
resourceLoader.when(url, response);
|
expectResponse(resourceLoader.get(url), url, response, () => done());
|
||||||
expectResponse(resourceLoader.get(url), url, response, () => async.done());
|
resourceLoader.flush();
|
||||||
resourceLoader.flush();
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should return a response from the expectations',
|
it('should return a response from the expectations', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const url = '/foo';
|
||||||
const url = '/foo';
|
const response = 'bar';
|
||||||
const response = 'bar';
|
resourceLoader.expect(url, response);
|
||||||
resourceLoader.expect(url, response);
|
expectResponse(resourceLoader.get(url), url, response, () => done());
|
||||||
expectResponse(resourceLoader.get(url), url, response, () => async.done());
|
resourceLoader.flush();
|
||||||
resourceLoader.flush();
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should return an error from the expectations',
|
it('should return an error from the expectations', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const url = '/foo';
|
||||||
const url = '/foo';
|
const response: string = null!;
|
||||||
const response: string = null!;
|
resourceLoader.expect(url, response);
|
||||||
resourceLoader.expect(url, response);
|
expectResponse(resourceLoader.get(url), url, response, () => done());
|
||||||
expectResponse(resourceLoader.get(url), url, response, () => async.done());
|
resourceLoader.flush();
|
||||||
resourceLoader.flush();
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should not reuse expectations', () => {
|
it('should not reuse expectations', () => {
|
||||||
const url = '/foo';
|
const url = '/foo';
|
||||||
|
@ -89,15 +84,14 @@ import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@ang
|
||||||
}).toThrowError('Unexpected request /foo');
|
}).toThrowError('Unexpected request /foo');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return expectations before definitions',
|
it('should return expectations before definitions', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const url = '/foo';
|
||||||
const url = '/foo';
|
resourceLoader.when(url, 'when');
|
||||||
resourceLoader.when(url, 'when');
|
resourceLoader.expect(url, 'expect');
|
||||||
resourceLoader.expect(url, 'expect');
|
expectResponse(resourceLoader.get(url), url, 'expect');
|
||||||
expectResponse(resourceLoader.get(url), url, 'expect');
|
expectResponse(resourceLoader.get(url), url, 'when', () => done());
|
||||||
expectResponse(resourceLoader.get(url), url, 'when', () => async.done());
|
resourceLoader.flush();
|
||||||
resourceLoader.flush();
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should throw when there is no definitions or expectations', () => {
|
it('should throw when there is no definitions or expectations', () => {
|
||||||
resourceLoader.get('/foo');
|
resourceLoader.get('/foo');
|
||||||
|
|
|
@ -13,8 +13,6 @@ import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||||
|
|
||||||
import {MockDirectiveResolver} from '../testing';
|
import {MockDirectiveResolver} from '../testing';
|
||||||
|
|
||||||
import {SpyResourceLoader} from './spies';
|
|
||||||
|
|
||||||
@Component({selector: 'child-cmp'})
|
@Component({selector: 'child-cmp'})
|
||||||
class ChildComp {
|
class ChildComp {
|
||||||
}
|
}
|
||||||
|
@ -91,22 +89,20 @@ class SomeCompWithUrlTemplate {
|
||||||
|
|
||||||
describe('RuntimeCompiler', () => {
|
describe('RuntimeCompiler', () => {
|
||||||
let compiler: Compiler;
|
let compiler: Compiler;
|
||||||
let resourceLoader: SpyResourceLoader;
|
let resourceLoader: {get: jasmine.Spy};
|
||||||
let dirResolver: MockDirectiveResolver;
|
let dirResolver: MockDirectiveResolver;
|
||||||
let injector: Injector;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureCompiler({providers: [SpyResourceLoader.PROVIDE]});
|
resourceLoader = jasmine.createSpyObj('ResourceLoader', ['get']);
|
||||||
|
TestBed.configureCompiler({providers: [{provide: ResourceLoader, useValue: resourceLoader}]});
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(fakeAsync(inject(
|
beforeEach(fakeAsync(inject(
|
||||||
[Compiler, ResourceLoader, DirectiveResolver, Injector],
|
[Compiler, ResourceLoader, DirectiveResolver, Injector],
|
||||||
(_compiler: Compiler, _resourceLoader: SpyResourceLoader,
|
(_compiler: Compiler, _resourceLoader: any, _dirResolver: MockDirectiveResolver) => {
|
||||||
_dirResolver: MockDirectiveResolver, _injector: Injector) => {
|
|
||||||
compiler = _compiler;
|
compiler = _compiler;
|
||||||
resourceLoader = _resourceLoader;
|
resourceLoader = _resourceLoader;
|
||||||
dirResolver = _dirResolver;
|
dirResolver = _dirResolver;
|
||||||
injector = _injector;
|
|
||||||
})));
|
})));
|
||||||
|
|
||||||
describe('compileModuleAsync', () => {
|
describe('compileModuleAsync', () => {
|
||||||
|
@ -118,7 +114,7 @@ class SomeCompWithUrlTemplate {
|
||||||
class SomeModule {
|
class SomeModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
resourceLoader.spy('get').and.callFake(() => Promise.resolve('hello'));
|
resourceLoader.get.and.callFake(() => Promise.resolve('hello'));
|
||||||
let ngModuleFactory: NgModuleFactory<any> = undefined!;
|
let ngModuleFactory: NgModuleFactory<any> = undefined!;
|
||||||
compiler.compileModuleAsync(SomeModule).then((f) => ngModuleFactory = f);
|
compiler.compileModuleAsync(SomeModule).then((f) => ngModuleFactory = f);
|
||||||
tick();
|
tick();
|
||||||
|
@ -133,7 +129,7 @@ class SomeCompWithUrlTemplate {
|
||||||
class SomeModule {
|
class SomeModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
resourceLoader.spy('get').and.callFake(() => Promise.resolve(''));
|
resourceLoader.get.and.callFake(() => Promise.resolve(''));
|
||||||
expect(() => compiler.compileModuleSync(SomeModule))
|
expect(() => compiler.compileModuleSync(SomeModule))
|
||||||
.toThrowError(`Can't compile synchronously as ${
|
.toThrowError(`Can't compile synchronously as ${
|
||||||
stringify(SomeCompWithUrlTemplate)} is still being loaded!`);
|
stringify(SomeCompWithUrlTemplate)} is still being loaded!`);
|
||||||
|
@ -145,7 +141,7 @@ class SomeCompWithUrlTemplate {
|
||||||
class SomeModule {
|
class SomeModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
resourceLoader.spy('get').and.callFake(() => Promise.resolve(''));
|
resourceLoader.get.and.callFake(() => Promise.resolve(''));
|
||||||
dirResolver.setDirective(SomeComp, new Component({selector: 'some-cmp', template: ''}));
|
dirResolver.setDirective(SomeComp, new Component({selector: 'some-cmp', template: ''}));
|
||||||
dirResolver.setDirective(
|
dirResolver.setDirective(
|
||||||
ChildComp, new Component({selector: 'child-cmp', templateUrl: '/someTpl.html'}));
|
ChildComp, new Component({selector: 'child-cmp', templateUrl: '/someTpl.html'}));
|
||||||
|
@ -163,7 +159,7 @@ class SomeCompWithUrlTemplate {
|
||||||
class SomeModule {
|
class SomeModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
resourceLoader.spy('get').and.callFake(() => Promise.resolve('hello'));
|
resourceLoader.get.and.callFake(() => Promise.resolve('hello'));
|
||||||
compiler.compileModuleAsync(SomeModule);
|
compiler.compileModuleAsync(SomeModule);
|
||||||
tick();
|
tick();
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
import {DomElementSchemaRegistry} from '@angular/compiler/src/schema/dom_element_schema_registry';
|
import {DomElementSchemaRegistry} from '@angular/compiler/src/schema/dom_element_schema_registry';
|
||||||
import {CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA, SecurityContext} from '@angular/core';
|
import {CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA, SecurityContext} from '@angular/core';
|
||||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {browserDetection} from '@angular/platform-browser/testing/src/browser_util';
|
import {browserDetection} from '@angular/platform-browser/testing/src/browser_util';
|
||||||
|
|
||||||
import {Element} from '../../src/ml_parser/ast';
|
import {Element} from '../../src/ml_parser/ast';
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {isTrustedTypesSink} from '@angular/compiler/src/schema/trusted_types_sinks';
|
import {isTrustedTypesSink} from '@angular/compiler/src/schema/trusted_types_sinks';
|
||||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
{
|
{
|
||||||
describe('isTrustedTypesSink', () => {
|
describe('isTrustedTypesSink', () => {
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
/**
|
|
||||||
* @license
|
|
||||||
* Copyright Google LLC 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 {ResourceLoader} from '@angular/compiler/src/resource_loader';
|
|
||||||
|
|
||||||
import {SpyObject} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
export class SpyResourceLoader extends SpyObject {
|
|
||||||
public static PROVIDE = {provide: ResourceLoader, useClass: SpyResourceLoader, deps: []};
|
|
||||||
constructor() {
|
|
||||||
super(ResourceLoader);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,7 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {beforeEach, describe, expect, inject, it} from '../../../core/testing/src/testing_internal';
|
import {inject} from '../../../core/testing';
|
||||||
import {Element} from '../../src/ml_parser/ast';
|
import {Element} from '../../src/ml_parser/ast';
|
||||||
import {HtmlParser} from '../../src/ml_parser/html_parser';
|
import {HtmlParser} from '../../src/ml_parser/html_parser';
|
||||||
import {PreparsedElement, PreparsedElementType, preparseElement} from '../../src/template_parser/template_preparser';
|
import {PreparsedElement, PreparsedElementType, preparseElement} from '../../src/template_parser/template_preparser';
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {createOfflineCompileUrlResolver, UrlResolver} from '@angular/compiler/src/url_resolver';
|
import {UrlResolver} from '@angular/compiler/src/url_resolver';
|
||||||
import {beforeEach, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
import {inject} from '@angular/core/testing';
|
||||||
|
|
||||||
{
|
{
|
||||||
describe('UrlResolver', () => {
|
describe('UrlResolver', () => {
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {ApplicationRef, COMPILER_OPTIONS, Component, destroyPlatform, NgModule, NgZone, TestabilityRegistry, ViewEncapsulation} from '@angular/core';
|
import {ApplicationRef, COMPILER_OPTIONS, Component, destroyPlatform, NgModule, NgZone, TestabilityRegistry, ViewEncapsulation} from '@angular/core';
|
||||||
import {expect} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {BrowserModule} from '@angular/platform-browser';
|
import {BrowserModule} from '@angular/platform-browser';
|
||||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||||
import {onlyInIvy, withBody} from '@angular/private/testing';
|
import {onlyInIvy, withBody} from '@angular/private/testing';
|
||||||
|
|
|
@ -14,7 +14,6 @@ import {isLView} from '@angular/core/src/render3/interfaces/type_checks';
|
||||||
import {CONTEXT} from '@angular/core/src/render3/interfaces/view';
|
import {CONTEXT} from '@angular/core/src/render3/interfaces/view';
|
||||||
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||||
import {getElementStyles} from '@angular/core/testing/src/styling';
|
import {getElementStyles} from '@angular/core/testing/src/styling';
|
||||||
import {expect} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {onlyInIvy} from '@angular/private/testing';
|
import {onlyInIvy} from '@angular/private/testing';
|
||||||
|
|
||||||
import {getLContext} from '../../src/render3/context_discovery';
|
import {getLContext} from '../../src/render3/context_discovery';
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
import {ProfilerEvent, setProfiler} from '@angular/core/src/render3/profiler';
|
import {ProfilerEvent, setProfiler} from '@angular/core/src/render3/profiler';
|
||||||
import {TestBed} from '@angular/core/testing';
|
import {TestBed} from '@angular/core/testing';
|
||||||
import {expect} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {onlyInIvy} from '@angular/private/testing';
|
import {onlyInIvy} from '@angular/private/testing';
|
||||||
|
|
||||||
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, Component, DoCheck, ErrorHandler, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, ViewChild} from '../../src/core';
|
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, Component, DoCheck, ErrorHandler, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, ViewChild} from '../../src/core';
|
||||||
|
|
|
@ -7,12 +7,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {DEFAULT_CURRENCY_CODE, LOCALE_ID} from '@angular/core';
|
import {DEFAULT_CURRENCY_CODE, LOCALE_ID} from '@angular/core';
|
||||||
|
import {inject} from '@angular/core/testing';
|
||||||
import {ivyEnabled} from '@angular/private/testing';
|
import {ivyEnabled} from '@angular/private/testing';
|
||||||
|
|
||||||
import {getLocaleId} from '../src/render3';
|
import {getLocaleId} from '../src/render3';
|
||||||
import {global} from '../src/util/global';
|
import {global} from '../src/util/global';
|
||||||
import {TestBed} from '../testing';
|
import {TestBed} from '../testing';
|
||||||
import {describe, expect, inject, it} from '../testing/src/testing_internal';
|
|
||||||
|
|
||||||
{
|
{
|
||||||
describe('Application module', () => {
|
describe('Application module', () => {
|
||||||
|
|
|
@ -9,8 +9,6 @@
|
||||||
import {Injector, IterableDiffer, IterableDifferFactory, IterableDiffers, NgModule, TrackByFunction} from '@angular/core';
|
import {Injector, IterableDiffer, IterableDifferFactory, IterableDiffers, NgModule, TrackByFunction} from '@angular/core';
|
||||||
import {TestBed} from '@angular/core/testing';
|
import {TestBed} from '@angular/core/testing';
|
||||||
|
|
||||||
import {SpyIterableDifferFactory} from '../../spies';
|
|
||||||
|
|
||||||
{
|
{
|
||||||
describe('IterableDiffers', function() {
|
describe('IterableDiffers', function() {
|
||||||
let factory1: any;
|
let factory1: any;
|
||||||
|
@ -18,9 +16,10 @@ import {SpyIterableDifferFactory} from '../../spies';
|
||||||
let factory3: any;
|
let factory3: any;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
factory1 = new SpyIterableDifferFactory();
|
const getFactory = () => jasmine.createSpyObj('IterableDifferFactory', ['supports']);
|
||||||
factory2 = new SpyIterableDifferFactory();
|
factory1 = getFactory();
|
||||||
factory3 = new SpyIterableDifferFactory();
|
factory2 = getFactory();
|
||||||
|
factory3 = getFactory();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw when no suitable implementation found', () => {
|
it('should throw when no suitable implementation found', () => {
|
||||||
|
@ -30,17 +29,17 @@ import {SpyIterableDifferFactory} from '../../spies';
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the first suitable implementation', () => {
|
it('should return the first suitable implementation', () => {
|
||||||
factory1.spy('supports').and.returnValue(false);
|
factory1.supports.and.returnValue(false);
|
||||||
factory2.spy('supports').and.returnValue(true);
|
factory2.supports.and.returnValue(true);
|
||||||
factory3.spy('supports').and.returnValue(true);
|
factory3.supports.and.returnValue(true);
|
||||||
|
|
||||||
const differs = IterableDiffers.create(<any>[factory1, factory2, factory3]);
|
const differs = IterableDiffers.create(<any>[factory1, factory2, factory3]);
|
||||||
expect(differs.find('some object')).toBe(factory2);
|
expect(differs.find('some object')).toBe(factory2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should copy over differs from the parent repo', () => {
|
it('should copy over differs from the parent repo', () => {
|
||||||
factory1.spy('supports').and.returnValue(true);
|
factory1.supports.and.returnValue(true);
|
||||||
factory2.spy('supports').and.returnValue(false);
|
factory2.supports.and.returnValue(false);
|
||||||
|
|
||||||
const parent = IterableDiffers.create(<any>[factory1]);
|
const parent = IterableDiffers.create(<any>[factory1]);
|
||||||
const child = IterableDiffers.create(<any>[factory2], parent);
|
const child = IterableDiffers.create(<any>[factory2], parent);
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
import {Type} from '@angular/core';
|
import {Type} from '@angular/core';
|
||||||
import {forwardRef, resolveForwardRef} from '@angular/core/src/di';
|
import {forwardRef, resolveForwardRef} from '@angular/core/src/di';
|
||||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
{
|
{
|
||||||
describe('forwardRef', function() {
|
describe('forwardRef', function() {
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
|
|
||||||
import {Injector} from '@angular/core';
|
import {Injector} from '@angular/core';
|
||||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
{
|
{
|
||||||
describe('Injector.NULL', () => {
|
describe('Injector.NULL', () => {
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {ɵgetDOM as getDOM} from '@angular/common';
|
import {ɵgetDOM as getDOM} from '@angular/common';
|
||||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {isTextNode} from '@angular/platform-browser/testing/src/browser_util';
|
import {isTextNode} from '@angular/platform-browser/testing/src/browser_util';
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,7 +6,9 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
// This isn't used for anything, but for some reason Bazel won't
|
||||||
|
// serve the file if there isn't at least one import.
|
||||||
|
import '@angular/core/testing';
|
||||||
|
|
||||||
{
|
{
|
||||||
describe('Shim', () => {
|
describe('Shim', () => {
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {filter} from 'rxjs/operators';
|
import {filter} from 'rxjs/operators';
|
||||||
|
|
||||||
import {EventEmitter} from '../src/event_emitter';
|
import {EventEmitter} from '../src/event_emitter';
|
||||||
|
@ -19,51 +18,47 @@ import {EventEmitter} from '../src/event_emitter';
|
||||||
emitter = new EventEmitter();
|
emitter = new EventEmitter();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call the next callback',
|
it('should call the next callback', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
emitter.subscribe({
|
||||||
emitter.subscribe({
|
next: (value: any) => {
|
||||||
next: (value: any) => {
|
expect(value).toEqual(99);
|
||||||
expect(value).toEqual(99);
|
done();
|
||||||
async.done();
|
}
|
||||||
}
|
});
|
||||||
});
|
emitter.emit(99);
|
||||||
emitter.emit(99);
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should call the throw callback',
|
it('should call the throw callback', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
emitter.subscribe({
|
||||||
emitter.subscribe({
|
next: () => {},
|
||||||
next: () => {},
|
error: (error: any) => {
|
||||||
error: (error: any) => {
|
expect(error).toEqual('Boom');
|
||||||
expect(error).toEqual('Boom');
|
done();
|
||||||
async.done();
|
}
|
||||||
}
|
});
|
||||||
});
|
emitter.error('Boom');
|
||||||
emitter.error('Boom');
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should work when no throw callback is provided',
|
it('should work when no throw callback is provided', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
emitter.subscribe({
|
||||||
emitter.subscribe({
|
next: () => {},
|
||||||
next: () => {},
|
error: (_: any) => {
|
||||||
error: (_: any) => {
|
done();
|
||||||
async.done();
|
}
|
||||||
}
|
});
|
||||||
});
|
emitter.error('Boom');
|
||||||
emitter.error('Boom');
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should call the return callback',
|
it('should call the return callback', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
emitter.subscribe({
|
||||||
emitter.subscribe({
|
next: () => {},
|
||||||
next: () => {},
|
error: (_: any) => {},
|
||||||
error: (_: any) => {},
|
complete: () => {
|
||||||
complete: () => {
|
done();
|
||||||
async.done();
|
}
|
||||||
}
|
});
|
||||||
});
|
emitter.complete();
|
||||||
emitter.complete();
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should subscribe to the wrapper synchronously', () => {
|
it('should subscribe to the wrapper synchronously', () => {
|
||||||
let called = false;
|
let called = false;
|
||||||
|
@ -77,27 +72,26 @@ import {EventEmitter} from '../src/event_emitter';
|
||||||
expect(called).toBe(true);
|
expect(called).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('delivers next and error events synchronously',
|
it('delivers next and error events synchronously', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const log: any[] /** TODO #9100 */ = [];
|
||||||
const log: any[] /** TODO #9100 */ = [];
|
|
||||||
|
|
||||||
emitter.subscribe({
|
emitter.subscribe({
|
||||||
next: (x: any) => {
|
next: (x: any) => {
|
||||||
log.push(x);
|
log.push(x);
|
||||||
expect(log).toEqual([1, 2]);
|
expect(log).toEqual([1, 2]);
|
||||||
},
|
},
|
||||||
error: (err: any) => {
|
error: (err: any) => {
|
||||||
log.push(err);
|
log.push(err);
|
||||||
expect(log).toEqual([1, 2, 3, 4]);
|
expect(log).toEqual([1, 2, 3, 4]);
|
||||||
async.done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
log.push(1);
|
log.push(1);
|
||||||
emitter.emit(2);
|
emitter.emit(2);
|
||||||
log.push(3);
|
log.push(3);
|
||||||
emitter.error(4);
|
emitter.error(4);
|
||||||
log.push(5);
|
log.push(5);
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('delivers next and complete events synchronously', () => {
|
it('delivers next and complete events synchronously', () => {
|
||||||
const log: any[] /** TODO #9100 */ = [];
|
const log: any[] /** TODO #9100 */ = [];
|
||||||
|
@ -121,19 +115,18 @@ import {EventEmitter} from '../src/event_emitter';
|
||||||
expect(log).toEqual([1, 2, 3, 4, 5]);
|
expect(log).toEqual([1, 2, 3, 4, 5]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('delivers events asynchronously when forced to async mode',
|
it('delivers events asynchronously when forced to async mode', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const e = new EventEmitter(true);
|
||||||
const e = new EventEmitter(true);
|
const log: any[] /** TODO #9100 */ = [];
|
||||||
const log: any[] /** TODO #9100 */ = [];
|
e.subscribe((x: any) => {
|
||||||
e.subscribe((x: any) => {
|
log.push(x);
|
||||||
log.push(x);
|
expect(log).toEqual([1, 3, 2]);
|
||||||
expect(log).toEqual([1, 3, 2]);
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
log.push(1);
|
||||||
log.push(1);
|
e.emit(2);
|
||||||
e.emit(2);
|
log.push(3);
|
||||||
log.push(3);
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('reports whether it has subscribers', () => {
|
it('reports whether it has subscribers', () => {
|
||||||
const e = new EventEmitter(false);
|
const e = new EventEmitter(false);
|
||||||
|
@ -156,21 +149,17 @@ import {EventEmitter} from '../src/event_emitter';
|
||||||
expect(emitter.observers.length).toBe(0);
|
expect(emitter.observers.length).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('unsubscribing a subscriber invokes the dispose method', () => {
|
it('unsubscribing a subscriber invokes the dispose method', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const sub = emitter.subscribe();
|
||||||
const sub = emitter.subscribe();
|
sub.add(() => done());
|
||||||
sub.add(() => async.done());
|
sub.unsubscribe();
|
||||||
sub.unsubscribe();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('unsubscribing a subscriber after applying operators with pipe() invokes the dispose method',
|
it('unsubscribing a subscriber after applying operators with pipe() invokes the dispose method',
|
||||||
() => {
|
done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const sub = emitter.pipe(filter(() => true)).subscribe();
|
||||||
const sub = emitter.pipe(filter(() => true)).subscribe();
|
sub.add(() => done());
|
||||||
sub.add(() => async.done());
|
sub.unsubscribe();
|
||||||
sub.unsubscribe();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('error thrown inside an Rx chain propagates to the error handler and disposes the chain',
|
it('error thrown inside an Rx chain propagates to the error handler and disposes the chain',
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {discardPeriodicTasks, fakeAsync, flush, flushMicrotasks, tick} from '@angular/core/testing';
|
import {discardPeriodicTasks, fakeAsync, flush, flushMicrotasks, inject, tick} from '@angular/core/testing';
|
||||||
import {beforeEach, describe, inject, it, Log} from '@angular/core/testing/src/testing_internal';
|
import {Log} from '@angular/core/testing/src/testing_internal';
|
||||||
import {EventManager} from '@angular/platform-browser';
|
import {EventManager} from '@angular/platform-browser';
|
||||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
import {Component, Directive, HostBinding} from '@angular/core';
|
import {Component, Directive, HostBinding} from '@angular/core';
|
||||||
import {TestBed} from '@angular/core/testing';
|
import {TestBed} from '@angular/core/testing';
|
||||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {modifiedInIvy, onlyInIvy} from '@angular/private/testing';
|
import {modifiedInIvy, onlyInIvy} from '@angular/private/testing';
|
||||||
|
|
||||||
@Directive({selector: '[directiveA]'})
|
@Directive({selector: '[directiveA]'})
|
||||||
|
|
|
@ -10,7 +10,6 @@ import {ɵgetDOM as getDOM} from '@angular/common';
|
||||||
import {iterateListLike} from '@angular/core/src/change_detection/change_detection_util';
|
import {iterateListLike} from '@angular/core/src/change_detection/change_detection_util';
|
||||||
import {QueryList} from '@angular/core/src/linker/query_list';
|
import {QueryList} from '@angular/core/src/linker/query_list';
|
||||||
import {fakeAsync, tick} from '@angular/core/testing';
|
import {fakeAsync, tick} from '@angular/core/testing';
|
||||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
{
|
{
|
||||||
describe('QueryList', () => {
|
describe('QueryList', () => {
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
import {Compiler, SystemJsNgModuleLoader} from '@angular/core';
|
import {Compiler, SystemJsNgModuleLoader} from '@angular/core';
|
||||||
import {global} from '@angular/core/src/util/global';
|
import {global} from '@angular/core/src/util/global';
|
||||||
import {waitForAsync} from '@angular/core/testing';
|
import {waitForAsync} from '@angular/core/testing';
|
||||||
import {afterEach, beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {modifiedInIvy, onlyInIvy} from '@angular/private/testing';
|
import {modifiedInIvy, onlyInIvy} from '@angular/private/testing';
|
||||||
|
|
||||||
function mockSystem(modules: {[module: string]: any}) {
|
function mockSystem(modules: {[module: string]: any}) {
|
||||||
|
|
|
@ -12,7 +12,6 @@ import {i18nStartFirstCreatePass} from '@angular/core/src/render3/i18n/i18n_pars
|
||||||
import {getTIcu} from '@angular/core/src/render3/i18n/i18n_util';
|
import {getTIcu} from '@angular/core/src/render3/i18n/i18n_util';
|
||||||
import {I18nUpdateOpCodes, IcuType, TI18n} from '@angular/core/src/render3/interfaces/i18n';
|
import {I18nUpdateOpCodes, IcuType, TI18n} from '@angular/core/src/render3/interfaces/i18n';
|
||||||
import {HEADER_OFFSET, HOST} from '@angular/core/src/render3/interfaces/view';
|
import {HEADER_OFFSET, HOST} from '@angular/core/src/render3/interfaces/view';
|
||||||
import {expect} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {matchTI18n, matchTIcu} from '../matchers';
|
import {matchTI18n, matchTIcu} from '../matchers';
|
||||||
import {matchDebug} from '../utils';
|
import {matchDebug} from '../utils';
|
||||||
import {ViewFixture} from '../view_fixture';
|
import {ViewFixture} from '../view_fixture';
|
||||||
|
|
|
@ -17,7 +17,6 @@ import {getNativeByIndex} from '@angular/core/src/render3/util/view_utils';
|
||||||
import {keyValueArraySet} from '@angular/core/src/util/array_utils';
|
import {keyValueArraySet} from '@angular/core/src/util/array_utils';
|
||||||
import {ngDevModeResetPerfCounters} from '@angular/core/src/util/ng_dev_mode';
|
import {ngDevModeResetPerfCounters} from '@angular/core/src/util/ng_dev_mode';
|
||||||
import {getElementClasses, getElementStyles} from '@angular/core/testing/src/styling';
|
import {getElementClasses, getElementStyles} from '@angular/core/testing/src/styling';
|
||||||
import {expect} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
import {clearFirstUpdatePass, enterViewWithOneDiv, rewindBindingIndex} from './shared_spec';
|
import {clearFirstUpdatePass, enterViewWithOneDiv, rewindBindingIndex} from './shared_spec';
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
import {AttributeMarker} from '@angular/core/src/render3';
|
import {AttributeMarker} from '@angular/core/src/render3';
|
||||||
import {TAttributes} from '@angular/core/src/render3/interfaces/node';
|
import {TAttributes} from '@angular/core/src/render3/interfaces/node';
|
||||||
import {mergeHostAttribute, mergeHostAttrs} from '@angular/core/src/render3/util/attrs_utils';
|
import {mergeHostAttribute, mergeHostAttrs} from '@angular/core/src/render3/util/attrs_utils';
|
||||||
import {describe} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
describe('attr_util', () => {
|
describe('attr_util', () => {
|
||||||
describe('mergeHostAttribute', () => {
|
describe('mergeHostAttribute', () => {
|
||||||
|
|
|
@ -6,16 +6,14 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as t from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
import {_sanitizeUrl, sanitizeSrcset} from '../../src/sanitization/url_sanitizer';
|
import {_sanitizeUrl, sanitizeSrcset} from '../../src/sanitization/url_sanitizer';
|
||||||
|
|
||||||
{
|
{
|
||||||
t.describe('URL sanitizer', () => {
|
describe('URL sanitizer', () => {
|
||||||
let logMsgs: string[];
|
let logMsgs: string[];
|
||||||
let originalLog: (msg: any) => any;
|
let originalLog: (msg: any) => any;
|
||||||
|
|
||||||
t.beforeEach(() => {
|
beforeEach(() => {
|
||||||
logMsgs = [];
|
logMsgs = [];
|
||||||
originalLog = console.warn; // Monkey patch DOM.log.
|
originalLog = console.warn; // Monkey patch DOM.log.
|
||||||
console.warn = (msg: any) => logMsgs.push(msg);
|
console.warn = (msg: any) => logMsgs.push(msg);
|
||||||
|
@ -25,12 +23,12 @@ import {_sanitizeUrl, sanitizeSrcset} from '../../src/sanitization/url_sanitizer
|
||||||
console.warn = originalLog;
|
console.warn = originalLog;
|
||||||
});
|
});
|
||||||
|
|
||||||
t.it('reports unsafe URLs', () => {
|
it('reports unsafe URLs', () => {
|
||||||
t.expect(_sanitizeUrl('javascript:evil()')).toBe('unsafe:javascript:evil()');
|
expect(_sanitizeUrl('javascript:evil()')).toBe('unsafe:javascript:evil()');
|
||||||
t.expect(logMsgs.join('\n')).toMatch(/sanitizing unsafe URL value/);
|
expect(logMsgs.join('\n')).toMatch(/sanitizing unsafe URL value/);
|
||||||
});
|
});
|
||||||
|
|
||||||
t.describe('valid URLs', () => {
|
describe('valid URLs', () => {
|
||||||
const validUrls = [
|
const validUrls = [
|
||||||
'',
|
'',
|
||||||
'http://abc',
|
'http://abc',
|
||||||
|
@ -51,11 +49,11 @@ import {_sanitizeUrl, sanitizeSrcset} from '../../src/sanitization/url_sanitizer
|
||||||
'data:audio/opus;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
|
'data:audio/opus;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
|
||||||
];
|
];
|
||||||
for (const url of validUrls) {
|
for (const url of validUrls) {
|
||||||
t.it(`valid ${url}`, () => t.expect(_sanitizeUrl(url)).toEqual(url));
|
it(`valid ${url}`, () => expect(_sanitizeUrl(url)).toEqual(url));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
t.describe('invalid URLs', () => {
|
describe('invalid URLs', () => {
|
||||||
const invalidUrls = [
|
const invalidUrls = [
|
||||||
'javascript:evil()',
|
'javascript:evil()',
|
||||||
'JavaScript:abc',
|
'JavaScript:abc',
|
||||||
|
@ -75,11 +73,11 @@ import {_sanitizeUrl, sanitizeSrcset} from '../../src/sanitization/url_sanitizer
|
||||||
'data:application/x-msdownload;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
|
'data:application/x-msdownload;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
|
||||||
];
|
];
|
||||||
for (const url of invalidUrls) {
|
for (const url of invalidUrls) {
|
||||||
t.it(`valid ${url}`, () => t.expect(_sanitizeUrl(url)).toMatch(/^unsafe:/));
|
it(`valid ${url}`, () => expect(_sanitizeUrl(url)).toMatch(/^unsafe:/));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
t.describe('valid srcsets', () => {
|
describe('valid srcsets', () => {
|
||||||
const validSrcsets = [
|
const validSrcsets = [
|
||||||
'',
|
'',
|
||||||
'http://angular.io/images/test.png',
|
'http://angular.io/images/test.png',
|
||||||
|
@ -102,17 +100,17 @@ import {_sanitizeUrl, sanitizeSrcset} from '../../src/sanitization/url_sanitizer
|
||||||
'http://angular.io/images/test.png?maxage=234, http://angular.io/images/test.png?maxage=234',
|
'http://angular.io/images/test.png?maxage=234, http://angular.io/images/test.png?maxage=234',
|
||||||
];
|
];
|
||||||
for (const srcset of validSrcsets) {
|
for (const srcset of validSrcsets) {
|
||||||
t.it(`valid ${srcset}`, () => t.expect(sanitizeSrcset(srcset)).toEqual(srcset));
|
it(`valid ${srcset}`, () => expect(sanitizeSrcset(srcset)).toEqual(srcset));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
t.describe('invalid srcsets', () => {
|
describe('invalid srcsets', () => {
|
||||||
const invalidSrcsets = [
|
const invalidSrcsets = [
|
||||||
'ht:tp://angular.io/images/test.png',
|
'ht:tp://angular.io/images/test.png',
|
||||||
'http://angular.io/images/test.png, ht:tp://angular.io/images/test.png',
|
'http://angular.io/images/test.png, ht:tp://angular.io/images/test.png',
|
||||||
];
|
];
|
||||||
for (const srcset of invalidSrcsets) {
|
for (const srcset of invalidSrcsets) {
|
||||||
t.it(`valid ${srcset}`, () => t.expect(sanitizeSrcset(srcset)).toMatch(/unsafe:/));
|
it(`valid ${srcset}`, () => expect(sanitizeSrcset(srcset)).toMatch(/unsafe:/));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
/**
|
|
||||||
* @license
|
|
||||||
* Copyright Google LLC 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 {DomAdapter} from '@angular/common/src/dom_adapter';
|
|
||||||
import {ElementRef} from '@angular/core';
|
|
||||||
import {ChangeDetectorRef} from '@angular/core/src/change_detection/change_detection';
|
|
||||||
import {SpyObject} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
export class SpyChangeDetectorRef extends SpyObject {
|
|
||||||
constructor() {
|
|
||||||
super(ChangeDetectorRef);
|
|
||||||
this.spy('detectChanges');
|
|
||||||
this.spy('checkNoChanges');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class SpyIterableDifferFactory extends SpyObject {}
|
|
||||||
|
|
||||||
export class SpyElementRef extends SpyObject {
|
|
||||||
constructor() {
|
|
||||||
super(ElementRef);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
/**
|
|
||||||
* @license
|
|
||||||
* Copyright Google LLC 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 {TestBed} from '@angular/core/testing/src/test_bed';
|
|
||||||
import {AsyncTestCompleter, ddescribe, describe, inject, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
describe('TestBed with async processing', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
TestBed.resetTestingModule();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should allow injecting AsyncTestCompleter',
|
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
|
||||||
async.done();
|
|
||||||
}));
|
|
||||||
});
|
|
|
@ -11,7 +11,6 @@ import {Injectable} from '@angular/core/src/di';
|
||||||
import {PendingMacrotask, Testability, TestabilityRegistry} from '@angular/core/src/testability/testability';
|
import {PendingMacrotask, Testability, TestabilityRegistry} from '@angular/core/src/testability/testability';
|
||||||
import {NgZone} from '@angular/core/src/zone/ng_zone';
|
import {NgZone} from '@angular/core/src/zone/ng_zone';
|
||||||
import {fakeAsync, flush, tick, waitForAsync} from '@angular/core/testing';
|
import {fakeAsync, flush, tick, waitForAsync} from '@angular/core/testing';
|
||||||
import {beforeEach, describe, expect, it, SpyObject} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
import {scheduleMicroTask} from '../../src/util/microtask';
|
import {scheduleMicroTask} from '../../src/util/microtask';
|
||||||
|
|
||||||
|
@ -58,9 +57,9 @@ class MockNgZone extends NgZone {
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
ngZone = new MockNgZone();
|
ngZone = new MockNgZone();
|
||||||
testability = new Testability(ngZone);
|
testability = new Testability(ngZone);
|
||||||
execute = new SpyObject().spy('execute');
|
execute = jasmine.createSpy('execute');
|
||||||
execute2 = new SpyObject().spy('execute');
|
execute2 = jasmine.createSpy('execute');
|
||||||
updateCallback = new SpyObject().spy('execute');
|
updateCallback = jasmine.createSpy('execute');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('Pending count logic', () => {
|
describe('Pending count logic', () => {
|
||||||
|
|
|
@ -1,144 +0,0 @@
|
||||||
/**
|
|
||||||
* @license
|
|
||||||
* Copyright Google LLC 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 {SpyObject} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
class TestObj {
|
|
||||||
prop: any;
|
|
||||||
constructor(prop: any) {
|
|
||||||
this.prop = prop;
|
|
||||||
}
|
|
||||||
someFunc(): number {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
someComplexFunc(a: any) {
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
describe('testing', () => {
|
|
||||||
describe('should respect custom equality tester', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
const equalIfMarried = (first: any, second: any) => {
|
|
||||||
return first === 'kevin' && second === 'patricia';
|
|
||||||
};
|
|
||||||
jasmine.addCustomEqualityTester(equalIfMarried);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('for positive test', () => {
|
|
||||||
expect('kevin').toEqual('patricia');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('for negative test', () => {
|
|
||||||
expect('kevin').not.toEqual('kevin');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('equality', () => {
|
|
||||||
it('should structurally compare objects', () => {
|
|
||||||
const expected = new TestObj(new TestObj({'one': [1, 2]}));
|
|
||||||
const actual = new TestObj(new TestObj({'one': [1, 2]}));
|
|
||||||
const falseActual = new TestObj(new TestObj({'one': [1, 3]}));
|
|
||||||
|
|
||||||
expect(actual).toEqual(expected);
|
|
||||||
expect(falseActual).not.toEqual(expected);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('toEqual for Maps', () => {
|
|
||||||
it('should detect equality for same reference', () => {
|
|
||||||
const m1: Map<string, number> = new Map();
|
|
||||||
m1.set('a', 1);
|
|
||||||
expect(m1).toEqual(m1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should detect equality for same content', () => {
|
|
||||||
const m1: Map<string, number> = new Map();
|
|
||||||
m1.set('a', 1);
|
|
||||||
const m2: Map<string, number> = new Map();
|
|
||||||
m2.set('a', 1);
|
|
||||||
expect(m1).toEqual(m2);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should detect missing entries', () => {
|
|
||||||
const m1: Map<string, number> = new Map();
|
|
||||||
m1.set('a', 1);
|
|
||||||
const m2: Map<string, number> = new Map();
|
|
||||||
expect(m1).not.toEqual(m2);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should detect different values', () => {
|
|
||||||
const m1: Map<string, number> = new Map();
|
|
||||||
m1.set('a', 1);
|
|
||||||
const m2: Map<string, number> = new Map();
|
|
||||||
m2.set('a', 2);
|
|
||||||
expect(m1).not.toEqual(m2);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should detect additional entries', () => {
|
|
||||||
const m1: Map<string, number> = new Map();
|
|
||||||
m1.set('a', 1);
|
|
||||||
const m2: Map<string, number> = new Map();
|
|
||||||
m2.set('a', 1);
|
|
||||||
m2.set('b', 2);
|
|
||||||
expect(m1).not.toEqual(m2);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('spy objects', () => {
|
|
||||||
let spyObj: any;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
spyObj = new SpyObject(TestObj);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return a new spy func with no calls', () => {
|
|
||||||
expect(spyObj.spy('someFunc')).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should record function calls', () => {
|
|
||||||
spyObj.spy('someFunc').and.callFake((a: any, b: any) => a + b);
|
|
||||||
|
|
||||||
expect(spyObj.someFunc(1, 2)).toEqual(3);
|
|
||||||
expect(spyObj.spy('someFunc')).toHaveBeenCalledWith(1, 2);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should match multiple function calls', () => {
|
|
||||||
spyObj.spy('someFunc');
|
|
||||||
spyObj.someFunc(1, 2);
|
|
||||||
spyObj.someFunc(3, 4);
|
|
||||||
expect(spyObj.spy('someFunc')).toHaveBeenCalledWith(1, 2);
|
|
||||||
expect(spyObj.spy('someFunc')).toHaveBeenCalledWith(3, 4);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should match null arguments', () => {
|
|
||||||
spyObj.spy('someFunc');
|
|
||||||
spyObj.someFunc(null, 'hello');
|
|
||||||
expect(spyObj.spy('someFunc')).toHaveBeenCalledWith(null, 'hello');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should match using deep equality', () => {
|
|
||||||
spyObj.spy('someComplexFunc');
|
|
||||||
spyObj.someComplexFunc([1]);
|
|
||||||
expect(spyObj.spy('someComplexFunc')).toHaveBeenCalledWith([1]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should support stubs', () => {
|
|
||||||
const s = SpyObject.stub({'a': 1}, {'b': 2});
|
|
||||||
expect(s.a()).toEqual(1);
|
|
||||||
expect(s.b()).toEqual(2);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create spys for all methods', () => {
|
|
||||||
spyObj.spy('someFunc');
|
|
||||||
expect(() => spyObj.someFunc()).not.toThrow();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,32 +0,0 @@
|
||||||
/**
|
|
||||||
* @license
|
|
||||||
* Copyright Google LLC 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
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Injectable completer that allows signaling completion of an asynchronous test. Used internally.
|
|
||||||
*/
|
|
||||||
export class AsyncTestCompleter {
|
|
||||||
// TODO(issue/24571): remove '!'.
|
|
||||||
private _resolve!: (result: any) => void;
|
|
||||||
// TODO(issue/24571): remove '!'.
|
|
||||||
private _reject!: (err: any) => void;
|
|
||||||
private _promise: Promise<any> = new Promise((res, rej) => {
|
|
||||||
this._resolve = res;
|
|
||||||
this._reject = rej;
|
|
||||||
});
|
|
||||||
done(value?: any) {
|
|
||||||
this._resolve(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
fail(error?: any, stackTrace?: string) {
|
|
||||||
this._reject(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
get promise(): Promise<any> {
|
|
||||||
return this._promise;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
import {ApplicationInitStatus, CompilerOptions, Component, Directive, InjectFlags, InjectionToken, Injector, NgModule, NgModuleFactory, NgModuleRef, NgZone, Optional, Pipe, PlatformRef, Provider, ProviderToken, SchemaMetadata, SkipSelf, StaticProvider, Type, ɵclearOverrides as clearOverrides, ɵDepFlags as DepFlags, ɵgetInjectableDef as getInjectableDef, ɵINJECTOR_SCOPE as INJECTOR_SCOPE, ɵivyEnabled as ivyEnabled, ɵNodeFlags as NodeFlags, ɵoverrideComponentView as overrideComponentView, ɵoverrideProvider as overrideProvider, ɵstringify as stringify, ɵɵInjectableDeclaration} from '@angular/core';
|
import {ApplicationInitStatus, CompilerOptions, Component, Directive, InjectFlags, InjectionToken, Injector, NgModule, NgModuleFactory, NgModuleRef, NgZone, Optional, Pipe, PlatformRef, Provider, ProviderToken, SchemaMetadata, SkipSelf, StaticProvider, Type, ɵclearOverrides as clearOverrides, ɵDepFlags as DepFlags, ɵgetInjectableDef as getInjectableDef, ɵINJECTOR_SCOPE as INJECTOR_SCOPE, ɵivyEnabled as ivyEnabled, ɵNodeFlags as NodeFlags, ɵoverrideComponentView as overrideComponentView, ɵoverrideProvider as overrideProvider, ɵstringify as stringify, ɵɵInjectableDeclaration} from '@angular/core';
|
||||||
|
|
||||||
import {AsyncTestCompleter} from './async_test_completer';
|
|
||||||
import {ComponentFixture} from './component_fixture';
|
import {ComponentFixture} from './component_fixture';
|
||||||
import {MetadataOverride} from './metadata_override';
|
import {MetadataOverride} from './metadata_override';
|
||||||
import {_getTestBedRender3, TestBedRender3} from './r3_test_bed';
|
import {_getTestBedRender3, TestBedRender3} from './r3_test_bed';
|
||||||
|
@ -660,32 +659,14 @@ function _getTestBedViewEngine(): TestBedViewEngine {
|
||||||
* })
|
* })
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* Notes:
|
|
||||||
* - inject is currently a function because of some Traceur limitation the syntax should
|
|
||||||
* eventually
|
|
||||||
* becomes `it('...', @Inject (object: AClass, async: AsyncTestCompleter) => { ... });`
|
|
||||||
*
|
|
||||||
* @publicApi
|
* @publicApi
|
||||||
*/
|
*/
|
||||||
export function inject(tokens: any[], fn: Function): () => any {
|
export function inject(tokens: any[], fn: Function): () => any {
|
||||||
const testBed = getTestBed();
|
const testBed = getTestBed();
|
||||||
if (tokens.indexOf(AsyncTestCompleter) >= 0) {
|
// Not using an arrow function to preserve context passed from call site
|
||||||
// Not using an arrow function to preserve context passed from call site
|
return function(this: unknown) {
|
||||||
return function(this: unknown) {
|
return testBed.execute(tokens, fn, this);
|
||||||
// Return an async test method that returns a Promise if AsyncTestCompleter is one of
|
};
|
||||||
// the injected tokens.
|
|
||||||
return testBed.compileComponents().then(() => {
|
|
||||||
const completer = testBed.inject(AsyncTestCompleter);
|
|
||||||
testBed.execute(tokens, fn, this);
|
|
||||||
return completer.promise;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
// Not using an arrow function to preserve context passed from call site
|
|
||||||
return function(this: unknown) {
|
|
||||||
return testBed.execute(tokens, fn, this);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,213 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {ɵisPromise as isPromise} from '@angular/core';
|
|
||||||
import {global} from '@angular/core/src/util/global';
|
|
||||||
|
|
||||||
import {AsyncTestCompleter} from './async_test_completer';
|
|
||||||
import {getTestBed, inject} from './test_bed';
|
|
||||||
|
|
||||||
export {AsyncTestCompleter} from './async_test_completer';
|
|
||||||
export {inject} from './test_bed';
|
export {inject} from './test_bed';
|
||||||
|
|
||||||
export * from './logger';
|
export * from './logger';
|
||||||
export * from './ng_zone_mock';
|
export * from './ng_zone_mock';
|
||||||
|
|
||||||
export const proxy: ClassDecorator = (t: any) => t;
|
|
||||||
|
|
||||||
const _global = <any>(typeof window === 'undefined' ? global : window);
|
|
||||||
|
|
||||||
export const afterEach: Function = _global.afterEach;
|
|
||||||
export const expect: <T>(actual: T) => jasmine.Matchers<T> = _global.expect;
|
|
||||||
|
|
||||||
const jsmBeforeEach = _global.beforeEach;
|
|
||||||
const jsmDescribe = _global.describe;
|
|
||||||
const jsmDDescribe = _global.fdescribe;
|
|
||||||
const jsmXDescribe = _global.xdescribe;
|
|
||||||
const jsmIt = _global.it;
|
|
||||||
const jsmFIt = _global.fit;
|
|
||||||
const jsmXIt = _global.xit;
|
|
||||||
|
|
||||||
const runnerStack: BeforeEachRunner[] = [];
|
|
||||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 3000;
|
|
||||||
const globalTimeOut = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
|
||||||
|
|
||||||
const testBed = getTestBed();
|
|
||||||
|
|
||||||
export type TestFn = ((done: DoneFn) => any)|(() => any);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mechanism to run `beforeEach()` functions of Angular tests.
|
|
||||||
*
|
|
||||||
* Note: Jasmine own `beforeEach` is used by this library to handle DI providers.
|
|
||||||
*/
|
|
||||||
class BeforeEachRunner {
|
|
||||||
private _fns: Array<Function> = [];
|
|
||||||
|
|
||||||
constructor(private _parent: BeforeEachRunner) {}
|
|
||||||
|
|
||||||
beforeEach(fn: Function): void {
|
|
||||||
this._fns.push(fn);
|
|
||||||
}
|
|
||||||
|
|
||||||
run(): void {
|
|
||||||
if (this._parent) this._parent.run();
|
|
||||||
this._fns.forEach((fn) => {
|
|
||||||
fn();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset the test providers before each test
|
|
||||||
jsmBeforeEach(() => {
|
|
||||||
testBed.resetTestingModule();
|
|
||||||
});
|
|
||||||
|
|
||||||
function _describe(jsmFn: Function, ...args: any[]) {
|
|
||||||
const parentRunner = runnerStack.length === 0 ? null : runnerStack[runnerStack.length - 1];
|
|
||||||
const runner = new BeforeEachRunner(parentRunner!);
|
|
||||||
runnerStack.push(runner);
|
|
||||||
const suite = jsmFn(...args);
|
|
||||||
runnerStack.pop();
|
|
||||||
return suite;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function describe(...args: any[]): void {
|
|
||||||
return _describe(jsmDescribe, ...args);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ddescribe(...args: any[]): void {
|
|
||||||
return _describe(jsmDDescribe, ...args);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function xdescribe(...args: any[]): void {
|
|
||||||
return _describe(jsmXDescribe, ...args);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function beforeEach(fn: Function): void {
|
|
||||||
if (runnerStack.length > 0) {
|
|
||||||
// Inside a describe block, beforeEach() uses a BeforeEachRunner
|
|
||||||
runnerStack[runnerStack.length - 1].beforeEach(fn);
|
|
||||||
} else {
|
|
||||||
// Top level beforeEach() are delegated to jasmine
|
|
||||||
jsmBeforeEach(fn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allows overriding default providers defined in test_injector.js.
|
|
||||||
*
|
|
||||||
* The given function must return a list of DI providers.
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
*
|
|
||||||
* beforeEachProviders(() => [
|
|
||||||
* {provide: Compiler, useClass: MockCompiler},
|
|
||||||
* {provide: SomeToken, useValue: myValue},
|
|
||||||
* ]);
|
|
||||||
*/
|
|
||||||
export function beforeEachProviders(fn: Function): void {
|
|
||||||
jsmBeforeEach(() => {
|
|
||||||
const providers = fn();
|
|
||||||
if (!providers) return;
|
|
||||||
testBed.configureTestingModule({providers: providers});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function _it(jsmFn: Function, testName: string, testFn: TestFn, testTimeout = 0): void {
|
|
||||||
if (runnerStack.length == 0) {
|
|
||||||
// This left here intentionally, as we should never get here, and it aids debugging.
|
|
||||||
// tslint:disable-next-line
|
|
||||||
debugger;
|
|
||||||
throw new Error('Empty Stack!');
|
|
||||||
}
|
|
||||||
const runner = runnerStack[runnerStack.length - 1];
|
|
||||||
const timeout = Math.max(globalTimeOut, testTimeout);
|
|
||||||
|
|
||||||
jsmFn(testName, (done: DoneFn) => {
|
|
||||||
const completerProvider = {
|
|
||||||
provide: AsyncTestCompleter,
|
|
||||||
useFactory: () => {
|
|
||||||
// Mark the test as async when an AsyncTestCompleter is injected in an it()
|
|
||||||
return new AsyncTestCompleter();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
testBed.configureTestingModule({providers: [completerProvider]});
|
|
||||||
runner.run();
|
|
||||||
|
|
||||||
if (testFn.length === 0) {
|
|
||||||
// TypeScript doesn't infer the TestFn type without parameters here, so we
|
|
||||||
// need to manually cast it.
|
|
||||||
const retVal = (testFn as () => any)();
|
|
||||||
if (isPromise(retVal)) {
|
|
||||||
// Asynchronous test function that returns a Promise - wait for completion.
|
|
||||||
retVal.then(done, done.fail);
|
|
||||||
} else {
|
|
||||||
// Synchronous test function - complete immediately.
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Asynchronous test function that takes in 'done' parameter.
|
|
||||||
testFn(done);
|
|
||||||
}
|
|
||||||
}, timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function it(expectation: string, assertion: TestFn, timeout?: number): void {
|
|
||||||
return _it(jsmIt, expectation, assertion, timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function fit(expectation: string, assertion: TestFn, timeout?: number): void {
|
|
||||||
return _it(jsmFIt, expectation, assertion, timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function xit(expectation: string, assertion: TestFn, timeout?: number): void {
|
|
||||||
return _it(jsmXIt, expectation, assertion, timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
export class SpyObject {
|
|
||||||
constructor(type?: any) {
|
|
||||||
if (type) {
|
|
||||||
for (const prop in type.prototype) {
|
|
||||||
let m: any = null;
|
|
||||||
try {
|
|
||||||
m = type.prototype[prop];
|
|
||||||
} catch {
|
|
||||||
// As we are creating spys for abstract classes,
|
|
||||||
// these classes might have getters that throw when they are accessed.
|
|
||||||
// As we are only auto creating spys for methods, this
|
|
||||||
// should not matter.
|
|
||||||
}
|
|
||||||
if (typeof m === 'function') {
|
|
||||||
this.spy(prop);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
spy(name: string) {
|
|
||||||
if (!(this as any)[name]) {
|
|
||||||
(this as any)[name] = jasmine.createSpy(name);
|
|
||||||
}
|
|
||||||
return (this as any)[name];
|
|
||||||
}
|
|
||||||
|
|
||||||
prop(name: string, value: any) {
|
|
||||||
(this as any)[name] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static stub(object: any = null, config: any = null, overrides: any = null) {
|
|
||||||
if (!(object instanceof SpyObject)) {
|
|
||||||
overrides = config;
|
|
||||||
config = object;
|
|
||||||
object = new SpyObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
const m = {...config, ...overrides};
|
|
||||||
Object.keys(m).forEach(key => {
|
|
||||||
object.spy(key).and.returnValue(m[key]);
|
|
||||||
});
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -8,11 +8,9 @@
|
||||||
|
|
||||||
import {SimpleChange} from '@angular/core';
|
import {SimpleChange} from '@angular/core';
|
||||||
import {fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
|
import {fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
|
||||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {AbstractControl, CheckboxControlValueAccessor, ControlValueAccessor, DefaultValueAccessor, FormArray, FormArrayName, FormControl, FormControlDirective, FormControlName, FormGroup, FormGroupDirective, FormGroupName, NgControl, NgForm, NgModel, NgModelGroup, SelectControlValueAccessor, SelectMultipleControlValueAccessor, ValidationErrors, Validator, Validators} from '@angular/forms';
|
import {AbstractControl, CheckboxControlValueAccessor, ControlValueAccessor, DefaultValueAccessor, FormArray, FormArrayName, FormControl, FormControlDirective, FormControlName, FormGroup, FormGroupDirective, FormGroupName, NgControl, NgForm, NgModel, NgModelGroup, SelectControlValueAccessor, SelectMultipleControlValueAccessor, ValidationErrors, Validator, Validators} from '@angular/forms';
|
||||||
import {selectValueAccessor} from '@angular/forms/src/directives/shared';
|
import {selectValueAccessor} from '@angular/forms/src/directives/shared';
|
||||||
import {composeValidators} from '@angular/forms/src/validators';
|
import {composeValidators} from '@angular/forms/src/validators';
|
||||||
import {SpyNgControl, SpyValueAccessor} from './spies';
|
|
||||||
import {asyncValidator} from './util';
|
import {asyncValidator} from './util';
|
||||||
|
|
||||||
class DummyControlValueAccessor implements ControlValueAccessor {
|
class DummyControlValueAccessor implements ControlValueAccessor {
|
||||||
|
@ -45,7 +43,7 @@ class CustomValidatorDirective implements Validator {
|
||||||
let dir: NgControl;
|
let dir: NgControl;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
dir = <any>new SpyNgControl();
|
dir = {path: []} as any;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw when given an empty array', () => {
|
it('should throw when given an empty array', () => {
|
||||||
|
@ -90,7 +88,7 @@ class CustomValidatorDirective implements Validator {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return custom accessor when provided', () => {
|
it('should return custom accessor when provided', () => {
|
||||||
const customAccessor: ControlValueAccessor = new SpyValueAccessor() as any;
|
const customAccessor: ControlValueAccessor = {} as any;
|
||||||
const checkboxAccessor = new CheckboxControlValueAccessor(null!, null!);
|
const checkboxAccessor = new CheckboxControlValueAccessor(null!, null!);
|
||||||
expect(selectValueAccessor(dir, <any>[
|
expect(selectValueAccessor(dir, <any>[
|
||||||
defaultAccessor, customAccessor, checkboxAccessor
|
defaultAccessor, customAccessor, checkboxAccessor
|
||||||
|
@ -98,7 +96,7 @@ class CustomValidatorDirective implements Validator {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return custom accessor when provided with select multiple', () => {
|
it('should return custom accessor when provided with select multiple', () => {
|
||||||
const customAccessor: ControlValueAccessor = new SpyValueAccessor() as any;
|
const customAccessor: ControlValueAccessor = {} as any;
|
||||||
const selectMultipleAccessor = new SelectMultipleControlValueAccessor(null!, null!);
|
const selectMultipleAccessor = new SelectMultipleControlValueAccessor(null!, null!);
|
||||||
expect(selectValueAccessor(dir, <any>[
|
expect(selectValueAccessor(dir, <any>[
|
||||||
defaultAccessor, customAccessor, selectMultipleAccessor
|
defaultAccessor, customAccessor, selectMultipleAccessor
|
||||||
|
@ -106,7 +104,7 @@ class CustomValidatorDirective implements Validator {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw when more than one custom accessor is provided', () => {
|
it('should throw when more than one custom accessor is provided', () => {
|
||||||
const customAccessor: ControlValueAccessor = <any>new SpyValueAccessor();
|
const customAccessor: ControlValueAccessor = {} as any;
|
||||||
expect(() => selectValueAccessor(dir, [customAccessor, customAccessor])).toThrowError();
|
expect(() => selectValueAccessor(dir, [customAccessor, customAccessor])).toThrowError();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {fakeAsync, tick} from '@angular/core/testing';
|
import {fakeAsync, tick} from '@angular/core/testing';
|
||||||
import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors, ValidatorFn} from '@angular/forms';
|
import {AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors, ValidatorFn} from '@angular/forms';
|
||||||
import {Validators} from '@angular/forms/src/validators';
|
import {Validators} from '@angular/forms/src/validators';
|
||||||
import {of} from 'rxjs';
|
import {of} from 'rxjs';
|
||||||
|
@ -856,64 +855,60 @@ describe('FormArray', () => {
|
||||||
a = new FormArray([c1, c2]);
|
a = new FormArray([c1, c2]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fire an event after the value has been updated',
|
it('should fire an event after the value has been updated', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
a.valueChanges.subscribe({
|
||||||
a.valueChanges.subscribe({
|
next: (value: any) => {
|
||||||
next: (value: any) => {
|
expect(a.value).toEqual(['new1', 'old2']);
|
||||||
expect(a.value).toEqual(['new1', 'old2']);
|
expect(value).toEqual(['new1', 'old2']);
|
||||||
expect(value).toEqual(['new1', 'old2']);
|
done();
|
||||||
async.done();
|
}
|
||||||
}
|
});
|
||||||
});
|
c1.setValue('new1');
|
||||||
c1.setValue('new1');
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should fire an event after the control\'s observable fired an event',
|
it('should fire an event after the control\'s observable fired an event', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
let controlCallbackIsCalled = false;
|
||||||
let controlCallbackIsCalled = false;
|
|
||||||
|
|
||||||
|
|
||||||
c1.valueChanges.subscribe({
|
c1.valueChanges.subscribe({
|
||||||
next: (value: any) => {
|
next: (value: any) => {
|
||||||
controlCallbackIsCalled = true;
|
controlCallbackIsCalled = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
a.valueChanges.subscribe({
|
a.valueChanges.subscribe({
|
||||||
next: (value: any) => {
|
next: (value: any) => {
|
||||||
expect(controlCallbackIsCalled).toBe(true);
|
expect(controlCallbackIsCalled).toBe(true);
|
||||||
async.done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
c1.setValue('new1');
|
c1.setValue('new1');
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should fire an event when a control is removed',
|
it('should fire an event when a control is removed', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
a.valueChanges.subscribe({
|
||||||
a.valueChanges.subscribe({
|
next: (value: any) => {
|
||||||
next: (value: any) => {
|
expect(value).toEqual(['old1']);
|
||||||
expect(value).toEqual(['old1']);
|
done();
|
||||||
async.done();
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
a.removeAt(1);
|
a.removeAt(1);
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should fire an event when a control is added',
|
it('should fire an event when a control is added', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
a.removeAt(1);
|
||||||
a.removeAt(1);
|
|
||||||
|
|
||||||
a.valueChanges.subscribe({
|
a.valueChanges.subscribe({
|
||||||
next: (value: any) => {
|
next: (value: any) => {
|
||||||
expect(value).toEqual(['old1', 'old2']);
|
expect(value).toEqual(['old1', 'old2']);
|
||||||
async.done();
|
done();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
a.push(c2);
|
a.push(c2);
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('get', () => {
|
describe('get', () => {
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
import {fakeAsync, tick} from '@angular/core/testing';
|
import {fakeAsync, tick} from '@angular/core/testing';
|
||||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {FormBuilder, Validators} from '@angular/forms';
|
import {FormBuilder, Validators} from '@angular/forms';
|
||||||
import {of} from 'rxjs';
|
import {of} from 'rxjs';
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {fakeAsync, tick} from '@angular/core/testing';
|
import {fakeAsync, tick} from '@angular/core/testing';
|
||||||
import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {FormControl, FormGroup, Validators} from '@angular/forms';
|
import {FormControl, FormGroup, Validators} from '@angular/forms';
|
||||||
|
|
||||||
import {FormArray} from '@angular/forms/src/model';
|
import {FormArray} from '@angular/forms/src/model';
|
||||||
|
@ -857,17 +856,16 @@ describe('FormControl', () => {
|
||||||
c = new FormControl('old', Validators.required);
|
c = new FormControl('old', Validators.required);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fire an event after the value has been updated',
|
it('should fire an event after the value has been updated', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
c.valueChanges.subscribe({
|
||||||
c.valueChanges.subscribe({
|
next: (value: any) => {
|
||||||
next: (value: any) => {
|
expect(c.value).toEqual('new');
|
||||||
expect(c.value).toEqual('new');
|
expect(value).toEqual('new');
|
||||||
expect(value).toEqual('new');
|
done();
|
||||||
async.done();
|
}
|
||||||
}
|
});
|
||||||
});
|
c.setValue('new');
|
||||||
c.setValue('new');
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should fire an event after the status has been updated to invalid', fakeAsync(() => {
|
it('should fire an event after the status has been updated to invalid', fakeAsync(() => {
|
||||||
c.statusChanges.subscribe({
|
c.statusChanges.subscribe({
|
||||||
|
@ -911,27 +909,25 @@ describe('FormControl', () => {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// TODO: remove the if statement after making observable delivery sync
|
// TODO: remove the if statement after making observable delivery sync
|
||||||
it('should update set errors and status before emitting an event',
|
it('should update set errors and status before emitting an event', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
c.valueChanges.subscribe((value: any /** TODO #9100 */) => {
|
||||||
c.valueChanges.subscribe((value: any /** TODO #9100 */) => {
|
expect(c.valid).toEqual(false);
|
||||||
expect(c.valid).toEqual(false);
|
expect(c.errors).toEqual({'required': true});
|
||||||
expect(c.errors).toEqual({'required': true});
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
c.setValue('');
|
||||||
c.setValue('');
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should return a cold observable',
|
it('should return a cold observable', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
c.setValue('will be ignored');
|
||||||
c.setValue('will be ignored');
|
c.valueChanges.subscribe({
|
||||||
c.valueChanges.subscribe({
|
next: (value: any) => {
|
||||||
next: (value: any) => {
|
expect(value).toEqual('new');
|
||||||
expect(value).toEqual('new');
|
done();
|
||||||
async.done();
|
}
|
||||||
}
|
});
|
||||||
});
|
c.setValue('new');
|
||||||
c.setValue('new');
|
});
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('setErrors', () => {
|
describe('setErrors', () => {
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {fakeAsync, tick, waitForAsync} from '@angular/core/testing';
|
import {fakeAsync, tick, waitForAsync} from '@angular/core/testing';
|
||||||
import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors, Validators} from '@angular/forms';
|
import {AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors, Validators} from '@angular/forms';
|
||||||
import {of} from 'rxjs';
|
import {of} from 'rxjs';
|
||||||
|
|
||||||
|
@ -822,20 +821,19 @@ describe('FormGroup', () => {
|
||||||
|
|
||||||
|
|
||||||
// TODO(kara): update these tests to use fake Async
|
// TODO(kara): update these tests to use fake Async
|
||||||
it('should fire a statusChange if child has async validation change',
|
it('should fire a statusChange if child has async validation change', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const loggedValues: string[] = [];
|
||||||
const loggedValues: string[] = [];
|
group.statusChanges.subscribe({
|
||||||
group.statusChanges.subscribe({
|
next: (status: string) => {
|
||||||
next: (status: string) => {
|
loggedValues.push(status);
|
||||||
loggedValues.push(status);
|
if (loggedValues.length === 2) {
|
||||||
if (loggedValues.length === 2) {
|
expect(loggedValues).toEqual(['PENDING', 'INVALID']);
|
||||||
expect(loggedValues).toEqual(['PENDING', 'INVALID']);
|
}
|
||||||
}
|
done();
|
||||||
async.done();
|
}
|
||||||
}
|
});
|
||||||
});
|
control.setValue('');
|
||||||
control.setValue('');
|
});
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getError', () => {
|
describe('getError', () => {
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
import {ɵgetDOM as getDOM} from '@angular/common';
|
import {ɵgetDOM as getDOM} from '@angular/common';
|
||||||
import {Component, Directive, forwardRef, Input, NgModule, OnDestroy, Type} from '@angular/core';
|
import {Component, Directive, forwardRef, Input, NgModule, OnDestroy, Type} from '@angular/core';
|
||||||
import {ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
|
import {ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
|
||||||
import {expect} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {AbstractControl, AsyncValidator, AsyncValidatorFn, COMPOSITION_BUFFER_MODE, ControlValueAccessor, DefaultValueAccessor, FormArray, FormControl, FormControlDirective, FormControlName, FormGroup, FormGroupDirective, FormsModule, MaxValidator, MinValidator, NG_ASYNC_VALIDATORS, NG_VALIDATORS, NG_VALUE_ACCESSOR, ReactiveFormsModule, Validator, Validators} from '@angular/forms';
|
import {AbstractControl, AsyncValidator, AsyncValidatorFn, COMPOSITION_BUFFER_MODE, ControlValueAccessor, DefaultValueAccessor, FormArray, FormControl, FormControlDirective, FormControlName, FormGroup, FormGroupDirective, FormsModule, MaxValidator, MinValidator, NG_ASYNC_VALIDATORS, NG_VALIDATORS, NG_VALUE_ACCESSOR, ReactiveFormsModule, Validator, Validators} from '@angular/forms';
|
||||||
import {By} from '@angular/platform-browser/src/dom/debug/by';
|
import {By} from '@angular/platform-browser/src/dom/debug/by';
|
||||||
import {dispatchEvent, sortedClassList} from '@angular/platform-browser/testing/src/browser_util';
|
import {dispatchEvent, sortedClassList} from '@angular/platform-browser/testing/src/browser_util';
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
/**
|
|
||||||
* @license
|
|
||||||
* Copyright Google LLC 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 {ChangeDetectorRef} from '@angular/core/src/change_detection/change_detector_ref';
|
|
||||||
import {SpyObject} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
export class SpyChangeDetectorRef extends SpyObject {
|
|
||||||
constructor() {
|
|
||||||
super(ChangeDetectorRef);
|
|
||||||
this.spy('markForCheck');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class SpyNgControl extends SpyObject {
|
|
||||||
path = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
export class SpyValueAccessor extends SpyObject {
|
|
||||||
writeValue: any;
|
|
||||||
}
|
|
|
@ -7,7 +7,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {fakeAsync, tick} from '@angular/core/testing';
|
import {fakeAsync, tick} from '@angular/core/testing';
|
||||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {AbstractControl, AsyncValidator, AsyncValidatorFn, FormArray, FormControl, ValidationErrors, ValidatorFn, Validators} from '@angular/forms';
|
import {AbstractControl, AsyncValidator, AsyncValidatorFn, FormArray, FormControl, ValidationErrors, ValidatorFn, Validators} from '@angular/forms';
|
||||||
import {Observable, of, timer} from 'rxjs';
|
import {Observable, of, timer} from 'rxjs';
|
||||||
import {first, map} from 'rxjs/operators';
|
import {first, map} from 'rxjs/operators';
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {ResourceLoaderImpl} from '@angular/platform-browser-dynamic/src/resource_loader/resource_loader_impl';
|
import {ResourceLoaderImpl} from '@angular/platform-browser-dynamic/src/resource_loader/resource_loader_impl';
|
||||||
|
|
||||||
if (isBrowser) {
|
if (isBrowser) {
|
||||||
|
@ -26,21 +25,19 @@ if (isBrowser) {
|
||||||
resourceLoader = new ResourceLoaderImpl();
|
resourceLoader = new ResourceLoaderImpl();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should resolve the Promise with the file content on success',
|
it('should resolve the Promise with the file content on success', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
resourceLoader.get(url200).then((text) => {
|
||||||
resourceLoader.get(url200).then((text) => {
|
expect(text.trim()).toEqual('<p>hey</p>');
|
||||||
expect(text.trim()).toEqual('<p>hey</p>');
|
done();
|
||||||
async.done();
|
});
|
||||||
});
|
}, 10000);
|
||||||
}), 10000);
|
|
||||||
|
|
||||||
it('should reject the Promise on failure',
|
it('should reject the Promise on failure', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
resourceLoader.get(url404).catch((e) => {
|
||||||
resourceLoader.get(url404).catch((e) => {
|
expect(e).toEqual(`Failed to load ${url404}`);
|
||||||
expect(e).toEqual(`Failed to load ${url404}`);
|
done();
|
||||||
async.done();
|
return null;
|
||||||
return null;
|
});
|
||||||
});
|
}, 10000);
|
||||||
}), 10000);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,8 @@ import {ApplicationRef, destroyPlatform} from '@angular/core/src/application_ref
|
||||||
import {Console} from '@angular/core/src/console';
|
import {Console} from '@angular/core/src/console';
|
||||||
import {ComponentRef} from '@angular/core/src/linker/component_factory';
|
import {ComponentRef} from '@angular/core/src/linker/component_factory';
|
||||||
import {Testability, TestabilityRegistry} from '@angular/core/src/testability/testability';
|
import {Testability, TestabilityRegistry} from '@angular/core/src/testability/testability';
|
||||||
import {afterEach, AsyncTestCompleter, beforeEach, beforeEachProviders, describe, inject, it, Log} from '@angular/core/testing/src/testing_internal';
|
import {inject, TestBed} from '@angular/core/testing';
|
||||||
|
import {Log} from '@angular/core/testing/src/testing_internal';
|
||||||
import {BrowserModule} from '@angular/platform-browser';
|
import {BrowserModule} from '@angular/platform-browser';
|
||||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||||
|
@ -61,10 +62,6 @@ class HelloRootCmp4 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({selector: 'hello-app'})
|
|
||||||
class HelloRootMissingTemplate {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Directive({selector: 'hello-app'})
|
@Directive({selector: 'hello-app'})
|
||||||
class HelloRootDirectiveIsNotCmp {
|
class HelloRootDirectiveIsNotCmp {
|
||||||
}
|
}
|
||||||
|
@ -81,29 +78,6 @@ class HelloOnDestroyTickCmp implements OnDestroy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({selector: 'hello-app', templateUrl: './sometemplate.html'})
|
|
||||||
class HelloUrlCmp {
|
|
||||||
greeting = 'hello';
|
|
||||||
}
|
|
||||||
|
|
||||||
@Directive({selector: '[someDir]', host: {'[title]': 'someDir'}})
|
|
||||||
class SomeDirective {
|
|
||||||
// TODO(issue/24571): remove '!'.
|
|
||||||
@Input() someDir!: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Pipe({name: 'somePipe'})
|
|
||||||
class SomePipe {
|
|
||||||
transform(value: string): any {
|
|
||||||
return `transformed ${value}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Component({selector: 'hello-app', template: `<div [someDir]="'someValue' | somePipe"></div>`})
|
|
||||||
class HelloCmpUsingPlatformDirectiveAndPipe {
|
|
||||||
show: boolean = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Component({selector: 'hello-app', template: '<some-el [someProp]="true">hello world!</some-el>'})
|
@Component({selector: 'hello-app', template: '<some-el [someProp]="true">hello world!</some-el>'})
|
||||||
class HelloCmpUsingCustomElement {
|
class HelloCmpUsingCustomElement {
|
||||||
}
|
}
|
||||||
|
@ -150,8 +124,8 @@ function bootstrap(
|
||||||
if (isNode) return;
|
if (isNode) return;
|
||||||
let compilerConsole: DummyConsole;
|
let compilerConsole: DummyConsole;
|
||||||
|
|
||||||
beforeEachProviders(() => {
|
beforeEach(() => {
|
||||||
return [Log];
|
TestBed.configureTestingModule({providers: [Log]});
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(inject([DOCUMENT], (doc: any) => {
|
beforeEach(inject([DOCUMENT], (doc: any) => {
|
||||||
|
@ -175,35 +149,31 @@ function bootstrap(
|
||||||
|
|
||||||
afterEach(destroyPlatform);
|
afterEach(destroyPlatform);
|
||||||
|
|
||||||
// TODO(misko): can't use `modifiedInIvy.it` because the `it` is somehow special here.
|
modifiedInIvy('bootstrapping non-Component throws in View Engine')
|
||||||
modifiedInIvy('bootstrapping non-Component throws in View Engine').isEnabled &&
|
.it('should throw if bootstrapped Directive is not a Component', done => {
|
||||||
it('should throw if bootstrapped Directive is not a Component',
|
const logger = new MockConsole();
|
||||||
inject([AsyncTestCompleter], (done: AsyncTestCompleter) => {
|
const errorHandler = new ErrorHandler();
|
||||||
const logger = new MockConsole();
|
(errorHandler as any)._console = logger as any;
|
||||||
const errorHandler = new ErrorHandler();
|
expect(
|
||||||
(errorHandler as any)._console = logger as any;
|
() => bootstrap(
|
||||||
expect(
|
HelloRootDirectiveIsNotCmp, [{provide: ErrorHandler, useValue: errorHandler}]))
|
||||||
() => bootstrap(
|
.toThrowError(`HelloRootDirectiveIsNotCmp cannot be used as an entry component.`);
|
||||||
HelloRootDirectiveIsNotCmp, [{provide: ErrorHandler, useValue: errorHandler}]))
|
done();
|
||||||
.toThrowError(`HelloRootDirectiveIsNotCmp cannot be used as an entry component.`);
|
});
|
||||||
done.done();
|
|
||||||
}));
|
|
||||||
|
|
||||||
// TODO(misko): can't use `onlyInIvy.it` because the `it` is somehow special here.
|
onlyInIvy('bootstrapping non-Component rejects Promise in Ivy')
|
||||||
onlyInIvy('bootstrapping non-Component rejects Promise in Ivy').isEnabled &&
|
.it('should throw if bootstrapped Directive is not a Component', done => {
|
||||||
it('should throw if bootstrapped Directive is not a Component',
|
const logger = new MockConsole();
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const errorHandler = new ErrorHandler();
|
||||||
const logger = new MockConsole();
|
(errorHandler as any)._console = logger as any;
|
||||||
const errorHandler = new ErrorHandler();
|
bootstrap(HelloRootDirectiveIsNotCmp, [
|
||||||
(errorHandler as any)._console = logger as any;
|
{provide: ErrorHandler, useValue: errorHandler}
|
||||||
bootstrap(HelloRootDirectiveIsNotCmp, [
|
]).catch((error: Error) => {
|
||||||
{provide: ErrorHandler, useValue: errorHandler}
|
expect(error).toEqual(
|
||||||
]).catch((error: Error) => {
|
new Error(`HelloRootDirectiveIsNotCmp cannot be used as an entry component.`));
|
||||||
expect(error).toEqual(
|
done();
|
||||||
new Error(`HelloRootDirectiveIsNotCmp cannot be used as an entry component.`));
|
});
|
||||||
async.done();
|
});
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should retrieve sanitizer', inject([Injector], (injector: Injector) => {
|
it('should retrieve sanitizer', inject([Injector], (injector: Injector) => {
|
||||||
const sanitizer: Sanitizer|null = injector.get(Sanitizer, null);
|
const sanitizer: Sanitizer|null = injector.get(Sanitizer, null);
|
||||||
|
@ -218,92 +188,88 @@ function bootstrap(
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should throw if no element is found',
|
it('should throw if no element is found', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const logger = new MockConsole();
|
||||||
const logger = new MockConsole();
|
const errorHandler = new ErrorHandler();
|
||||||
const errorHandler = new ErrorHandler();
|
(errorHandler as any)._console = logger as any;
|
||||||
(errorHandler as any)._console = logger as any;
|
bootstrap(NonExistentComp, [
|
||||||
bootstrap(NonExistentComp, [
|
{provide: ErrorHandler, useValue: errorHandler}
|
||||||
{provide: ErrorHandler, useValue: errorHandler}
|
]).then(null, (reason) => {
|
||||||
]).then(null, (reason) => {
|
expect(reason.message).toContain('The selector "non-existent" did not match any elements');
|
||||||
expect(reason.message)
|
done();
|
||||||
.toContain('The selector "non-existent" did not match any elements');
|
return null;
|
||||||
async.done();
|
});
|
||||||
return null;
|
});
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should throw if no provider', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
it('should throw if no provider', done => {
|
||||||
const logger = new MockConsole();
|
const logger = new MockConsole();
|
||||||
const errorHandler = new ErrorHandler();
|
const errorHandler = new ErrorHandler();
|
||||||
(errorHandler as any)._console = logger as any;
|
(errorHandler as any)._console = logger as any;
|
||||||
|
|
||||||
class IDontExist {}
|
class IDontExist {}
|
||||||
|
|
||||||
@Component({selector: 'cmp', template: 'Cmp'})
|
@Component({selector: 'cmp', template: 'Cmp'})
|
||||||
class CustomCmp {
|
class CustomCmp {
|
||||||
constructor(iDontExist: IDontExist) {}
|
constructor(iDontExist: IDontExist) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'hello-app',
|
selector: 'hello-app',
|
||||||
template: '<cmp></cmp>',
|
template: '<cmp></cmp>',
|
||||||
})
|
})
|
||||||
class RootCmp {
|
class RootCmp {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NgModule({declarations: [CustomCmp], exports: [CustomCmp]})
|
@NgModule({declarations: [CustomCmp], exports: [CustomCmp]})
|
||||||
class CustomModule {
|
class CustomModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
bootstrap(RootCmp, [{provide: ErrorHandler, useValue: errorHandler}], [], [
|
bootstrap(RootCmp, [{provide: ErrorHandler, useValue: errorHandler}], [], [
|
||||||
CustomModule
|
CustomModule
|
||||||
]).then(null, (e: Error) => {
|
]).then(null, (e: Error) => {
|
||||||
let errorMsg: string;
|
let errorMsg: string;
|
||||||
if (ivyEnabled) {
|
if (ivyEnabled) {
|
||||||
errorMsg = `R3InjectorError(TestModule)[IDontExist -> IDontExist -> IDontExist]: \n`;
|
errorMsg = `R3InjectorError(TestModule)[IDontExist -> IDontExist -> IDontExist]: \n`;
|
||||||
} else {
|
} else {
|
||||||
errorMsg = `StaticInjectorError(TestModule)[CustomCmp -> IDontExist]: \n` +
|
errorMsg = `StaticInjectorError(TestModule)[CustomCmp -> IDontExist]: \n` +
|
||||||
' StaticInjectorError(Platform: core)[CustomCmp -> IDontExist]: \n' +
|
' StaticInjectorError(Platform: core)[CustomCmp -> IDontExist]: \n' +
|
||||||
' NullInjectorError: No provider for IDontExist!';
|
' NullInjectorError: No provider for IDontExist!';
|
||||||
}
|
}
|
||||||
expect(e.message).toContain(errorMsg);
|
expect(e.message).toContain(errorMsg);
|
||||||
async.done();
|
done();
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
|
||||||
if (getDOM().supportsDOMEvents) {
|
if (getDOM().supportsDOMEvents) {
|
||||||
it('should forward the error to promise when bootstrap fails',
|
it('should forward the error to promise when bootstrap fails', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const logger = new MockConsole();
|
||||||
const logger = new MockConsole();
|
const errorHandler = new ErrorHandler();
|
||||||
const errorHandler = new ErrorHandler();
|
(errorHandler as any)._console = logger as any;
|
||||||
(errorHandler as any)._console = logger as any;
|
|
||||||
|
|
||||||
const refPromise =
|
const refPromise =
|
||||||
bootstrap(NonExistentComp, [{provide: ErrorHandler, useValue: errorHandler}]);
|
bootstrap(NonExistentComp, [{provide: ErrorHandler, useValue: errorHandler}]);
|
||||||
refPromise.then(null, (reason: any) => {
|
refPromise.then(null, (reason: any) => {
|
||||||
expect(reason.message)
|
expect(reason.message)
|
||||||
.toContain('The selector "non-existent" did not match any elements');
|
.toContain('The selector "non-existent" did not match any elements');
|
||||||
async.done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should invoke the default exception handler when bootstrap fails',
|
it('should invoke the default exception handler when bootstrap fails', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const logger = new MockConsole();
|
||||||
const logger = new MockConsole();
|
const errorHandler = new ErrorHandler();
|
||||||
const errorHandler = new ErrorHandler();
|
(errorHandler as any)._console = logger as any;
|
||||||
(errorHandler as any)._console = logger as any;
|
|
||||||
|
|
||||||
const refPromise =
|
const refPromise =
|
||||||
bootstrap(NonExistentComp, [{provide: ErrorHandler, useValue: errorHandler}]);
|
bootstrap(NonExistentComp, [{provide: ErrorHandler, useValue: errorHandler}]);
|
||||||
refPromise.then(null, (reason) => {
|
refPromise.then(null, (reason) => {
|
||||||
expect(logger.res[0].join('#'))
|
expect(logger.res[0].join('#'))
|
||||||
.toContain('ERROR#Error: The selector "non-existent" did not match any elements');
|
.toContain('ERROR#Error: The selector "non-existent" did not match any elements');
|
||||||
async.done();
|
done();
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it('should create an injector promise', () => {
|
it('should create an injector promise', () => {
|
||||||
|
@ -311,26 +277,25 @@ function bootstrap(
|
||||||
expect(refPromise).toEqual(jasmine.any(Promise));
|
expect(refPromise).toEqual(jasmine.any(Promise));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set platform name to browser',
|
it('should set platform name to browser', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const refPromise = bootstrap(HelloRootCmp, testProviders);
|
||||||
const refPromise = bootstrap(HelloRootCmp, testProviders);
|
refPromise.then((ref) => {
|
||||||
refPromise.then((ref) => {
|
expect(isPlatformBrowser(ref.injector.get(PLATFORM_ID))).toBe(true);
|
||||||
expect(isPlatformBrowser(ref.injector.get(PLATFORM_ID))).toBe(true);
|
done();
|
||||||
async.done();
|
}, done.fail);
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should display hello world', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
it('should display hello world', done => {
|
||||||
const refPromise = bootstrap(HelloRootCmp, testProviders);
|
const refPromise = bootstrap(HelloRootCmp, testProviders);
|
||||||
refPromise.then((ref) => {
|
refPromise.then((ref) => {
|
||||||
expect(el).toHaveText('hello world!');
|
expect(el).toHaveText('hello world!');
|
||||||
expect(el.getAttribute('ng-version')).toEqual(VERSION.full);
|
expect(el.getAttribute('ng-version')).toEqual(VERSION.full);
|
||||||
async.done();
|
done();
|
||||||
});
|
}, done.fail);
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should throw a descriptive error if BrowserModule is installed again via a lazily loaded module',
|
it('should throw a descriptive error if BrowserModule is installed again via a lazily loaded module',
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
done => {
|
||||||
@NgModule({imports: [BrowserModule]})
|
@NgModule({imports: [BrowserModule]})
|
||||||
class AsyncModule {
|
class AsyncModule {
|
||||||
}
|
}
|
||||||
|
@ -343,158 +308,155 @@ function bootstrap(
|
||||||
`BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead.`);
|
`BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead.`);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(() => async.done(), err => async.fail(err));
|
.then(() => done(), err => done.fail(err));
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should support multiple calls to bootstrap',
|
it('should support multiple calls to bootstrap', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const refPromise1 = bootstrap(HelloRootCmp, testProviders);
|
||||||
const refPromise1 = bootstrap(HelloRootCmp, testProviders);
|
const refPromise2 = bootstrap(HelloRootCmp2, testProviders);
|
||||||
const refPromise2 = bootstrap(HelloRootCmp2, testProviders);
|
Promise.all([refPromise1, refPromise2]).then((refs) => {
|
||||||
Promise.all([refPromise1, refPromise2]).then((refs) => {
|
expect(el).toHaveText('hello world!');
|
||||||
expect(el).toHaveText('hello world!');
|
expect(el2).toHaveText('hello world, again!');
|
||||||
expect(el2).toHaveText('hello world, again!');
|
done();
|
||||||
async.done();
|
}, done.fail);
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should not crash if change detection is invoked when the root component is disposed',
|
it('should not crash if change detection is invoked when the root component is disposed',
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
done => {
|
||||||
bootstrap(HelloOnDestroyTickCmp, testProviders).then((ref) => {
|
bootstrap(HelloOnDestroyTickCmp, testProviders).then((ref) => {
|
||||||
expect(() => ref.destroy()).not.toThrow();
|
expect(() => ref.destroy()).not.toThrow();
|
||||||
async.done();
|
done();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should unregister change detectors when components are disposed',
|
it('should unregister change detectors when components are disposed', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
bootstrap(HelloRootCmp, testProviders).then((ref) => {
|
||||||
bootstrap(HelloRootCmp, testProviders).then((ref) => {
|
const appRef = ref.injector.get(ApplicationRef);
|
||||||
const appRef = ref.injector.get(ApplicationRef);
|
ref.destroy();
|
||||||
ref.destroy();
|
expect(() => appRef.tick()).not.toThrow();
|
||||||
expect(() => appRef.tick()).not.toThrow();
|
done();
|
||||||
async.done();
|
}, done.fail);
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
it('should make the provided bindings available to the application component',
|
it('should make the provided bindings available to the application component', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const refPromise = bootstrap(
|
||||||
const refPromise = bootstrap(
|
HelloRootCmp3, [testProviders, {provide: 'appBinding', useValue: 'BoundValue'}]);
|
||||||
HelloRootCmp3, [testProviders, {provide: 'appBinding', useValue: 'BoundValue'}]);
|
|
||||||
|
|
||||||
refPromise.then((ref) => {
|
refPromise.then((ref) => {
|
||||||
expect(ref.injector.get('appBinding')).toEqual('BoundValue');
|
expect(ref.injector.get('appBinding')).toEqual('BoundValue');
|
||||||
async.done();
|
done();
|
||||||
});
|
}, done.fail);
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should not override locale provided during bootstrap',
|
it('should not override locale provided during bootstrap', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const refPromise =
|
||||||
const refPromise =
|
bootstrap(HelloRootCmp, [testProviders], [{provide: LOCALE_ID, useValue: 'fr-FR'}]);
|
||||||
bootstrap(HelloRootCmp, [testProviders], [{provide: LOCALE_ID, useValue: 'fr-FR'}]);
|
|
||||||
|
|
||||||
refPromise.then(ref => {
|
refPromise.then(ref => {
|
||||||
expect(ref.injector.get(LOCALE_ID)).toEqual('fr-FR');
|
expect(ref.injector.get(LOCALE_ID)).toEqual('fr-FR');
|
||||||
async.done();
|
done();
|
||||||
});
|
}, done.fail);
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should avoid cyclic dependencies when root component requires Lifecycle through DI',
|
it('should avoid cyclic dependencies when root component requires Lifecycle through DI',
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
done => {
|
||||||
const refPromise = bootstrap(HelloRootCmp4, testProviders);
|
const refPromise = bootstrap(HelloRootCmp4, testProviders);
|
||||||
|
|
||||||
refPromise.then((ref) => {
|
refPromise.then((ref) => {
|
||||||
const appRef = ref.injector.get(ApplicationRef);
|
const appRef = ref.injector.get(ApplicationRef);
|
||||||
expect(appRef).toBeDefined();
|
expect(appRef).toBeDefined();
|
||||||
async.done();
|
done();
|
||||||
});
|
}, done.fail);
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should run platform initializers',
|
it('should run platform initializers', done => {
|
||||||
inject([Log, AsyncTestCompleter], (log: Log, async: AsyncTestCompleter) => {
|
inject([Log], (log: Log) => {
|
||||||
const p = createPlatformFactory(platformBrowserDynamic, 'someName', [
|
const p = createPlatformFactory(platformBrowserDynamic, 'someName', [
|
||||||
{provide: PLATFORM_INITIALIZER, useValue: log.fn('platform_init1'), multi: true},
|
{provide: PLATFORM_INITIALIZER, useValue: log.fn('platform_init1'), multi: true},
|
||||||
{provide: PLATFORM_INITIALIZER, useValue: log.fn('platform_init2'), multi: true}
|
{provide: PLATFORM_INITIALIZER, useValue: log.fn('platform_init2'), multi: true}
|
||||||
])();
|
])();
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [BrowserModule],
|
imports: [BrowserModule],
|
||||||
providers: [
|
providers: [
|
||||||
{provide: APP_INITIALIZER, useValue: log.fn('app_init1'), multi: true},
|
{provide: APP_INITIALIZER, useValue: log.fn('app_init1'), multi: true},
|
||||||
{provide: APP_INITIALIZER, useValue: log.fn('app_init2'), multi: true}
|
{provide: APP_INITIALIZER, useValue: log.fn('app_init2'), multi: true}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
class SomeModule {
|
class SomeModule {
|
||||||
ngDoBootstrap() {}
|
ngDoBootstrap() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(log.result()).toEqual('platform_init1; platform_init2');
|
expect(log.result()).toEqual('platform_init1; platform_init2');
|
||||||
log.clear();
|
log.clear();
|
||||||
p.bootstrapModule(SomeModule).then(() => {
|
p.bootstrapModule(SomeModule).then(() => {
|
||||||
expect(log.result()).toEqual('app_init1; app_init2');
|
expect(log.result()).toEqual('app_init1; app_init2');
|
||||||
async.done();
|
done();
|
||||||
});
|
}, done.fail);
|
||||||
}));
|
})();
|
||||||
|
});
|
||||||
|
|
||||||
it('should remove styles when transitioning from a server render',
|
it('should remove styles when transitioning from a server render', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
@Component({
|
||||||
@Component({
|
selector: 'root',
|
||||||
selector: 'root',
|
template: 'root',
|
||||||
template: 'root',
|
})
|
||||||
})
|
class RootCmp {
|
||||||
class RootCmp {
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
bootstrap: [RootCmp],
|
bootstrap: [RootCmp],
|
||||||
declarations: [RootCmp],
|
declarations: [RootCmp],
|
||||||
imports: [BrowserModule.withServerTransition({appId: 'my-app'})],
|
imports: [BrowserModule.withServerTransition({appId: 'my-app'})],
|
||||||
})
|
})
|
||||||
class TestModule {
|
class TestModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, set up styles to be removed.
|
// First, set up styles to be removed.
|
||||||
const dom = getDOM();
|
const dom = getDOM();
|
||||||
const platform = platformBrowserDynamic();
|
const platform = platformBrowserDynamic();
|
||||||
const document = platform.injector.get(DOCUMENT);
|
const document = platform.injector.get(DOCUMENT);
|
||||||
const style = dom.createElement('style', document);
|
const style = dom.createElement('style', document);
|
||||||
style.setAttribute('ng-transition', 'my-app');
|
style.setAttribute('ng-transition', 'my-app');
|
||||||
document.head.appendChild(style);
|
document.head.appendChild(style);
|
||||||
|
|
||||||
const root = dom.createElement('root', document);
|
const root = dom.createElement('root', document);
|
||||||
document.body.appendChild(root);
|
document.body.appendChild(root);
|
||||||
|
|
||||||
platform.bootstrapModule(TestModule).then(() => {
|
platform.bootstrapModule(TestModule).then(() => {
|
||||||
const styles: HTMLElement[] =
|
const styles: HTMLElement[] =
|
||||||
Array.prototype.slice.apply(document.getElementsByTagName('style') || []);
|
Array.prototype.slice.apply(document.getElementsByTagName('style') || []);
|
||||||
styles.forEach(style => {
|
styles.forEach(style => {
|
||||||
expect(style.getAttribute('ng-transition')).not.toBe('my-app');
|
expect(style.getAttribute('ng-transition')).not.toBe('my-app');
|
||||||
});
|
});
|
||||||
async.done();
|
done();
|
||||||
});
|
}, done.fail);
|
||||||
}));
|
});
|
||||||
|
|
||||||
it('should register each application with the testability registry',
|
it('should register each application with the testability registry', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const refPromise1: Promise<ComponentRef<any>> = bootstrap(HelloRootCmp, testProviders);
|
||||||
const refPromise1: Promise<ComponentRef<any>> = bootstrap(HelloRootCmp, testProviders);
|
const refPromise2: Promise<ComponentRef<any>> = bootstrap(HelloRootCmp2, testProviders);
|
||||||
const refPromise2: Promise<ComponentRef<any>> = bootstrap(HelloRootCmp2, testProviders);
|
|
||||||
|
|
||||||
Promise.all([refPromise1, refPromise2]).then((refs: ComponentRef<any>[]) => {
|
Promise.all([refPromise1, refPromise2]).then((refs: ComponentRef<any>[]) => {
|
||||||
const registry = refs[0].injector.get(TestabilityRegistry);
|
const registry = refs[0].injector.get(TestabilityRegistry);
|
||||||
const testabilities =
|
const testabilities =
|
||||||
[refs[0].injector.get(Testability), refs[1].injector.get(Testability)];
|
[refs[0].injector.get(Testability), refs[1].injector.get(Testability)];
|
||||||
Promise.all(testabilities).then((testabilities: Testability[]) => {
|
|
||||||
expect(registry.findTestabilityInTree(el)).toEqual(testabilities[0]);
|
|
||||||
expect(registry.findTestabilityInTree(el2)).toEqual(testabilities[1]);
|
|
||||||
async.done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should allow to pass schemas', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
Promise.all(testabilities).then((testabilities: Testability[]) => {
|
||||||
bootstrap(HelloCmpUsingCustomElement, testProviders).then((compRef) => {
|
expect(registry.findTestabilityInTree(el)).toEqual(testabilities[0]);
|
||||||
expect(el).toHaveText('hello world!');
|
expect(registry.findTestabilityInTree(el2)).toEqual(testabilities[1]);
|
||||||
async.done();
|
|
||||||
});
|
done();
|
||||||
}));
|
}, done.fail);
|
||||||
|
}, done.fail);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow to pass schemas', done => {
|
||||||
|
bootstrap(HelloCmpUsingCustomElement, testProviders).then(() => {
|
||||||
|
expect(el).toHaveText('hello world!');
|
||||||
|
done();
|
||||||
|
}, done.fail);
|
||||||
|
});
|
||||||
|
|
||||||
describe('change detection', () => {
|
describe('change detection', () => {
|
||||||
const log: string[] = [];
|
const log: string[] = [];
|
||||||
|
@ -529,7 +491,7 @@ function bootstrap(
|
||||||
}
|
}
|
||||||
|
|
||||||
it('should be triggered for all bootstrapped components in case change happens in one of them',
|
it('should be triggered for all bootstrapped components in case change happens in one of them',
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
done => {
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [BrowserModule],
|
imports: [BrowserModule],
|
||||||
declarations: [CompA, CompB],
|
declarations: [CompA, CompB],
|
||||||
|
@ -551,31 +513,30 @@ function bootstrap(
|
||||||
expect(log).toContain('CompA:ngDoCheck');
|
expect(log).toContain('CompA:ngDoCheck');
|
||||||
expect(log).toContain('CompB:ngDoCheck');
|
expect(log).toContain('CompB:ngDoCheck');
|
||||||
|
|
||||||
async.done();
|
done();
|
||||||
});
|
}, done.fail);
|
||||||
}));
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should work in isolation for each component bootstrapped individually',
|
it('should work in isolation for each component bootstrapped individually', done => {
|
||||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
const refPromise1 = bootstrap(CompA);
|
||||||
const refPromise1 = bootstrap(CompA);
|
const refPromise2 = bootstrap(CompB);
|
||||||
const refPromise2 = bootstrap(CompB);
|
Promise.all([refPromise1, refPromise2]).then((refs) => {
|
||||||
Promise.all([refPromise1, refPromise2]).then((refs) => {
|
log.length = 0;
|
||||||
log.length = 0;
|
el.querySelectorAll('#button-a')[0].click();
|
||||||
el.querySelectorAll('#button-a')[0].click();
|
expect(log).toContain('CompA:onClick');
|
||||||
expect(log).toContain('CompA:onClick');
|
expect(log).toContain('CompA:ngDoCheck');
|
||||||
expect(log).toContain('CompA:ngDoCheck');
|
expect(log).not.toContain('CompB:ngDoCheck');
|
||||||
expect(log).not.toContain('CompB:ngDoCheck');
|
|
||||||
|
|
||||||
log.length = 0;
|
log.length = 0;
|
||||||
el2.querySelectorAll('#button-b')[0].click();
|
el2.querySelectorAll('#button-b')[0].click();
|
||||||
expect(log).toContain('CompB:onClick');
|
expect(log).toContain('CompB:onClick');
|
||||||
expect(log).toContain('CompB:ngDoCheck');
|
expect(log).toContain('CompB:ngDoCheck');
|
||||||
expect(log).not.toContain('CompA:ngDoCheck');
|
expect(log).not.toContain('CompA:ngDoCheck');
|
||||||
|
|
||||||
async.done();
|
done();
|
||||||
});
|
}, done.fail);
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
/**
|
|
||||||
* @license
|
|
||||||
* Copyright Google LLC 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 {Injector, ɵglobal as global} from '@angular/core';
|
|
||||||
import {ApplicationRef} from '@angular/core/src/application_ref';
|
|
||||||
import {SpyObject} from '@angular/core/testing/src/testing_internal';
|
|
||||||
|
|
||||||
export class SpyApplicationRef extends SpyObject {
|
|
||||||
constructor() {
|
|
||||||
super(ApplicationRef);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class SpyComponentRef extends SpyObject {
|
|
||||||
injector: any /** TODO #9100 */;
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
this.injector =
|
|
||||||
Injector.create([{provide: ApplicationRef, useClass: SpyApplicationRef, deps: []}]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function callNgProfilerTimeChangeDetection(config?: any /** TODO #9100 */): void {
|
|
||||||
(<any>global).ng.profiler.timeChangeDetection(config);
|
|
||||||
}
|
|
|
@ -6,15 +6,22 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {ApplicationRef, Injector, ɵglobal as global} from '@angular/core';
|
||||||
import {disableDebugTools, enableDebugTools} from '@angular/platform-browser';
|
import {disableDebugTools, enableDebugTools} from '@angular/platform-browser';
|
||||||
|
|
||||||
import {callNgProfilerTimeChangeDetection, SpyComponentRef} from './spies';
|
|
||||||
|
|
||||||
{
|
{
|
||||||
describe('profiler', () => {
|
describe('profiler', () => {
|
||||||
if (isNode) return;
|
if (isNode) return;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
enableDebugTools((<any>new SpyComponentRef()));
|
enableDebugTools({
|
||||||
|
injector: Injector.create([{
|
||||||
|
provide: ApplicationRef,
|
||||||
|
useValue: jasmine.createSpyObj(
|
||||||
|
'ApplicationRef', ['bootstrap', 'tick', 'attachView', 'detachView']),
|
||||||
|
deps: []
|
||||||
|
}])
|
||||||
|
} as any);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
@ -30,3 +37,7 @@ import {callNgProfilerTimeChangeDetection, SpyComponentRef} from './spies';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function callNgProfilerTimeChangeDetection(config?: any /** TODO #9100 */): void {
|
||||||
|
(<any>global).ng.profiler.timeChangeDetection(config);
|
||||||
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
import {ɵgetDOM as getDOM} from '@angular/common';
|
import {ɵgetDOM as getDOM} from '@angular/common';
|
||||||
import {NgZone} from '@angular/core/src/zone/ng_zone';
|
import {NgZone} from '@angular/core/src/zone/ng_zone';
|
||||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {DomEventsPlugin} from '@angular/platform-browser/src/dom/events/dom_events';
|
import {DomEventsPlugin} from '@angular/platform-browser/src/dom/events/dom_events';
|
||||||
import {EventManager, EventManagerPlugin} from '@angular/platform-browser/src/dom/events/event_manager';
|
import {EventManager, EventManagerPlugin} from '@angular/platform-browser/src/dom/events/event_manager';
|
||||||
import {createMouseEvent, el} from '../../../testing/src/browser_util';
|
import {createMouseEvent, el} from '../../../testing/src/browser_util';
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
*/
|
*/
|
||||||
import {NgZone} from '@angular/core';
|
import {NgZone} from '@angular/core';
|
||||||
import {fakeAsync, inject, tick} from '@angular/core/testing';
|
import {fakeAsync, inject, tick} from '@angular/core/testing';
|
||||||
import {afterEach, beforeEach, describe, expect, it,} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {EventManager} from '@angular/platform-browser';
|
import {EventManager} from '@angular/platform-browser';
|
||||||
import {HammerGestureConfig, HammerGesturesPlugin,} from '@angular/platform-browser/src/dom/events/hammer_gestures';
|
import {HammerGestureConfig, HammerGesturesPlugin,} from '@angular/platform-browser/src/dom/events/hammer_gestures';
|
||||||
|
|
||||||
|
@ -58,7 +57,7 @@ import {HammerGestureConfig, HammerGesturesPlugin,} from '@angular/platform-brow
|
||||||
let originalHammerGlobal: any;
|
let originalHammerGlobal: any;
|
||||||
|
|
||||||
// Fake Hammer instance ("mc") used to test the underlying event registration.
|
// Fake Hammer instance ("mc") used to test the underlying event registration.
|
||||||
let fakeHammerInstance: {on: () => void, off: () => void};
|
let fakeHammerInstance: {on: jasmine.Spy, off: jasmine.Spy};
|
||||||
|
|
||||||
// Inject the NgZone so that we can make it available to the plugin through a fake
|
// Inject the NgZone so that we can make it available to the plugin through a fake
|
||||||
// EventManager.
|
// EventManager.
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {KeyEventsPlugin} from '@angular/platform-browser/src/dom/events/key_events';
|
import {KeyEventsPlugin} from '@angular/platform-browser/src/dom/events/key_events';
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {ɵgetDOM as getDOM} from '@angular/common';
|
import {ɵgetDOM as getDOM} from '@angular/common';
|
||||||
import {beforeEach, describe, it} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {DomSharedStylesHost} from '@angular/platform-browser/src/dom/shared_styles_host';
|
import {DomSharedStylesHost} from '@angular/platform-browser/src/dom/shared_styles_host';
|
||||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||||
|
|
||||||
|
|
|
@ -7,15 +7,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {SecurityContext} from '@angular/core';
|
import {SecurityContext} from '@angular/core';
|
||||||
import * as t from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {DomSanitizerImpl} from '@angular/platform-browser/src/security/dom_sanitization_service';
|
import {DomSanitizerImpl} from '@angular/platform-browser/src/security/dom_sanitization_service';
|
||||||
|
|
||||||
{
|
{
|
||||||
t.describe('DOM Sanitization Service', () => {
|
describe('DOM Sanitization Service', () => {
|
||||||
t.it('accepts resource URL values for resource contexts', () => {
|
it('accepts resource URL values for resource contexts', () => {
|
||||||
const svc = new DomSanitizerImpl(null);
|
const svc = new DomSanitizerImpl(null);
|
||||||
const resourceUrl = svc.bypassSecurityTrustResourceUrl('http://hello/world');
|
const resourceUrl = svc.bypassSecurityTrustResourceUrl('http://hello/world');
|
||||||
t.expect(svc.sanitize(SecurityContext.URL, resourceUrl)).toBe('http://hello/world');
|
expect(svc.sanitize(SecurityContext.URL, resourceUrl)).toBe('http://hello/world');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -335,9 +335,9 @@ const bTok = new InjectionToken<string>('b');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('components with template url', () => {
|
describe('components with template url', () => {
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(async () => {
|
||||||
TestBed.configureTestingModule({declarations: [CompWithUrlTemplate]});
|
TestBed.configureTestingModule({declarations: [CompWithUrlTemplate]});
|
||||||
TestBed.compileComponents();
|
await TestBed.compileComponents();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
isBrowser &&
|
isBrowser &&
|
||||||
|
|
|
@ -10,7 +10,6 @@ import {CommonModule, Location} from '@angular/common';
|
||||||
import {SpyLocation} from '@angular/common/testing';
|
import {SpyLocation} from '@angular/common/testing';
|
||||||
import {ChangeDetectionStrategy, Component, Injectable, NgModule, NgModuleFactoryLoader, NgModuleRef, NgZone, OnDestroy, ViewChild, ɵConsole as Console, ɵNoopNgZone as NoopNgZone} from '@angular/core';
|
import {ChangeDetectionStrategy, Component, Injectable, NgModule, NgModuleFactoryLoader, NgModuleRef, NgZone, OnDestroy, ViewChild, ɵConsole as Console, ɵNoopNgZone as NoopNgZone} from '@angular/core';
|
||||||
import {ComponentFixture, fakeAsync, inject, TestBed, tick} from '@angular/core/testing';
|
import {ComponentFixture, fakeAsync, inject, TestBed, tick} from '@angular/core/testing';
|
||||||
import {describe} from '@angular/core/testing/src/testing_internal';
|
|
||||||
import {By} from '@angular/platform-browser/src/dom/debug/by';
|
import {By} from '@angular/platform-browser/src/dom/debug/by';
|
||||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||||
import {ActivatedRoute, ActivatedRouteSnapshot, ActivationEnd, ActivationStart, CanActivate, CanDeactivate, ChildActivationEnd, ChildActivationStart, DefaultUrlSerializer, DetachedRouteHandle, Event, GuardsCheckEnd, GuardsCheckStart, Navigation, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, ParamMap, Params, PreloadAllModules, PreloadingStrategy, PRIMARY_OUTLET, Resolve, ResolveEnd, ResolveStart, RouteConfigLoadEnd, RouteConfigLoadStart, Router, RouteReuseStrategy, RouterEvent, RouterLink, RouterLinkWithHref, RouterModule, RouterPreloader, RouterStateSnapshot, RoutesRecognized, RunGuardsAndResolvers, UrlHandlingStrategy, UrlSegmentGroup, UrlSerializer, UrlTree} from '@angular/router';
|
import {ActivatedRoute, ActivatedRouteSnapshot, ActivationEnd, ActivationStart, CanActivate, CanDeactivate, ChildActivationEnd, ChildActivationStart, DefaultUrlSerializer, DetachedRouteHandle, Event, GuardsCheckEnd, GuardsCheckStart, Navigation, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, ParamMap, Params, PreloadAllModules, PreloadingStrategy, PRIMARY_OUTLET, Resolve, ResolveEnd, ResolveStart, RouteConfigLoadEnd, RouteConfigLoadStart, Router, RouteReuseStrategy, RouterEvent, RouterLink, RouterLinkWithHref, RouterModule, RouterPreloader, RouterStateSnapshot, RoutesRecognized, RunGuardsAndResolvers, UrlHandlingStrategy, UrlSegmentGroup, UrlSerializer, UrlTree} from '@angular/router';
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
// Tun on full stack traces in errors to help debugging
|
// Tun on full stack traces in errors to help debugging
|
||||||
Error.stackTraceLimit = Infinity;
|
Error.stackTraceLimit = Infinity;
|
||||||
|
|
||||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 100;
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 3000;
|
||||||
|
|
||||||
// Cancel Karma's synchronous start,
|
// Cancel Karma's synchronous start,
|
||||||
// we will call `__karma__.start()` later, once all the specs are loaded.
|
// we will call `__karma__.start()` later, once all the specs are loaded.
|
||||||
|
|
Loading…
Reference in New Issue