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
|
||||
*/
|
||||
|
||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
import {Injector, Metric, MultiMetric} from '../../index';
|
||||
|
||||
(function() {
|
||||
|
@ -22,29 +20,27 @@ function createMetric(ids: any[]) {
|
|||
}
|
||||
|
||||
describe('multi metric', () => {
|
||||
it('should merge descriptions', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createMetric(['m1', 'm2']).then((m) => {
|
||||
expect(m.describe()).toEqual({'m1': 'describe', 'm2': 'describe'});
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should merge descriptions', done => {
|
||||
createMetric(['m1', 'm2']).then((m) => {
|
||||
expect(m.describe()).toEqual({'m1': 'describe', 'm2': 'describe'});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should merge all beginMeasure calls',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createMetric(['m1', 'm2']).then((m) => m.beginMeasure()).then((values) => {
|
||||
expect(values).toEqual(['m1_beginMeasure', 'm2_beginMeasure']);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should merge all beginMeasure calls', done => {
|
||||
createMetric(['m1', 'm2']).then((m) => m.beginMeasure()).then((values) => {
|
||||
expect(values).toEqual(['m1_beginMeasure', 'm2_beginMeasure']);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
[false, true].forEach((restartFlag) => {
|
||||
it(`should merge all endMeasure calls for restart=${restartFlag}`,
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createMetric(['m1', 'm2']).then((m) => m.endMeasure(restartFlag)).then((values) => {
|
||||
expect(values).toEqual({'m1': {'restart': restartFlag}, 'm2': {'restart': restartFlag}});
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it(`should merge all endMeasure calls for restart=${restartFlag}`, done => {
|
||||
createMetric(['m1', 'm2']).then((m) => m.endMeasure(restartFlag)).then((values) => {
|
||||
expect(values).toEqual({'m1': {'restart': restartFlag}, 'm2': {'restart': restartFlag}});
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
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 {TraceEventFactory} from '../trace_event_factory';
|
||||
|
@ -130,152 +129,145 @@ describe('perflog metric', () => {
|
|||
});
|
||||
|
||||
describe('beginMeasure', () => {
|
||||
it('should not force gc and mark the timeline',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const metric = createMetric([[]], null!);
|
||||
metric.beginMeasure().then((_) => {
|
||||
expect(commandLog).toEqual([['timeBegin', 'benchpress0']]);
|
||||
it('should not force gc and mark the timeline', done => {
|
||||
const metric = createMetric([[]], null!);
|
||||
metric.beginMeasure().then((_) => {
|
||||
expect(commandLog).toEqual([['timeBegin', 'benchpress0']]);
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should force gc and mark the timeline',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const metric = createMetric([[]], null!, {forceGc: true});
|
||||
metric.beginMeasure().then((_) => {
|
||||
expect(commandLog).toEqual([['gc'], ['timeBegin', 'benchpress0']]);
|
||||
it('should force gc and mark the timeline', done => {
|
||||
const metric = createMetric([[]], null!, {forceGc: true});
|
||||
metric.beginMeasure().then((_) => {
|
||||
expect(commandLog).toEqual([['gc'], ['timeBegin', 'benchpress0']]);
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('endMeasure', () => {
|
||||
it('should mark and aggregate events in between the marks',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const events = [[
|
||||
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 4),
|
||||
eventFactory.end('script', 6), eventFactory.markEnd('benchpress0', 10)
|
||||
]];
|
||||
const metric = createMetric(events, null!);
|
||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||
expect(commandLog).toEqual([
|
||||
['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', null], 'readPerfLog'
|
||||
]);
|
||||
expect(data['scriptTime']).toBe(2);
|
||||
it('should mark and aggregate events in between the marks', done => {
|
||||
const events = [[
|
||||
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 4),
|
||||
eventFactory.end('script', 6), eventFactory.markEnd('benchpress0', 10)
|
||||
]];
|
||||
const metric = createMetric(events, null!);
|
||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||
expect(commandLog).toEqual([
|
||||
['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', null], 'readPerfLog'
|
||||
]);
|
||||
expect(data['scriptTime']).toBe(2);
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should mark and aggregate events since navigationStart',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const events = [[
|
||||
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 4),
|
||||
eventFactory.end('script', 6), eventFactory.instant('navigationStart', 7),
|
||||
eventFactory.start('script', 8), eventFactory.end('script', 9),
|
||||
eventFactory.markEnd('benchpress0', 10)
|
||||
]];
|
||||
const metric = createMetric(events, null!);
|
||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||
expect(data['scriptTime']).toBe(1);
|
||||
it('should mark and aggregate events since navigationStart', done => {
|
||||
const events = [[
|
||||
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 4),
|
||||
eventFactory.end('script', 6), eventFactory.instant('navigationStart', 7),
|
||||
eventFactory.start('script', 8), eventFactory.end('script', 9),
|
||||
eventFactory.markEnd('benchpress0', 10)
|
||||
]];
|
||||
const metric = createMetric(events, null!);
|
||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||
expect(data['scriptTime']).toBe(1);
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should ignore navigationStart if ignoreNavigation is set',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const events = [[
|
||||
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 4),
|
||||
eventFactory.end('script', 6), eventFactory.instant('navigationStart', 7),
|
||||
eventFactory.start('script', 8), eventFactory.end('script', 9),
|
||||
eventFactory.markEnd('benchpress0', 10)
|
||||
]];
|
||||
const metric = createMetric(events, null!, {ignoreNavigation: true});
|
||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||
expect(data['scriptTime']).toBe(3);
|
||||
it('should ignore navigationStart if ignoreNavigation is set', done => {
|
||||
const events = [[
|
||||
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 4),
|
||||
eventFactory.end('script', 6), eventFactory.instant('navigationStart', 7),
|
||||
eventFactory.start('script', 8), eventFactory.end('script', 9),
|
||||
eventFactory.markEnd('benchpress0', 10)
|
||||
]];
|
||||
const metric = createMetric(events, null!, {ignoreNavigation: true});
|
||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||
expect(data['scriptTime']).toBe(3);
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should restart timing', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const events = [
|
||||
[
|
||||
eventFactory.markStart('benchpress0', 0),
|
||||
eventFactory.markEnd('benchpress0', 1),
|
||||
eventFactory.markStart('benchpress1', 2),
|
||||
],
|
||||
[eventFactory.markEnd('benchpress1', 3)]
|
||||
];
|
||||
const metric = createMetric(events, null!);
|
||||
metric.beginMeasure()
|
||||
.then((_) => metric.endMeasure(true))
|
||||
.then((_) => metric.endMeasure(true))
|
||||
.then((_) => {
|
||||
expect(commandLog).toEqual([
|
||||
['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', 'benchpress1'],
|
||||
'readPerfLog', ['timeEnd', 'benchpress1', 'benchpress2'], 'readPerfLog'
|
||||
]);
|
||||
it('should restart timing', done => {
|
||||
const events = [
|
||||
[
|
||||
eventFactory.markStart('benchpress0', 0),
|
||||
eventFactory.markEnd('benchpress0', 1),
|
||||
eventFactory.markStart('benchpress1', 2),
|
||||
],
|
||||
[eventFactory.markEnd('benchpress1', 3)]
|
||||
];
|
||||
const metric = createMetric(events, null!);
|
||||
metric.beginMeasure()
|
||||
.then((_) => metric.endMeasure(true))
|
||||
.then((_) => metric.endMeasure(true))
|
||||
.then((_) => {
|
||||
expect(commandLog).toEqual([
|
||||
['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', 'benchpress1'],
|
||||
'readPerfLog', ['timeEnd', 'benchpress1', 'benchpress2'], 'readPerfLog'
|
||||
]);
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should loop and aggregate until the end mark is present',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const events = [
|
||||
[eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 1)],
|
||||
[eventFactory.end('script', 2)],
|
||||
[
|
||||
eventFactory.start('script', 3), eventFactory.end('script', 5),
|
||||
eventFactory.markEnd('benchpress0', 10)
|
||||
]
|
||||
];
|
||||
const metric = createMetric(events, null!);
|
||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||
expect(commandLog).toEqual([
|
||||
['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', null], 'readPerfLog',
|
||||
['setTimeout', 100], 'readPerfLog', ['setTimeout', 100], 'readPerfLog'
|
||||
]);
|
||||
expect(data['scriptTime']).toBe(3);
|
||||
it('should loop and aggregate until the end mark is present', done => {
|
||||
const events = [
|
||||
[eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 1)],
|
||||
[eventFactory.end('script', 2)],
|
||||
[
|
||||
eventFactory.start('script', 3), eventFactory.end('script', 5),
|
||||
eventFactory.markEnd('benchpress0', 10)
|
||||
]
|
||||
];
|
||||
const metric = createMetric(events, null!);
|
||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||
expect(commandLog).toEqual([
|
||||
['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', null], 'readPerfLog',
|
||||
['setTimeout', 100], 'readPerfLog', ['setTimeout', 100], 'readPerfLog'
|
||||
]);
|
||||
expect(data['scriptTime']).toBe(3);
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should store events after the end mark for the next call',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const events = [
|
||||
[
|
||||
eventFactory.markStart('benchpress0', 0), eventFactory.markEnd('benchpress0', 1),
|
||||
eventFactory.markStart('benchpress1', 1), eventFactory.start('script', 1),
|
||||
eventFactory.end('script', 2)
|
||||
],
|
||||
[
|
||||
eventFactory.start('script', 3), eventFactory.end('script', 5),
|
||||
eventFactory.markEnd('benchpress1', 6)
|
||||
]
|
||||
];
|
||||
const metric = createMetric(events, null!);
|
||||
metric.beginMeasure()
|
||||
.then((_) => metric.endMeasure(true))
|
||||
.then((data) => {
|
||||
expect(data['scriptTime']).toBe(0);
|
||||
return metric.endMeasure(true);
|
||||
})
|
||||
.then((data) => {
|
||||
expect(commandLog).toEqual([
|
||||
['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', 'benchpress1'],
|
||||
'readPerfLog', ['timeEnd', 'benchpress1', 'benchpress2'], 'readPerfLog'
|
||||
]);
|
||||
expect(data['scriptTime']).toBe(3);
|
||||
it('should store events after the end mark for the next call', done => {
|
||||
const events = [
|
||||
[
|
||||
eventFactory.markStart('benchpress0', 0), eventFactory.markEnd('benchpress0', 1),
|
||||
eventFactory.markStart('benchpress1', 1), eventFactory.start('script', 1),
|
||||
eventFactory.end('script', 2)
|
||||
],
|
||||
[
|
||||
eventFactory.start('script', 3), eventFactory.end('script', 5),
|
||||
eventFactory.markEnd('benchpress1', 6)
|
||||
]
|
||||
];
|
||||
const metric = createMetric(events, null!);
|
||||
metric.beginMeasure()
|
||||
.then((_) => metric.endMeasure(true))
|
||||
.then((data) => {
|
||||
expect(data['scriptTime']).toBe(0);
|
||||
return metric.endMeasure(true);
|
||||
})
|
||||
.then((data) => {
|
||||
expect(commandLog).toEqual([
|
||||
['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', 'benchpress1'],
|
||||
'readPerfLog', ['timeEnd', 'benchpress1', 'benchpress2'], 'readPerfLog'
|
||||
]);
|
||||
expect(data['scriptTime']).toBe(3);
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('with forced gc', () => {
|
||||
let events: PerfLogEvent[][];
|
||||
|
@ -290,29 +282,28 @@ describe('perflog metric', () => {
|
|||
]];
|
||||
});
|
||||
|
||||
it('should measure forced gc', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const metric = createMetric(events, null!, {forceGc: true});
|
||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||
expect(commandLog).toEqual([
|
||||
['gc'], ['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', 'benchpress1'],
|
||||
'readPerfLog', ['gc'], ['timeEnd', 'benchpress1', null], 'readPerfLog'
|
||||
]);
|
||||
expect(data['forcedGcTime']).toBe(3);
|
||||
expect(data['forcedGcAmount']).toBe(1.5);
|
||||
it('should measure forced gc', done => {
|
||||
const metric = createMetric(events, null!, {forceGc: true});
|
||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||
expect(commandLog).toEqual([
|
||||
['gc'], ['timeBegin', 'benchpress0'], ['timeEnd', 'benchpress0', 'benchpress1'],
|
||||
'readPerfLog', ['gc'], ['timeEnd', 'benchpress1', null], 'readPerfLog'
|
||||
]);
|
||||
expect(data['forcedGcTime']).toBe(3);
|
||||
expect(data['forcedGcAmount']).toBe(1.5);
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should restart after the forced gc if needed',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const metric = createMetric(events, null!, {forceGc: true});
|
||||
metric.beginMeasure().then((_) => metric.endMeasure(true)).then((data) => {
|
||||
expect(commandLog[5]).toEqual(['timeEnd', 'benchpress1', 'benchpress2']);
|
||||
it('should restart after the forced gc if needed', done => {
|
||||
const metric = createMetric(events, null!, {forceGc: true});
|
||||
metric.beginMeasure().then((_) => metric.endMeasure(true)).then((data) => {
|
||||
expect(commandLog[5]).toEqual(['timeEnd', 'benchpress1', 'benchpress2']);
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -335,352 +326,314 @@ describe('perflog metric', () => {
|
|||
}
|
||||
|
||||
describe('frame metrics', () => {
|
||||
it('should calculate mean frame time',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.markStart('frameCapture', 0), eventFactory.instant('frame', 1),
|
||||
eventFactory.instant('frame', 3), eventFactory.instant('frame', 4),
|
||||
eventFactory.markEnd('frameCapture', 5)
|
||||
],
|
||||
{captureFrames: true})
|
||||
.then((data) => {
|
||||
expect(data['frameTime.mean']).toBe(((3 - 1) + (4 - 3)) / 2);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should calculate mean frame time', done => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.markStart('frameCapture', 0), eventFactory.instant('frame', 1),
|
||||
eventFactory.instant('frame', 3), eventFactory.instant('frame', 4),
|
||||
eventFactory.markEnd('frameCapture', 5)
|
||||
],
|
||||
{captureFrames: true})
|
||||
.then((data) => {
|
||||
expect(data['frameTime.mean']).toBe(((3 - 1) + (4 - 3)) / 2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw if no start event',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate([eventFactory.instant('frame', 4), eventFactory.markEnd('frameCapture', 5)], {
|
||||
captureFrames: true
|
||||
}).catch((err): any => {
|
||||
expect(() => {
|
||||
throw err;
|
||||
}).toThrowError('missing start event for frame capture');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should throw if no start event', done => {
|
||||
aggregate([eventFactory.instant('frame', 4), eventFactory.markEnd('frameCapture', 5)], {
|
||||
captureFrames: true
|
||||
}).catch((err): any => {
|
||||
expect(() => {
|
||||
throw err;
|
||||
}).toThrowError('missing start event for frame capture');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw if no end event',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate(
|
||||
[eventFactory.markStart('frameCapture', 3), eventFactory.instant('frame', 4)],
|
||||
{captureFrames: true})
|
||||
.catch((err): any => {
|
||||
expect(() => {
|
||||
throw err;
|
||||
}).toThrowError('missing end event for frame capture');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should throw if no end event', done => {
|
||||
aggregate([eventFactory.markStart('frameCapture', 3), eventFactory.instant('frame', 4)], {
|
||||
captureFrames: true
|
||||
}).catch((err): any => {
|
||||
expect(() => {
|
||||
throw err;
|
||||
}).toThrowError('missing end event for frame capture');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw if trying to capture twice',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.markStart('frameCapture', 3),
|
||||
eventFactory.markStart('frameCapture', 4)
|
||||
],
|
||||
{captureFrames: true})
|
||||
.catch((err): any => {
|
||||
expect(() => {
|
||||
throw err;
|
||||
}).toThrowError('can capture frames only once per benchmark run');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should throw if trying to capture twice', done => {
|
||||
aggregate(
|
||||
[eventFactory.markStart('frameCapture', 3), eventFactory.markStart('frameCapture', 4)],
|
||||
{captureFrames: true})
|
||||
.catch((err): any => {
|
||||
expect(() => {
|
||||
throw err;
|
||||
}).toThrowError('can capture frames only once per benchmark run');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw if trying to capture when frame capture is disabled',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate([eventFactory.markStart('frameCapture', 3)]).catch((err) => {
|
||||
expect(() => {
|
||||
throw err;
|
||||
})
|
||||
.toThrowError(
|
||||
'found start event for frame capture, but frame capture was not requested in benchpress');
|
||||
async.done();
|
||||
return null;
|
||||
});
|
||||
}));
|
||||
it('should throw if trying to capture when frame capture is disabled', done => {
|
||||
aggregate([eventFactory.markStart('frameCapture', 3)]).catch((err) => {
|
||||
expect(() => {
|
||||
throw err;
|
||||
})
|
||||
.toThrowError(
|
||||
'found start event for frame capture, but frame capture was not requested in benchpress');
|
||||
done();
|
||||
return null;
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw if frame capture is enabled, but nothing is captured',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate([], {captureFrames: true}).catch((err): any => {
|
||||
expect(() => {
|
||||
throw err;
|
||||
}).toThrowError('frame capture requested in benchpress, but no start event was found');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should throw if frame capture is enabled, but nothing is captured', done => {
|
||||
aggregate([], {captureFrames: true}).catch((err): any => {
|
||||
expect(() => {
|
||||
throw err;
|
||||
}).toThrowError('frame capture requested in benchpress, but no start event was found');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should calculate best and worst frame time',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.markStart('frameCapture', 0), eventFactory.instant('frame', 1),
|
||||
eventFactory.instant('frame', 9), eventFactory.instant('frame', 15),
|
||||
eventFactory.instant('frame', 18), eventFactory.instant('frame', 28),
|
||||
eventFactory.instant('frame', 32), eventFactory.markEnd('frameCapture', 10)
|
||||
],
|
||||
{captureFrames: true})
|
||||
.then((data) => {
|
||||
expect(data['frameTime.worst']).toBe(10);
|
||||
expect(data['frameTime.best']).toBe(3);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should calculate best and worst frame time', done => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.markStart('frameCapture', 0), eventFactory.instant('frame', 1),
|
||||
eventFactory.instant('frame', 9), eventFactory.instant('frame', 15),
|
||||
eventFactory.instant('frame', 18), eventFactory.instant('frame', 28),
|
||||
eventFactory.instant('frame', 32), eventFactory.markEnd('frameCapture', 10)
|
||||
],
|
||||
{captureFrames: true})
|
||||
.then((data) => {
|
||||
expect(data['frameTime.worst']).toBe(10);
|
||||
expect(data['frameTime.best']).toBe(3);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should calculate percentage of smoothness to be good',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.markStart('frameCapture', 0), eventFactory.instant('frame', 1),
|
||||
eventFactory.instant('frame', 2), eventFactory.instant('frame', 3),
|
||||
eventFactory.markEnd('frameCapture', 4)
|
||||
],
|
||||
{captureFrames: true})
|
||||
.then((data) => {
|
||||
expect(data['frameTime.smooth']).toBe(1.0);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should calculate percentage of smoothness to be good', done => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.markStart('frameCapture', 0), eventFactory.instant('frame', 1),
|
||||
eventFactory.instant('frame', 2), eventFactory.instant('frame', 3),
|
||||
eventFactory.markEnd('frameCapture', 4)
|
||||
],
|
||||
{captureFrames: true})
|
||||
.then((data) => {
|
||||
expect(data['frameTime.smooth']).toBe(1.0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should calculate percentage of smoothness to be bad',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.markStart('frameCapture', 0), eventFactory.instant('frame', 1),
|
||||
eventFactory.instant('frame', 2), eventFactory.instant('frame', 22),
|
||||
eventFactory.instant('frame', 23), eventFactory.instant('frame', 24),
|
||||
eventFactory.markEnd('frameCapture', 4)
|
||||
],
|
||||
{captureFrames: true})
|
||||
.then((data) => {
|
||||
expect(data['frameTime.smooth']).toBe(0.75);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should calculate percentage of smoothness to be bad', done => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.markStart('frameCapture', 0), eventFactory.instant('frame', 1),
|
||||
eventFactory.instant('frame', 2), eventFactory.instant('frame', 22),
|
||||
eventFactory.instant('frame', 23), eventFactory.instant('frame', 24),
|
||||
eventFactory.markEnd('frameCapture', 4)
|
||||
],
|
||||
{captureFrames: true})
|
||||
.then((data) => {
|
||||
expect(data['frameTime.smooth']).toBe(0.75);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should report a single interval',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate([
|
||||
eventFactory.start('script', 0), eventFactory.end('script', 5)
|
||||
]).then((data) => {
|
||||
expect(data['scriptTime']).toBe(5);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should report a single interval', done => {
|
||||
aggregate([eventFactory.start('script', 0), eventFactory.end('script', 5)]).then((data) => {
|
||||
expect(data['scriptTime']).toBe(5);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should sum up multiple intervals',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate([
|
||||
eventFactory.start('script', 0), eventFactory.end('script', 5),
|
||||
eventFactory.start('script', 10), eventFactory.end('script', 17)
|
||||
]).then((data) => {
|
||||
expect(data['scriptTime']).toBe(12);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should sum up multiple intervals', done => {
|
||||
aggregate([
|
||||
eventFactory.start('script', 0), eventFactory.end('script', 5),
|
||||
eventFactory.start('script', 10), eventFactory.end('script', 17)
|
||||
]).then((data) => {
|
||||
expect(data['scriptTime']).toBe(12);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should ignore not started intervals',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate([eventFactory.end('script', 10)]).then((data) => {
|
||||
expect(data['scriptTime']).toBe(0);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should ignore not started intervals', done => {
|
||||
aggregate([eventFactory.end('script', 10)]).then((data) => {
|
||||
expect(data['scriptTime']).toBe(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should ignore not ended intervals',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate([eventFactory.start('script', 10)]).then((data) => {
|
||||
expect(data['scriptTime']).toBe(0);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should ignore not ended intervals', done => {
|
||||
aggregate([eventFactory.start('script', 10)]).then((data) => {
|
||||
expect(data['scriptTime']).toBe(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should ignore nested intervals',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate([
|
||||
eventFactory.start('script', 0), eventFactory.start('script', 5),
|
||||
eventFactory.end('script', 10), eventFactory.end('script', 17)
|
||||
]).then((data) => {
|
||||
expect(data['scriptTime']).toBe(17);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should ignore nested intervals', done => {
|
||||
aggregate([
|
||||
eventFactory.start('script', 0), eventFactory.start('script', 5),
|
||||
eventFactory.end('script', 10), eventFactory.end('script', 17)
|
||||
]).then((data) => {
|
||||
expect(data['scriptTime']).toBe(17);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should ignore events from different processed as the start mark',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const otherProcessEventFactory = new TraceEventFactory('timeline', 'pid1');
|
||||
const metric = createMetric(
|
||||
[[
|
||||
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 0, null),
|
||||
eventFactory.end('script', 5, null),
|
||||
otherProcessEventFactory.start('script', 10, null),
|
||||
otherProcessEventFactory.end('script', 17, null),
|
||||
eventFactory.markEnd('benchpress0', 20)
|
||||
]],
|
||||
null!);
|
||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||
expect(data['scriptTime']).toBe(5);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should ignore events from different processed as the start mark', done => {
|
||||
const otherProcessEventFactory = new TraceEventFactory('timeline', 'pid1');
|
||||
const metric = createMetric(
|
||||
[[
|
||||
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 0, null),
|
||||
eventFactory.end('script', 5, null), otherProcessEventFactory.start('script', 10, null),
|
||||
otherProcessEventFactory.end('script', 17, null),
|
||||
eventFactory.markEnd('benchpress0', 20)
|
||||
]],
|
||||
null!);
|
||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||
expect(data['scriptTime']).toBe(5);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should mark a run as invalid if the start and end marks are different',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const otherProcessEventFactory = new TraceEventFactory('timeline', 'pid1');
|
||||
const metric = createMetric(
|
||||
[[
|
||||
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 0, null),
|
||||
eventFactory.end('script', 5, null),
|
||||
otherProcessEventFactory.start('script', 10, null),
|
||||
otherProcessEventFactory.end('script', 17, null),
|
||||
otherProcessEventFactory.markEnd('benchpress0', 20)
|
||||
]],
|
||||
null!);
|
||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||
expect(data['invalid']).toBe(1);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should mark a run as invalid if the start and end marks are different', done => {
|
||||
const otherProcessEventFactory = new TraceEventFactory('timeline', 'pid1');
|
||||
const metric = createMetric(
|
||||
[[
|
||||
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 0, null),
|
||||
eventFactory.end('script', 5, null), otherProcessEventFactory.start('script', 10, null),
|
||||
otherProcessEventFactory.end('script', 17, null),
|
||||
otherProcessEventFactory.markEnd('benchpress0', 20)
|
||||
]],
|
||||
null!);
|
||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||
expect(data['invalid']).toBe(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should support scriptTime metric',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate([
|
||||
eventFactory.start('script', 0), eventFactory.end('script', 5)
|
||||
]).then((data) => {
|
||||
expect(data['scriptTime']).toBe(5);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should support scriptTime metric', done => {
|
||||
aggregate([eventFactory.start('script', 0), eventFactory.end('script', 5)]).then((data) => {
|
||||
expect(data['scriptTime']).toBe(5);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should support renderTime metric',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate([
|
||||
eventFactory.start('render', 0), eventFactory.end('render', 5)
|
||||
]).then((data) => {
|
||||
expect(data['renderTime']).toBe(5);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should support renderTime metric', done => {
|
||||
aggregate([eventFactory.start('render', 0), eventFactory.end('render', 5)]).then((data) => {
|
||||
expect(data['renderTime']).toBe(5);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should support gcTime/gcAmount metric',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate([
|
||||
eventFactory.start('gc', 0, {'usedHeapSize': 2500}),
|
||||
eventFactory.end('gc', 5, {'usedHeapSize': 1000})
|
||||
]).then((data) => {
|
||||
expect(data['gcTime']).toBe(5);
|
||||
expect(data['gcAmount']).toBe(1.5);
|
||||
expect(data['majorGcTime']).toBe(0);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should support gcTime/gcAmount metric', done => {
|
||||
aggregate([
|
||||
eventFactory.start('gc', 0, {'usedHeapSize': 2500}),
|
||||
eventFactory.end('gc', 5, {'usedHeapSize': 1000})
|
||||
]).then((data) => {
|
||||
expect(data['gcTime']).toBe(5);
|
||||
expect(data['gcAmount']).toBe(1.5);
|
||||
expect(data['majorGcTime']).toBe(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should support majorGcTime metric',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate([
|
||||
eventFactory.start('gc', 0, {'usedHeapSize': 2500}),
|
||||
eventFactory.end('gc', 5, {'usedHeapSize': 1000, 'majorGc': true})
|
||||
]).then((data) => {
|
||||
expect(data['gcTime']).toBe(5);
|
||||
expect(data['majorGcTime']).toBe(5);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should support majorGcTime metric', done => {
|
||||
aggregate([
|
||||
eventFactory.start('gc', 0, {'usedHeapSize': 2500}),
|
||||
eventFactory.end('gc', 5, {'usedHeapSize': 1000, 'majorGc': true})
|
||||
]).then((data) => {
|
||||
expect(data['gcTime']).toBe(5);
|
||||
expect(data['majorGcTime']).toBe(5);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should support pureScriptTime = scriptTime-gcTime-renderTime',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate([
|
||||
eventFactory.start('script', 0), eventFactory.start('gc', 1, {'usedHeapSize': 1000}),
|
||||
eventFactory.end('gc', 4, {'usedHeapSize': 0}), eventFactory.start('render', 4),
|
||||
eventFactory.end('render', 5), eventFactory.end('script', 6)
|
||||
]).then((data) => {
|
||||
expect(data['scriptTime']).toBe(6);
|
||||
expect(data['pureScriptTime']).toBe(2);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should support pureScriptTime = scriptTime-gcTime-renderTime', done => {
|
||||
aggregate([
|
||||
eventFactory.start('script', 0), eventFactory.start('gc', 1, {'usedHeapSize': 1000}),
|
||||
eventFactory.end('gc', 4, {'usedHeapSize': 0}), eventFactory.start('render', 4),
|
||||
eventFactory.end('render', 5), eventFactory.end('script', 6)
|
||||
]).then((data) => {
|
||||
expect(data['scriptTime']).toBe(6);
|
||||
expect(data['pureScriptTime']).toBe(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('receivedData', () => {
|
||||
it('should report received data since last navigationStart',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.instant('receivedData', 0, {'encodedDataLength': 1}),
|
||||
eventFactory.instant('navigationStart', 1),
|
||||
eventFactory.instant('receivedData', 2, {'encodedDataLength': 2}),
|
||||
eventFactory.instant('navigationStart', 3),
|
||||
eventFactory.instant('receivedData', 4, {'encodedDataLength': 4}),
|
||||
eventFactory.instant('receivedData', 5, {'encodedDataLength': 8})
|
||||
],
|
||||
{receivedData: true})
|
||||
.then((data) => {
|
||||
expect(data['receivedData']).toBe(12);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should report received data since last navigationStart', done => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.instant('receivedData', 0, {'encodedDataLength': 1}),
|
||||
eventFactory.instant('navigationStart', 1),
|
||||
eventFactory.instant('receivedData', 2, {'encodedDataLength': 2}),
|
||||
eventFactory.instant('navigationStart', 3),
|
||||
eventFactory.instant('receivedData', 4, {'encodedDataLength': 4}),
|
||||
eventFactory.instant('receivedData', 5, {'encodedDataLength': 8})
|
||||
],
|
||||
{receivedData: true})
|
||||
.then((data) => {
|
||||
expect(data['receivedData']).toBe(12);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('requestCount', () => {
|
||||
it('should report count of requests sent since last navigationStart',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.instant('sendRequest', 0), eventFactory.instant('navigationStart', 1),
|
||||
eventFactory.instant('sendRequest', 2), eventFactory.instant('navigationStart', 3),
|
||||
eventFactory.instant('sendRequest', 4), eventFactory.instant('sendRequest', 5)
|
||||
],
|
||||
{requestCount: true})
|
||||
.then((data) => {
|
||||
expect(data['requestCount']).toBe(2);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should report count of requests sent since last navigationStart', done => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.instant('sendRequest', 0), eventFactory.instant('navigationStart', 1),
|
||||
eventFactory.instant('sendRequest', 2), eventFactory.instant('navigationStart', 3),
|
||||
eventFactory.instant('sendRequest', 4), eventFactory.instant('sendRequest', 5)
|
||||
],
|
||||
{requestCount: true})
|
||||
.then((data) => {
|
||||
expect(data['requestCount']).toBe(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('microMetrics', () => {
|
||||
it('should report micro metrics',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.markStart('mm1', 0),
|
||||
eventFactory.markEnd('mm1', 5),
|
||||
],
|
||||
{microMetrics: {'mm1': 'micro metric 1'}})
|
||||
.then((data) => {
|
||||
expect(data['mm1']).toBe(5.0);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should report micro metrics', done => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.markStart('mm1', 0),
|
||||
eventFactory.markEnd('mm1', 5),
|
||||
],
|
||||
{microMetrics: {'mm1': 'micro metric 1'}})
|
||||
.then((data) => {
|
||||
expect(data['mm1']).toBe(5.0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should ignore micro metrics that were not specified',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate([
|
||||
eventFactory.markStart('mm1', 0),
|
||||
eventFactory.markEnd('mm1', 5),
|
||||
]).then((data) => {
|
||||
expect(data['mm1']).toBeFalsy();
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should ignore micro metrics that were not specified', done => {
|
||||
aggregate([
|
||||
eventFactory.markStart('mm1', 0),
|
||||
eventFactory.markEnd('mm1', 5),
|
||||
]).then((data) => {
|
||||
expect(data['mm1']).toBeFalsy();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should report micro metric averages',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.markStart('mm1*20', 0),
|
||||
eventFactory.markEnd('mm1*20', 5),
|
||||
],
|
||||
{microMetrics: {'mm1': 'micro metric 1'}})
|
||||
.then((data) => {
|
||||
expect(data['mm1']).toBe(5 / 20);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should report micro metric averages', done => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.markStart('mm1*20', 0),
|
||||
eventFactory.markEnd('mm1*20', 5),
|
||||
],
|
||||
{microMetrics: {'mm1': 'micro metric 1'}})
|
||||
.then((data) => {
|
||||
expect(data['mm1']).toBe(5 / 20);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
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';
|
||||
|
||||
|
@ -42,23 +41,22 @@ describe('user metric', () => {
|
|||
});
|
||||
|
||||
describe('endMeasure', () => {
|
||||
it('should stop measuring when all properties have numeric values',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const metric = createMetric(
|
||||
[[]], new PerfLogFeatures(),
|
||||
{userMetrics: {'loadTime': 'time to load', 'content': 'time to see content'}});
|
||||
metric.beginMeasure().then(() => metric.endMeasure(true)).then(values => {
|
||||
expect(values['loadTime']).toBe(25);
|
||||
expect(values['content']).toBe(250);
|
||||
async.done();
|
||||
});
|
||||
it('should stop measuring when all properties have numeric values', done => {
|
||||
const metric = createMetric(
|
||||
[[]], new PerfLogFeatures(),
|
||||
{userMetrics: {'loadTime': 'time to load', 'content': 'time to see content'}});
|
||||
metric.beginMeasure().then(() => metric.endMeasure(true)).then(values => {
|
||||
expect(values['loadTime']).toBe(25);
|
||||
expect(values['content']).toBe(250);
|
||||
done();
|
||||
});
|
||||
|
||||
wdAdapter.data['loadTime'] = 25;
|
||||
// Wait before setting 2nd property.
|
||||
setTimeout(() => {
|
||||
wdAdapter.data['content'] = 250;
|
||||
}, 50);
|
||||
}), 600);
|
||||
wdAdapter.data['loadTime'] = 25;
|
||||
// Wait before setting 2nd property.
|
||||
setTimeout(() => {
|
||||
wdAdapter.data['content'] = 250;
|
||||
}, 50);
|
||||
}, 600);
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
import {StaticProvider} from '@angular/core';
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
import {ConsoleReporter, Injector, MeasureValues, SampleDescription} from '../../index';
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
* 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';
|
||||
|
||||
{
|
||||
|
@ -37,37 +35,35 @@ import {Injector, JsonFileReporter, MeasureValues, Options, SampleDescription} f
|
|||
return Injector.create(providers).get<JsonFileReporter>(JsonFileReporter);
|
||||
}
|
||||
|
||||
it('should write all data into a file',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createReporter({
|
||||
sampleId: 'someId',
|
||||
descriptions: [{'a': 2}],
|
||||
path: 'somePath',
|
||||
metrics: {'a': 'script time', 'b': 'render time'}
|
||||
})
|
||||
.reportSample(
|
||||
[mv(0, 0, {'a': 3, 'b': 6})],
|
||||
[mv(0, 0, {'a': 3, 'b': 6}), mv(1, 1, {'a': 5, 'b': 9})]);
|
||||
const regExp = /somePath\/someId_\d+\.json/;
|
||||
expect(loggedFile['filename'].match(regExp) != null).toBe(true);
|
||||
const parsedContent = JSON.parse(loggedFile['content']) as {[key: string]: any};
|
||||
expect(parsedContent).toEqual({
|
||||
'description': {
|
||||
'id': 'someId',
|
||||
'description': {'a': 2},
|
||||
'metrics': {'a': 'script time', 'b': 'render time'}
|
||||
},
|
||||
'stats': {'a': '4.00+-25%', 'b': '7.50+-20%'},
|
||||
'completeSample': [
|
||||
{'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}},
|
||||
{'timeStamp': '1970-01-01T00:00:00.001Z', 'runIndex': 1, 'values': {'a': 5, 'b': 9}}
|
||||
]
|
||||
});
|
||||
async.done();
|
||||
}));
|
||||
it('should write all data into a file', done => {
|
||||
createReporter({
|
||||
sampleId: 'someId',
|
||||
descriptions: [{'a': 2}],
|
||||
path: 'somePath',
|
||||
metrics: {'a': 'script time', 'b': 'render time'}
|
||||
})
|
||||
.reportSample(
|
||||
[mv(0, 0, {'a': 3, 'b': 6})],
|
||||
[mv(0, 0, {'a': 3, 'b': 6}), mv(1, 1, {'a': 5, 'b': 9})]);
|
||||
const regExp = /somePath\/someId_\d+\.json/;
|
||||
expect(loggedFile['filename'].match(regExp) != null).toBe(true);
|
||||
const parsedContent = JSON.parse(loggedFile['content']) as {[key: string]: any};
|
||||
expect(parsedContent).toEqual({
|
||||
'description': {
|
||||
'id': 'someId',
|
||||
'description': {'a': 2},
|
||||
'metrics': {'a': 'script time', 'b': 'render time'}
|
||||
},
|
||||
'stats': {'a': '4.00+-25%', 'b': '7.50+-20%'},
|
||||
'completeSample':
|
||||
[{'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}},
|
||||
{'timeStamp': '1970-01-01T00:00:00.001Z', 'runIndex': 1, 'values': {'a': 5, 'b': 9}}
|
||||
]
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
* 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';
|
||||
|
||||
(function() {
|
||||
|
@ -22,30 +20,29 @@ function createReporters(ids: any[]) {
|
|||
}
|
||||
|
||||
describe('multi reporter', () => {
|
||||
it('should reportMeasureValues to all',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const mv = new MeasureValues(0, new Date(), {});
|
||||
createReporters(['m1', 'm2']).then((r) => r.reportMeasureValues(mv)).then((values) => {
|
||||
expect(values).toEqual([{'id': 'm1', 'values': mv}, {'id': 'm2', 'values': mv}]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should reportMeasureValues to all', done => {
|
||||
const mv = new MeasureValues(0, new Date(), {});
|
||||
createReporters(['m1', 'm2']).then((r) => r.reportMeasureValues(mv)).then((values) => {
|
||||
expect(values).toEqual([{'id': 'm1', 'values': mv}, {'id': 'm2', 'values': mv}]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should reportSample to call', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const completeSample =
|
||||
[new MeasureValues(0, new Date(), {}), new MeasureValues(1, new Date(), {})];
|
||||
const validSample = [completeSample[1]];
|
||||
it('should reportSample to call', done => {
|
||||
const completeSample =
|
||||
[new MeasureValues(0, new Date(), {}), new MeasureValues(1, new Date(), {})];
|
||||
const validSample = [completeSample[1]];
|
||||
|
||||
createReporters(['m1', 'm2'])
|
||||
.then((r) => r.reportSample(completeSample, validSample))
|
||||
.then((values) => {
|
||||
expect(values).toEqual([
|
||||
{'id': 'm1', 'completeSample': completeSample, 'validSample': validSample},
|
||||
{'id': 'm2', 'completeSample': completeSample, 'validSample': validSample}
|
||||
]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
createReporters(['m1', 'm2'])
|
||||
.then((r) => r.reportSample(completeSample, validSample))
|
||||
.then((values) => {
|
||||
expect(values).toEqual([
|
||||
{'id': 'm1', 'completeSample': completeSample, 'validSample': validSample},
|
||||
{'id': 'm2', 'completeSample': completeSample, 'validSample': validSample}
|
||||
]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
* 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';
|
||||
|
||||
{
|
||||
|
@ -35,83 +33,75 @@ import {Injector, Metric, Options, Runner, SampleDescription, Sampler, SampleSta
|
|||
return runner;
|
||||
}
|
||||
|
||||
it('should set SampleDescription.id',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createRunner()
|
||||
.sample({id: 'someId'})
|
||||
.then((_) => injector.get(SampleDescription))
|
||||
.then((desc) => {
|
||||
expect(desc.id).toBe('someId');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should set SampleDescription.id', done => {
|
||||
createRunner()
|
||||
.sample({id: 'someId'})
|
||||
.then((_) => injector.get(SampleDescription))
|
||||
.then((desc) => {
|
||||
expect(desc.id).toBe('someId');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should merge SampleDescription.description',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createRunner([{provide: Options.DEFAULT_DESCRIPTION, useValue: {'a': 1}}])
|
||||
.sample({
|
||||
id: 'someId',
|
||||
providers: [{provide: Options.SAMPLE_DESCRIPTION, useValue: {'b': 2}}]
|
||||
})
|
||||
.then((_) => injector.get(SampleDescription))
|
||||
.then((desc) => {
|
||||
expect(desc.description)
|
||||
.toEqual(
|
||||
{'forceGc': false, 'userAgent': 'someUserAgent', 'a': 1, 'b': 2, 'v': 11});
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should merge SampleDescription.description', done => {
|
||||
createRunner([{provide: Options.DEFAULT_DESCRIPTION, useValue: {'a': 1}}])
|
||||
.sample({
|
||||
id: 'someId',
|
||||
providers: [{provide: Options.SAMPLE_DESCRIPTION, useValue: {'b': 2}}]
|
||||
})
|
||||
.then((_) => injector.get(SampleDescription))
|
||||
.then((desc) => {
|
||||
expect(desc.description)
|
||||
.toEqual({'forceGc': false, 'userAgent': 'someUserAgent', 'a': 1, 'b': 2, 'v': 11});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fill SampleDescription.metrics from the Metric',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createRunner()
|
||||
.sample({id: 'someId'})
|
||||
.then((_) => injector.get(SampleDescription))
|
||||
.then((desc) => {
|
||||
expect(desc.metrics).toEqual({'m1': 'some metric'});
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should fill SampleDescription.metrics from the Metric', done => {
|
||||
createRunner()
|
||||
.sample({id: 'someId'})
|
||||
.then((_) => injector.get(SampleDescription))
|
||||
.then((desc) => {
|
||||
expect(desc.metrics).toEqual({'m1': 'some metric'});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should provide Options.EXECUTE',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const execute = () => {};
|
||||
createRunner().sample({id: 'someId', execute: execute}).then((_) => {
|
||||
expect(injector.get(Options.EXECUTE)).toEqual(execute);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should provide Options.EXECUTE', done => {
|
||||
const execute = () => {};
|
||||
createRunner().sample({id: 'someId', execute: execute}).then((_) => {
|
||||
expect(injector.get(Options.EXECUTE)).toEqual(execute);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should provide Options.PREPARE',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const prepare = () => {};
|
||||
createRunner().sample({id: 'someId', prepare: prepare}).then((_) => {
|
||||
expect(injector.get(Options.PREPARE)).toEqual(prepare);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should provide Options.PREPARE', done => {
|
||||
const prepare = () => {};
|
||||
createRunner().sample({id: 'someId', prepare: prepare}).then((_) => {
|
||||
expect(injector.get(Options.PREPARE)).toEqual(prepare);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should provide Options.MICRO_METRICS',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createRunner().sample({id: 'someId', microMetrics: {'a': 'b'}}).then((_) => {
|
||||
expect(injector.get(Options.MICRO_METRICS)).toEqual({'a': 'b'});
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should provide Options.MICRO_METRICS', done => {
|
||||
createRunner().sample({id: 'someId', microMetrics: {'a': 'b'}}).then((_) => {
|
||||
expect(injector.get(Options.MICRO_METRICS)).toEqual({'a': 'b'});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should overwrite providers per sample call',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createRunner([{provide: Options.DEFAULT_DESCRIPTION, useValue: {'a': 1}}])
|
||||
.sample({
|
||||
id: 'someId',
|
||||
providers: [{provide: Options.DEFAULT_DESCRIPTION, useValue: {'a': 2}}]
|
||||
})
|
||||
.then((_) => injector.get(SampleDescription))
|
||||
.then((desc) => {
|
||||
expect(desc.description['a']).toBe(2);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should overwrite providers per sample call', done => {
|
||||
createRunner([{provide: Options.DEFAULT_DESCRIPTION, useValue: {'a': 1}}])
|
||||
.sample({
|
||||
id: 'someId',
|
||||
providers: [{provide: Options.DEFAULT_DESCRIPTION, useValue: {'a': 2}}]
|
||||
})
|
||||
.then((_) => injector.get(SampleDescription))
|
||||
.then((desc) => {
|
||||
expect(desc.description['a']).toBe(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
* 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';
|
||||
|
||||
{
|
||||
|
@ -47,59 +45,57 @@ import {Injector, MeasureValues, Metric, Options, Reporter, Sampler, Validator,
|
|||
sampler = Injector.create(providers).get(Sampler);
|
||||
}
|
||||
|
||||
it('should call the prepare and execute callbacks using WebDriverAdapter.waitFor',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const log: any[] = [];
|
||||
let count = 0;
|
||||
const driver = new MockDriverAdapter([], (callback: Function) => {
|
||||
const result = callback();
|
||||
log.push(result);
|
||||
return Promise.resolve(result);
|
||||
});
|
||||
createSampler({
|
||||
driver: driver,
|
||||
validator: createCountingValidator(2),
|
||||
prepare: () => count++,
|
||||
execute: () => count++,
|
||||
});
|
||||
sampler.sample().then((_) => {
|
||||
expect(count).toBe(4);
|
||||
expect(log).toEqual([0, 1, 2, 3]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should call the prepare and execute callbacks using WebDriverAdapter.waitFor', done => {
|
||||
const log: any[] = [];
|
||||
let count = 0;
|
||||
const driver = new MockDriverAdapter([], (callback: Function) => {
|
||||
const result = callback();
|
||||
log.push(result);
|
||||
return Promise.resolve(result);
|
||||
});
|
||||
createSampler({
|
||||
driver: driver,
|
||||
validator: createCountingValidator(2),
|
||||
prepare: () => count++,
|
||||
execute: () => count++,
|
||||
});
|
||||
sampler.sample().then((_) => {
|
||||
expect(count).toBe(4);
|
||||
expect(log).toEqual([0, 1, 2, 3]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should call prepare, beginMeasure, execute, endMeasure for every iteration',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
let workCount = 0;
|
||||
const log: any[] = [];
|
||||
createSampler({
|
||||
metric: createCountingMetric(log),
|
||||
validator: createCountingValidator(2),
|
||||
prepare: () => {
|
||||
log.push(`p${workCount++}`);
|
||||
},
|
||||
execute: () => {
|
||||
log.push(`w${workCount++}`);
|
||||
}
|
||||
});
|
||||
sampler.sample().then((_) => {
|
||||
expect(log).toEqual([
|
||||
'p0',
|
||||
['beginMeasure'],
|
||||
'w1',
|
||||
['endMeasure', false, {'script': 0}],
|
||||
'p2',
|
||||
['beginMeasure'],
|
||||
'w3',
|
||||
['endMeasure', false, {'script': 1}],
|
||||
]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should call prepare, beginMeasure, execute, endMeasure for every iteration', done => {
|
||||
let workCount = 0;
|
||||
const log: any[] = [];
|
||||
createSampler({
|
||||
metric: createCountingMetric(log),
|
||||
validator: createCountingValidator(2),
|
||||
prepare: () => {
|
||||
log.push(`p${workCount++}`);
|
||||
},
|
||||
execute: () => {
|
||||
log.push(`w${workCount++}`);
|
||||
}
|
||||
});
|
||||
sampler.sample().then((_) => {
|
||||
expect(log).toEqual([
|
||||
'p0',
|
||||
['beginMeasure'],
|
||||
'w1',
|
||||
['endMeasure', false, {'script': 0}],
|
||||
'p2',
|
||||
['beginMeasure'],
|
||||
'w3',
|
||||
['endMeasure', false, {'script': 1}],
|
||||
]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should call execute, endMeasure for every iteration if there is no prepare callback',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
const log: any[] = [];
|
||||
let workCount = 0;
|
||||
createSampler({
|
||||
|
@ -118,93 +114,90 @@ import {Injector, MeasureValues, Metric, Options, Reporter, Sampler, Validator,
|
|||
'w1',
|
||||
['endMeasure', true, {'script': 1}],
|
||||
]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should only collect metrics for execute and ignore metrics from prepare',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
let scriptTime = 0;
|
||||
let iterationCount = 1;
|
||||
createSampler({
|
||||
validator: createCountingValidator(2),
|
||||
metric: new MockMetric(
|
||||
[],
|
||||
() => {
|
||||
const result = Promise.resolve({'script': scriptTime});
|
||||
scriptTime = 0;
|
||||
return result;
|
||||
}),
|
||||
prepare: () => {
|
||||
scriptTime = 1 * iterationCount;
|
||||
},
|
||||
execute: () => {
|
||||
scriptTime = 10 * iterationCount;
|
||||
iterationCount++;
|
||||
}
|
||||
});
|
||||
sampler.sample().then((state) => {
|
||||
expect(state.completeSample.length).toBe(2);
|
||||
expect(state.completeSample[0]).toEqual(mv(0, 1000, {'script': 10}));
|
||||
expect(state.completeSample[1]).toEqual(mv(1, 1001, {'script': 20}));
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should only collect metrics for execute and ignore metrics from prepare', done => {
|
||||
let scriptTime = 0;
|
||||
let iterationCount = 1;
|
||||
createSampler({
|
||||
validator: createCountingValidator(2),
|
||||
metric: new MockMetric(
|
||||
[],
|
||||
() => {
|
||||
const result = Promise.resolve({'script': scriptTime});
|
||||
scriptTime = 0;
|
||||
return result;
|
||||
}),
|
||||
prepare: () => {
|
||||
scriptTime = 1 * iterationCount;
|
||||
},
|
||||
execute: () => {
|
||||
scriptTime = 10 * iterationCount;
|
||||
iterationCount++;
|
||||
}
|
||||
});
|
||||
sampler.sample().then((state) => {
|
||||
expect(state.completeSample.length).toBe(2);
|
||||
expect(state.completeSample[0]).toEqual(mv(0, 1000, {'script': 10}));
|
||||
expect(state.completeSample[1]).toEqual(mv(1, 1001, {'script': 20}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should call the validator for every execution and store the valid sample',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const log: any[] = [];
|
||||
const validSample = [mv(null!, null!, {})];
|
||||
it('should call the validator for every execution and store the valid sample', done => {
|
||||
const log: any[] = [];
|
||||
const validSample = [mv(null!, null!, {})];
|
||||
|
||||
createSampler({
|
||||
metric: createCountingMetric(),
|
||||
validator: createCountingValidator(2, validSample, log),
|
||||
execute: EMPTY_EXECUTE
|
||||
});
|
||||
sampler.sample().then((state) => {
|
||||
expect(state.validSample).toBe(validSample);
|
||||
// TODO(tbosch): Why does this fail??
|
||||
// expect(log).toEqual([
|
||||
// ['validate', [{'script': 0}], null],
|
||||
// ['validate', [{'script': 0}, {'script': 1}], validSample]
|
||||
// ]);
|
||||
createSampler({
|
||||
metric: createCountingMetric(),
|
||||
validator: createCountingValidator(2, validSample, log),
|
||||
execute: EMPTY_EXECUTE
|
||||
});
|
||||
sampler.sample().then((state) => {
|
||||
expect(state.validSample).toBe(validSample);
|
||||
// TODO(tbosch): Why does this fail??
|
||||
// expect(log).toEqual([
|
||||
// ['validate', [{'script': 0}], null],
|
||||
// ['validate', [{'script': 0}, {'script': 1}], validSample]
|
||||
// ]);
|
||||
|
||||
expect(log.length).toBe(2);
|
||||
expect(log[0]).toEqual(['validate', [mv(0, 1000, {'script': 0})], null]);
|
||||
expect(log[1]).toEqual(
|
||||
['validate', [mv(0, 1000, {'script': 0}), mv(1, 1001, {'script': 1})], validSample]);
|
||||
expect(log.length).toBe(2);
|
||||
expect(log[0]).toEqual(['validate', [mv(0, 1000, {'script': 0})], null]);
|
||||
expect(log[1]).toEqual(
|
||||
['validate', [mv(0, 1000, {'script': 0}), mv(1, 1001, {'script': 1})], validSample]);
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should report the metric values',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const log: any[] = [];
|
||||
const validSample = [mv(null!, null!, {})];
|
||||
createSampler({
|
||||
validator: createCountingValidator(2, validSample),
|
||||
metric: createCountingMetric(),
|
||||
reporter: new MockReporter(log),
|
||||
execute: EMPTY_EXECUTE
|
||||
});
|
||||
sampler.sample().then((_) => {
|
||||
// TODO(tbosch): Why does this fail??
|
||||
// expect(log).toEqual([
|
||||
// ['reportMeasureValues', 0, {'script': 0}],
|
||||
// ['reportMeasureValues', 1, {'script': 1}],
|
||||
// ['reportSample', [{'script': 0}, {'script': 1}], validSample]
|
||||
// ]);
|
||||
expect(log.length).toBe(3);
|
||||
expect(log[0]).toEqual(['reportMeasureValues', mv(0, 1000, {'script': 0})]);
|
||||
expect(log[1]).toEqual(['reportMeasureValues', mv(1, 1001, {'script': 1})]);
|
||||
expect(log[2]).toEqual([
|
||||
'reportSample', [mv(0, 1000, {'script': 0}), mv(1, 1001, {'script': 1})], validSample
|
||||
]);
|
||||
it('should report the metric values', done => {
|
||||
const log: any[] = [];
|
||||
const validSample = [mv(null!, null!, {})];
|
||||
createSampler({
|
||||
validator: createCountingValidator(2, validSample),
|
||||
metric: createCountingMetric(),
|
||||
reporter: new MockReporter(log),
|
||||
execute: EMPTY_EXECUTE
|
||||
});
|
||||
sampler.sample().then((_) => {
|
||||
// TODO(tbosch): Why does this fail??
|
||||
// expect(log).toEqual([
|
||||
// ['reportMeasureValues', 0, {'script': 0}],
|
||||
// ['reportMeasureValues', 1, {'script': 1}],
|
||||
// ['reportSample', [{'script': 0}, {'script': 1}], validSample]
|
||||
// ]);
|
||||
expect(log.length).toBe(3);
|
||||
expect(log[0]).toEqual(['reportMeasureValues', mv(0, 1000, {'script': 0})]);
|
||||
expect(log[1]).toEqual(['reportMeasureValues', mv(1, 1001, {'script': 1})]);
|
||||
expect(log[2]).toEqual([
|
||||
'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
|
||||
*/
|
||||
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {Statistic} from '../src/statistic';
|
||||
|
||||
{
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
* 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';
|
||||
|
||||
{
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
* 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';
|
||||
|
||||
{
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
* 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';
|
||||
|
||||
(function() {
|
||||
|
@ -28,21 +26,19 @@ function createExtension(ids: any[], caps: any) {
|
|||
}
|
||||
|
||||
describe('WebDriverExtension.provideFirstSupported', () => {
|
||||
it('should provide the extension that matches the capabilities',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension(['m1', 'm2', 'm3'], {'browser': 'm2'}).then((m) => {
|
||||
expect(m.id).toEqual('m2');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should provide the extension that matches the capabilities', done => {
|
||||
createExtension(['m1', 'm2', 'm3'], {'browser': 'm2'}).then((m) => {
|
||||
expect(m.id).toEqual('m2');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw if there is no match',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension(['m1'], {'browser': 'm2'}).catch((err) => {
|
||||
expect(err != null).toBe(true);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should throw if there is no match', done => {
|
||||
createExtension(['m1'], {'browser': 'm2'}).catch((err) => {
|
||||
expect(err != null).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
* 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 {TraceEventFactory} from '../trace_event_factory';
|
||||
|
||||
|
@ -54,344 +52,323 @@ import {TraceEventFactory} from '../trace_event_factory';
|
|||
return extension;
|
||||
}
|
||||
|
||||
it('should force gc via window.gc()',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension().gc().then((_) => {
|
||||
expect(log).toEqual([['executeScript', 'window.gc()']]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should force gc via window.gc()', done => {
|
||||
createExtension().gc().then((_) => {
|
||||
expect(log).toEqual([['executeScript', 'window.gc()']]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
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(() => {
|
||||
expect(log).toEqual([
|
||||
['logs', 'performance'], ['executeScript', `performance.mark('someName-bpstart');`]
|
||||
]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should mark the timeline via performance.mark() on the second call',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const ext = createExtension();
|
||||
ext.timeBegin('someName')
|
||||
.then((_) => {
|
||||
log.splice(0, log.length);
|
||||
ext.timeBegin('someName');
|
||||
})
|
||||
.then(() => {
|
||||
expect(log).toEqual([['executeScript', `performance.mark('someName-bpstart');`]]);
|
||||
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 mark the timeline via performance.mark() on the second call', done => {
|
||||
const ext = createExtension();
|
||||
ext.timeBegin('someName')
|
||||
.then((_) => {
|
||||
log.splice(0, log.length);
|
||||
ext.timeBegin('someName');
|
||||
})
|
||||
.then(() => {
|
||||
expect(log).toEqual([['executeScript', `performance.mark('someName-bpstart');`]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it(`should report UpdateLayoutTree as "render"`,
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
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),
|
||||
]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should mark the timeline via performance.mark()', done => {
|
||||
createExtension().timeEnd('someName', null).then((_) => {
|
||||
expect(log).toEqual([['executeScript', `performance.mark('someName-bpend');`]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should ignore FunctionCalls from webdriver',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension([chromeTimelineV8Events.start(
|
||||
'FunctionCall', 0, {'data': {'scriptName': 'InjectedScript'}})])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should mark the timeline via performance.mark() with start and end of a test', done => {
|
||||
createExtension().timeEnd('name1', 'name2').then((_) => {
|
||||
expect(log).toEqual([
|
||||
['executeScript', `performance.mark('name1-bpend');performance.mark('name2-bpstart');`]
|
||||
]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should ignore FunctionCalls with empty scriptName',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension(
|
||||
[chromeTimelineV8Events.start('FunctionCall', 0, {'data': {'scriptName': ''}})])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should normalize times to ms and forward ph and pid event properties', done => {
|
||||
createExtension([chromeTimelineV8Events.complete('FunctionCall', 1100, 5500, null)])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([
|
||||
normEvents.complete('script', 1.1, 5.5, null),
|
||||
]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should report navigationStart',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension([chromeBlinkUserTimingEvents.instant('navigationStart', 1234)])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([normEvents.instant('navigationStart', 1.234)]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should normalize "tdur" to "dur"', done => {
|
||||
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),
|
||||
]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should report receivedData', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension(
|
||||
[chrome45TimelineEvents.instant(
|
||||
'ResourceReceivedData', 1234, {'data': {'encodedDataLength': 987}})],
|
||||
)
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual(
|
||||
[normEvents.instant('receivedData', 1.234, {'encodedDataLength': 987})]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should report FunctionCall events as "script"', done => {
|
||||
createExtension([chromeTimelineV8Events.start('FunctionCall', 0)])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([
|
||||
normEvents.start('script', 0),
|
||||
]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should report sendRequest', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
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'})]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should report EvaluateScript events as "script"', done => {
|
||||
createExtension([chromeTimelineV8Events.start('EvaluateScript', 0)])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([
|
||||
normEvents.start('script', 0),
|
||||
]);
|
||||
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)', () => {
|
||||
it('should execute a dummy script before reading them',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
// TODO(tbosch): This seems to be a bug in ChromeDriver:
|
||||
// Sometimes it does not report the newest events of the performance log
|
||||
// to the WebDriver client unless a script is executed...
|
||||
createExtension([]).readPerfLog().then((_) => {
|
||||
expect(log).toEqual([['executeScript', '1+1'], ['logs', 'performance']]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should execute a dummy script before reading them', done => {
|
||||
// TODO(tbosch): This seems to be a bug in ChromeDriver:
|
||||
// Sometimes it does not report the newest events of the performance log
|
||||
// to the WebDriver client unless a script is executed...
|
||||
createExtension([]).readPerfLog().then((_) => {
|
||||
expect(log).toEqual([['executeScript', '1+1'], ['logs', 'performance']]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
['Rasterize', 'CompositeLayers'].forEach((recordType) => {
|
||||
it(`should report ${recordType} as "render"`,
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension(
|
||||
[
|
||||
chromeTimelineEvents.start(recordType, 1234),
|
||||
chromeTimelineEvents.end(recordType, 2345)
|
||||
],
|
||||
)
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([
|
||||
normEvents.start('render', 1.234),
|
||||
normEvents.end('render', 2.345),
|
||||
]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it(`should report ${recordType} as "render"`, done => {
|
||||
createExtension(
|
||||
[
|
||||
chromeTimelineEvents.start(recordType, 1234),
|
||||
chromeTimelineEvents.end(recordType, 2345)
|
||||
],
|
||||
)
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([
|
||||
normEvents.start('render', 1.234),
|
||||
normEvents.end('render', 2.345),
|
||||
]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('frame metrics', () => {
|
||||
it('should report ImplThreadRenderingStats as frame event',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension([benchmarkEvents.instant(
|
||||
'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
|
||||
{'data': {'frame_count': 1}})])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([
|
||||
normEvents.instant('frame', 1.1),
|
||||
]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should report ImplThreadRenderingStats as frame event', done => {
|
||||
createExtension([benchmarkEvents.instant(
|
||||
'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
|
||||
{'data': {'frame_count': 1}})])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([
|
||||
normEvents.instant('frame', 1.1),
|
||||
]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not report ImplThreadRenderingStats with zero frames',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension([benchmarkEvents.instant(
|
||||
'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
|
||||
{'data': {'frame_count': 0}})])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should not report ImplThreadRenderingStats with zero frames', done => {
|
||||
createExtension([benchmarkEvents.instant(
|
||||
'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
|
||||
{'data': {'frame_count': 0}})])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw when ImplThreadRenderingStats contains more than one frame',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension([benchmarkEvents.instant(
|
||||
'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
|
||||
{'data': {'frame_count': 2}})])
|
||||
.readPerfLog()
|
||||
.catch((err): any => {
|
||||
expect(() => {
|
||||
throw err;
|
||||
}).toThrowError('multi-frame render stats not supported');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should throw when ImplThreadRenderingStats contains more than one frame', done => {
|
||||
createExtension([benchmarkEvents.instant(
|
||||
'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
|
||||
{'data': {'frame_count': 2}})])
|
||||
.readPerfLog()
|
||||
.catch((err): any => {
|
||||
expect(() => {
|
||||
throw err;
|
||||
}).toThrowError('multi-frame render stats not supported');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should report begin timestamps',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension([blinkEvents.create('S', 'someName', 1000)])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([normEvents.markStart('someName', 1.0)]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should report begin timestamps', done => {
|
||||
createExtension([blinkEvents.create('S', 'someName', 1000)])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([normEvents.markStart('someName', 1.0)]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should report end timestamps',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension([blinkEvents.create('F', 'someName', 1000)])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([normEvents.markEnd('someName', 1.0)]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should report end timestamps', done => {
|
||||
createExtension([blinkEvents.create('F', 'someName', 1000)])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([normEvents.markEnd('someName', 1.0)]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw an error on buffer overflow',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension(
|
||||
[
|
||||
chromeTimelineEvents.start('FunctionCall', 1234),
|
||||
],
|
||||
CHROME45_USER_AGENT, 'Tracing.bufferUsage')
|
||||
.readPerfLog()
|
||||
.catch((err): any => {
|
||||
expect(() => {
|
||||
throw err;
|
||||
}).toThrowError('The DevTools trace buffer filled during the test!');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should throw an error on buffer overflow', done => {
|
||||
createExtension(
|
||||
[
|
||||
chromeTimelineEvents.start('FunctionCall', 1234),
|
||||
],
|
||||
CHROME45_USER_AGENT, 'Tracing.bufferUsage')
|
||||
.readPerfLog()
|
||||
.catch((err): any => {
|
||||
expect(() => {
|
||||
throw err;
|
||||
}).toThrowError('The DevTools trace buffer filled during the test!');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should match chrome browsers', () => {
|
||||
expect(createExtension().supports({'browserName': 'chrome'})).toBe(true);
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
* 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 {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');
|
||||
});
|
||||
|
||||
it('should mark the timeline via console.time()',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension().timeBegin('someName').then((_) => {
|
||||
expect(log).toEqual([['executeScript', `console.time('someName');`]]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should mark the timeline via console.time()', done => {
|
||||
createExtension().timeBegin('someName').then((_) => {
|
||||
expect(log).toEqual([['executeScript', `console.time('someName');`]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should mark the timeline via console.timeEnd()',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension().timeEnd('someName', null).then((_) => {
|
||||
expect(log).toEqual([['executeScript', `console.timeEnd('someName');`]]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should mark the timeline via console.timeEnd()', done => {
|
||||
createExtension().timeEnd('someName', null).then((_) => {
|
||||
expect(log).toEqual([['executeScript', `console.timeEnd('someName');`]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should mark the timeline via console.time() and console.timeEnd()',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension().timeEnd('name1', 'name2').then((_) => {
|
||||
expect(log).toEqual(
|
||||
[['executeScript', `console.timeEnd('name1');console.time('name2');`]]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should mark the timeline via console.time() and console.timeEnd()', done => {
|
||||
createExtension().timeEnd('name1', 'name2').then((_) => {
|
||||
expect(log).toEqual([['executeScript', `console.timeEnd('name1');console.time('name2');`]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('readPerfLog', () => {
|
||||
it('should execute a dummy script before reading them',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
// TODO(tbosch): This seems to be a bug in ChromeDriver:
|
||||
// Sometimes it does not report the newest events of the performance log
|
||||
// to the WebDriver client unless a script is executed...
|
||||
createExtension([]).readPerfLog().then((_) => {
|
||||
expect(log).toEqual([['executeScript', '1+1'], ['logs', 'performance']]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should execute a dummy script before reading them', done => {
|
||||
// TODO(tbosch): This seems to be a bug in ChromeDriver:
|
||||
// Sometimes it does not report the newest events of the performance log
|
||||
// to the WebDriver client unless a script is executed...
|
||||
createExtension([]).readPerfLog().then((_) => {
|
||||
expect(log).toEqual([['executeScript', '1+1'], ['logs', 'performance']]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should report FunctionCall records as "script"',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension([durationRecord('FunctionCall', 1, 5)]).readPerfLog().then((events) => {
|
||||
expect(events).toEqual([normEvents.start('script', 1), normEvents.end('script', 5)]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should report FunctionCall records as "script"', done => {
|
||||
createExtension([durationRecord('FunctionCall', 1, 5)]).readPerfLog().then((events) => {
|
||||
expect(events).toEqual([normEvents.start('script', 1), normEvents.end('script', 5)]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should ignore FunctionCalls from webdriver',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension([internalScriptRecord(1, 5)]).readPerfLog().then((events) => {
|
||||
expect(events).toEqual([]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should ignore FunctionCalls from webdriver', done => {
|
||||
createExtension([internalScriptRecord(1, 5)]).readPerfLog().then((events) => {
|
||||
expect(events).toEqual([]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should report begin time', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension([timeBeginRecord('someName', 12)]).readPerfLog().then((events) => {
|
||||
expect(events).toEqual([normEvents.markStart('someName', 12)]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should report begin time', done => {
|
||||
createExtension([timeBeginRecord('someName', 12)]).readPerfLog().then((events) => {
|
||||
expect(events).toEqual([normEvents.markStart('someName', 12)]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should report end timestamps',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension([timeEndRecord('someName', 12)]).readPerfLog().then((events) => {
|
||||
expect(events).toEqual([normEvents.markEnd('someName', 12)]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should report end timestamps', done => {
|
||||
createExtension([timeEndRecord('someName', 12)]).readPerfLog().then((events) => {
|
||||
expect(events).toEqual([normEvents.markEnd('someName', 12)]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
['RecalculateStyles', 'Layout', 'UpdateLayerTree', 'Paint', 'Rasterize', 'CompositeLayers']
|
||||
.forEach((recordType) => {
|
||||
it(`should report ${recordType}`,
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension([durationRecord(recordType, 0, 1)])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([
|
||||
normEvents.start('render', 0),
|
||||
normEvents.end('render', 1),
|
||||
]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it(`should report ${recordType}`, done => {
|
||||
createExtension([durationRecord(recordType, 0, 1)]).readPerfLog().then((events) => {
|
||||
expect(events).toEqual([
|
||||
normEvents.start('render', 0),
|
||||
normEvents.end('render', 1),
|
||||
]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should walk children', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension([durationRecord('FunctionCall', 1, 5, [timeBeginRecord('someName', 2)])])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([
|
||||
normEvents.start('script', 1), normEvents.markStart('someName', 2),
|
||||
normEvents.end('script', 5)
|
||||
]);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should walk children', done => {
|
||||
createExtension([durationRecord('FunctionCall', 1, 5, [timeBeginRecord('someName', 2)])])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([
|
||||
normEvents.start('script', 1), normEvents.markStart('someName', 2),
|
||||
normEvents.end('script', 5)
|
||||
]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should match safari browsers', () => {
|
||||
expect(createExtension().supports({'browserName': 'safari'})).toBe(true);
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
import {HttpClient} from '@angular/common/http/src/client';
|
||||
import {HttpErrorResponse, HttpEventType, HttpResponse, HttpStatusCode} from '@angular/common/http/src/response';
|
||||
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';
|
||||
|
||||
{
|
||||
|
|
|
@ -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 {HttpRequest} from '@angular/common/http/src/request';
|
||||
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 {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 {HttpParams} from '@angular/common/http/src/params';
|
||||
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_STRING = `I'm a body!`;
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
import {HttpHeaders} from '@angular/common/http/src/headers';
|
||||
import {HttpResponse, HttpStatusCode} from '@angular/common/http/src/response';
|
||||
import {describe, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
{
|
||||
describe('HttpResponse', () => {
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
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 {HttpXhrBackend} from '@angular/common/http/src/xhr';
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {Observable} from 'rxjs';
|
||||
import {toArray} from 'rxjs/operators';
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
*/
|
||||
|
||||
import {parseCookieValue} from '@angular/common/src/cookie';
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
{
|
||||
describe('cookies', () => {
|
||||
|
|
|
@ -12,7 +12,6 @@ import localeEn from '@angular/common/locales/en';
|
|||
import localeEsUS from '@angular/common/locales/es-US';
|
||||
import localeFr from '@angular/common/locales/fr';
|
||||
import {ɵDEFAULT_LOCALE_ID, ɵregisterLocaleData, ɵunregisterLocaleData} from '@angular/core';
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
describe('Format number', () => {
|
||||
beforeAll(() => {
|
||||
|
|
|
@ -7,15 +7,16 @@
|
|||
*/
|
||||
|
||||
import {AsyncPipe, ɵgetDOM as getDOM} from '@angular/common';
|
||||
import {EventEmitter} from '@angular/core';
|
||||
import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {ChangeDetectorRef, EventEmitter} from '@angular/core';
|
||||
import {browserDetection} from '@angular/platform-browser/testing/src/browser_util';
|
||||
import {Subscribable, Unsubscribable} from 'rxjs';
|
||||
|
||||
import {SpyChangeDetectorRef} from '../spies';
|
||||
|
||||
{
|
||||
describe('AsyncPipe', () => {
|
||||
function getChangeDetectorRefSpy() {
|
||||
return jasmine.createSpyObj('ChangeDetectorRef', ['markForCheck', 'detectChanges']);
|
||||
}
|
||||
|
||||
describe('Observable', () => {
|
||||
// only expose methods from the Subscribable interface, to ensure that
|
||||
// the implementation does not rely on other methods:
|
||||
|
@ -33,13 +34,13 @@ import {SpyChangeDetectorRef} from '../spies';
|
|||
let emitter: EventEmitter<any>;
|
||||
let subscribable: Subscribable<any>;
|
||||
let pipe: AsyncPipe;
|
||||
let ref: any;
|
||||
let ref: ChangeDetectorRef&jasmine.SpyObj<ChangeDetectorRef>;
|
||||
const message = {};
|
||||
|
||||
beforeEach(() => {
|
||||
emitter = new EventEmitter();
|
||||
subscribable = wrapSubscribable(emitter);
|
||||
ref = new SpyChangeDetectorRef();
|
||||
ref = getChangeDetectorRefSpy();
|
||||
pipe = new AsyncPipe(ref);
|
||||
});
|
||||
|
||||
|
@ -48,32 +49,30 @@ import {SpyChangeDetectorRef} from '../spies';
|
|||
expect(pipe.transform(subscribable)).toBe(null);
|
||||
});
|
||||
|
||||
it('should return the latest available value',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
pipe.transform(subscribable);
|
||||
emitter.emit(message);
|
||||
it('should return the latest available value', done => {
|
||||
pipe.transform(subscribable);
|
||||
emitter.emit(message);
|
||||
|
||||
setTimeout(() => {
|
||||
expect(pipe.transform(subscribable)).toEqual(message);
|
||||
async.done();
|
||||
}, 0);
|
||||
}));
|
||||
setTimeout(() => {
|
||||
expect(pipe.transform(subscribable)).toEqual(message);
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
|
||||
it('should return same value when nothing has changed since the last call',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
pipe.transform(subscribable);
|
||||
emitter.emit(message);
|
||||
it('should return same value when nothing has changed since the last call', done => {
|
||||
pipe.transform(subscribable);
|
||||
emitter.emit(message);
|
||||
|
||||
setTimeout(() => {
|
||||
pipe.transform(subscribable);
|
||||
expect(pipe.transform(subscribable)).toBe(message);
|
||||
async.done();
|
||||
}, 0);
|
||||
}));
|
||||
setTimeout(() => {
|
||||
pipe.transform(subscribable);
|
||||
expect(pipe.transform(subscribable)).toBe(message);
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('should dispose of the existing subscription when subscribing to a new observable',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
pipe.transform(subscribable);
|
||||
|
||||
const newEmitter = new EventEmitter();
|
||||
|
@ -84,20 +83,19 @@ import {SpyChangeDetectorRef} from '../spies';
|
|||
// this should not affect the pipe
|
||||
setTimeout(() => {
|
||||
expect(pipe.transform(newSubscribable)).toBe(null);
|
||||
async.done();
|
||||
done();
|
||||
}, 0);
|
||||
}));
|
||||
});
|
||||
|
||||
it('should request a change detection check upon receiving a new value',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
pipe.transform(subscribable);
|
||||
emitter.emit(message);
|
||||
it('should request a change detection check upon receiving a new value', done => {
|
||||
pipe.transform(subscribable);
|
||||
emitter.emit(message);
|
||||
|
||||
setTimeout(() => {
|
||||
expect(ref.spy('markForCheck')).toHaveBeenCalled();
|
||||
async.done();
|
||||
}, 10);
|
||||
}));
|
||||
setTimeout(() => {
|
||||
expect(ref.markForCheck).toHaveBeenCalled();
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
it('should return value for unchanged NaN', () => {
|
||||
emitter.emit(null);
|
||||
|
@ -115,23 +113,22 @@ import {SpyChangeDetectorRef} from '../spies';
|
|||
expect(() => pipe.ngOnDestroy()).not.toThrow();
|
||||
});
|
||||
|
||||
it('should dispose of the existing subscription',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
pipe.transform(subscribable);
|
||||
pipe.ngOnDestroy();
|
||||
emitter.emit(message);
|
||||
it('should dispose of the existing subscription', done => {
|
||||
pipe.transform(subscribable);
|
||||
pipe.ngOnDestroy();
|
||||
emitter.emit(message);
|
||||
|
||||
setTimeout(() => {
|
||||
expect(pipe.transform(subscribable)).toBe(null);
|
||||
async.done();
|
||||
}, 0);
|
||||
}));
|
||||
setTimeout(() => {
|
||||
expect(pipe.transform(subscribable)).toBe(null);
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Subscribable', () => {
|
||||
it('should infer the type from the subscribable', () => {
|
||||
const ref = new SpyChangeDetectorRef() as any;
|
||||
const ref = getChangeDetectorRefSpy();
|
||||
const pipe = new AsyncPipe(ref);
|
||||
const emitter = new EventEmitter<{name: 'T'}>();
|
||||
// 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 reject: (error: any) => void;
|
||||
let promise: Promise<any>;
|
||||
let ref: SpyChangeDetectorRef;
|
||||
let ref: any;
|
||||
// adds longer timers for passing tests in IE
|
||||
const timer = (getDOM() && browserDetection.isIE) ? 50 : 10;
|
||||
|
||||
|
@ -154,8 +151,8 @@ import {SpyChangeDetectorRef} from '../spies';
|
|||
resolve = res;
|
||||
reject = rej;
|
||||
});
|
||||
ref = new SpyChangeDetectorRef();
|
||||
pipe = new AsyncPipe(ref as any);
|
||||
ref = getChangeDetectorRefSpy();
|
||||
pipe = new AsyncPipe(ref);
|
||||
});
|
||||
|
||||
describe('transform', () => {
|
||||
|
@ -163,32 +160,30 @@ import {SpyChangeDetectorRef} from '../spies';
|
|||
expect(pipe.transform(promise)).toBe(null);
|
||||
});
|
||||
|
||||
it('should return the latest available value',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
pipe.transform(promise);
|
||||
it('should return the latest available value', done => {
|
||||
pipe.transform(promise);
|
||||
|
||||
resolve(message);
|
||||
resolve(message);
|
||||
|
||||
setTimeout(() => {
|
||||
expect(pipe.transform(promise)).toEqual(message);
|
||||
async.done();
|
||||
}, timer);
|
||||
}));
|
||||
setTimeout(() => {
|
||||
expect(pipe.transform(promise)).toEqual(message);
|
||||
done();
|
||||
}, timer);
|
||||
});
|
||||
|
||||
it('should return value when nothing has changed since the last call',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
pipe.transform(promise);
|
||||
resolve(message);
|
||||
it('should return value when nothing has changed since the last call', done => {
|
||||
pipe.transform(promise);
|
||||
resolve(message);
|
||||
|
||||
setTimeout(() => {
|
||||
pipe.transform(promise);
|
||||
expect(pipe.transform(promise)).toBe(message);
|
||||
async.done();
|
||||
}, timer);
|
||||
}));
|
||||
setTimeout(() => {
|
||||
pipe.transform(promise);
|
||||
expect(pipe.transform(promise)).toBe(message);
|
||||
done();
|
||||
}, timer);
|
||||
});
|
||||
|
||||
it('should dispose of the existing subscription when subscribing to a new promise',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
pipe.transform(promise);
|
||||
|
||||
promise = new Promise<any>(() => {});
|
||||
|
@ -198,41 +193,38 @@ import {SpyChangeDetectorRef} from '../spies';
|
|||
|
||||
setTimeout(() => {
|
||||
expect(pipe.transform(promise)).toBe(null);
|
||||
async.done();
|
||||
done();
|
||||
}, timer);
|
||||
}));
|
||||
});
|
||||
|
||||
it('should request a change detection check upon receiving a new value',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const markForCheck = ref.spy('markForCheck');
|
||||
pipe.transform(promise);
|
||||
resolve(message);
|
||||
it('should request a change detection check upon receiving a new value', done => {
|
||||
pipe.transform(promise);
|
||||
resolve(message);
|
||||
|
||||
setTimeout(() => {
|
||||
expect(markForCheck).toHaveBeenCalled();
|
||||
async.done();
|
||||
}, timer);
|
||||
}));
|
||||
setTimeout(() => {
|
||||
expect(ref.markForCheck).toHaveBeenCalled();
|
||||
done();
|
||||
}, timer);
|
||||
});
|
||||
|
||||
describe('ngOnDestroy', () => {
|
||||
it('should do nothing when no source', () => {
|
||||
expect(() => pipe.ngOnDestroy()).not.toThrow();
|
||||
});
|
||||
|
||||
it('should dispose of the existing source',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
pipe.transform(promise);
|
||||
expect(pipe.transform(promise)).toBe(null);
|
||||
resolve(message);
|
||||
it('should dispose of the existing source', done => {
|
||||
pipe.transform(promise);
|
||||
expect(pipe.transform(promise)).toBe(null);
|
||||
resolve(message);
|
||||
|
||||
|
||||
setTimeout(() => {
|
||||
expect(pipe.transform(promise)).toEqual(message);
|
||||
pipe.ngOnDestroy();
|
||||
expect(pipe.transform(promise)).toBe(null);
|
||||
async.done();
|
||||
}, timer);
|
||||
}));
|
||||
setTimeout(() => {
|
||||
expect(pipe.transform(promise)).toEqual(message);
|
||||
pipe.ngOnDestroy();
|
||||
expect(pipe.transform(promise)).toBe(null);
|
||||
done();
|
||||
}, timer);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
import {I18nPluralPipe, NgLocalization} from '@angular/common';
|
||||
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';
|
||||
|
||||
{
|
||||
|
|
|
@ -14,7 +14,6 @@ import localeEn from '@angular/common/locales/en';
|
|||
import localeEsUS from '@angular/common/locales/es-US';
|
||||
import localeFr from '@angular/common/locales/fr';
|
||||
import {ɵregisterLocaleData, ɵunregisterLocaleData} from '@angular/core';
|
||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
{
|
||||
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
|
||||
*/
|
||||
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {browserDetection} from '@angular/platform-browser/testing/src/browser_util';
|
||||
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 {HtmlParser} from '@angular/compiler/src/ml_parser/html_parser';
|
||||
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 {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import {By} from '@angular/platform-browser/src/dom/debug/by';
|
||||
import {stringifyElement} from '@angular/platform-browser/testing/src/browser_util';
|
||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
|
||||
import {SpyResourceLoader} from '../spies';
|
||||
|
||||
@Component({
|
||||
selector: 'i18n-cmp',
|
||||
template: '',
|
||||
|
@ -180,7 +179,7 @@ export const HTML = `
|
|||
export async function configureCompiler(translationsToMerge: string, format: string) {
|
||||
TestBed.configureCompiler({
|
||||
providers: [
|
||||
SpyResourceLoader.PROVIDE,
|
||||
{provide: ResourceLoader, useValue: jasmine.createSpyObj('ResourceLoader', ['get'])},
|
||||
FrLocalization.PROVIDE,
|
||||
{provide: TRANSLATIONS, useValue: translationsToMerge},
|
||||
{provide: TRANSLATIONS_FORMAT, useValue: format},
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Injector, NgModule} from '@angular/core';
|
||||
import {beforeEach, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {NgModule} from '@angular/core';
|
||||
import {JitReflector} from '@angular/platform-browser-dynamic/src/compiler_reflector';
|
||||
|
||||
import {MockNgModuleResolver} from '../testing';
|
||||
|
@ -16,9 +15,9 @@ import {MockNgModuleResolver} from '../testing';
|
|||
describe('MockNgModuleResolver', () => {
|
||||
let ngModuleResolver: MockNgModuleResolver;
|
||||
|
||||
beforeEach(inject([Injector], (injector: Injector) => {
|
||||
beforeEach(() => {
|
||||
ngModuleResolver = new MockNgModuleResolver(new JitReflector());
|
||||
}));
|
||||
});
|
||||
|
||||
describe('NgModule overriding', () => {
|
||||
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 {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
{
|
||||
describe('MockResourceLoader', () => {
|
||||
|
@ -42,41 +41,37 @@ import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@ang
|
|||
request.then(onResponse, onError);
|
||||
}
|
||||
|
||||
it('should return a response from the definitions',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const url = '/foo';
|
||||
const response = 'bar';
|
||||
resourceLoader.when(url, response);
|
||||
expectResponse(resourceLoader.get(url), url, response, () => async.done());
|
||||
resourceLoader.flush();
|
||||
}));
|
||||
it('should return a response from the definitions', done => {
|
||||
const url = '/foo';
|
||||
const response = 'bar';
|
||||
resourceLoader.when(url, response);
|
||||
expectResponse(resourceLoader.get(url), url, response, () => done());
|
||||
resourceLoader.flush();
|
||||
});
|
||||
|
||||
it('should return an error from the definitions',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const url = '/foo';
|
||||
const response: string = null!;
|
||||
resourceLoader.when(url, response);
|
||||
expectResponse(resourceLoader.get(url), url, response, () => async.done());
|
||||
resourceLoader.flush();
|
||||
}));
|
||||
it('should return an error from the definitions', done => {
|
||||
const url = '/foo';
|
||||
const response: string = null!;
|
||||
resourceLoader.when(url, response);
|
||||
expectResponse(resourceLoader.get(url), url, response, () => done());
|
||||
resourceLoader.flush();
|
||||
});
|
||||
|
||||
it('should return a response from the expectations',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const url = '/foo';
|
||||
const response = 'bar';
|
||||
resourceLoader.expect(url, response);
|
||||
expectResponse(resourceLoader.get(url), url, response, () => async.done());
|
||||
resourceLoader.flush();
|
||||
}));
|
||||
it('should return a response from the expectations', done => {
|
||||
const url = '/foo';
|
||||
const response = 'bar';
|
||||
resourceLoader.expect(url, response);
|
||||
expectResponse(resourceLoader.get(url), url, response, () => done());
|
||||
resourceLoader.flush();
|
||||
});
|
||||
|
||||
it('should return an error from the expectations',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const url = '/foo';
|
||||
const response: string = null!;
|
||||
resourceLoader.expect(url, response);
|
||||
expectResponse(resourceLoader.get(url), url, response, () => async.done());
|
||||
resourceLoader.flush();
|
||||
}));
|
||||
it('should return an error from the expectations', done => {
|
||||
const url = '/foo';
|
||||
const response: string = null!;
|
||||
resourceLoader.expect(url, response);
|
||||
expectResponse(resourceLoader.get(url), url, response, () => done());
|
||||
resourceLoader.flush();
|
||||
});
|
||||
|
||||
it('should not reuse expectations', () => {
|
||||
const url = '/foo';
|
||||
|
@ -89,15 +84,14 @@ import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@ang
|
|||
}).toThrowError('Unexpected request /foo');
|
||||
});
|
||||
|
||||
it('should return expectations before definitions',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const url = '/foo';
|
||||
resourceLoader.when(url, 'when');
|
||||
resourceLoader.expect(url, 'expect');
|
||||
expectResponse(resourceLoader.get(url), url, 'expect');
|
||||
expectResponse(resourceLoader.get(url), url, 'when', () => async.done());
|
||||
resourceLoader.flush();
|
||||
}));
|
||||
it('should return expectations before definitions', done => {
|
||||
const url = '/foo';
|
||||
resourceLoader.when(url, 'when');
|
||||
resourceLoader.expect(url, 'expect');
|
||||
expectResponse(resourceLoader.get(url), url, 'expect');
|
||||
expectResponse(resourceLoader.get(url), url, 'when', () => done());
|
||||
resourceLoader.flush();
|
||||
});
|
||||
|
||||
it('should throw when there is no definitions or expectations', () => {
|
||||
resourceLoader.get('/foo');
|
||||
|
|
|
@ -13,8 +13,6 @@ import {expect} from '@angular/platform-browser/testing/src/matchers';
|
|||
|
||||
import {MockDirectiveResolver} from '../testing';
|
||||
|
||||
import {SpyResourceLoader} from './spies';
|
||||
|
||||
@Component({selector: 'child-cmp'})
|
||||
class ChildComp {
|
||||
}
|
||||
|
@ -91,22 +89,20 @@ class SomeCompWithUrlTemplate {
|
|||
|
||||
describe('RuntimeCompiler', () => {
|
||||
let compiler: Compiler;
|
||||
let resourceLoader: SpyResourceLoader;
|
||||
let resourceLoader: {get: jasmine.Spy};
|
||||
let dirResolver: MockDirectiveResolver;
|
||||
let injector: Injector;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureCompiler({providers: [SpyResourceLoader.PROVIDE]});
|
||||
resourceLoader = jasmine.createSpyObj('ResourceLoader', ['get']);
|
||||
TestBed.configureCompiler({providers: [{provide: ResourceLoader, useValue: resourceLoader}]});
|
||||
});
|
||||
|
||||
beforeEach(fakeAsync(inject(
|
||||
[Compiler, ResourceLoader, DirectiveResolver, Injector],
|
||||
(_compiler: Compiler, _resourceLoader: SpyResourceLoader,
|
||||
_dirResolver: MockDirectiveResolver, _injector: Injector) => {
|
||||
(_compiler: Compiler, _resourceLoader: any, _dirResolver: MockDirectiveResolver) => {
|
||||
compiler = _compiler;
|
||||
resourceLoader = _resourceLoader;
|
||||
dirResolver = _dirResolver;
|
||||
injector = _injector;
|
||||
})));
|
||||
|
||||
describe('compileModuleAsync', () => {
|
||||
|
@ -118,7 +114,7 @@ class SomeCompWithUrlTemplate {
|
|||
class SomeModule {
|
||||
}
|
||||
|
||||
resourceLoader.spy('get').and.callFake(() => Promise.resolve('hello'));
|
||||
resourceLoader.get.and.callFake(() => Promise.resolve('hello'));
|
||||
let ngModuleFactory: NgModuleFactory<any> = undefined!;
|
||||
compiler.compileModuleAsync(SomeModule).then((f) => ngModuleFactory = f);
|
||||
tick();
|
||||
|
@ -133,7 +129,7 @@ class SomeCompWithUrlTemplate {
|
|||
class SomeModule {
|
||||
}
|
||||
|
||||
resourceLoader.spy('get').and.callFake(() => Promise.resolve(''));
|
||||
resourceLoader.get.and.callFake(() => Promise.resolve(''));
|
||||
expect(() => compiler.compileModuleSync(SomeModule))
|
||||
.toThrowError(`Can't compile synchronously as ${
|
||||
stringify(SomeCompWithUrlTemplate)} is still being loaded!`);
|
||||
|
@ -145,7 +141,7 @@ class SomeCompWithUrlTemplate {
|
|||
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(
|
||||
ChildComp, new Component({selector: 'child-cmp', templateUrl: '/someTpl.html'}));
|
||||
|
@ -163,7 +159,7 @@ class SomeCompWithUrlTemplate {
|
|||
class SomeModule {
|
||||
}
|
||||
|
||||
resourceLoader.spy('get').and.callFake(() => Promise.resolve('hello'));
|
||||
resourceLoader.get.and.callFake(() => Promise.resolve('hello'));
|
||||
compiler.compileModuleAsync(SomeModule);
|
||||
tick();
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
import {DomElementSchemaRegistry} from '@angular/compiler/src/schema/dom_element_schema_registry';
|
||||
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 {Element} from '../../src/ml_parser/ast';
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
import {isTrustedTypesSink} from '@angular/compiler/src/schema/trusted_types_sinks';
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
{
|
||||
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
|
||||
*/
|
||||
|
||||
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 {HtmlParser} from '../../src/ml_parser/html_parser';
|
||||
import {PreparsedElement, PreparsedElementType, preparseElement} from '../../src/template_parser/template_preparser';
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {createOfflineCompileUrlResolver, UrlResolver} from '@angular/compiler/src/url_resolver';
|
||||
import {beforeEach, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {UrlResolver} from '@angular/compiler/src/url_resolver';
|
||||
import {inject} from '@angular/core/testing';
|
||||
|
||||
{
|
||||
describe('UrlResolver', () => {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
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 {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
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 {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import {getElementStyles} from '@angular/core/testing/src/styling';
|
||||
import {expect} from '@angular/core/testing/src/testing_internal';
|
||||
import {onlyInIvy} from '@angular/private/testing';
|
||||
|
||||
import {getLContext} from '../../src/render3/context_discovery';
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
import {ProfilerEvent, setProfiler} from '@angular/core/src/render3/profiler';
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {expect} from '@angular/core/testing/src/testing_internal';
|
||||
import {onlyInIvy} from '@angular/private/testing';
|
||||
|
||||
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 {inject} from '@angular/core/testing';
|
||||
import {ivyEnabled} from '@angular/private/testing';
|
||||
|
||||
import {getLocaleId} from '../src/render3';
|
||||
import {global} from '../src/util/global';
|
||||
import {TestBed} from '../testing';
|
||||
import {describe, expect, inject, it} from '../testing/src/testing_internal';
|
||||
|
||||
{
|
||||
describe('Application module', () => {
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
import {Injector, IterableDiffer, IterableDifferFactory, IterableDiffers, NgModule, TrackByFunction} from '@angular/core';
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
|
||||
import {SpyIterableDifferFactory} from '../../spies';
|
||||
|
||||
{
|
||||
describe('IterableDiffers', function() {
|
||||
let factory1: any;
|
||||
|
@ -18,9 +16,10 @@ import {SpyIterableDifferFactory} from '../../spies';
|
|||
let factory3: any;
|
||||
|
||||
beforeEach(() => {
|
||||
factory1 = new SpyIterableDifferFactory();
|
||||
factory2 = new SpyIterableDifferFactory();
|
||||
factory3 = new SpyIterableDifferFactory();
|
||||
const getFactory = () => jasmine.createSpyObj('IterableDifferFactory', ['supports']);
|
||||
factory1 = getFactory();
|
||||
factory2 = getFactory();
|
||||
factory3 = getFactory();
|
||||
});
|
||||
|
||||
it('should throw when no suitable implementation found', () => {
|
||||
|
@ -30,17 +29,17 @@ import {SpyIterableDifferFactory} from '../../spies';
|
|||
});
|
||||
|
||||
it('should return the first suitable implementation', () => {
|
||||
factory1.spy('supports').and.returnValue(false);
|
||||
factory2.spy('supports').and.returnValue(true);
|
||||
factory3.spy('supports').and.returnValue(true);
|
||||
factory1.supports.and.returnValue(false);
|
||||
factory2.supports.and.returnValue(true);
|
||||
factory3.supports.and.returnValue(true);
|
||||
|
||||
const differs = IterableDiffers.create(<any>[factory1, factory2, factory3]);
|
||||
expect(differs.find('some object')).toBe(factory2);
|
||||
});
|
||||
|
||||
it('should copy over differs from the parent repo', () => {
|
||||
factory1.spy('supports').and.returnValue(true);
|
||||
factory2.spy('supports').and.returnValue(false);
|
||||
factory1.supports.and.returnValue(true);
|
||||
factory2.supports.and.returnValue(false);
|
||||
|
||||
const parent = IterableDiffers.create(<any>[factory1]);
|
||||
const child = IterableDiffers.create(<any>[factory2], parent);
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
import {Type} from '@angular/core';
|
||||
import {forwardRef, resolveForwardRef} from '@angular/core/src/di';
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
{
|
||||
describe('forwardRef', function() {
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
|
||||
import {Injector} from '@angular/core';
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
{
|
||||
describe('Injector.NULL', () => {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
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';
|
||||
|
||||
{
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
* 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', () => {
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
* 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 {EventEmitter} from '../src/event_emitter';
|
||||
|
@ -19,51 +18,47 @@ import {EventEmitter} from '../src/event_emitter';
|
|||
emitter = new EventEmitter();
|
||||
});
|
||||
|
||||
it('should call the next callback',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
emitter.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(value).toEqual(99);
|
||||
async.done();
|
||||
}
|
||||
});
|
||||
emitter.emit(99);
|
||||
}));
|
||||
it('should call the next callback', done => {
|
||||
emitter.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(value).toEqual(99);
|
||||
done();
|
||||
}
|
||||
});
|
||||
emitter.emit(99);
|
||||
});
|
||||
|
||||
it('should call the throw callback',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
emitter.subscribe({
|
||||
next: () => {},
|
||||
error: (error: any) => {
|
||||
expect(error).toEqual('Boom');
|
||||
async.done();
|
||||
}
|
||||
});
|
||||
emitter.error('Boom');
|
||||
}));
|
||||
it('should call the throw callback', done => {
|
||||
emitter.subscribe({
|
||||
next: () => {},
|
||||
error: (error: any) => {
|
||||
expect(error).toEqual('Boom');
|
||||
done();
|
||||
}
|
||||
});
|
||||
emitter.error('Boom');
|
||||
});
|
||||
|
||||
it('should work when no throw callback is provided',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
emitter.subscribe({
|
||||
next: () => {},
|
||||
error: (_: any) => {
|
||||
async.done();
|
||||
}
|
||||
});
|
||||
emitter.error('Boom');
|
||||
}));
|
||||
it('should work when no throw callback is provided', done => {
|
||||
emitter.subscribe({
|
||||
next: () => {},
|
||||
error: (_: any) => {
|
||||
done();
|
||||
}
|
||||
});
|
||||
emitter.error('Boom');
|
||||
});
|
||||
|
||||
it('should call the return callback',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
emitter.subscribe({
|
||||
next: () => {},
|
||||
error: (_: any) => {},
|
||||
complete: () => {
|
||||
async.done();
|
||||
}
|
||||
});
|
||||
emitter.complete();
|
||||
}));
|
||||
it('should call the return callback', done => {
|
||||
emitter.subscribe({
|
||||
next: () => {},
|
||||
error: (_: any) => {},
|
||||
complete: () => {
|
||||
done();
|
||||
}
|
||||
});
|
||||
emitter.complete();
|
||||
});
|
||||
|
||||
it('should subscribe to the wrapper synchronously', () => {
|
||||
let called = false;
|
||||
|
@ -77,27 +72,26 @@ import {EventEmitter} from '../src/event_emitter';
|
|||
expect(called).toBe(true);
|
||||
});
|
||||
|
||||
it('delivers next and error events synchronously',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const log: any[] /** TODO #9100 */ = [];
|
||||
it('delivers next and error events synchronously', done => {
|
||||
const log: any[] /** TODO #9100 */ = [];
|
||||
|
||||
emitter.subscribe({
|
||||
next: (x: any) => {
|
||||
log.push(x);
|
||||
expect(log).toEqual([1, 2]);
|
||||
},
|
||||
error: (err: any) => {
|
||||
log.push(err);
|
||||
expect(log).toEqual([1, 2, 3, 4]);
|
||||
async.done();
|
||||
}
|
||||
});
|
||||
log.push(1);
|
||||
emitter.emit(2);
|
||||
log.push(3);
|
||||
emitter.error(4);
|
||||
log.push(5);
|
||||
}));
|
||||
emitter.subscribe({
|
||||
next: (x: any) => {
|
||||
log.push(x);
|
||||
expect(log).toEqual([1, 2]);
|
||||
},
|
||||
error: (err: any) => {
|
||||
log.push(err);
|
||||
expect(log).toEqual([1, 2, 3, 4]);
|
||||
done();
|
||||
}
|
||||
});
|
||||
log.push(1);
|
||||
emitter.emit(2);
|
||||
log.push(3);
|
||||
emitter.error(4);
|
||||
log.push(5);
|
||||
});
|
||||
|
||||
it('delivers next and complete events synchronously', () => {
|
||||
const log: any[] /** TODO #9100 */ = [];
|
||||
|
@ -121,19 +115,18 @@ import {EventEmitter} from '../src/event_emitter';
|
|||
expect(log).toEqual([1, 2, 3, 4, 5]);
|
||||
});
|
||||
|
||||
it('delivers events asynchronously when forced to async mode',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const e = new EventEmitter(true);
|
||||
const log: any[] /** TODO #9100 */ = [];
|
||||
e.subscribe((x: any) => {
|
||||
log.push(x);
|
||||
expect(log).toEqual([1, 3, 2]);
|
||||
async.done();
|
||||
});
|
||||
log.push(1);
|
||||
e.emit(2);
|
||||
log.push(3);
|
||||
}));
|
||||
it('delivers events asynchronously when forced to async mode', done => {
|
||||
const e = new EventEmitter(true);
|
||||
const log: any[] /** TODO #9100 */ = [];
|
||||
e.subscribe((x: any) => {
|
||||
log.push(x);
|
||||
expect(log).toEqual([1, 3, 2]);
|
||||
done();
|
||||
});
|
||||
log.push(1);
|
||||
e.emit(2);
|
||||
log.push(3);
|
||||
});
|
||||
|
||||
it('reports whether it has subscribers', () => {
|
||||
const e = new EventEmitter(false);
|
||||
|
@ -156,21 +149,17 @@ import {EventEmitter} from '../src/event_emitter';
|
|||
expect(emitter.observers.length).toBe(0);
|
||||
});
|
||||
|
||||
it('unsubscribing a subscriber invokes the dispose method', () => {
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const sub = emitter.subscribe();
|
||||
sub.add(() => async.done());
|
||||
sub.unsubscribe();
|
||||
});
|
||||
it('unsubscribing a subscriber invokes the dispose method', done => {
|
||||
const sub = emitter.subscribe();
|
||||
sub.add(() => done());
|
||||
sub.unsubscribe();
|
||||
});
|
||||
|
||||
it('unsubscribing a subscriber after applying operators with pipe() invokes the dispose method',
|
||||
() => {
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const sub = emitter.pipe(filter(() => true)).subscribe();
|
||||
sub.add(() => async.done());
|
||||
sub.unsubscribe();
|
||||
});
|
||||
done => {
|
||||
const sub = emitter.pipe(filter(() => true)).subscribe();
|
||||
sub.add(() => done());
|
||||
sub.unsubscribe();
|
||||
});
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
import {discardPeriodicTasks, fakeAsync, flush, flushMicrotasks, tick} from '@angular/core/testing';
|
||||
import {beforeEach, describe, inject, it, Log} from '@angular/core/testing/src/testing_internal';
|
||||
import {discardPeriodicTasks, fakeAsync, flush, flushMicrotasks, inject, tick} from '@angular/core/testing';
|
||||
import {Log} from '@angular/core/testing/src/testing_internal';
|
||||
import {EventManager} from '@angular/platform-browser';
|
||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
import {Component, Directive, HostBinding} from '@angular/core';
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {modifiedInIvy, onlyInIvy} from '@angular/private/testing';
|
||||
|
||||
@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 {QueryList} from '@angular/core/src/linker/query_list';
|
||||
import {fakeAsync, tick} from '@angular/core/testing';
|
||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
{
|
||||
describe('QueryList', () => {
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
import {Compiler, SystemJsNgModuleLoader} from '@angular/core';
|
||||
import {global} from '@angular/core/src/util/global';
|
||||
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';
|
||||
|
||||
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 {I18nUpdateOpCodes, IcuType, TI18n} from '@angular/core/src/render3/interfaces/i18n';
|
||||
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 {matchDebug} from '../utils';
|
||||
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 {ngDevModeResetPerfCounters} from '@angular/core/src/util/ng_dev_mode';
|
||||
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';
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
import {AttributeMarker} from '@angular/core/src/render3';
|
||||
import {TAttributes} from '@angular/core/src/render3/interfaces/node';
|
||||
import {mergeHostAttribute, mergeHostAttrs} from '@angular/core/src/render3/util/attrs_utils';
|
||||
import {describe} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
describe('attr_util', () => {
|
||||
describe('mergeHostAttribute', () => {
|
||||
|
|
|
@ -6,16 +6,14 @@
|
|||
* 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';
|
||||
|
||||
{
|
||||
t.describe('URL sanitizer', () => {
|
||||
describe('URL sanitizer', () => {
|
||||
let logMsgs: string[];
|
||||
let originalLog: (msg: any) => any;
|
||||
|
||||
t.beforeEach(() => {
|
||||
beforeEach(() => {
|
||||
logMsgs = [];
|
||||
originalLog = console.warn; // Monkey patch DOM.log.
|
||||
console.warn = (msg: any) => logMsgs.push(msg);
|
||||
|
@ -25,12 +23,12 @@ import {_sanitizeUrl, sanitizeSrcset} from '../../src/sanitization/url_sanitizer
|
|||
console.warn = originalLog;
|
||||
});
|
||||
|
||||
t.it('reports unsafe URLs', () => {
|
||||
t.expect(_sanitizeUrl('javascript:evil()')).toBe('unsafe:javascript:evil()');
|
||||
t.expect(logMsgs.join('\n')).toMatch(/sanitizing unsafe URL value/);
|
||||
it('reports unsafe URLs', () => {
|
||||
expect(_sanitizeUrl('javascript:evil()')).toBe('unsafe:javascript:evil()');
|
||||
expect(logMsgs.join('\n')).toMatch(/sanitizing unsafe URL value/);
|
||||
});
|
||||
|
||||
t.describe('valid URLs', () => {
|
||||
describe('valid URLs', () => {
|
||||
const validUrls = [
|
||||
'',
|
||||
'http://abc',
|
||||
|
@ -51,11 +49,11 @@ import {_sanitizeUrl, sanitizeSrcset} from '../../src/sanitization/url_sanitizer
|
|||
'data:audio/opus;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
|
||||
];
|
||||
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 = [
|
||||
'javascript:evil()',
|
||||
'JavaScript:abc',
|
||||
|
@ -75,11 +73,11 @@ import {_sanitizeUrl, sanitizeSrcset} from '../../src/sanitization/url_sanitizer
|
|||
'data:application/x-msdownload;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
|
||||
];
|
||||
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 = [
|
||||
'',
|
||||
'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',
|
||||
];
|
||||
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 = [
|
||||
'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) {
|
||||
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 {NgZone} from '@angular/core/src/zone/ng_zone';
|
||||
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';
|
||||
|
||||
|
@ -58,9 +57,9 @@ class MockNgZone extends NgZone {
|
|||
beforeEach(waitForAsync(() => {
|
||||
ngZone = new MockNgZone();
|
||||
testability = new Testability(ngZone);
|
||||
execute = new SpyObject().spy('execute');
|
||||
execute2 = new SpyObject().spy('execute');
|
||||
updateCallback = new SpyObject().spy('execute');
|
||||
execute = jasmine.createSpy('execute');
|
||||
execute2 = jasmine.createSpy('execute');
|
||||
updateCallback = jasmine.createSpy('execute');
|
||||
}));
|
||||
|
||||
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 {AsyncTestCompleter} from './async_test_completer';
|
||||
import {ComponentFixture} from './component_fixture';
|
||||
import {MetadataOverride} from './metadata_override';
|
||||
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
|
||||
*/
|
||||
export function inject(tokens: any[], fn: Function): () => any {
|
||||
const testBed = getTestBed();
|
||||
if (tokens.indexOf(AsyncTestCompleter) >= 0) {
|
||||
// Not using an arrow function to preserve context passed from call site
|
||||
return function(this: unknown) {
|
||||
// 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);
|
||||
};
|
||||
}
|
||||
// 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
|
||||
*/
|
||||
|
||||
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 * from './logger';
|
||||
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 {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 {selectValueAccessor} from '@angular/forms/src/directives/shared';
|
||||
import {composeValidators} from '@angular/forms/src/validators';
|
||||
import {SpyNgControl, SpyValueAccessor} from './spies';
|
||||
import {asyncValidator} from './util';
|
||||
|
||||
class DummyControlValueAccessor implements ControlValueAccessor {
|
||||
|
@ -45,7 +43,7 @@ class CustomValidatorDirective implements Validator {
|
|||
let dir: NgControl;
|
||||
|
||||
beforeEach(() => {
|
||||
dir = <any>new SpyNgControl();
|
||||
dir = {path: []} as any;
|
||||
});
|
||||
|
||||
it('should throw when given an empty array', () => {
|
||||
|
@ -90,7 +88,7 @@ class CustomValidatorDirective implements Validator {
|
|||
});
|
||||
|
||||
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!);
|
||||
expect(selectValueAccessor(dir, <any>[
|
||||
defaultAccessor, customAccessor, checkboxAccessor
|
||||
|
@ -98,7 +96,7 @@ class CustomValidatorDirective implements Validator {
|
|||
});
|
||||
|
||||
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!);
|
||||
expect(selectValueAccessor(dir, <any>[
|
||||
defaultAccessor, customAccessor, selectMultipleAccessor
|
||||
|
@ -106,7 +104,7 @@ class CustomValidatorDirective implements Validator {
|
|||
});
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
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 {Validators} from '@angular/forms/src/validators';
|
||||
import {of} from 'rxjs';
|
||||
|
@ -856,64 +855,60 @@ describe('FormArray', () => {
|
|||
a = new FormArray([c1, c2]);
|
||||
});
|
||||
|
||||
it('should fire an event after the value has been updated',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
a.valueChanges.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(a.value).toEqual(['new1', 'old2']);
|
||||
expect(value).toEqual(['new1', 'old2']);
|
||||
async.done();
|
||||
}
|
||||
});
|
||||
c1.setValue('new1');
|
||||
}));
|
||||
it('should fire an event after the value has been updated', done => {
|
||||
a.valueChanges.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(a.value).toEqual(['new1', 'old2']);
|
||||
expect(value).toEqual(['new1', 'old2']);
|
||||
done();
|
||||
}
|
||||
});
|
||||
c1.setValue('new1');
|
||||
});
|
||||
|
||||
it('should fire an event after the control\'s observable fired an event',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
let controlCallbackIsCalled = false;
|
||||
it('should fire an event after the control\'s observable fired an event', done => {
|
||||
let controlCallbackIsCalled = false;
|
||||
|
||||
|
||||
c1.valueChanges.subscribe({
|
||||
next: (value: any) => {
|
||||
controlCallbackIsCalled = true;
|
||||
}
|
||||
});
|
||||
c1.valueChanges.subscribe({
|
||||
next: (value: any) => {
|
||||
controlCallbackIsCalled = true;
|
||||
}
|
||||
});
|
||||
|
||||
a.valueChanges.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(controlCallbackIsCalled).toBe(true);
|
||||
async.done();
|
||||
}
|
||||
});
|
||||
a.valueChanges.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(controlCallbackIsCalled).toBe(true);
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
c1.setValue('new1');
|
||||
}));
|
||||
c1.setValue('new1');
|
||||
});
|
||||
|
||||
it('should fire an event when a control is removed',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
a.valueChanges.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(value).toEqual(['old1']);
|
||||
async.done();
|
||||
}
|
||||
});
|
||||
it('should fire an event when a control is removed', done => {
|
||||
a.valueChanges.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(value).toEqual(['old1']);
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
a.removeAt(1);
|
||||
}));
|
||||
a.removeAt(1);
|
||||
});
|
||||
|
||||
it('should fire an event when a control is added',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
a.removeAt(1);
|
||||
it('should fire an event when a control is added', done => {
|
||||
a.removeAt(1);
|
||||
|
||||
a.valueChanges.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(value).toEqual(['old1', 'old2']);
|
||||
async.done();
|
||||
}
|
||||
});
|
||||
a.valueChanges.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(value).toEqual(['old1', 'old2']);
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
a.push(c2);
|
||||
}));
|
||||
a.push(c2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('get', () => {
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
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 {of} from 'rxjs';
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
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 {FormArray} from '@angular/forms/src/model';
|
||||
|
@ -857,17 +856,16 @@ describe('FormControl', () => {
|
|||
c = new FormControl('old', Validators.required);
|
||||
});
|
||||
|
||||
it('should fire an event after the value has been updated',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
c.valueChanges.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(c.value).toEqual('new');
|
||||
expect(value).toEqual('new');
|
||||
async.done();
|
||||
}
|
||||
});
|
||||
c.setValue('new');
|
||||
}));
|
||||
it('should fire an event after the value has been updated', done => {
|
||||
c.valueChanges.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(c.value).toEqual('new');
|
||||
expect(value).toEqual('new');
|
||||
done();
|
||||
}
|
||||
});
|
||||
c.setValue('new');
|
||||
});
|
||||
|
||||
it('should fire an event after the status has been updated to invalid', fakeAsync(() => {
|
||||
c.statusChanges.subscribe({
|
||||
|
@ -911,27 +909,25 @@ describe('FormControl', () => {
|
|||
}));
|
||||
|
||||
// TODO: remove the if statement after making observable delivery sync
|
||||
it('should update set errors and status before emitting an event',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
c.valueChanges.subscribe((value: any /** TODO #9100 */) => {
|
||||
expect(c.valid).toEqual(false);
|
||||
expect(c.errors).toEqual({'required': true});
|
||||
async.done();
|
||||
});
|
||||
c.setValue('');
|
||||
}));
|
||||
it('should update set errors and status before emitting an event', done => {
|
||||
c.valueChanges.subscribe((value: any /** TODO #9100 */) => {
|
||||
expect(c.valid).toEqual(false);
|
||||
expect(c.errors).toEqual({'required': true});
|
||||
done();
|
||||
});
|
||||
c.setValue('');
|
||||
});
|
||||
|
||||
it('should return a cold observable',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
c.setValue('will be ignored');
|
||||
c.valueChanges.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(value).toEqual('new');
|
||||
async.done();
|
||||
}
|
||||
});
|
||||
c.setValue('new');
|
||||
}));
|
||||
it('should return a cold observable', done => {
|
||||
c.setValue('will be ignored');
|
||||
c.valueChanges.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(value).toEqual('new');
|
||||
done();
|
||||
}
|
||||
});
|
||||
c.setValue('new');
|
||||
});
|
||||
});
|
||||
|
||||
describe('setErrors', () => {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
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 {of} from 'rxjs';
|
||||
|
||||
|
@ -822,20 +821,19 @@ describe('FormGroup', () => {
|
|||
|
||||
|
||||
// TODO(kara): update these tests to use fake Async
|
||||
it('should fire a statusChange if child has async validation change',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const loggedValues: string[] = [];
|
||||
group.statusChanges.subscribe({
|
||||
next: (status: string) => {
|
||||
loggedValues.push(status);
|
||||
if (loggedValues.length === 2) {
|
||||
expect(loggedValues).toEqual(['PENDING', 'INVALID']);
|
||||
}
|
||||
async.done();
|
||||
}
|
||||
});
|
||||
control.setValue('');
|
||||
}));
|
||||
it('should fire a statusChange if child has async validation change', done => {
|
||||
const loggedValues: string[] = [];
|
||||
group.statusChanges.subscribe({
|
||||
next: (status: string) => {
|
||||
loggedValues.push(status);
|
||||
if (loggedValues.length === 2) {
|
||||
expect(loggedValues).toEqual(['PENDING', 'INVALID']);
|
||||
}
|
||||
done();
|
||||
}
|
||||
});
|
||||
control.setValue('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getError', () => {
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
import {ɵgetDOM as getDOM} from '@angular/common';
|
||||
import {Component, Directive, forwardRef, Input, NgModule, OnDestroy, Type} from '@angular/core';
|
||||
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 {By} from '@angular/platform-browser/src/dom/debug/by';
|
||||
import {dispatchEvent, sortedClassList} from '@angular/platform-browser/testing/src/browser_util';
|
||||
|
@ -5018,4 +5017,4 @@ class MinMaxFormControlComp {
|
|||
form!: FormGroup;
|
||||
min: number|string = 1;
|
||||
max: number|string = 10;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {AbstractControl, AsyncValidator, AsyncValidatorFn, FormArray, FormControl, ValidationErrors, ValidatorFn, Validators} from '@angular/forms';
|
||||
import {Observable, of, timer} from 'rxjs';
|
||||
import {first, map} from 'rxjs/operators';
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
* 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';
|
||||
|
||||
if (isBrowser) {
|
||||
|
@ -26,21 +25,19 @@ if (isBrowser) {
|
|||
resourceLoader = new ResourceLoaderImpl();
|
||||
});
|
||||
|
||||
it('should resolve the Promise with the file content on success',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
resourceLoader.get(url200).then((text) => {
|
||||
expect(text.trim()).toEqual('<p>hey</p>');
|
||||
async.done();
|
||||
});
|
||||
}), 10000);
|
||||
it('should resolve the Promise with the file content on success', done => {
|
||||
resourceLoader.get(url200).then((text) => {
|
||||
expect(text.trim()).toEqual('<p>hey</p>');
|
||||
done();
|
||||
});
|
||||
}, 10000);
|
||||
|
||||
it('should reject the Promise on failure',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
resourceLoader.get(url404).catch((e) => {
|
||||
expect(e).toEqual(`Failed to load ${url404}`);
|
||||
async.done();
|
||||
return null;
|
||||
});
|
||||
}), 10000);
|
||||
it('should reject the Promise on failure', done => {
|
||||
resourceLoader.get(url404).catch((e) => {
|
||||
expect(e).toEqual(`Failed to load ${url404}`);
|
||||
done();
|
||||
return null;
|
||||
});
|
||||
}, 10000);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -12,7 +12,8 @@ import {ApplicationRef, destroyPlatform} from '@angular/core/src/application_ref
|
|||
import {Console} from '@angular/core/src/console';
|
||||
import {ComponentRef} from '@angular/core/src/linker/component_factory';
|
||||
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 {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
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'})
|
||||
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>'})
|
||||
class HelloCmpUsingCustomElement {
|
||||
}
|
||||
|
@ -150,8 +124,8 @@ function bootstrap(
|
|||
if (isNode) return;
|
||||
let compilerConsole: DummyConsole;
|
||||
|
||||
beforeEachProviders(() => {
|
||||
return [Log];
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({providers: [Log]});
|
||||
});
|
||||
|
||||
beforeEach(inject([DOCUMENT], (doc: any) => {
|
||||
|
@ -175,35 +149,31 @@ function bootstrap(
|
|||
|
||||
afterEach(destroyPlatform);
|
||||
|
||||
// TODO(misko): can't use `modifiedInIvy.it` because the `it` is somehow special here.
|
||||
modifiedInIvy('bootstrapping non-Component throws in View Engine').isEnabled &&
|
||||
it('should throw if bootstrapped Directive is not a Component',
|
||||
inject([AsyncTestCompleter], (done: AsyncTestCompleter) => {
|
||||
const logger = new MockConsole();
|
||||
const errorHandler = new ErrorHandler();
|
||||
(errorHandler as any)._console = logger as any;
|
||||
expect(
|
||||
() => bootstrap(
|
||||
HelloRootDirectiveIsNotCmp, [{provide: ErrorHandler, useValue: errorHandler}]))
|
||||
.toThrowError(`HelloRootDirectiveIsNotCmp cannot be used as an entry component.`);
|
||||
done.done();
|
||||
}));
|
||||
modifiedInIvy('bootstrapping non-Component throws in View Engine')
|
||||
.it('should throw if bootstrapped Directive is not a Component', done => {
|
||||
const logger = new MockConsole();
|
||||
const errorHandler = new ErrorHandler();
|
||||
(errorHandler as any)._console = logger as any;
|
||||
expect(
|
||||
() => bootstrap(
|
||||
HelloRootDirectiveIsNotCmp, [{provide: ErrorHandler, useValue: errorHandler}]))
|
||||
.toThrowError(`HelloRootDirectiveIsNotCmp cannot be used as an entry component.`);
|
||||
done();
|
||||
});
|
||||
|
||||
// TODO(misko): can't use `onlyInIvy.it` because the `it` is somehow special here.
|
||||
onlyInIvy('bootstrapping non-Component rejects Promise in Ivy').isEnabled &&
|
||||
it('should throw if bootstrapped Directive is not a Component',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const logger = new MockConsole();
|
||||
const errorHandler = new ErrorHandler();
|
||||
(errorHandler as any)._console = logger as any;
|
||||
bootstrap(HelloRootDirectiveIsNotCmp, [
|
||||
{provide: ErrorHandler, useValue: errorHandler}
|
||||
]).catch((error: Error) => {
|
||||
expect(error).toEqual(
|
||||
new Error(`HelloRootDirectiveIsNotCmp cannot be used as an entry component.`));
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
onlyInIvy('bootstrapping non-Component rejects Promise in Ivy')
|
||||
.it('should throw if bootstrapped Directive is not a Component', done => {
|
||||
const logger = new MockConsole();
|
||||
const errorHandler = new ErrorHandler();
|
||||
(errorHandler as any)._console = logger as any;
|
||||
bootstrap(HelloRootDirectiveIsNotCmp, [
|
||||
{provide: ErrorHandler, useValue: errorHandler}
|
||||
]).catch((error: Error) => {
|
||||
expect(error).toEqual(
|
||||
new Error(`HelloRootDirectiveIsNotCmp cannot be used as an entry component.`));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should retrieve sanitizer', inject([Injector], (injector: Injector) => {
|
||||
const sanitizer: Sanitizer|null = injector.get(Sanitizer, null);
|
||||
|
@ -218,92 +188,88 @@ function bootstrap(
|
|||
}
|
||||
}));
|
||||
|
||||
it('should throw if no element is found',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const logger = new MockConsole();
|
||||
const errorHandler = new ErrorHandler();
|
||||
(errorHandler as any)._console = logger as any;
|
||||
bootstrap(NonExistentComp, [
|
||||
{provide: ErrorHandler, useValue: errorHandler}
|
||||
]).then(null, (reason) => {
|
||||
expect(reason.message)
|
||||
.toContain('The selector "non-existent" did not match any elements');
|
||||
async.done();
|
||||
return null;
|
||||
});
|
||||
}));
|
||||
it('should throw if no element is found', done => {
|
||||
const logger = new MockConsole();
|
||||
const errorHandler = new ErrorHandler();
|
||||
(errorHandler as any)._console = logger as any;
|
||||
bootstrap(NonExistentComp, [
|
||||
{provide: ErrorHandler, useValue: errorHandler}
|
||||
]).then(null, (reason) => {
|
||||
expect(reason.message).toContain('The selector "non-existent" did not match any elements');
|
||||
done();
|
||||
return null;
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw if no provider', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const logger = new MockConsole();
|
||||
const errorHandler = new ErrorHandler();
|
||||
(errorHandler as any)._console = logger as any;
|
||||
it('should throw if no provider', done => {
|
||||
const logger = new MockConsole();
|
||||
const errorHandler = new ErrorHandler();
|
||||
(errorHandler as any)._console = logger as any;
|
||||
|
||||
class IDontExist {}
|
||||
class IDontExist {}
|
||||
|
||||
@Component({selector: 'cmp', template: 'Cmp'})
|
||||
class CustomCmp {
|
||||
constructor(iDontExist: IDontExist) {}
|
||||
}
|
||||
@Component({selector: 'cmp', template: 'Cmp'})
|
||||
class CustomCmp {
|
||||
constructor(iDontExist: IDontExist) {}
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'hello-app',
|
||||
template: '<cmp></cmp>',
|
||||
})
|
||||
class RootCmp {
|
||||
}
|
||||
@Component({
|
||||
selector: 'hello-app',
|
||||
template: '<cmp></cmp>',
|
||||
})
|
||||
class RootCmp {
|
||||
}
|
||||
|
||||
@NgModule({declarations: [CustomCmp], exports: [CustomCmp]})
|
||||
class CustomModule {
|
||||
}
|
||||
@NgModule({declarations: [CustomCmp], exports: [CustomCmp]})
|
||||
class CustomModule {
|
||||
}
|
||||
|
||||
bootstrap(RootCmp, [{provide: ErrorHandler, useValue: errorHandler}], [], [
|
||||
CustomModule
|
||||
]).then(null, (e: Error) => {
|
||||
let errorMsg: string;
|
||||
if (ivyEnabled) {
|
||||
errorMsg = `R3InjectorError(TestModule)[IDontExist -> IDontExist -> IDontExist]: \n`;
|
||||
} else {
|
||||
errorMsg = `StaticInjectorError(TestModule)[CustomCmp -> IDontExist]: \n` +
|
||||
' StaticInjectorError(Platform: core)[CustomCmp -> IDontExist]: \n' +
|
||||
' NullInjectorError: No provider for IDontExist!';
|
||||
}
|
||||
expect(e.message).toContain(errorMsg);
|
||||
async.done();
|
||||
return null;
|
||||
});
|
||||
}));
|
||||
bootstrap(RootCmp, [{provide: ErrorHandler, useValue: errorHandler}], [], [
|
||||
CustomModule
|
||||
]).then(null, (e: Error) => {
|
||||
let errorMsg: string;
|
||||
if (ivyEnabled) {
|
||||
errorMsg = `R3InjectorError(TestModule)[IDontExist -> IDontExist -> IDontExist]: \n`;
|
||||
} else {
|
||||
errorMsg = `StaticInjectorError(TestModule)[CustomCmp -> IDontExist]: \n` +
|
||||
' StaticInjectorError(Platform: core)[CustomCmp -> IDontExist]: \n' +
|
||||
' NullInjectorError: No provider for IDontExist!';
|
||||
}
|
||||
expect(e.message).toContain(errorMsg);
|
||||
done();
|
||||
return null;
|
||||
});
|
||||
});
|
||||
|
||||
if (getDOM().supportsDOMEvents) {
|
||||
it('should forward the error to promise when bootstrap fails',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const logger = new MockConsole();
|
||||
const errorHandler = new ErrorHandler();
|
||||
(errorHandler as any)._console = logger as any;
|
||||
it('should forward the error to promise when bootstrap fails', done => {
|
||||
const logger = new MockConsole();
|
||||
const errorHandler = new ErrorHandler();
|
||||
(errorHandler as any)._console = logger as any;
|
||||
|
||||
const refPromise =
|
||||
bootstrap(NonExistentComp, [{provide: ErrorHandler, useValue: errorHandler}]);
|
||||
refPromise.then(null, (reason: any) => {
|
||||
expect(reason.message)
|
||||
.toContain('The selector "non-existent" did not match any elements');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
const refPromise =
|
||||
bootstrap(NonExistentComp, [{provide: ErrorHandler, useValue: errorHandler}]);
|
||||
refPromise.then(null, (reason: any) => {
|
||||
expect(reason.message)
|
||||
.toContain('The selector "non-existent" did not match any elements');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should invoke the default exception handler when bootstrap fails',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const logger = new MockConsole();
|
||||
const errorHandler = new ErrorHandler();
|
||||
(errorHandler as any)._console = logger as any;
|
||||
it('should invoke the default exception handler when bootstrap fails', done => {
|
||||
const logger = new MockConsole();
|
||||
const errorHandler = new ErrorHandler();
|
||||
(errorHandler as any)._console = logger as any;
|
||||
|
||||
const refPromise =
|
||||
bootstrap(NonExistentComp, [{provide: ErrorHandler, useValue: errorHandler}]);
|
||||
refPromise.then(null, (reason) => {
|
||||
expect(logger.res[0].join('#'))
|
||||
.toContain('ERROR#Error: The selector "non-existent" did not match any elements');
|
||||
async.done();
|
||||
return null;
|
||||
});
|
||||
}));
|
||||
const refPromise =
|
||||
bootstrap(NonExistentComp, [{provide: ErrorHandler, useValue: errorHandler}]);
|
||||
refPromise.then(null, (reason) => {
|
||||
expect(logger.res[0].join('#'))
|
||||
.toContain('ERROR#Error: The selector "non-existent" did not match any elements');
|
||||
done();
|
||||
return null;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
it('should create an injector promise', () => {
|
||||
|
@ -311,26 +277,25 @@ function bootstrap(
|
|||
expect(refPromise).toEqual(jasmine.any(Promise));
|
||||
});
|
||||
|
||||
it('should set platform name to browser',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const refPromise = bootstrap(HelloRootCmp, testProviders);
|
||||
refPromise.then((ref) => {
|
||||
expect(isPlatformBrowser(ref.injector.get(PLATFORM_ID))).toBe(true);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should set platform name to browser', done => {
|
||||
const refPromise = bootstrap(HelloRootCmp, testProviders);
|
||||
refPromise.then((ref) => {
|
||||
expect(isPlatformBrowser(ref.injector.get(PLATFORM_ID))).toBe(true);
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
|
||||
it('should display hello world', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const refPromise = bootstrap(HelloRootCmp, testProviders);
|
||||
refPromise.then((ref) => {
|
||||
expect(el).toHaveText('hello world!');
|
||||
expect(el.getAttribute('ng-version')).toEqual(VERSION.full);
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should display hello world', done => {
|
||||
const refPromise = bootstrap(HelloRootCmp, testProviders);
|
||||
refPromise.then((ref) => {
|
||||
expect(el).toHaveText('hello world!');
|
||||
expect(el.getAttribute('ng-version')).toEqual(VERSION.full);
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
|
||||
it('should throw a descriptive error if BrowserModule is installed again via a lazily loaded module',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
@NgModule({imports: [BrowserModule]})
|
||||
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.`);
|
||||
});
|
||||
})
|
||||
.then(() => async.done(), err => async.fail(err));
|
||||
}));
|
||||
.then(() => done(), err => done.fail(err));
|
||||
});
|
||||
|
||||
it('should support multiple calls to bootstrap',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const refPromise1 = bootstrap(HelloRootCmp, testProviders);
|
||||
const refPromise2 = bootstrap(HelloRootCmp2, testProviders);
|
||||
Promise.all([refPromise1, refPromise2]).then((refs) => {
|
||||
expect(el).toHaveText('hello world!');
|
||||
expect(el2).toHaveText('hello world, again!');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should support multiple calls to bootstrap', done => {
|
||||
const refPromise1 = bootstrap(HelloRootCmp, testProviders);
|
||||
const refPromise2 = bootstrap(HelloRootCmp2, testProviders);
|
||||
Promise.all([refPromise1, refPromise2]).then((refs) => {
|
||||
expect(el).toHaveText('hello world!');
|
||||
expect(el2).toHaveText('hello world, again!');
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
|
||||
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) => {
|
||||
expect(() => ref.destroy()).not.toThrow();
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should unregister change detectors when components are disposed',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
bootstrap(HelloRootCmp, testProviders).then((ref) => {
|
||||
const appRef = ref.injector.get(ApplicationRef);
|
||||
ref.destroy();
|
||||
expect(() => appRef.tick()).not.toThrow();
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
it('should unregister change detectors when components are disposed', done => {
|
||||
bootstrap(HelloRootCmp, testProviders).then((ref) => {
|
||||
const appRef = ref.injector.get(ApplicationRef);
|
||||
ref.destroy();
|
||||
expect(() => appRef.tick()).not.toThrow();
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
|
||||
it('should make the provided bindings available to the application component',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const refPromise = bootstrap(
|
||||
HelloRootCmp3, [testProviders, {provide: 'appBinding', useValue: 'BoundValue'}]);
|
||||
it('should make the provided bindings available to the application component', done => {
|
||||
const refPromise = bootstrap(
|
||||
HelloRootCmp3, [testProviders, {provide: 'appBinding', useValue: 'BoundValue'}]);
|
||||
|
||||
refPromise.then((ref) => {
|
||||
expect(ref.injector.get('appBinding')).toEqual('BoundValue');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
refPromise.then((ref) => {
|
||||
expect(ref.injector.get('appBinding')).toEqual('BoundValue');
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
|
||||
it('should not override locale provided during bootstrap',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const refPromise =
|
||||
bootstrap(HelloRootCmp, [testProviders], [{provide: LOCALE_ID, useValue: 'fr-FR'}]);
|
||||
it('should not override locale provided during bootstrap', done => {
|
||||
const refPromise =
|
||||
bootstrap(HelloRootCmp, [testProviders], [{provide: LOCALE_ID, useValue: 'fr-FR'}]);
|
||||
|
||||
refPromise.then(ref => {
|
||||
expect(ref.injector.get(LOCALE_ID)).toEqual('fr-FR');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
refPromise.then(ref => {
|
||||
expect(ref.injector.get(LOCALE_ID)).toEqual('fr-FR');
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
|
||||
it('should avoid cyclic dependencies when root component requires Lifecycle through DI',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
const refPromise = bootstrap(HelloRootCmp4, testProviders);
|
||||
|
||||
refPromise.then((ref) => {
|
||||
const appRef = ref.injector.get(ApplicationRef);
|
||||
expect(appRef).toBeDefined();
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
|
||||
it('should run platform initializers',
|
||||
inject([Log, AsyncTestCompleter], (log: Log, async: AsyncTestCompleter) => {
|
||||
const p = createPlatformFactory(platformBrowserDynamic, 'someName', [
|
||||
{provide: PLATFORM_INITIALIZER, useValue: log.fn('platform_init1'), multi: true},
|
||||
{provide: PLATFORM_INITIALIZER, useValue: log.fn('platform_init2'), multi: true}
|
||||
])();
|
||||
it('should run platform initializers', done => {
|
||||
inject([Log], (log: Log) => {
|
||||
const p = createPlatformFactory(platformBrowserDynamic, 'someName', [
|
||||
{provide: PLATFORM_INITIALIZER, useValue: log.fn('platform_init1'), multi: true},
|
||||
{provide: PLATFORM_INITIALIZER, useValue: log.fn('platform_init2'), multi: true}
|
||||
])();
|
||||
|
||||
@NgModule({
|
||||
imports: [BrowserModule],
|
||||
providers: [
|
||||
{provide: APP_INITIALIZER, useValue: log.fn('app_init1'), multi: true},
|
||||
{provide: APP_INITIALIZER, useValue: log.fn('app_init2'), multi: true}
|
||||
]
|
||||
})
|
||||
class SomeModule {
|
||||
ngDoBootstrap() {}
|
||||
}
|
||||
@NgModule({
|
||||
imports: [BrowserModule],
|
||||
providers: [
|
||||
{provide: APP_INITIALIZER, useValue: log.fn('app_init1'), multi: true},
|
||||
{provide: APP_INITIALIZER, useValue: log.fn('app_init2'), multi: true}
|
||||
]
|
||||
})
|
||||
class SomeModule {
|
||||
ngDoBootstrap() {}
|
||||
}
|
||||
|
||||
expect(log.result()).toEqual('platform_init1; platform_init2');
|
||||
log.clear();
|
||||
p.bootstrapModule(SomeModule).then(() => {
|
||||
expect(log.result()).toEqual('app_init1; app_init2');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
expect(log.result()).toEqual('platform_init1; platform_init2');
|
||||
log.clear();
|
||||
p.bootstrapModule(SomeModule).then(() => {
|
||||
expect(log.result()).toEqual('app_init1; app_init2');
|
||||
done();
|
||||
}, done.fail);
|
||||
})();
|
||||
});
|
||||
|
||||
it('should remove styles when transitioning from a server render',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
@Component({
|
||||
selector: 'root',
|
||||
template: 'root',
|
||||
})
|
||||
class RootCmp {
|
||||
}
|
||||
it('should remove styles when transitioning from a server render', done => {
|
||||
@Component({
|
||||
selector: 'root',
|
||||
template: 'root',
|
||||
})
|
||||
class RootCmp {
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
bootstrap: [RootCmp],
|
||||
declarations: [RootCmp],
|
||||
imports: [BrowserModule.withServerTransition({appId: 'my-app'})],
|
||||
})
|
||||
class TestModule {
|
||||
}
|
||||
@NgModule({
|
||||
bootstrap: [RootCmp],
|
||||
declarations: [RootCmp],
|
||||
imports: [BrowserModule.withServerTransition({appId: 'my-app'})],
|
||||
})
|
||||
class TestModule {
|
||||
}
|
||||
|
||||
// First, set up styles to be removed.
|
||||
const dom = getDOM();
|
||||
const platform = platformBrowserDynamic();
|
||||
const document = platform.injector.get(DOCUMENT);
|
||||
const style = dom.createElement('style', document);
|
||||
style.setAttribute('ng-transition', 'my-app');
|
||||
document.head.appendChild(style);
|
||||
// First, set up styles to be removed.
|
||||
const dom = getDOM();
|
||||
const platform = platformBrowserDynamic();
|
||||
const document = platform.injector.get(DOCUMENT);
|
||||
const style = dom.createElement('style', document);
|
||||
style.setAttribute('ng-transition', 'my-app');
|
||||
document.head.appendChild(style);
|
||||
|
||||
const root = dom.createElement('root', document);
|
||||
document.body.appendChild(root);
|
||||
const root = dom.createElement('root', document);
|
||||
document.body.appendChild(root);
|
||||
|
||||
platform.bootstrapModule(TestModule).then(() => {
|
||||
const styles: HTMLElement[] =
|
||||
Array.prototype.slice.apply(document.getElementsByTagName('style') || []);
|
||||
styles.forEach(style => {
|
||||
expect(style.getAttribute('ng-transition')).not.toBe('my-app');
|
||||
});
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
platform.bootstrapModule(TestModule).then(() => {
|
||||
const styles: HTMLElement[] =
|
||||
Array.prototype.slice.apply(document.getElementsByTagName('style') || []);
|
||||
styles.forEach(style => {
|
||||
expect(style.getAttribute('ng-transition')).not.toBe('my-app');
|
||||
});
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
|
||||
it('should register each application with the testability registry',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const refPromise1: Promise<ComponentRef<any>> = bootstrap(HelloRootCmp, testProviders);
|
||||
const refPromise2: Promise<ComponentRef<any>> = bootstrap(HelloRootCmp2, testProviders);
|
||||
it('should register each application with the testability registry', done => {
|
||||
const refPromise1: Promise<ComponentRef<any>> = bootstrap(HelloRootCmp, testProviders);
|
||||
const refPromise2: Promise<ComponentRef<any>> = bootstrap(HelloRootCmp2, testProviders);
|
||||
|
||||
Promise.all([refPromise1, refPromise2]).then((refs: ComponentRef<any>[]) => {
|
||||
const registry = refs[0].injector.get(TestabilityRegistry);
|
||||
const testabilities =
|
||||
[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();
|
||||
});
|
||||
});
|
||||
}));
|
||||
Promise.all([refPromise1, refPromise2]).then((refs: ComponentRef<any>[]) => {
|
||||
const registry = refs[0].injector.get(TestabilityRegistry);
|
||||
const testabilities =
|
||||
[refs[0].injector.get(Testability), refs[1].injector.get(Testability)];
|
||||
|
||||
it('should allow to pass schemas', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
bootstrap(HelloCmpUsingCustomElement, testProviders).then((compRef) => {
|
||||
expect(el).toHaveText('hello world!');
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
Promise.all(testabilities).then((testabilities: Testability[]) => {
|
||||
expect(registry.findTestabilityInTree(el)).toEqual(testabilities[0]);
|
||||
expect(registry.findTestabilityInTree(el2)).toEqual(testabilities[1]);
|
||||
|
||||
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', () => {
|
||||
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',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
@NgModule({
|
||||
imports: [BrowserModule],
|
||||
declarations: [CompA, CompB],
|
||||
|
@ -551,31 +513,30 @@ function bootstrap(
|
|||
expect(log).toContain('CompA:ngDoCheck');
|
||||
expect(log).toContain('CompB:ngDoCheck');
|
||||
|
||||
async.done();
|
||||
});
|
||||
}));
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
|
||||
|
||||
it('should work in isolation for each component bootstrapped individually',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const refPromise1 = bootstrap(CompA);
|
||||
const refPromise2 = bootstrap(CompB);
|
||||
Promise.all([refPromise1, refPromise2]).then((refs) => {
|
||||
log.length = 0;
|
||||
el.querySelectorAll('#button-a')[0].click();
|
||||
expect(log).toContain('CompA:onClick');
|
||||
expect(log).toContain('CompA:ngDoCheck');
|
||||
expect(log).not.toContain('CompB:ngDoCheck');
|
||||
it('should work in isolation for each component bootstrapped individually', done => {
|
||||
const refPromise1 = bootstrap(CompA);
|
||||
const refPromise2 = bootstrap(CompB);
|
||||
Promise.all([refPromise1, refPromise2]).then((refs) => {
|
||||
log.length = 0;
|
||||
el.querySelectorAll('#button-a')[0].click();
|
||||
expect(log).toContain('CompA:onClick');
|
||||
expect(log).toContain('CompA:ngDoCheck');
|
||||
expect(log).not.toContain('CompB:ngDoCheck');
|
||||
|
||||
log.length = 0;
|
||||
el2.querySelectorAll('#button-b')[0].click();
|
||||
expect(log).toContain('CompB:onClick');
|
||||
expect(log).toContain('CompB:ngDoCheck');
|
||||
expect(log).not.toContain('CompA:ngDoCheck');
|
||||
log.length = 0;
|
||||
el2.querySelectorAll('#button-b')[0].click();
|
||||
expect(log).toContain('CompB:onClick');
|
||||
expect(log).toContain('CompB: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
|
||||
*/
|
||||
|
||||
import {ApplicationRef, Injector, ɵglobal as global} from '@angular/core';
|
||||
import {disableDebugTools, enableDebugTools} from '@angular/platform-browser';
|
||||
|
||||
import {callNgProfilerTimeChangeDetection, SpyComponentRef} from './spies';
|
||||
|
||||
{
|
||||
describe('profiler', () => {
|
||||
if (isNode) return;
|
||||
|
||||
beforeEach(() => {
|
||||
enableDebugTools((<any>new SpyComponentRef()));
|
||||
enableDebugTools({
|
||||
injector: Injector.create([{
|
||||
provide: ApplicationRef,
|
||||
useValue: jasmine.createSpyObj(
|
||||
'ApplicationRef', ['bootstrap', 'tick', 'attachView', 'detachView']),
|
||||
deps: []
|
||||
}])
|
||||
} as any);
|
||||
});
|
||||
|
||||
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 {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 {EventManager, EventManagerPlugin} from '@angular/platform-browser/src/dom/events/event_manager';
|
||||
import {createMouseEvent, el} from '../../../testing/src/browser_util';
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
import {NgZone} from '@angular/core';
|
||||
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 {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;
|
||||
|
||||
// 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
|
||||
// EventManager.
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
* 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';
|
||||
|
||||
{
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
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 {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
|
||||
|
|
|
@ -7,15 +7,14 @@
|
|||
*/
|
||||
|
||||
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';
|
||||
|
||||
{
|
||||
t.describe('DOM Sanitization Service', () => {
|
||||
t.it('accepts resource URL values for resource contexts', () => {
|
||||
describe('DOM Sanitization Service', () => {
|
||||
it('accepts resource URL values for resource contexts', () => {
|
||||
const svc = new DomSanitizerImpl(null);
|
||||
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', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
beforeEach(waitForAsync(async () => {
|
||||
TestBed.configureTestingModule({declarations: [CompWithUrlTemplate]});
|
||||
TestBed.compileComponents();
|
||||
await TestBed.compileComponents();
|
||||
}));
|
||||
|
||||
isBrowser &&
|
||||
|
|
|
@ -10,7 +10,6 @@ import {CommonModule, Location} from '@angular/common';
|
|||
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 {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 {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';
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
// Tun on full stack traces in errors to help debugging
|
||||
Error.stackTraceLimit = Infinity;
|
||||
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 100;
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 3000;
|
||||
|
||||
// Cancel Karma's synchronous start,
|
||||
// we will call `__karma__.start()` later, once all the specs are loaded.
|
||||
|
|
Loading…
Reference in New Issue