diff --git a/packages/benchpress/test/metric/multi_metric_spec.ts b/packages/benchpress/test/metric/multi_metric_spec.ts index 347152d4fc..bc3ab5ca33 100644 --- a/packages/benchpress/test/metric/multi_metric_spec.ts +++ b/packages/benchpress/test/metric/multi_metric_spec.ts @@ -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(); + }); + }); }); }); })(); diff --git a/packages/benchpress/test/metric/perflog_metric_spec.ts b/packages/benchpress/test/metric/perflog_metric_spec.ts index 20e6469318..b93046ac89 100644 --- a/packages/benchpress/test/metric/perflog_metric_spec.ts +++ b/packages/benchpress/test/metric/perflog_metric_spec.ts @@ -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(); + }); + }); }); }); }); diff --git a/packages/benchpress/test/metric/user_metric_spec.ts b/packages/benchpress/test/metric/user_metric_spec.ts index cb4e17b81d..419caca3d4 100644 --- a/packages/benchpress/test/metric/user_metric_spec.ts +++ b/packages/benchpress/test/metric/user_metric_spec.ts @@ -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); }); }); })(); diff --git a/packages/benchpress/test/reporter/console_reporter_spec.ts b/packages/benchpress/test/reporter/console_reporter_spec.ts index d042a992ee..c5cb5c98a8 100644 --- a/packages/benchpress/test/reporter/console_reporter_spec.ts +++ b/packages/benchpress/test/reporter/console_reporter_spec.ts @@ -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'; diff --git a/packages/benchpress/test/reporter/json_file_reporter_spec.ts b/packages/benchpress/test/reporter/json_file_reporter_spec.ts index 6fc2657ba7..613991cc28 100644 --- a/packages/benchpress/test/reporter/json_file_reporter_spec.ts +++ b/packages/benchpress/test/reporter/json_file_reporter_spec.ts @@ -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); } - 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(); + }); }); } diff --git a/packages/benchpress/test/reporter/multi_reporter_spec.ts b/packages/benchpress/test/reporter/multi_reporter_spec.ts index 3f10fbaa59..494d909836 100644 --- a/packages/benchpress/test/reporter/multi_reporter_spec.ts +++ b/packages/benchpress/test/reporter/multi_reporter_spec.ts @@ -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(); + }); + }); }); })(); diff --git a/packages/benchpress/test/runner_spec.ts b/packages/benchpress/test/runner_spec.ts index 7cda672e33..d304fa356b 100644 --- a/packages/benchpress/test/runner_spec.ts +++ b/packages/benchpress/test/runner_spec.ts @@ -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(); + }); + }); }); } diff --git a/packages/benchpress/test/sampler_spec.ts b/packages/benchpress/test/sampler_spec.ts index feeea4253f..8ca4f2a067 100644 --- a/packages/benchpress/test/sampler_spec.ts +++ b/packages/benchpress/test/sampler_spec.ts @@ -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(); + }); + }); }); } diff --git a/packages/benchpress/test/statistic_spec.ts b/packages/benchpress/test/statistic_spec.ts index 2255c5488d..b2f3fba7b5 100644 --- a/packages/benchpress/test/statistic_spec.ts +++ b/packages/benchpress/test/statistic_spec.ts @@ -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'; { diff --git a/packages/benchpress/test/validator/regression_slope_validator_spec.ts b/packages/benchpress/test/validator/regression_slope_validator_spec.ts index d6c20a3e99..7ea0969109 100644 --- a/packages/benchpress/test/validator/regression_slope_validator_spec.ts +++ b/packages/benchpress/test/validator/regression_slope_validator_spec.ts @@ -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'; { diff --git a/packages/benchpress/test/validator/size_validator_spec.ts b/packages/benchpress/test/validator/size_validator_spec.ts index 5e7c11c05a..852c7c57fc 100644 --- a/packages/benchpress/test/validator/size_validator_spec.ts +++ b/packages/benchpress/test/validator/size_validator_spec.ts @@ -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'; { diff --git a/packages/benchpress/test/web_driver_extension_spec.ts b/packages/benchpress/test/web_driver_extension_spec.ts index f9c0b274d7..9303524c75 100644 --- a/packages/benchpress/test/web_driver_extension_spec.ts +++ b/packages/benchpress/test/web_driver_extension_spec.ts @@ -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(); + }); + }); }); })(); diff --git a/packages/benchpress/test/webdriver/chrome_driver_extension_spec.ts b/packages/benchpress/test/webdriver/chrome_driver_extension_spec.ts index cce37e50e2..f9da9e31e8 100644 --- a/packages/benchpress/test/webdriver/chrome_driver_extension_spec.ts +++ b/packages/benchpress/test/webdriver/chrome_driver_extension_spec.ts @@ -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); diff --git a/packages/benchpress/test/webdriver/ios_driver_extension_spec.ts b/packages/benchpress/test/webdriver/ios_driver_extension_spec.ts index 1c5006b46b..9d7b9c198b 100644 --- a/packages/benchpress/test/webdriver/ios_driver_extension_spec.ts +++ b/packages/benchpress/test/webdriver/ios_driver_extension_spec.ts @@ -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); diff --git a/packages/common/http/test/client_spec.ts b/packages/common/http/test/client_spec.ts index 193c5f8233..fb0e3e7c13 100644 --- a/packages/common/http/test/client_spec.ts +++ b/packages/common/http/test/client_spec.ts @@ -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'; { diff --git a/packages/common/http/test/jsonp_spec.ts b/packages/common/http/test/jsonp_spec.ts index 10b0e6574d..0abcf88e22 100644 --- a/packages/common/http/test/jsonp_spec.ts +++ b/packages/common/http/test/jsonp_spec.ts @@ -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'; diff --git a/packages/common/http/test/request_spec.ts b/packages/common/http/test/request_spec.ts index f1800092e1..7fa9577f8e 100644 --- a/packages/common/http/test/request_spec.ts +++ b/packages/common/http/test/request_spec.ts @@ -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!`; diff --git a/packages/common/http/test/response_spec.ts b/packages/common/http/test/response_spec.ts index c9d31174d5..0b1bb17482 100644 --- a/packages/common/http/test/response_spec.ts +++ b/packages/common/http/test/response_spec.ts @@ -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', () => { diff --git a/packages/common/http/test/xhr_spec.ts b/packages/common/http/test/xhr_spec.ts index e8a462a0b1..9c513f3f1b 100644 --- a/packages/common/http/test/xhr_spec.ts +++ b/packages/common/http/test/xhr_spec.ts @@ -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'; diff --git a/packages/common/test/cookie_spec.ts b/packages/common/test/cookie_spec.ts index 2a83cb7b9c..132724700e 100644 --- a/packages/common/test/cookie_spec.ts +++ b/packages/common/test/cookie_spec.ts @@ -17,7 +17,6 @@ */ import {parseCookieValue} from '@angular/common/src/cookie'; -import {describe, expect, it} from '@angular/core/testing/src/testing_internal'; { describe('cookies', () => { diff --git a/packages/common/test/i18n/format_number_spec.ts b/packages/common/test/i18n/format_number_spec.ts index be5320eea7..7043d42224 100644 --- a/packages/common/test/i18n/format_number_spec.ts +++ b/packages/common/test/i18n/format_number_spec.ts @@ -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(() => { diff --git a/packages/common/test/pipes/async_pipe_spec.ts b/packages/common/test/pipes/async_pipe_spec.ts index 19cf051ed8..ef51153240 100644 --- a/packages/common/test/pipes/async_pipe_spec.ts +++ b/packages/common/test/pipes/async_pipe_spec.ts @@ -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; let subscribable: Subscribable; let pipe: AsyncPipe; - let ref: any; + let ref: ChangeDetectorRef&jasmine.SpyObj; 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; - 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(() => {}); @@ -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); + }); }); }); }); diff --git a/packages/common/test/pipes/i18n_plural_pipe_spec.ts b/packages/common/test/pipes/i18n_plural_pipe_spec.ts index 19757f367d..a78defb346 100644 --- a/packages/common/test/pipes/i18n_plural_pipe_spec.ts +++ b/packages/common/test/pipes/i18n_plural_pipe_spec.ts @@ -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'; { diff --git a/packages/common/test/pipes/number_pipe_spec.ts b/packages/common/test/pipes/number_pipe_spec.ts index 249cc57eee..fcef65caef 100644 --- a/packages/common/test/pipes/number_pipe_spec.ts +++ b/packages/common/test/pipes/number_pipe_spec.ts @@ -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', () => { diff --git a/packages/common/test/spies.ts b/packages/common/test/spies.ts deleted file mode 100644 index 1f5290bb45..0000000000 --- a/packages/common/test/spies.ts +++ /dev/null @@ -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; -} diff --git a/packages/common/test/viewport_scroller_spec.ts b/packages/common/test/viewport_scroller_spec.ts index 68c0518e36..404731f242 100644 --- a/packages/common/test/viewport_scroller_spec.ts +++ b/packages/common/test/viewport_scroller_spec.ts @@ -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'; diff --git a/packages/compiler/test/i18n/integration_common.ts b/packages/compiler/test/i18n/integration_common.ts index 2cefca7946..63bfb6e0dd 100644 --- a/packages/compiler/test/i18n/integration_common.ts +++ b/packages/compiler/test/i18n/integration_common.ts @@ -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}, diff --git a/packages/compiler/test/ng_module_resolver_mock_spec.ts b/packages/compiler/test/ng_module_resolver_mock_spec.ts index cb6ea2feee..487b7ed4e2 100644 --- a/packages/compiler/test/ng_module_resolver_mock_spec.ts +++ b/packages/compiler/test/ng_module_resolver_mock_spec.ts @@ -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', diff --git a/packages/compiler/test/resource_loader_mock_spec.ts b/packages/compiler/test/resource_loader_mock_spec.ts index 4d19081d99..6723fa5d2e 100644 --- a/packages/compiler/test/resource_loader_mock_spec.ts +++ b/packages/compiler/test/resource_loader_mock_spec.ts @@ -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'); diff --git a/packages/compiler/test/runtime_compiler_spec.ts b/packages/compiler/test/runtime_compiler_spec.ts index ce37f36e9f..c0fbe40cd7 100644 --- a/packages/compiler/test/runtime_compiler_spec.ts +++ b/packages/compiler/test/runtime_compiler_spec.ts @@ -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 = 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(); diff --git a/packages/compiler/test/schema/dom_element_schema_registry_spec.ts b/packages/compiler/test/schema/dom_element_schema_registry_spec.ts index 425a95c7a1..c4812c7b24 100644 --- a/packages/compiler/test/schema/dom_element_schema_registry_spec.ts +++ b/packages/compiler/test/schema/dom_element_schema_registry_spec.ts @@ -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'; diff --git a/packages/compiler/test/schema/trusted_types_sinks_spec.ts b/packages/compiler/test/schema/trusted_types_sinks_spec.ts index 49023439a7..16504814a6 100644 --- a/packages/compiler/test/schema/trusted_types_sinks_spec.ts +++ b/packages/compiler/test/schema/trusted_types_sinks_spec.ts @@ -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', () => { diff --git a/packages/compiler/test/spies.ts b/packages/compiler/test/spies.ts deleted file mode 100644 index 5799817226..0000000000 --- a/packages/compiler/test/spies.ts +++ /dev/null @@ -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); - } -} diff --git a/packages/compiler/test/template_parser/template_preparser_spec.ts b/packages/compiler/test/template_parser/template_preparser_spec.ts index e43efd1322..f07caa14fb 100644 --- a/packages/compiler/test/template_parser/template_preparser_spec.ts +++ b/packages/compiler/test/template_parser/template_preparser_spec.ts @@ -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'; diff --git a/packages/compiler/test/url_resolver_spec.ts b/packages/compiler/test/url_resolver_spec.ts index c0b1349567..ffbd0f4379 100644 --- a/packages/compiler/test/url_resolver_spec.ts +++ b/packages/compiler/test/url_resolver_spec.ts @@ -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', () => { diff --git a/packages/core/test/acceptance/bootstrap_spec.ts b/packages/core/test/acceptance/bootstrap_spec.ts index edd8eaa43d..0f96eda3e0 100644 --- a/packages/core/test/acceptance/bootstrap_spec.ts +++ b/packages/core/test/acceptance/bootstrap_spec.ts @@ -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'; diff --git a/packages/core/test/acceptance/discover_utils_spec.ts b/packages/core/test/acceptance/discover_utils_spec.ts index a1d589eabe..513bb26065 100644 --- a/packages/core/test/acceptance/discover_utils_spec.ts +++ b/packages/core/test/acceptance/discover_utils_spec.ts @@ -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'; diff --git a/packages/core/test/acceptance/profiler_spec.ts b/packages/core/test/acceptance/profiler_spec.ts index c9b4177af4..1c07528cb5 100644 --- a/packages/core/test/acceptance/profiler_spec.ts +++ b/packages/core/test/acceptance/profiler_spec.ts @@ -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'; diff --git a/packages/core/test/application_module_spec.ts b/packages/core/test/application_module_spec.ts index a802cb6aed..d4bf51945a 100644 --- a/packages/core/test/application_module_spec.ts +++ b/packages/core/test/application_module_spec.ts @@ -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', () => { diff --git a/packages/core/test/change_detection/differs/iterable_differs_spec.ts b/packages/core/test/change_detection/differs/iterable_differs_spec.ts index 19cdd0e691..396d09b229 100644 --- a/packages/core/test/change_detection/differs/iterable_differs_spec.ts +++ b/packages/core/test/change_detection/differs/iterable_differs_spec.ts @@ -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([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([factory1]); const child = IterableDiffers.create([factory2], parent); diff --git a/packages/core/test/di/forward_ref_spec.ts b/packages/core/test/di/forward_ref_spec.ts index 81c0dd0364..cc156bf637 100644 --- a/packages/core/test/di/forward_ref_spec.ts +++ b/packages/core/test/di/forward_ref_spec.ts @@ -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() { diff --git a/packages/core/test/di/injector_spec.ts b/packages/core/test/di/injector_spec.ts index a1dab42636..c72103b806 100644 --- a/packages/core/test/di/injector_spec.ts +++ b/packages/core/test/di/injector_spec.ts @@ -8,7 +8,6 @@ import {Injector} from '@angular/core'; -import {describe, expect, it} from '@angular/core/testing/src/testing_internal'; { describe('Injector.NULL', () => { diff --git a/packages/core/test/dom/dom_adapter_spec.ts b/packages/core/test/dom/dom_adapter_spec.ts index 859b12a716..97172b6c50 100644 --- a/packages/core/test/dom/dom_adapter_spec.ts +++ b/packages/core/test/dom/dom_adapter_spec.ts @@ -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'; { diff --git a/packages/core/test/dom/shim_spec.ts b/packages/core/test/dom/shim_spec.ts index deb135b11f..9f39856cef 100644 --- a/packages/core/test/dom/shim_spec.ts +++ b/packages/core/test/dom/shim_spec.ts @@ -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', () => { diff --git a/packages/core/test/event_emitter_spec.ts b/packages/core/test/event_emitter_spec.ts index e822a62485..3715b0fc1b 100644 --- a/packages/core/test/event_emitter_spec.ts +++ b/packages/core/test/event_emitter_spec.ts @@ -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', diff --git a/packages/core/test/fake_async_spec.ts b/packages/core/test/fake_async_spec.ts index 54b494f84e..705d34669c 100644 --- a/packages/core/test/fake_async_spec.ts +++ b/packages/core/test/fake_async_spec.ts @@ -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'; diff --git a/packages/core/test/linker/inheritance_integration_spec.ts b/packages/core/test/linker/inheritance_integration_spec.ts index 3b9efcf117..a02b610d27 100644 --- a/packages/core/test/linker/inheritance_integration_spec.ts +++ b/packages/core/test/linker/inheritance_integration_spec.ts @@ -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]'}) diff --git a/packages/core/test/linker/query_list_spec.ts b/packages/core/test/linker/query_list_spec.ts index c5b1fb7070..9acfaf7ac8 100644 --- a/packages/core/test/linker/query_list_spec.ts +++ b/packages/core/test/linker/query_list_spec.ts @@ -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', () => { diff --git a/packages/core/test/linker/system_ng_module_factory_loader_spec.ts b/packages/core/test/linker/system_ng_module_factory_loader_spec.ts index a3b780e038..516be3006c 100644 --- a/packages/core/test/linker/system_ng_module_factory_loader_spec.ts +++ b/packages/core/test/linker/system_ng_module_factory_loader_spec.ts @@ -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}) { diff --git a/packages/core/test/render3/i18n/i18n_parse_spec.ts b/packages/core/test/render3/i18n/i18n_parse_spec.ts index 7608ac69aa..d3317471af 100644 --- a/packages/core/test/render3/i18n/i18n_parse_spec.ts +++ b/packages/core/test/render3/i18n/i18n_parse_spec.ts @@ -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'; diff --git a/packages/core/test/render3/instructions/styling_spec.ts b/packages/core/test/render3/instructions/styling_spec.ts index 2e5abdf4ab..6e64cdab19 100644 --- a/packages/core/test/render3/instructions/styling_spec.ts +++ b/packages/core/test/render3/instructions/styling_spec.ts @@ -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'; diff --git a/packages/core/test/render3/util/attr_util_spec.ts b/packages/core/test/render3/util/attr_util_spec.ts index e8910f4875..8502b9ffd9 100644 --- a/packages/core/test/render3/util/attr_util_spec.ts +++ b/packages/core/test/render3/util/attr_util_spec.ts @@ -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', () => { diff --git a/packages/core/test/sanitization/url_sanitizer_spec.ts b/packages/core/test/sanitization/url_sanitizer_spec.ts index 026dbb77c2..41330e6317 100644 --- a/packages/core/test/sanitization/url_sanitizer_spec.ts +++ b/packages/core/test/sanitization/url_sanitizer_spec.ts @@ -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:/)); } }); }); diff --git a/packages/core/test/spies.ts b/packages/core/test/spies.ts deleted file mode 100644 index 557bf44fe8..0000000000 --- a/packages/core/test/spies.ts +++ /dev/null @@ -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); - } -} diff --git a/packages/core/test/test_bed_async_spec.ts b/packages/core/test/test_bed_async_spec.ts deleted file mode 100644 index e4f11a9080..0000000000 --- a/packages/core/test/test_bed_async_spec.ts +++ /dev/null @@ -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(); - })); -}); diff --git a/packages/core/test/testability/testability_spec.ts b/packages/core/test/testability/testability_spec.ts index d3415a85e8..63dd0bffc8 100644 --- a/packages/core/test/testability/testability_spec.ts +++ b/packages/core/test/testability/testability_spec.ts @@ -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', () => { diff --git a/packages/core/test/testing_internal_spec.ts b/packages/core/test/testing_internal_spec.ts deleted file mode 100644 index b6252ad164..0000000000 --- a/packages/core/test/testing_internal_spec.ts +++ /dev/null @@ -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 = new Map(); - m1.set('a', 1); - expect(m1).toEqual(m1); - }); - - it('should detect equality for same content', () => { - const m1: Map = new Map(); - m1.set('a', 1); - const m2: Map = new Map(); - m2.set('a', 1); - expect(m1).toEqual(m2); - }); - - it('should detect missing entries', () => { - const m1: Map = new Map(); - m1.set('a', 1); - const m2: Map = new Map(); - expect(m1).not.toEqual(m2); - }); - - it('should detect different values', () => { - const m1: Map = new Map(); - m1.set('a', 1); - const m2: Map = new Map(); - m2.set('a', 2); - expect(m1).not.toEqual(m2); - }); - - it('should detect additional entries', () => { - const m1: Map = new Map(); - m1.set('a', 1); - const m2: Map = 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(); - }); - }); - }); -} diff --git a/packages/core/test/zone/ng_zone_spec.ts b/packages/core/test/zone/ng_zone_spec.ts index 2ab461b0b1..2cfd8fe0f9 100644 --- a/packages/core/test/zone/ng_zone_spec.ts +++ b/packages/core/test/zone/ng_zone_spec.ts @@ -7,8 +7,8 @@ */ import {EventEmitter, NgZone} from '@angular/core'; -import {fakeAsync, flushMicrotasks, waitForAsync} from '@angular/core/testing'; -import {AsyncTestCompleter, beforeEach, describe, expect, inject, it, Log, xit} from '@angular/core/testing/src/testing_internal'; +import {fakeAsync, flushMicrotasks, inject, waitForAsync} from '@angular/core/testing'; +import {Log} from '@angular/core/testing/src/testing_internal'; import {browserDetection} from '@angular/platform-browser/testing/src/browser_util'; import {global} from '../../src/util/global'; @@ -18,7 +18,6 @@ import {NoopNgZone} from '../../src/zone/ng_zone'; const needsLongerTimers = browserDetection.isSlow || browserDetection.isEdge; const resultTimer = 1000; -const testTimeout = browserDetection.isEdge ? 1200 : 500; // Schedules a macrotask (using a timer) function macroTask(fn: (...args: any[]) => void, timer = 1): void { // adds longer timers for passing tests in IE and Edge @@ -88,55 +87,53 @@ function runNgZoneNoLog(fn: () => any) { commonTests(); - it('should produce long stack traces', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - macroTask(() => { - let resolve: (result: any) => void; - const promise: Promise = new Promise((res) => { - resolve = res; - }); + it('should produce long stack traces', done => { + macroTask(() => { + let resolve: (result: any) => void; + const promise: Promise = new Promise((res) => { + resolve = res; + }); - _zone.run(() => { - setTimeout(() => { - setTimeout(() => { - resolve(null); - throw new Error('ccc'); - }, 0); - }, 0); - }); + _zone.run(() => { + setTimeout(() => { + setTimeout(() => { + resolve(null); + throw new Error('ccc'); + }, 0); + }, 0); + }); - promise.then((_) => { - expect(_traces.length).toBe(1); - expect(_traces[0].length).toBeGreaterThan(1); - async.done(); - }); - }); - }), testTimeout); + promise.then((_) => { + expect(_traces.length).toBe(1); + expect(_traces[0].length).toBeGreaterThan(1); + done(); + }); + }); + }); - it('should produce long stack traces (when using microtasks)', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - macroTask(() => { - let resolve: (result: any) => void; - const promise: Promise = new Promise((res) => { - resolve = res; - }); + it('should produce long stack traces (when using microtasks)', done => { + macroTask(() => { + let resolve: (result: any) => void; + const promise: Promise = new Promise((res) => { + resolve = res; + }); - _zone.run(() => { - scheduleMicroTask(() => { - scheduleMicroTask(() => { - resolve(null); - throw new Error('ddd'); - }); - }); - }); + _zone.run(() => { + scheduleMicroTask(() => { + scheduleMicroTask(() => { + resolve(null); + throw new Error('ddd'); + }); + }); + }); - promise.then((_) => { - expect(_traces.length).toBe(1); - expect(_traces[0].length).toBeGreaterThan(1); - async.done(); - }); - }); - }), testTimeout); + promise.then((_) => { + expect(_traces.length).toBe(1); + expect(_traces[0].length).toBeGreaterThan(1); + done(); + }); + }); + }); }); describe('short stack trace', () => { @@ -150,33 +147,32 @@ function runNgZoneNoLog(fn: () => any) { commonTests(); - it('should disable long stack traces', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - macroTask(() => { - let resolve: (result: any) => void; - const promise: Promise = new Promise((res) => { - resolve = res; - }); + it('should disable long stack traces', done => { + macroTask(() => { + let resolve: (result: any) => void; + const promise: Promise = new Promise((res) => { + resolve = res; + }); - _zone.run(() => { - setTimeout(() => { - setTimeout(() => { - resolve(null); - throw new Error('ccc'); - }, 0); - }, 0); - }); + _zone.run(() => { + setTimeout(() => { + setTimeout(() => { + resolve(null); + throw new Error('ccc'); + }, 0); + }, 0); + }); - promise.then((_) => { - expect(_traces.length).toBe(1); - if (_traces[0] != null) { - // some browsers don't have stack traces. - expect(_traces[0].indexOf('---')).toEqual(-1); - } - async.done(); - }); - }); - }), testTimeout); + promise.then((_) => { + expect(_traces.length).toBe(1); + if (_traces[0] != null) { + // some browsers don't have stack traces. + expect(_traces[0].indexOf('---')).toEqual(-1); + } + done(); + }); + }); + }); }); }); @@ -287,173 +283,164 @@ function commonTests() { runNgZoneNoLog(() => { expect(NgZone.isInAngularZone()).toEqual(true); }); - }, testTimeout); + }); }); describe('run', () => { - it('should return the body return value from run', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - macroTask(() => { - expect(_zone.run(() => 6)).toEqual(6); - }); + it('should return the body return value from run', done => { + macroTask(() => { + expect(_zone.run(() => 6)).toEqual(6); + }); - macroTask(() => { - async.done(); - }); - }), testTimeout); + macroTask(() => { + done(); + }); + }); - it('should return the body return value from runTask', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - macroTask(() => { - expect(_zone.runTask(() => 6)).toEqual(6); - }); + it('should return the body return value from runTask', done => { + macroTask(() => { + expect(_zone.runTask(() => 6)).toEqual(6); + }); - macroTask(() => { - async.done(); - }); - }), testTimeout); + macroTask(() => { + done(); + }); + }); - it('should call onUnstable and onMicrotaskEmpty', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - runNgZoneNoLog(() => macroTask(_log.fn('run'))); - macroTask(() => { - expect(_log.result()).toEqual('onUnstable; run; onMicrotaskEmpty; onStable'); - async.done(); - }); - }), testTimeout); + it('should call onUnstable and onMicrotaskEmpty', done => { + runNgZoneNoLog(() => macroTask(_log.fn('run'))); + macroTask(() => { + expect(_log.result()).toEqual('onUnstable; run; onMicrotaskEmpty; onStable'); + done(); + }); + }); - it('should call onStable once at the end of event', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - // The test is set up in a way that causes the zone loop to run onMicrotaskEmpty twice - // then verified that onStable is only called once at the end + it('should call onStable once at the end of event', done => { + // The test is set up in a way that causes the zone loop to run onMicrotaskEmpty twice + // then verified that onStable is only called once at the end - runNgZoneNoLog(() => macroTask(_log.fn('run'))); + runNgZoneNoLog(() => macroTask(_log.fn('run'))); - let times = 0; - _zone.onMicrotaskEmpty.subscribe({ - next: () => { - times++; - _log.add(`onMicrotaskEmpty ${times}`); - if (times < 2) { - // Scheduling a microtask causes a second digest - runNgZoneNoLog(() => { - scheduleMicroTask(() => {}); - }); - } - } - }); - - macroTask(() => { - expect(_log.result()) - .toEqual( - 'onUnstable; run; onMicrotaskEmpty; onMicrotaskEmpty 1; ' + - 'onMicrotaskEmpty; onMicrotaskEmpty 2; onStable'); - async.done(); - }, resultTimer); - }), testTimeout); - - it('should call standalone onStable', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - runNgZoneNoLog(() => macroTask(_log.fn('run'))); - - macroTask(() => { - expect(_log.result()).toEqual('onUnstable; run; onMicrotaskEmpty; onStable'); - async.done(); - }, resultTimer); - }), testTimeout); - - xit('should run subscriber listeners in the subscription zone (outside)', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - // Each subscriber fires a microtask outside the Angular zone. The test - // then verifies that those microtasks do not cause additional digests. - - let turnStart = false; - _zone.onUnstable.subscribe({ - next: () => { - if (turnStart) throw 'Should not call this more than once'; - _log.add('onUnstable'); + let times = 0; + _zone.onMicrotaskEmpty.subscribe({ + next: () => { + times++; + _log.add(`onMicrotaskEmpty ${times}`); + if (times < 2) { + // Scheduling a microtask causes a second digest + runNgZoneNoLog(() => { scheduleMicroTask(() => {}); - turnStart = true; - } + }); + } + } + }); + + macroTask(() => { + expect(_log.result()) + .toEqual( + 'onUnstable; run; onMicrotaskEmpty; onMicrotaskEmpty 1; ' + + 'onMicrotaskEmpty; onMicrotaskEmpty 2; onStable'); + done(); + }, resultTimer); + }); + + it('should call standalone onStable', done => { + runNgZoneNoLog(() => macroTask(_log.fn('run'))); + + macroTask(() => { + expect(_log.result()).toEqual('onUnstable; run; onMicrotaskEmpty; onStable'); + done(); + }, resultTimer); + }); + + xit('should run subscriber listeners in the subscription zone (outside)', done => { + // Each subscriber fires a microtask outside the Angular zone. The test + // then verifies that those microtasks do not cause additional digests. + + let turnStart = false; + _zone.onUnstable.subscribe({ + next: () => { + if (turnStart) throw 'Should not call this more than once'; + _log.add('onUnstable'); + scheduleMicroTask(() => {}); + turnStart = true; + } + }); + + let turnDone = false; + _zone.onMicrotaskEmpty.subscribe({ + next: () => { + if (turnDone) throw 'Should not call this more than once'; + _log.add('onMicrotaskEmpty'); + scheduleMicroTask(() => {}); + turnDone = true; + } + }); + + let eventDone = false; + _zone.onStable.subscribe({ + next: () => { + if (eventDone) throw 'Should not call this more than once'; + _log.add('onStable'); + scheduleMicroTask(() => {}); + eventDone = true; + } + }); + + macroTask(() => { + _zone.run(_log.fn('run')); + }); + + macroTask(() => { + expect(_log.result()).toEqual('onUnstable; run; onMicrotaskEmpty; onStable'); + done(); + }, resultTimer); + }); + + it('should run subscriber listeners in the subscription zone (inside)', done => { + runNgZoneNoLog(() => macroTask(_log.fn('run'))); + + // the only practical use-case to run a callback inside the zone is + // change detection after "onMicrotaskEmpty". That's the only case tested. + let turnDone = false; + _zone.onMicrotaskEmpty.subscribe({ + next: () => { + _log.add('onMyMicrotaskEmpty'); + if (turnDone) return; + _zone.run(() => { + scheduleMicroTask(() => {}); }); + turnDone = true; + } + }); - let turnDone = false; - _zone.onMicrotaskEmpty.subscribe({ - next: () => { - if (turnDone) throw 'Should not call this more than once'; - _log.add('onMicrotaskEmpty'); - scheduleMicroTask(() => {}); - turnDone = true; - } - }); + macroTask(() => { + expect(_log.result()) + .toEqual( + 'onUnstable; run; onMicrotaskEmpty; onMyMicrotaskEmpty; ' + + 'onMicrotaskEmpty; onMyMicrotaskEmpty; onStable'); + done(); + }, resultTimer); + }); - let eventDone = false; - _zone.onStable.subscribe({ - next: () => { - if (eventDone) throw 'Should not call this more than once'; - _log.add('onStable'); - scheduleMicroTask(() => {}); - eventDone = true; - } - }); + it('should run async tasks scheduled inside onStable outside Angular zone', done => { + runNgZoneNoLog(() => macroTask(_log.fn('run'))); - macroTask(() => { - _zone.run(_log.fn('run')); - }); + _zone.onStable.subscribe({ + next: () => { + NgZone.assertNotInAngularZone(); + _log.add('onMyTaskDone'); + } + }); - macroTask(() => { - expect(_log.result()).toEqual('onUnstable; run; onMicrotaskEmpty; onStable'); - async.done(); - }, resultTimer); - }), testTimeout); - - it('should run subscriber listeners in the subscription zone (inside)', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - runNgZoneNoLog(() => macroTask(_log.fn('run'))); - - // the only practical use-case to run a callback inside the zone is - // change detection after "onMicrotaskEmpty". That's the only case tested. - let turnDone = false; - _zone.onMicrotaskEmpty.subscribe({ - next: () => { - _log.add('onMyMicrotaskEmpty'); - if (turnDone) return; - _zone.run(() => { - scheduleMicroTask(() => {}); - }); - turnDone = true; - } - }); - - macroTask(() => { - expect(_log.result()) - .toEqual( - 'onUnstable; run; onMicrotaskEmpty; onMyMicrotaskEmpty; ' + - 'onMicrotaskEmpty; onMyMicrotaskEmpty; onStable'); - async.done(); - }, resultTimer); - }), testTimeout); - - it('should run async tasks scheduled inside onStable outside Angular zone', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - runNgZoneNoLog(() => macroTask(_log.fn('run'))); - - _zone.onStable.subscribe({ - next: () => { - NgZone.assertNotInAngularZone(); - _log.add('onMyTaskDone'); - } - }); - - macroTask(() => { - expect(_log.result()) - .toEqual('onUnstable; run; onMicrotaskEmpty; onStable; onMyTaskDone'); - async.done(); - }); - }), testTimeout); + macroTask(() => { + expect(_log.result()).toEqual('onUnstable; run; onMicrotaskEmpty; onStable; onMyTaskDone'); + done(); + }); + }); it('should call onUnstable once before a turn and onMicrotaskEmpty once after the turn', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { + done => { runNgZoneNoLog(() => { macroTask(() => { _log.add('run start'); @@ -466,33 +453,32 @@ function commonTests() { // The microtask (async) is executed after the macrotask (run) expect(_log.result()) .toEqual('onUnstable; run start; run end; async; onMicrotaskEmpty; onStable'); - async.done(); + done(); }, resultTimer); - }), testTimeout); + }); - it('should not run onUnstable and onMicrotaskEmpty for nested Zone.run', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - runNgZoneNoLog(() => { - macroTask(() => { - _log.add('start run'); - _zone.run(() => { - _log.add('nested run'); - scheduleMicroTask(_log.fn('nested run microtask')); - }); - _log.add('end run'); - }); - }); + it('should not run onUnstable and onMicrotaskEmpty for nested Zone.run', done => { + runNgZoneNoLog(() => { + macroTask(() => { + _log.add('start run'); + _zone.run(() => { + _log.add('nested run'); + scheduleMicroTask(_log.fn('nested run microtask')); + }); + _log.add('end run'); + }); + }); - macroTask(() => { - expect(_log.result()) - .toEqual( - 'onUnstable; start run; nested run; end run; nested run microtask; onMicrotaskEmpty; onStable'); - async.done(); - }, resultTimer); - }), testTimeout); + macroTask(() => { + expect(_log.result()) + .toEqual( + 'onUnstable; start run; nested run; end run; nested run microtask; onMicrotaskEmpty; onStable'); + done(); + }, resultTimer); + }); it('should not run onUnstable and onMicrotaskEmpty for nested Zone.run invoked from onMicrotaskEmpty', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { + done => { runNgZoneNoLog(() => macroTask(_log.fn('start run'))); _zone.onMicrotaskEmpty.subscribe({ @@ -507,74 +493,71 @@ function commonTests() { expect(_log.result()) .toEqual( 'onUnstable; start run; onMicrotaskEmpty; onMicrotaskEmpty:started; nested run; onMicrotaskEmpty:finished; onStable'); - async.done(); + done(); }, resultTimer); - }), testTimeout); + }); - it('should call onUnstable and onMicrotaskEmpty before and after each top-level run', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - runNgZoneNoLog(() => macroTask(_log.fn('run1'))); - runNgZoneNoLog(() => macroTask(_log.fn('run2'))); + it('should call onUnstable and onMicrotaskEmpty before and after each top-level run', done => { + runNgZoneNoLog(() => macroTask(_log.fn('run1'))); + runNgZoneNoLog(() => macroTask(_log.fn('run2'))); - macroTask(() => { - expect(_log.result()) - .toEqual( - 'onUnstable; run1; onMicrotaskEmpty; onStable; onUnstable; run2; onMicrotaskEmpty; onStable'); - async.done(); - }, resultTimer); - }), testTimeout); + macroTask(() => { + expect(_log.result()) + .toEqual( + 'onUnstable; run1; onMicrotaskEmpty; onStable; onUnstable; run2; onMicrotaskEmpty; onStable'); + done(); + }, resultTimer); + }); - it('should call onUnstable and onMicrotaskEmpty before and after each turn', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - let aResolve: (result: string) => void; - let aPromise: Promise; - let bResolve: (result: string) => void; - let bPromise: Promise; + it('should call onUnstable and onMicrotaskEmpty before and after each turn', done => { + let aResolve: (result: string) => void; + let aPromise: Promise; + let bResolve: (result: string) => void; + let bPromise: Promise; - runNgZoneNoLog(() => { - macroTask(() => { - aPromise = new Promise(res => { - aResolve = res; - }); - bPromise = new Promise(res => { - bResolve = res; - }); + runNgZoneNoLog(() => { + macroTask(() => { + aPromise = new Promise(res => { + aResolve = res; + }); + bPromise = new Promise(res => { + bResolve = res; + }); - _log.add('run start'); - aPromise.then(_log.fn('a then')); - bPromise.then(_log.fn('b then')); - }); - }); + _log.add('run start'); + aPromise.then(_log.fn('a then')); + bPromise.then(_log.fn('b then')); + }); + }); - runNgZoneNoLog(() => { - macroTask(() => { - aResolve('a'); - bResolve('b'); - }); - }); + runNgZoneNoLog(() => { + macroTask(() => { + aResolve('a'); + bResolve('b'); + }); + }); - macroTask(() => { - expect(_log.result()) - .toEqual( - 'onUnstable; run start; onMicrotaskEmpty; onStable; onUnstable; a then; b then; onMicrotaskEmpty; onStable'); - async.done(); - }, resultTimer); - }), testTimeout); + macroTask(() => { + expect(_log.result()) + .toEqual( + 'onUnstable; run start; onMicrotaskEmpty; onStable; onUnstable; a then; b then; onMicrotaskEmpty; onStable'); + done(); + }, resultTimer); + }); - it('should run a function outside of the angular zone', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - macroTask(() => { - _zone.runOutsideAngular(_log.fn('run')); - }); + it('should run a function outside of the angular zone', done => { + macroTask(() => { + _zone.runOutsideAngular(_log.fn('run')); + }); - macroTask(() => { - expect(_log.result()).toEqual('run'); - async.done(); - }); - }), testTimeout); + macroTask(() => { + expect(_log.result()).toEqual('run'); + done(); + }); + }); it('should call onUnstable and onMicrotaskEmpty when an inner microtask is scheduled from outside angular', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { + done => { let resolve: (result: string|null) => void; let promise: Promise; @@ -608,13 +591,13 @@ function commonTests() { // Third VM Turn => execute the microtask (inside angular) // No onUnstable; because we don't own the task which started the turn. 'executedMicrotask; onMicrotaskEmpty; onStable'); - async.done(); + done(); }, resultTimer); - }), testTimeout); + }); it('should call onUnstable only before executing a microtask scheduled in onMicrotaskEmpty ' + 'and not onMicrotaskEmpty after executing the task', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { + done => { runNgZoneNoLog(() => macroTask(_log.fn('run'))); let ran = false; @@ -642,13 +625,13 @@ function commonTests() { 'onUnstable; run; onMicrotaskEmpty; onMicrotaskEmpty(begin); onMicrotaskEmpty(end); ' + // Second microtaskDrain Turn => microtask enqueued from onMicrotaskEmpty 'executedMicrotask; onMicrotaskEmpty; onMicrotaskEmpty(begin); onMicrotaskEmpty(end); onStable'); - async.done(); + done(); }, resultTimer); - }), testTimeout); + }); it('should call onUnstable and onMicrotaskEmpty for a scheduleMicroTask in onMicrotaskEmpty triggered by ' + 'a scheduleMicroTask in run', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { + done => { runNgZoneNoLog(() => { macroTask(() => { _log.add('scheduleMicroTask'); @@ -680,76 +663,75 @@ function commonTests() { 'onUnstable; scheduleMicroTask; run(executeMicrotask); onMicrotaskEmpty; onMicrotaskEmpty(begin); onMicrotaskEmpty(scheduleMicroTask); onMicrotaskEmpty(end); ' + // Second VM Turn => the microtask enqueued from onMicrotaskEmpty 'onMicrotaskEmpty(executeMicrotask); onMicrotaskEmpty; onMicrotaskEmpty(begin); onMicrotaskEmpty(end); onStable'); - async.done(); + done(); }, resultTimer); - }), testTimeout); + }); - it('should execute promises scheduled in onUnstable before promises scheduled in run', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - runNgZoneNoLog(() => { - macroTask(() => { - _log.add('run start'); - resolvedPromise - .then((_) => { - _log.add('promise then'); - resolvedPromise.then(_log.fn('promise foo')); - return Promise.resolve(null); - }) - .then(_log.fn('promise bar')); - _log.add('run end'); - }); - }); + it('should execute promises scheduled in onUnstable before promises scheduled in run', done => { + runNgZoneNoLog(() => { + macroTask(() => { + _log.add('run start'); + resolvedPromise + .then((_) => { + _log.add('promise then'); + resolvedPromise.then(_log.fn('promise foo')); + return Promise.resolve(null); + }) + .then(_log.fn('promise bar')); + _log.add('run end'); + }); + }); - let donePromiseRan = false; - let startPromiseRan = false; + let donePromiseRan = false; + let startPromiseRan = false; - _zone.onUnstable.subscribe({ - next: () => { - _log.add('onUnstable(begin)'); - if (!startPromiseRan) { - _log.add('onUnstable(schedulePromise)'); - _zone.run(() => { - scheduleMicroTask(_log.fn('onUnstable(executePromise)')); - }); - startPromiseRan = true; - } - _log.add('onUnstable(end)'); - } - }); + _zone.onUnstable.subscribe({ + next: () => { + _log.add('onUnstable(begin)'); + if (!startPromiseRan) { + _log.add('onUnstable(schedulePromise)'); + _zone.run(() => { + scheduleMicroTask(_log.fn('onUnstable(executePromise)')); + }); + startPromiseRan = true; + } + _log.add('onUnstable(end)'); + } + }); - _zone.onMicrotaskEmpty.subscribe({ - next: () => { - _log.add('onMicrotaskEmpty(begin)'); - if (!donePromiseRan) { - _log.add('onMicrotaskEmpty(schedulePromise)'); - _zone.run(() => { - scheduleMicroTask(_log.fn('onMicrotaskEmpty(executePromise)')); - }); - donePromiseRan = true; - } - _log.add('onMicrotaskEmpty(end)'); - } - }); + _zone.onMicrotaskEmpty.subscribe({ + next: () => { + _log.add('onMicrotaskEmpty(begin)'); + if (!donePromiseRan) { + _log.add('onMicrotaskEmpty(schedulePromise)'); + _zone.run(() => { + scheduleMicroTask(_log.fn('onMicrotaskEmpty(executePromise)')); + }); + donePromiseRan = true; + } + _log.add('onMicrotaskEmpty(end)'); + } + }); - macroTask(() => { - expect(_log.result()) - .toEqual( - // First VM turn: enqueue a microtask in onUnstable - 'onUnstable; onUnstable(begin); onUnstable(schedulePromise); onUnstable(end); ' + - // First VM turn: execute the macrotask which enqueues microtasks - 'run start; run end; ' + - // First VM turn: execute enqueued microtasks - 'onUnstable(executePromise); promise then; promise foo; promise bar; onMicrotaskEmpty; ' + - // First VM turn: onTurnEnd, enqueue a microtask - 'onMicrotaskEmpty(begin); onMicrotaskEmpty(schedulePromise); onMicrotaskEmpty(end); ' + - // Second VM turn: execute the microtask from onTurnEnd - 'onMicrotaskEmpty(executePromise); onMicrotaskEmpty; onMicrotaskEmpty(begin); onMicrotaskEmpty(end); onStable'); - async.done(); - }, resultTimer); - }), testTimeout); + macroTask(() => { + expect(_log.result()) + .toEqual( + // First VM turn: enqueue a microtask in onUnstable + 'onUnstable; onUnstable(begin); onUnstable(schedulePromise); onUnstable(end); ' + + // First VM turn: execute the macrotask which enqueues microtasks + 'run start; run end; ' + + // First VM turn: execute enqueued microtasks + 'onUnstable(executePromise); promise then; promise foo; promise bar; onMicrotaskEmpty; ' + + // First VM turn: onTurnEnd, enqueue a microtask + 'onMicrotaskEmpty(begin); onMicrotaskEmpty(schedulePromise); onMicrotaskEmpty(end); ' + + // Second VM turn: execute the microtask from onTurnEnd + 'onMicrotaskEmpty(executePromise); onMicrotaskEmpty; onMicrotaskEmpty(begin); onMicrotaskEmpty(end); onStable'); + done(); + }, resultTimer); + }); it('should call onUnstable and onMicrotaskEmpty before and after each turn, respectively', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { + done => { let aResolve: (result: string|null) => void; let aPromise: Promise; let bResolve: (result: string|null) => void; @@ -790,12 +772,12 @@ function commonTests() { 'onUnstable; a then; onMicrotaskEmpty; onStable; ' + // Third VM turn 'onUnstable; b then; onMicrotaskEmpty; onStable'); - async.done(); + done(); }, resultTimer); - }), testTimeout); + }); it('should call onUnstable and onMicrotaskEmpty before and after (respectively) all turns in a chain', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { + done => { runNgZoneNoLog(() => { macroTask(() => { _log.add('run start'); @@ -811,12 +793,12 @@ function commonTests() { expect(_log.result()) .toEqual( 'onUnstable; run start; run end; async1; async2; onMicrotaskEmpty; onStable'); - async.done(); + done(); }, resultTimer); - }), testTimeout); + }); it('should call onUnstable and onMicrotaskEmpty for promises created outside of run body', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { + done => { let promise: Promise; runNgZoneNoLog(() => { @@ -835,29 +817,28 @@ function commonTests() { .toEqual( 'onUnstable; zone run; onMicrotaskEmpty; onStable; ' + 'onUnstable; promise then; onMicrotaskEmpty; onStable'); - async.done(); + done(); }, resultTimer); - }), testTimeout); + }); }); describe('exceptions', () => { - it('should call the on error callback when it is invoked via zone.runGuarded', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - macroTask(() => { - const exception = new Error('sync'); + it('should call the on error callback when it is invoked via zone.runGuarded', done => { + macroTask(() => { + const exception = new Error('sync'); - _zone.runGuarded(() => { - throw exception; - }); + _zone.runGuarded(() => { + throw exception; + }); - expect(_errors.length).toBe(1); - expect(_errors[0]).toBe(exception); - async.done(); - }); - }), testTimeout); + expect(_errors.length).toBe(1); + expect(_errors[0]).toBe(exception); + done(); + }); + }); it('should not call the on error callback but rethrow when it is invoked via zone.run', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { + done => { macroTask(() => { const exception = new Error('sync'); expect(() => _zone.run(() => { @@ -865,28 +846,27 @@ function commonTests() { })).toThrowError('sync'); expect(_errors.length).toBe(0); - async.done(); + done(); }); - }), testTimeout); + }); - it('should call onError for errors from microtasks', - inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { - const exception = new Error('async'); + it('should call onError for errors from microtasks', done => { + const exception = new Error('async'); - macroTask(() => { - _zone.run(() => { - scheduleMicroTask(() => { - throw exception; - }); - }); - }); + macroTask(() => { + _zone.run(() => { + scheduleMicroTask(() => { + throw exception; + }); + }); + }); - macroTask(() => { - expect(_errors.length).toBe(1); - expect(_errors[0]).toEqual(exception); - async.done(); - }, resultTimer); - }), testTimeout); + macroTask(() => { + expect(_errors.length).toBe(1); + expect(_errors[0]).toEqual(exception); + done(); + }, resultTimer); + }); }); describe('bugs', () => { @@ -1009,7 +989,7 @@ function commonTests() { global.setImmediate = patchedImmediate; }); - it('should run in requestAnimationFrame async', (done: DoneFn) => { + it('should run in requestAnimationFrame async', done => { let task: Task|undefined = undefined; coalesceZone.run(() => { task = Zone.current.scheduleEventTask('myEvent', () => { @@ -1025,7 +1005,7 @@ function commonTests() { }); it('should only emit onMicroTaskEmpty once within the same event loop for multiple event tasks', - (done: DoneFn) => { + done => { const tasks: Task[] = []; coalesceZone.run(() => { tasks.push(Zone.current.scheduleEventTask('myEvent', () => { @@ -1045,7 +1025,7 @@ function commonTests() { }); it('should only emit onMicroTaskEmpty once within the same event loop for ngZone.run in onMicrotaskEmpty subscription', - (done: DoneFn) => { + done => { const tasks: Task[] = []; coalesceZone.onMicrotaskEmpty.subscribe(() => { coalesceZone.run(() => {}); @@ -1071,7 +1051,7 @@ function commonTests() { }); it('should emit onMicroTaskEmpty once within the same event loop for not only event tasks, but event tasks are before other tasks', - (done: DoneFn) => { + done => { const tasks: Task[] = []; coalesceZone.run(() => { tasks.push(Zone.current.scheduleEventTask('myEvent', () => { @@ -1094,7 +1074,7 @@ function commonTests() { }); it('should emit multiple onMicroTaskEmpty within the same event loop for not only event tasks, but event tasks are after other tasks', - (done: DoneFn) => { + done => { const tasks: Task[] = []; coalesceZone.run(() => { tasks.push(Zone.current.scheduleMacroTask('myMacro', () => { @@ -1148,7 +1128,7 @@ function commonTests() { global.setImmediate = patchedImmediate; }); - it('should run in requestAnimationFrame async', (done: DoneFn) => { + it('should run in requestAnimationFrame async', done => { coalesceZone.run(() => {}); expect(logs).toEqual([]); nativeRequestAnimationFrame(() => { @@ -1158,7 +1138,7 @@ function commonTests() { }); it('should only emit onMicroTaskEmpty once within the same event loop for multiple ngZone.run', - (done: DoneFn) => { + done => { coalesceZone.run(() => {}); coalesceZone.run(() => {}); expect(logs).toEqual([]); @@ -1169,7 +1149,7 @@ function commonTests() { }); it('should only emit onMicroTaskEmpty once within the same event loop for ngZone.run in onMicrotaskEmpty subscription', - (done: DoneFn) => { + done => { coalesceZone.onMicrotaskEmpty.subscribe(() => { coalesceZone.run(() => {}); }); @@ -1183,7 +1163,7 @@ function commonTests() { }); it('should only emit onMicroTaskEmpty once within the same event loop for multiple tasks', - (done: DoneFn) => { + done => { const tasks: Task[] = []; coalesceZone.run(() => { tasks.push(Zone.current.scheduleMacroTask('myMacro', () => { diff --git a/packages/core/testing/src/async_test_completer.ts b/packages/core/testing/src/async_test_completer.ts deleted file mode 100644 index 2d2385a3de..0000000000 --- a/packages/core/testing/src/async_test_completer.ts +++ /dev/null @@ -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 = 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 { - return this._promise; - } -} diff --git a/packages/core/testing/src/test_bed.ts b/packages/core/testing/src/test_bed.ts index 68c413b237..9859681c07 100644 --- a/packages/core/testing/src/test_bed.ts +++ b/packages/core/testing/src/test_bed.ts @@ -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); + }; } /** diff --git a/packages/core/testing/src/testing_internal.ts b/packages/core/testing/src/testing_internal.ts index 5cd971d5ec..1307ecf157 100644 --- a/packages/core/testing/src/testing_internal.ts +++ b/packages/core/testing/src/testing_internal.ts @@ -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 = (typeof window === 'undefined' ? global : window); - -export const afterEach: Function = _global.afterEach; -export const expect: (actual: T) => jasmine.Matchers = _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 = []; - - 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; - } -} diff --git a/packages/forms/test/directives_spec.ts b/packages/forms/test/directives_spec.ts index 2b99f910e1..0b94bdc02b 100644 --- a/packages/forms/test/directives_spec.ts +++ b/packages/forms/test/directives_spec.ts @@ -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 = 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, [ 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, [ 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 = new SpyValueAccessor(); + const customAccessor: ControlValueAccessor = {} as any; expect(() => selectValueAccessor(dir, [customAccessor, customAccessor])).toThrowError(); }); }); diff --git a/packages/forms/test/form_array_spec.ts b/packages/forms/test/form_array_spec.ts index c810230d17..5097be6621 100644 --- a/packages/forms/test/form_array_spec.ts +++ b/packages/forms/test/form_array_spec.ts @@ -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', () => { diff --git a/packages/forms/test/form_builder_spec.ts b/packages/forms/test/form_builder_spec.ts index e0d0da0b03..0e0e100ab9 100644 --- a/packages/forms/test/form_builder_spec.ts +++ b/packages/forms/test/form_builder_spec.ts @@ -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'; diff --git a/packages/forms/test/form_control_spec.ts b/packages/forms/test/form_control_spec.ts index 7caff35c0b..d4344e8ce5 100644 --- a/packages/forms/test/form_control_spec.ts +++ b/packages/forms/test/form_control_spec.ts @@ -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', () => { diff --git a/packages/forms/test/form_group_spec.ts b/packages/forms/test/form_group_spec.ts index 6a8578bef1..830a3ae587 100644 --- a/packages/forms/test/form_group_spec.ts +++ b/packages/forms/test/form_group_spec.ts @@ -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', () => { diff --git a/packages/forms/test/reactive_integration_spec.ts b/packages/forms/test/reactive_integration_spec.ts index acbe4eb995..99de565ea2 100644 --- a/packages/forms/test/reactive_integration_spec.ts +++ b/packages/forms/test/reactive_integration_spec.ts @@ -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; -} \ No newline at end of file +} diff --git a/packages/forms/test/spies.ts b/packages/forms/test/spies.ts deleted file mode 100644 index d90f06f324..0000000000 --- a/packages/forms/test/spies.ts +++ /dev/null @@ -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; -} diff --git a/packages/forms/test/validators_spec.ts b/packages/forms/test/validators_spec.ts index a42c14774c..c125836df1 100644 --- a/packages/forms/test/validators_spec.ts +++ b/packages/forms/test/validators_spec.ts @@ -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'; diff --git a/packages/platform-browser-dynamic/test/resource_loader/resource_loader_impl_spec.ts b/packages/platform-browser-dynamic/test/resource_loader/resource_loader_impl_spec.ts index ba1777b0a0..e950c202d8 100644 --- a/packages/platform-browser-dynamic/test/resource_loader/resource_loader_impl_spec.ts +++ b/packages/platform-browser-dynamic/test/resource_loader/resource_loader_impl_spec.ts @@ -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('

hey

'); - async.done(); - }); - }), 10000); + it('should resolve the Promise with the file content on success', done => { + resourceLoader.get(url200).then((text) => { + expect(text.trim()).toEqual('

hey

'); + 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); }); } diff --git a/packages/platform-browser/test/browser/bootstrap_spec.ts b/packages/platform-browser/test/browser/bootstrap_spec.ts index d49260773f..e8ae8b2b0b 100644 --- a/packages/platform-browser/test/browser/bootstrap_spec.ts +++ b/packages/platform-browser/test/browser/bootstrap_spec.ts @@ -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: `
`}) -class HelloCmpUsingPlatformDirectiveAndPipe { - show: boolean = false; -} - @Component({selector: 'hello-app', template: 'hello world!'}) 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: '', - }) - class RootCmp { - } + @Component({ + selector: 'hello-app', + template: '', + }) + 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> = bootstrap(HelloRootCmp, testProviders); - const refPromise2: Promise> = bootstrap(HelloRootCmp2, testProviders); + it('should register each application with the testability registry', done => { + const refPromise1: Promise> = bootstrap(HelloRootCmp, testProviders); + const refPromise2: Promise> = bootstrap(HelloRootCmp2, testProviders); - Promise.all([refPromise1, refPromise2]).then((refs: ComponentRef[]) => { - 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[]) => { + 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); + }); }); }); } diff --git a/packages/platform-browser/test/browser/tools/spies.ts b/packages/platform-browser/test/browser/tools/spies.ts deleted file mode 100644 index c7c3c0d476..0000000000 --- a/packages/platform-browser/test/browser/tools/spies.ts +++ /dev/null @@ -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 { - (global).ng.profiler.timeChangeDetection(config); -} diff --git a/packages/platform-browser/test/browser/tools/tools_spec.ts b/packages/platform-browser/test/browser/tools/tools_spec.ts index 3d26ddefe4..8c078a8138 100644 --- a/packages/platform-browser/test/browser/tools/tools_spec.ts +++ b/packages/platform-browser/test/browser/tools/tools_spec.ts @@ -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((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 { + (global).ng.profiler.timeChangeDetection(config); +} diff --git a/packages/platform-browser/test/dom/events/event_manager_spec.ts b/packages/platform-browser/test/dom/events/event_manager_spec.ts index 0f08c19018..24014ffb7c 100644 --- a/packages/platform-browser/test/dom/events/event_manager_spec.ts +++ b/packages/platform-browser/test/dom/events/event_manager_spec.ts @@ -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'; diff --git a/packages/platform-browser/test/dom/events/hammer_gestures_spec.ts b/packages/platform-browser/test/dom/events/hammer_gestures_spec.ts index 715cc5b482..a6e1007c80 100644 --- a/packages/platform-browser/test/dom/events/hammer_gestures_spec.ts +++ b/packages/platform-browser/test/dom/events/hammer_gestures_spec.ts @@ -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. diff --git a/packages/platform-browser/test/dom/events/key_events_spec.ts b/packages/platform-browser/test/dom/events/key_events_spec.ts index f29d909759..b422577a6b 100644 --- a/packages/platform-browser/test/dom/events/key_events_spec.ts +++ b/packages/platform-browser/test/dom/events/key_events_spec.ts @@ -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'; { diff --git a/packages/platform-browser/test/dom/shared_styles_host_spec.ts b/packages/platform-browser/test/dom/shared_styles_host_spec.ts index ac00e735d1..2891d54ccd 100644 --- a/packages/platform-browser/test/dom/shared_styles_host_spec.ts +++ b/packages/platform-browser/test/dom/shared_styles_host_spec.ts @@ -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'; diff --git a/packages/platform-browser/test/security/dom_sanitization_service_spec.ts b/packages/platform-browser/test/security/dom_sanitization_service_spec.ts index ee9ecb6a0a..147d0756a2 100644 --- a/packages/platform-browser/test/security/dom_sanitization_service_spec.ts +++ b/packages/platform-browser/test/security/dom_sanitization_service_spec.ts @@ -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'); }); }); } diff --git a/packages/platform-browser/test/testing_public_spec.ts b/packages/platform-browser/test/testing_public_spec.ts index f1e5c8430f..253507fbe3 100644 --- a/packages/platform-browser/test/testing_public_spec.ts +++ b/packages/platform-browser/test/testing_public_spec.ts @@ -335,9 +335,9 @@ const bTok = new InjectionToken('b'); }); describe('components with template url', () => { - beforeEach(waitForAsync(() => { + beforeEach(waitForAsync(async () => { TestBed.configureTestingModule({declarations: [CompWithUrlTemplate]}); - TestBed.compileComponents(); + await TestBed.compileComponents(); })); isBrowser && diff --git a/packages/router/test/integration.spec.ts b/packages/router/test/integration.spec.ts index 094c4de668..bd76ed5432 100644 --- a/packages/router/test/integration.spec.ts +++ b/packages/router/test/integration.spec.ts @@ -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'; diff --git a/test-main.js b/test-main.js index b935f6bf39..66f74c22d4 100644 --- a/test-main.js +++ b/test-main.js @@ -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.