license 'use strict' ; ( ( _global ) => { const __extends = function ( d , b ) { for ( const p in b ) if ( b . hasOwnProperty ( p ) ) d [ p ] = b [ p ] ; function __ ( ) { this . constructor = d ; } d . prototype = b === null ? Object . create ( b ) : ( ( __ . prototype = b . prototype ) , new ( __ as any ) ( ) ) ; } ; if ( ! Zone ) throw new Error ( 'Missing: zone.js' ) ; if ( typeof jasmine == 'undefined' ) throw new Error ( 'Missing: jasmine.js' ) ; if ( ( jasmine as any ) [ '__zone_patch__' ] ) throw new Error ( `'jasmine' has already been patched with 'Zone'.` ) ; ( jasmine as any ) [ '__zone_patch__' ] = true ; const SyncTestZoneSpec = ( Zone as any ) [ 'SyncTestZoneSpec' ] ; const ProxyZoneSpec = ( Zone as any ) [ 'ProxyZoneSpec' ] ; if ( ! SyncTestZoneSpec ) throw new Error ( 'Missing: SyncTestZoneSpec' ) ; if ( ! ProxyZoneSpec ) throw new Error ( 'Missing: ProxyZoneSpec' ) ; const ambientZone = Zone . current ; const syncZone = ambientZone . fork ( new SyncTestZoneSpec ( 'jasmine.describe' ) ) ; const symbol = Zone . __symbol__ ; const disablePatchingJasmineClock = _global [ symbol ( 'fakeAsyncDisablePatchingClock' ) ] === true ; const enableAutoFakeAsyncWhenClockPatched = ! disablePatchingJasmineClock && ( ( _global [ symbol ( 'fakeAsyncPatchLock' ) ] === true ) || ( _global [ symbol ( 'fakeAsyncAutoFakeAsyncWhenClockPatched' ) ] === true ) ) ; const ignoreUnhandledRejection = _global [ symbol ( 'ignoreUnhandledRejection' ) ] === true ; if ( ! ignoreUnhandledRejection ) { const globalErrors = ( jasmine as any ) . GlobalErrors ; if ( globalErrors && ! ( jasmine as any ) [ symbol ( 'GlobalErrors' ) ] ) { ( jasmine as any ) [ symbol ( 'GlobalErrors' ) ] = globalErrors ; ( jasmine as any ) . GlobalErrors = function ( ) { const instance = new globalErrors ( ) ; const originalInstall = instance . install ; if ( originalInstall && ! instance [ symbol ( 'install' ) ] ) { instance [ symbol ( 'install' ) ] = originalInstall ; instance . install = function ( ) { const originalHandlers = process . listeners ( 'unhandledRejection' ) ; const r = originalInstall . apply ( this , arguments ) ; process . removeAllListeners ( 'unhandledRejection' ) ; if ( originalHandlers ) { originalHandlers . forEach ( h => process . on ( 'unhandledRejection' , h ) ) ; } return r ; } ; } return instance ; } ; } } const jasmineEnv = jasmine . getEnv ( ) ; [ 'describe' , 'xdescribe' , 'fdescribe' ] . forEach ( methodName => { let originalJasmineFn = jasmineEnv [ methodName ] ; jasmineEnv [ methodName ] = function ( description , specDefinitions ) { return originalJasmineFn . call ( this , description , wrapDescribeInZone ( specDefinitions ) ) ; } ; } ) ; [ 'it' , 'xit' , 'fit' ] . forEach ( methodName => { let originalJasmineFn = jasmineEnv [ methodName ] ; jasmineEnv [ symbol ( methodName ) ] = originalJasmineFn ; jasmineEnv [ methodName ] = function ( description , specDefinitions , timeout ) { arguments [ 1 ] = wrapTestInZone ( specDefinitions ) ; return originalJasmineFn . apply ( this , arguments ) ; } ; } ) ; [ 'beforeEach' , 'afterEach' , 'beforeAll' , 'afterAll' ] . forEach ( methodName => { let originalJasmineFn = jasmineEnv [ methodName ] ; jasmineEnv [ symbol ( methodName ) ] = originalJasmineFn ; jasmineEnv [ methodName ] = function ( specDefinitions , timeout ) { arguments [ 0 ] = wrapTestInZone ( specDefinitions ) ; return originalJasmineFn . apply ( this , arguments ) ; } ; } ) ; if ( ! disablePatchingJasmineClock ) { const originalClockFn = ( ( jasmine as any ) [ symbol ( 'clock' ) ] = jasmine [ 'clock' ] ) ; ( jasmine as any ) [ 'clock' ] = function ( ) { const clock = originalClockFn . apply ( this , arguments ) ; if ( ! clock [ symbol ( 'patched' ) ] ) { clock [ symbol ( 'patched' ) ] = symbol ( 'patched' ) ; const originalTick = ( clock [ symbol ( 'tick' ) ] = clock . tick ) ; clock . tick = function ( ) { const fakeAsyncZoneSpec = Zone . current . get ( 'FakeAsyncTestZoneSpec' ) ; if ( fakeAsyncZoneSpec ) { return fakeAsyncZoneSpec . tick . apply ( fakeAsyncZoneSpec , arguments ) ; } return originalTick . apply ( this , arguments ) ; } ; const originalMockDate = ( clock [ symbol ( 'mockDate' ) ] = clock . mockDate ) ; clock . mockDate = function ( ) { const fakeAsyncZoneSpec = Zone . current . get ( 'FakeAsyncTestZoneSpec' ) ; if ( fakeAsyncZoneSpec ) { const dateTime = arguments . length > 0 ? arguments [ 0 ] : new Date ( ) ; return fakeAsyncZoneSpec . setCurrentRealTime . apply ( fakeAsyncZoneSpec , dateTime && typeof dateTime . getTime === 'function' ? [ dateTime . getTime ( ) ] : arguments ) ; } return originalMockDate . apply ( this , arguments ) ; } ; if ( enableAutoFakeAsyncWhenClockPatched ) { [ 'install' , 'uninstall' ] . forEach ( methodName => { const originalClockFn = ( clock [ symbol ( methodName ) ] = clock [ methodName ] ) ; clock [ methodName ] = function ( ) { const FakeAsyncTestZoneSpec = ( Zone as any ) [ 'FakeAsyncTestZoneSpec' ] ; if ( FakeAsyncTestZoneSpec ) { ( jasmine as any ) [ symbol ( 'clockInstalled' ) ] = 'install' === methodName ; return ; } return originalClockFn . apply ( this , arguments ) ; } ; } ) ; } } return clock ; } ; } /**
     * Gets a function wrapping the body of a Jasmine `describe` block to execute in a
     * synchronous-only zone.
     */ function wrapDescribeInZone ( describeBody ) { return function ( ) { return syncZone . run ( describeBody , this , ( arguments as any ) as any [ ] ) ; } ; } function runInTestZone ( testBody , applyThis , queueRunner , done ? ) { const isClockInstalled = ! ! ( jasmine as any ) [ symbol ( 'clockInstalled' ) ] ; const testProxyZoneSpec = queueRunner . testProxyZoneSpec ; const testProxyZone = queueRunner . testProxyZone ; let lastDelegate ; if ( isClockInstalled && enableAutoFakeAsyncWhenClockPatched ) { const fakeAsyncModule = ( Zone as any ) [ Zone . __symbol__ ( 'fakeAsyncTest' ) ] ; if ( fakeAsyncModule && typeof fakeAsyncModule . fakeAsync === 'function' ) { testBody = fakeAsyncModule . fakeAsync ( testBody ) ; } } if ( done ) { return testProxyZone . run ( testBody , applyThis , [ done ] ) ; } else { return testProxyZone . run ( testBody , applyThis ) ; } } /**
     * Gets a function wrapping the body of a Jasmine `it/beforeEach/afterEach` block to
     * execute in a ProxyZone zone.
     * This will run in `testProxyZone`. The `testProxyZone` will be reset by the `ZoneQueueRunner`
     */ function wrapTestInZone ( testBody ) { return ( testBody && ( testBody . length ? function ( done ) { return runInTestZone ( testBody , this , this . queueRunner , done ) ; } : function ( ) { return runInTestZone ( testBody , this , this . queueRunner ) ; } ) ) ; } interface QueueRunner { execute ( ) : void ; } interface QueueRunnerAttrs { queueableFns : { fn : Function ; } [ ] ; clearStack : ( fn : any ) => void ; catchException : ( ) => boolean ; fail : ( ) => void ; onComplete : ( ) => void ; onException : ( error : any ) => void ; userContext : any ; timeout : { setTimeout : Function ; clearTimeout : Function ; } ; } const QueueRunner = ( jasmine as any ) . QueueRunner as { new ( attrs ) : QueueRunner ; } ; ( jasmine as any ) . QueueRunner = ( function ( _super ) { __extends ( ZoneQueueRunner , _super ) ; function ZoneQueueRunner ( attrs ) { attrs . onComplete = ( fn => ( ) => { this . testProxyZone = null ; this . testProxyZoneSpec = null ; ambientZone . scheduleMicroTask ( 'jasmine.onComplete' , fn ) ; } ) ( attrs . onComplete ) ; const nativeSetTimeout = _global [ Zone . __symbol__ ( 'setTimeout' ) ] ; const nativeClearTimeout = _global [ Zone . __symbol__ ( 'clearTimeout' ) ] ; if ( nativeSetTimeout ) { attrs . timeout = { setTimeout : nativeSetTimeout ? nativeSetTimeout : _global . setTimeout , clearTimeout : nativeClearTimeout ? nativeClearTimeout : _global . clearTimeout } ; } if ( ( jasmine as any ) . UserContext ) { if ( ! attrs . userContext ) { attrs . userContext = new ( jasmine as any ) . UserContext ( ) ; } attrs . userContext . queueRunner = this ; } else { if ( ! attrs . userContext ) { attrs . userContext = { } ; } attrs . userContext . queueRunner = this ; } const onException = attrs . onException ; attrs . onException = function ( error ) { if ( error && error . message === 'Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.' ) { const proxyZoneSpec = this && this . testProxyZoneSpec ; if ( proxyZoneSpec ) { const pendingTasksInfo = proxyZoneSpec . getAndClearPendingTasksInfo ( ) ; try { error . message += pendingTasksInfo ; } catch ( err ) { } } } if ( onException ) { onException . call ( this , error ) ; } } ; _super . call ( this , attrs ) ; } ZoneQueueRunner . prototype . execute = function ( ) { let zone = Zone . current ; let isChildOfAmbientZone = false ; while ( zone ) { if ( zone === ambientZone ) { isChildOfAmbientZone = true ; break ; } zone = zone . parent ; } if ( ! isChildOfAmbientZone ) throw new Error ( 'Unexpected Zone: ' + Zone . current . name ) ; this . testProxyZoneSpec = new ProxyZoneSpec ( ) ; this . testProxyZone = ambientZone . fork ( this . testProxyZoneSpec ) ; if ( ! Zone . currentTask ) { Zone . current . scheduleMicroTask ( 'jasmine.execute().forceTask' , ( ) => QueueRunner . prototype . execute . call ( this ) ) ; } else { _super . prototype . execute . call ( this ) ; } } ; return ZoneQueueRunner ; } ) ( QueueRunner ) ; } ) ( global ) ;