diff --git a/aio/content/examples/service-worker-getting-started/src/app/prompt-update.service.ts b/aio/content/examples/service-worker-getting-started/src/app/prompt-update.service.ts index 45059eda7a6..0f3fe53c6fe 100755 --- a/aio/content/examples/service-worker-getting-started/src/app/prompt-update.service.ts +++ b/aio/content/examples/service-worker-getting-started/src/app/prompt-update.service.ts @@ -1,8 +1,6 @@ // #docplaster import { Injectable } from '@angular/core'; -// #docregion sw-replicate-available - import { filter, map } from 'rxjs/operators'; -// #enddocregion sw-replicate-available +import { filter, map } from 'rxjs/operators'; import { SwUpdate, VersionReadyEvent } from '@angular/service-worker'; function promptUser(event: VersionReadyEvent): boolean { @@ -23,7 +21,6 @@ export class PromptUpdateService { } }); // #enddocregion sw-version-ready - // #docregion sw-replicate-available // ... const updatesAvailable = swUpdate.versionUpdates.pipe( filter((evt): evt is VersionReadyEvent => evt.type === 'VERSION_READY'), @@ -32,7 +29,6 @@ export class PromptUpdateService { current: evt.currentVersion, available: evt.latestVersion, }))); - // #enddocregion sw-replicate-available // #docregion sw-version-ready } diff --git a/aio/content/guide/deprecations.md b/aio/content/guide/deprecations.md index 5d701ad48cb..223623a5728 100644 --- a/aio/content/guide/deprecations.md +++ b/aio/content/guide/deprecations.md @@ -96,8 +96,7 @@ v16 - v19 | `@angular/platform-browser-dynamic` | [`JitCompilerFactory`](#platform-browser-dynamic) | v13 | v16 | | `@angular/platform-browser-dynamic` | [`RESOURCE_CACHE_PROVIDER`](#platform-browser-dynamic) | v13 | v16 | | `@angular/platform-server` | [`ServerTransferStateModule`](#platform-server) | v14 | v16 | -| `@angular/service-worker` | [`SwUpdate#activated`](api/service-worker/SwUpdate#activated) | v13 | v16 | -| `@angular/service-worker` | [`SwUpdate#available`](api/service-worker/SwUpdate#available) | v13 | v16 | +| `@angular/platform-browser` | [`BrowserModule.withServerTransition`](api/platform-browser/BrowserModule#withservertransition) | v16 | v18 | ### Deprecated features that can be removed in v17 or later @@ -253,15 +252,6 @@ In the [API reference section](api) of this site, deprecated APIs are indicated | [`ngModel` with reactive forms](#ngmodel-reactive) | [`FormControlDirective`](api/forms/FormControlDirective) | v6 | none | | [`FormBuilder.group` legacy options parameter](api/forms/FormBuilder#group) | [`AbstractControlOptions` parameter value](api/forms/AbstractControlOptions) | v11 | none | - - -### @angular/service-worker - -| API | Replacement | Deprecation announced | Details | -|:--- |:--- |:--- |:--- | -| [`SwUpdate#activated`](api/service-worker/SwUpdate#activated) | [`SwUpdate#activateUpdate()` return value](api/service-worker/SwUpdate#activateUpdate) | v13 | The return value of `SwUpdate#activateUpdate()` indicates whether an update was successfully activated. | -| [`SwUpdate#available`](api/service-worker/SwUpdate#available) | [`SwUpdate#versionUpdates`](api/service-worker/SwUpdate#versionUpdates) | v13 | The behavior of `SwUpdate#available` can be rebuilt by filtering for `VersionReadyEvent` events on [`SwUpdate#versionUpdates`](api/service-worker/SwUpdate#versionUpdates) | - ### @angular/upgrade diff --git a/aio/content/guide/service-worker-intro.md b/aio/content/guide/service-worker-intro.md index 68b564a014e..6e336a45985 100644 --- a/aio/content/guide/service-worker-intro.md +++ b/aio/content/guide/service-worker-intro.md @@ -73,7 +73,7 @@ More specifically: * The browser does not download the service worker script and the `ngsw.json` manifest file * Active attempts to interact with the service worker, such as calling `SwUpdate.checkForUpdate()`, return rejected promises -* The observable events of related services, such as `SwUpdate.available`, are not triggered +* The observable events of related services, such as `SwUpdate.versionUpdates`, are not triggered It is highly recommended that you ensure that your application works even without service worker support in the browser. Although an unsupported browser ignores service worker caching, it still reports errors if the application attempts to interact with the service worker. diff --git a/aio/content/guide/update-to-version-14.md b/aio/content/guide/update-to-version-14.md index 0459db1b886..2713f9452f4 100644 --- a/aio/content/guide/update-to-version-14.md +++ b/aio/content/guide/update-to-version-14.md @@ -67,7 +67,7 @@ For information about the deprecation and removal practices of Angular, see [Ang | `relativeLinkResolution` in the Router [`ExtraOptions`](api/router/ExtraOptions) | Switch to the default of `'corrected'` link resolution | This option was introduced to fix a bug with link resolution in a backwards compatible way. Existing apps which still depend on the buggy legacy behavior should switch to the new corrected behavior and stop passing this flag. | | `resolver` argument in [`RouterOutletContract.activateWith`](api/router/RouterOutletContract#activateWith) | n/a | `ComponentFactory` and `ComponentFactoryResolver` are deprecated, and passing an argument for a resolver to retrieve a `ComponentFactory` is no longer required. | | [`OutletContext#resolver](https://v14.angular.io/api/router/OutletContext#resolver) | n/a | `ComponentFactory` and `ComponentFactoryResolver` are deprecated, and using a resolver to retrieve a `ComponentFactory` is no longer required. | -| [`SwUpdate#activated`](api/service-worker/SwUpdate#activated) | Return value of [`SwUpdate#activateUpdate`](api/service-worker/SwUpdate#activateUpdate) | The `activated` property is deprecated. Existing usages can migrate to [`SwUpdate#activateUpdate`](api/service-worker/SwUpdate#activateUpdate). | -| [`SwUpdate#available`](api/service-worker/SwUpdate#available) | [`SwUpdate#versionUpdates`](api/service-worker/SwUpdate#versionUpdates) | The behavior of [`SwUpdate#available`](api/service-worker/SwUpdate#available) can be achieved by filtering for the [`VersionReadyEvent`](api/service-worker/VersionReadyEvent) from [`SwUpdate#versionUpdates`](api/service-worker/SwUpdate#versionUpdates) | +| [`SwUpdate#activated`](https://v14.angular.io/api/service-worker/SwUpdate#activated) | Return value of [`SwUpdate#activateUpdate`](api/service-worker/SwUpdate#activateUpdate) | The `activated` property is deprecated. Existing usages can migrate to [`SwUpdate#activateUpdate`](api/service-worker/SwUpdate#activateUpdate). | +| [`SwUpdate#available`](https://v14.angular.io/api/service-worker/SwUpdate#available) | [`SwUpdate#versionUpdates`](https://v14.angular.io/api/service-worker/SwUpdate#versionUpdates) | The behavior of [`SwUpdate#available`](https://v14.angular.io/api/service-worker/SwUpdate#available) can be achieved by filtering for the [`VersionReadyEvent`](https://v14.angular.io/api/service-worker/VersionReadyEvent) from [`SwUpdate#versionUpdates`](api/service-worker/SwUpdate#versionUpdates) | @reviewed 2022-05-31 diff --git a/aio/src/app/sw-updates/sw-updates.service.spec.ts b/aio/src/app/sw-updates/sw-updates.service.spec.ts index 8b7cff2c9bf..b096bf018c3 100644 --- a/aio/src/app/sw-updates/sw-updates.service.spec.ts +++ b/aio/src/app/sw-updates/sw-updates.service.spec.ts @@ -1,6 +1,6 @@ import { ApplicationRef, ErrorHandler, Injector } from '@angular/core'; import { discardPeriodicTasks, fakeAsync, tick } from '@angular/core/testing'; -import { SwUpdate, VersionEvent, VersionReadyEvent } from '@angular/service-worker'; +import { SwUpdate, VersionEvent } from '@angular/service-worker'; import { BehaviorSubject, Subject } from 'rxjs'; import { LocationService } from 'app/shared/location.service'; @@ -89,7 +89,7 @@ describe('SwUpdatesService', () => { appRef.isStable.next(true); expect(swu.activateUpdate).not.toHaveBeenCalled(); - swu.$$versionUpdatesSubj.next({latestVersion: {hash: 'foo'}, type: 'VERSION_READY'} as VersionReadyEvent); + swu.$$availableSubj.next({latestVersion: {hash: 'foo'}, type: 'VERSION_READY'}); expect(swu.activateUpdate).toHaveBeenCalled(); }))); @@ -100,7 +100,7 @@ describe('SwUpdatesService', () => { tick(checkInterval); expect(swu.checkForUpdate).toHaveBeenCalledTimes(1); - swu.$$versionUpdatesSubj.next({latestVersion: {hash: 'foo'}, type: 'VERSION_READY'} as VersionReadyEvent); + swu.$$availableSubj.next({latestVersion: {hash: 'foo'}, type: 'VERSION_READY'}); tick(checkInterval); expect(swu.checkForUpdate).toHaveBeenCalledTimes(2); @@ -111,14 +111,15 @@ describe('SwUpdatesService', () => { discardPeriodicTasks(); }))); - it('should request a full page navigation when an update has been activated', fakeAsync(run(() => { - swu.$$versionUpdatesSubj.next({latestVersion: {hash: 'foo'}, type: 'VERSION_READY'} as VersionReadyEvent); - tick(); + it('should request a full page navigation when an update has been activated', fakeAsync(run(async () => { + expect(location.fullPageNavigationNeeded).toHaveBeenCalledTimes(0); + + swu.$$availableSubj.next({latestVersion: {hash: 'foo'}, type: 'VERSION_READY'}); + tick(checkInterval); expect(location.fullPageNavigationNeeded).toHaveBeenCalledTimes(1); - - swu.$$versionUpdatesSubj.next({latestVersion: {hash: 'foo'}, type: 'VERSION_READY'} as VersionReadyEvent); - tick(); + swu.$$availableSubj.next({latestVersion: {hash: 'baz'}, type: 'VERSION_READY'}); + tick(checkInterval); expect(location.fullPageNavigationNeeded).toHaveBeenCalledTimes(2); }))); @@ -159,9 +160,7 @@ describe('SwUpdatesService', () => { tick(checkInterval); tick(checkInterval); - swu.$$versionUpdatesSubj.next({ - latestVersion: {hash: 'foo'}, currentVersion: {hash: 'bar'} , type: 'VERSION_READY' - }); + swu.$$availableSubj.next({latestVersion: {hash: 'foo'}, type: 'VERSION_READY'}); tick(checkInterval); tick(checkInterval); @@ -170,21 +169,18 @@ describe('SwUpdatesService', () => { }))); it('should not activate available updates', fakeAsync(runDeactivated(() => { - swu.$$versionUpdatesSubj.next({latestVersion: {hash: 'foo'}, type: 'VERSION_READY'} as VersionReadyEvent); - + swu.$$availableSubj.next({latestVersion: {hash: 'foo'}, type: 'VERSION_READY'}); expect(swu.activateUpdate).not.toHaveBeenCalled(); }))); - it('should never request a full page navigation', runDeactivated(() => { - swu.$$versionUpdatesSubj.next({ - latestVersion: {hash: 'foo'}, currentVersion: {hash: 'bar'} , type: 'VERSION_READY' - }); - swu.$$versionUpdatesSubj.next({ - latestVersion: {hash: 'baz'}, currentVersion: {hash: 'qux'} , type: 'VERSION_READY' - }); + it('should never request a full page navigation', fakeAsync(runDeactivated(() => { + swu.$$availableSubj.next({latestVersion: {hash: 'foo'}, type: 'VERSION_READY'}); + tick(checkInterval); + swu.$$availableSubj.next({latestVersion: {hash: 'baz'}, type: 'VERSION_READY'}); + tick(checkInterval); expect(location.fullPageNavigationNeeded).not.toHaveBeenCalled(); - })); + }))); it('should never request a page reload', runDeactivated(() => { swu.$$unrecoverableSubj.next({reason: 'Something bad happened'}); @@ -216,9 +212,7 @@ describe('SwUpdatesService', () => { service.disable(); swu.checkForUpdate.calls.reset(); - swu.$$versionUpdatesSubj.next({ - latestVersion: {hash: 'foo'}, currentVersion: {hash: 'baz'} , type: 'VERSION_READY' - }); + swu.$$availableSubj.next({latestVersion: {hash: 'foo'}, type: 'VERSION_READY'}); tick(checkInterval); tick(checkInterval); @@ -228,24 +222,22 @@ describe('SwUpdatesService', () => { it('should not activate available updates', fakeAsync(run(() => { service.disable(); - swu.$$versionUpdatesSubj.next({latestVersion: {hash: 'foo'}} as VersionReadyEvent); + swu.$$availableSubj.next({latestVersion: {hash: 'foo'}, type: 'VERSION_READY'}); expect(swu.activateUpdate).not.toHaveBeenCalled(); }))); it('should stop requesting full page navigations when updates are activated', fakeAsync(run(() => { - swu.$$versionUpdatesSubj.next({ - latestVersion: {hash: 'foo'}, currentVersion: {hash: 'bar'}, type: 'VERSION_READY' - }); - tick(); + swu.$$availableSubj.next({latestVersion: {hash: 'foo'}, type: 'VERSION_READY'}); + tick(checkInterval); expect(location.fullPageNavigationNeeded).toHaveBeenCalledTimes(1); service.disable(); location.fullPageNavigationNeeded.calls.reset(); - swu.$$versionUpdatesSubj.next({ - latestVersion: {hash: 'baz'}, currentVersion: {hash: 'qux'}, type: 'VERSION_READY' - }); + swu.$$availableSubj.next({latestVersion: {hash: 'baz'}, type: 'VERSION_READY'}); + tick(checkInterval); + expect(location.fullPageNavigationNeeded).not.toHaveBeenCalled(); }))); @@ -281,6 +273,7 @@ describe('SwUpdatesService', () => { service.enable(); swu.checkForUpdate.calls.reset(); + swu.$$availableSubj.next({latestVersion: {hash: 'foo'}, type: 'VERSION_READY'}); tick(checkInterval); expect(swu.checkForUpdate).toHaveBeenCalled(); @@ -290,10 +283,7 @@ describe('SwUpdatesService', () => { service.disable(); service.enable(); - swu.$$versionUpdatesSubj.next({ - latestVersion: {hash: 'foo'}, type: 'VERSION_READY' - } as VersionReadyEvent); - + swu.$$availableSubj.next({latestVersion: {hash: 'foo'}, type: 'VERSION_READY'}); expect(swu.activateUpdate).toHaveBeenCalled(); }))); }); @@ -316,11 +306,12 @@ class MockApplicationRef { } class MockSwUpdate { + $$availableSubj = new Subject<{latestVersion: {hash: string}, type: 'VERSION_READY'}>(); $$unrecoverableSubj = new Subject<{reason: string}>(); $$versionUpdatesSubj = new Subject(); + versionUpdates = this.$$availableSubj.asObservable(); unrecoverable = this.$$unrecoverableSubj.asObservable(); - versionUpdates =this.$$versionUpdatesSubj.asObservable(); activateUpdate = jasmine.createSpy('MockSwUpdate.activateUpdate') .and.callFake(() => Promise.resolve(true)); diff --git a/aio/src/app/sw-updates/sw-updates.service.ts b/aio/src/app/sw-updates/sw-updates.service.ts index d870af1b867..001bb9a3e0e 100644 --- a/aio/src/app/sw-updates/sw-updates.service.ts +++ b/aio/src/app/sw-updates/sw-updates.service.ts @@ -1,5 +1,5 @@ import { ApplicationRef, ErrorHandler, Injectable, OnDestroy } from '@angular/core'; -import { SwUpdate, VersionReadyEvent } from '@angular/service-worker'; +import { SwUpdate, VersionEvent, VersionReadyEvent } from '@angular/service-worker'; import { concat, from, interval, Subject } from 'rxjs'; import { filter, first, switchMap, takeUntil, tap } from 'rxjs/operators'; @@ -45,11 +45,12 @@ export class SwUpdatesService implements OnDestroy { // Activate available updates. this.swu.versionUpdates .pipe( - filter((evt): evt is VersionReadyEvent => evt.type === 'VERSION_READY'), + filter((evt: VersionEvent): evt is VersionReadyEvent => evt.type === 'VERSION_READY'), tap(evt => this.log(`Update available: ${JSON.stringify(evt)}`)), takeUntil(this.onDisable), switchMap(() => from(this.swu.activateUpdate())) ) + .subscribe((isActivated) => { if(isActivated) { this.log('Update activated'); diff --git a/goldens/public-api/service-worker/index.md b/goldens/public-api/service-worker/index.md index b94cfccd35e..8f3e4586c57 100644 --- a/goldens/public-api/service-worker/index.md +++ b/goldens/public-api/service-worker/index.md @@ -66,11 +66,7 @@ export abstract class SwRegistrationOptions { // @public export class SwUpdate { constructor(sw: NgswCommChannel); - // @deprecated - readonly activated: Observable; activateUpdate(): Promise; - // @deprecated - readonly available: Observable; checkForUpdate(): Promise; get isEnabled(): boolean; readonly unrecoverable: Observable; @@ -89,38 +85,6 @@ export interface UnrecoverableStateEvent { type: 'UNRECOVERABLE_STATE'; } -// @public @deprecated -export interface UpdateActivatedEvent { - // (undocumented) - current: { - hash: string; - appData?: Object; - }; - // (undocumented) - previous?: { - hash: string; - appData?: Object; - }; - // (undocumented) - type: 'UPDATE_ACTIVATED'; -} - -// @public @deprecated -export interface UpdateAvailableEvent { - // (undocumented) - available: { - hash: string; - appData?: Object; - }; - // (undocumented) - current: { - hash: string; - appData?: Object; - }; - // (undocumented) - type: 'UPDATE_AVAILABLE'; -} - // @public export interface VersionDetectedEvent { // (undocumented) diff --git a/goldens/size-tracking/aio-payloads.json b/goldens/size-tracking/aio-payloads.json index 90aebc5a03b..d7e719e4a52 100755 --- a/goldens/size-tracking/aio-payloads.json +++ b/goldens/size-tracking/aio-payloads.json @@ -19,4 +19,4 @@ "dark-theme": 34598 } } -} \ No newline at end of file +} diff --git a/packages/service-worker/src/index.ts b/packages/service-worker/src/index.ts index fb3ea0f7da5..dc9277ab8dd 100644 --- a/packages/service-worker/src/index.ts +++ b/packages/service-worker/src/index.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -export {NoNewVersionDetectedEvent, UnrecoverableStateEvent, UpdateActivatedEvent, UpdateAvailableEvent, VersionDetectedEvent, VersionEvent, VersionInstallationFailedEvent, VersionReadyEvent} from './low_level'; +export {NoNewVersionDetectedEvent, UnrecoverableStateEvent, VersionDetectedEvent, VersionEvent, VersionInstallationFailedEvent, VersionReadyEvent} from './low_level'; export {ServiceWorkerModule} from './module'; export {provideServiceWorker, SwRegistrationOptions} from './provider'; export {SwPush} from './push'; diff --git a/packages/service-worker/src/low_level.ts b/packages/service-worker/src/low_level.ts index 28c2da367ef..e3ebfea73b9 100644 --- a/packages/service-worker/src/low_level.ts +++ b/packages/service-worker/src/low_level.ts @@ -11,41 +11,6 @@ import {filter, map, publish, switchMap, take, tap} from 'rxjs/operators'; export const ERR_SW_NOT_SUPPORTED = 'Service workers are disabled or not supported by this browser'; -/** - * An event emitted when a new version of the app is available. - * - * @see {@link guide/service-worker-communications Service worker communication guide} - * - * @deprecated - * This event is only emitted by the deprecated {@link SwUpdate#available}. - * Use the {@link VersionReadyEvent} instead, which is emitted by {@link SwUpdate#versionUpdates}. - * See {@link SwUpdate#available} docs for an example. - * - * @publicApi - */ -export interface UpdateAvailableEvent { - type: 'UPDATE_AVAILABLE'; - current: {hash: string, appData?: Object}; - available: {hash: string, appData?: Object}; -} - -/** - * An event emitted when a new version of the app has been downloaded and activated. - * - * @see {@link guide/service-worker-communications Service worker communication guide} - * - * @deprecated - * This event is only emitted by the deprecated {@link SwUpdate#activated}. - * Use the return value of {@link SwUpdate#activateUpdate} instead. - * - * @publicApi - */ -export interface UpdateActivatedEvent { - type: 'UPDATE_ACTIVATED'; - previous?: {hash: string, appData?: Object}; - current: {hash: string, appData?: Object}; -} - /** * An event emitted when the service worker has checked the version of the app on the server and it * didn't find a new version that it doesn't have already downloaded. @@ -135,7 +100,7 @@ export interface PushEvent { data: any; } -export type IncomingEvent = UpdateActivatedEvent|UnrecoverableStateEvent|VersionEvent; +export type IncomingEvent = UnrecoverableStateEvent|VersionEvent; export interface TypedEvent { type: string; diff --git a/packages/service-worker/src/update.ts b/packages/service-worker/src/update.ts index 3b2523b3553..1e8edba2e41 100644 --- a/packages/service-worker/src/update.ts +++ b/packages/service-worker/src/update.ts @@ -8,11 +8,8 @@ import {Injectable} from '@angular/core'; import {NEVER, Observable} from 'rxjs'; -import {filter, map} from 'rxjs/operators'; - -import {ERR_SW_NOT_SUPPORTED, NgswCommChannel, UnrecoverableStateEvent, UpdateActivatedEvent, UpdateAvailableEvent, VersionEvent, VersionReadyEvent} from './low_level'; - +import {ERR_SW_NOT_SUPPORTED, NgswCommChannel, UnrecoverableStateEvent, VersionEvent} from './low_level'; /** * Subscribe to update notifications from the Service Worker, trigger update @@ -35,27 +32,6 @@ export class SwUpdate { */ readonly versionUpdates: Observable; - /** - * Emits an `UpdateAvailableEvent` event whenever a new app version is available. - * - * @deprecated Use {@link versionUpdates} instead. - * - * The behavior of `available` can be replicated by using `versionUpdates` by filtering for the - * `VersionReadyEvent`: - * - * {@example service-worker-getting-started/src/app/prompt-update.service.ts - * region='sw-replicate-available'} - */ - readonly available: Observable; - - /** - * Emits an `UpdateActivatedEvent` event whenever the app has been updated to a new version. - * - * @deprecated Use the return value of {@link SwUpdate#activateUpdate} instead. - * - */ - readonly activated: Observable; - /** * Emits an `UnrecoverableStateEvent` event whenever the version of the app used by the service * worker to serve this client is in a broken state that cannot be recovered from without a full @@ -74,8 +50,6 @@ export class SwUpdate { constructor(private sw: NgswCommChannel) { if (!sw.isEnabled) { this.versionUpdates = NEVER; - this.available = NEVER; - this.activated = NEVER; this.unrecoverable = NEVER; return; } @@ -85,14 +59,6 @@ export class SwUpdate { 'VERSION_READY', 'NO_NEW_VERSION_DETECTED', ]); - this.available = this.versionUpdates.pipe( - filter((evt: VersionEvent): evt is VersionReadyEvent => evt.type === 'VERSION_READY'), - map(evt => ({ - type: 'UPDATE_AVAILABLE', - current: evt.currentVersion, - available: evt.latestVersion, - }))); - this.activated = this.sw.eventsOfType('UPDATE_ACTIVATED'); this.unrecoverable = this.sw.eventsOfType('UNRECOVERABLE_STATE'); } diff --git a/packages/service-worker/test/comm_spec.ts b/packages/service-worker/test/comm_spec.ts index c96570c8d56..3aa89dbe897 100644 --- a/packages/service-worker/test/comm_spec.ts +++ b/packages/service-worker/test/comm_spec.ts @@ -8,11 +8,12 @@ import {PLATFORM_ID} from '@angular/core'; import {TestBed} from '@angular/core/testing'; -import {NgswCommChannel, NoNewVersionDetectedEvent, VersionDetectedEvent} from '@angular/service-worker/src/low_level'; +import {NgswCommChannel, NoNewVersionDetectedEvent, VersionDetectedEvent, VersionEvent, VersionReadyEvent} from '@angular/service-worker/src/low_level'; import {ngswCommChannelFactory, SwRegistrationOptions} from '@angular/service-worker/src/provider'; import {SwPush} from '@angular/service-worker/src/push'; import {SwUpdate} from '@angular/service-worker/src/update'; import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockServiceWorkerRegistration, patchDecodeBase64} from '@angular/service-worker/testing/mock'; +import {filter} from 'rxjs/operators'; { describe('ServiceWorker library', () => { @@ -419,12 +420,14 @@ import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockS mock.setupSw(); }); it('processes update availability notifications when sent', done => { - update.available.subscribe(event => { - expect(event.current).toEqual({hash: 'A'}); - expect(event.available).toEqual({hash: 'B'}); - expect(event.type).toEqual('UPDATE_AVAILABLE'); - done(); - }); + update.versionUpdates + .pipe(filter( + (evt: VersionEvent): evt is VersionReadyEvent => evt.type === 'VERSION_READY')) + .subscribe(event => { + expect(event.currentVersion).toEqual({hash: 'A'}); + expect(event.latestVersion).toEqual({hash: 'B'}); + done(); + }); mock.sendMessage({ type: 'VERSION_READY', currentVersion: { @@ -443,23 +446,7 @@ import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockS }); mock.sendMessage({type: 'UNRECOVERABLE_STATE', reason: 'Invalid Resource'}); }); - it('processes update activation notifications when sent', done => { - update.activated.subscribe(event => { - expect(event.previous).toEqual({hash: 'A'}); - expect(event.current).toEqual({hash: 'B'}); - expect(event.type).toEqual('UPDATE_ACTIVATED'); - done(); - }); - mock.sendMessage({ - type: 'UPDATE_ACTIVATED', - previous: { - hash: 'A', - }, - current: { - hash: 'B', - }, - }); - }); + it('processes a no new version event when sent', done => { update.versionUpdates.subscribe(event => { expect(event.type).toEqual('NO_NEW_VERSION_DETECTED'); @@ -526,8 +513,6 @@ import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockS }); it('does not crash on subscription to observables', () => { update = new SwUpdate(comm); - update.available.toPromise().catch(err => fail(err)); - update.activated.toPromise().catch(err => fail(err)); update.unrecoverable.toPromise().catch(err => fail(err)); update.versionUpdates.toPromise().catch(err => fail(err)); }); diff --git a/packages/service-worker/test/integration_spec.ts b/packages/service-worker/test/integration_spec.ts index 6f07246906e..83c6f31aeea 100644 --- a/packages/service-worker/test/integration_spec.ts +++ b/packages/service-worker/test/integration_spec.ts @@ -116,7 +116,7 @@ describe('ngsw + companion lib', () => { const update = new SwUpdate(comm); scope.updateServerState(serverUpdate); - const gotUpdateNotice = (async () => await obsToSinglePromise(update.available))(); + const gotUpdateNotice = (async () => await obsToSinglePromise(update.versionUpdates))(); await update.checkForUpdate(); await gotUpdateNotice; diff --git a/packages/service-worker/worker/src/driver.ts b/packages/service-worker/worker/src/driver.ts index c38e903bef0..317421b5f69 100644 --- a/packages/service-worker/worker/src/driver.ts +++ b/packages/service-worker/worker/src/driver.ts @@ -446,13 +446,7 @@ export class Driver implements Debuggable, UpdateSource { // Notify the client about this activation. const current = this.versions.get(this.latestHash!)!; - const notice = { - type: 'UPDATE_ACTIVATED', - previous, - current: this.mergeHashWithAppData(current.manifest, this.latestHash!), - }; - client.postMessage(notice); return true; } diff --git a/packages/service-worker/worker/test/happy_spec.ts b/packages/service-worker/worker/test/happy_spec.ts index f83b2008d81..c43f6a69cbe 100644 --- a/packages/service-worker/worker/test/happy_spec.ts +++ b/packages/service-worker/worker/test/happy_spec.ts @@ -542,11 +542,6 @@ describe('Driver', () => { type: 'VERSION_READY', currentVersion: {hash: manifestHash, appData: {version: 'original'}}, latestVersion: {hash: manifestUpdateHash, appData: {version: 'update'}}, - }, - { - type: 'UPDATE_ACTIVATED', - previous: {hash: manifestHash, appData: {version: 'original'}}, - current: {hash: manifestUpdateHash, appData: {version: 'update'}}, } ]); @@ -659,11 +654,6 @@ describe('Driver', () => { type: 'VERSION_READY', currentVersion: {hash: manifestHash, appData: {version: 'original'}}, latestVersion: {hash: manifestUpdateHash, appData: {version: 'update'}}, - }, - { - type: 'UPDATE_ACTIVATED', - previous: {hash: manifestHash, appData: {version: 'original'}}, - current: {hash: manifestUpdateHash, appData: {version: 'update'}}, } ]); serverUpdate.assertNoOtherRequests();