test(service-worker): remove obsolete async test helpers (#30977)
Jasmine natively supports returning promises from spec functions for quite some time now. We don't need special async helpers. PR Close #30977
This commit is contained in:

committed by
Alex Rickabaugh

parent
6c0cca093a
commit
b6e8d19313
@ -1,28 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. 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
|
||||
*/
|
||||
|
||||
function wrap(fn: () => Promise<void>): (done: DoneFn) => void {
|
||||
return (done: DoneFn) => { fn().then(() => done()).catch(err => done.fail(err)); };
|
||||
}
|
||||
|
||||
export function async_beforeAll(fn: () => Promise<void>): void {
|
||||
beforeAll(wrap(fn));
|
||||
}
|
||||
|
||||
export function async_beforeEach(fn: () => Promise<void>): void {
|
||||
beforeEach(wrap(fn));
|
||||
}
|
||||
|
||||
export function async_it(desc: string, fn: () => Promise<void>): void {
|
||||
it(desc, wrap(fn));
|
||||
}
|
||||
|
||||
export function async_fit(desc: string, fn: () => Promise<void>): void {
|
||||
// tslint:disable-next-line:no-jasmine-focus
|
||||
fit(desc, wrap(fn));
|
||||
}
|
@ -14,8 +14,6 @@ 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 {async_fit, async_it} from './async';
|
||||
|
||||
{
|
||||
describe('ServiceWorker library', () => {
|
||||
let mock: MockServiceWorkerContainer;
|
||||
@ -160,7 +158,7 @@ import {async_fit, async_it} from './async';
|
||||
});
|
||||
|
||||
describe('requestSubscription()', () => {
|
||||
async_it('returns a promise that resolves to the subscription', async() => {
|
||||
it('returns a promise that resolves to the subscription', async() => {
|
||||
const promise = push.requestSubscription({serverPublicKey: 'test'});
|
||||
expect(promise).toEqual(jasmine.any(Promise));
|
||||
|
||||
@ -168,7 +166,7 @@ import {async_fit, async_it} from './async';
|
||||
expect(sub).toEqual(jasmine.any(MockPushSubscription));
|
||||
});
|
||||
|
||||
async_it('calls `PushManager.subscribe()` (with appropriate options)', async() => {
|
||||
it('calls `PushManager.subscribe()` (with appropriate options)', async() => {
|
||||
const decode = (charCodeArr: Uint8Array) =>
|
||||
Array.from(charCodeArr).map(c => String.fromCharCode(c)).join('');
|
||||
|
||||
@ -190,7 +188,7 @@ import {async_fit, async_it} from './async';
|
||||
expect(actualAppServerKeyStr).toBe(appServerKeyStr);
|
||||
});
|
||||
|
||||
async_it('emits the new `PushSubscription` on `SwPush.subscription`', async() => {
|
||||
it('emits the new `PushSubscription` on `SwPush.subscription`', async() => {
|
||||
const subscriptionSpy = jasmine.createSpy('subscriptionSpy');
|
||||
push.subscription.subscribe(subscriptionSpy);
|
||||
const sub = await push.requestSubscription({serverPublicKey: 'test'});
|
||||
@ -206,7 +204,7 @@ import {async_fit, async_it} from './async';
|
||||
psUnsubscribeSpy = spyOn(MockPushSubscription.prototype, 'unsubscribe').and.callThrough();
|
||||
});
|
||||
|
||||
async_it('rejects if currently not subscribed to push notifications', async() => {
|
||||
it('rejects if currently not subscribed to push notifications', async() => {
|
||||
try {
|
||||
await push.unsubscribe();
|
||||
throw new Error('`unsubscribe()` should fail');
|
||||
@ -215,14 +213,14 @@ import {async_fit, async_it} from './async';
|
||||
}
|
||||
});
|
||||
|
||||
async_it('calls `PushSubscription.unsubscribe()`', async() => {
|
||||
it('calls `PushSubscription.unsubscribe()`', async() => {
|
||||
await push.requestSubscription({serverPublicKey: 'test'});
|
||||
await push.unsubscribe();
|
||||
|
||||
expect(psUnsubscribeSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
async_it('rejects if `PushSubscription.unsubscribe()` fails', async() => {
|
||||
it('rejects if `PushSubscription.unsubscribe()` fails', async() => {
|
||||
psUnsubscribeSpy.and.callFake(() => { throw new Error('foo'); });
|
||||
|
||||
try {
|
||||
@ -234,7 +232,7 @@ import {async_fit, async_it} from './async';
|
||||
}
|
||||
});
|
||||
|
||||
async_it('rejects if `PushSubscription.unsubscribe()` returns false', async() => {
|
||||
it('rejects if `PushSubscription.unsubscribe()` returns false', async() => {
|
||||
psUnsubscribeSpy.and.returnValue(Promise.resolve(false));
|
||||
|
||||
try {
|
||||
@ -246,7 +244,7 @@ import {async_fit, async_it} from './async';
|
||||
}
|
||||
});
|
||||
|
||||
async_it('emits `null` on `SwPush.subscription`', async() => {
|
||||
it('emits `null` on `SwPush.subscription`', async() => {
|
||||
const subscriptionSpy = jasmine.createSpy('subscriptionSpy');
|
||||
push.subscription.subscribe(subscriptionSpy);
|
||||
|
||||
@ -256,7 +254,7 @@ import {async_fit, async_it} from './async';
|
||||
expect(subscriptionSpy).toHaveBeenCalledWith(null);
|
||||
});
|
||||
|
||||
async_it('does not emit on `SwPush.subscription` on failure', async() => {
|
||||
it('does not emit on `SwPush.subscription` on failure', async() => {
|
||||
const subscriptionSpy = jasmine.createSpy('subscriptionSpy');
|
||||
const initialSubEmit = new Promise(resolve => subscriptionSpy.and.callFake(resolve));
|
||||
|
||||
@ -340,7 +338,7 @@ import {async_fit, async_it} from './async';
|
||||
push.subscription.subscribe(subscriptionSpy);
|
||||
});
|
||||
|
||||
async_it('emits on worker-driven changes (i.e. when the controller changes)', async() => {
|
||||
it('emits on worker-driven changes (i.e. when the controller changes)', async() => {
|
||||
// Initial emit for the current `ServiceWorkerController`.
|
||||
await nextSubEmitPromise;
|
||||
expect(subscriptionSpy).toHaveBeenCalledTimes(1);
|
||||
@ -355,7 +353,7 @@ import {async_fit, async_it} from './async';
|
||||
expect(subscriptionSpy).toHaveBeenCalledWith(null);
|
||||
});
|
||||
|
||||
async_it('emits on subscription changes (i.e. when subscribing/unsubscribing)', async() => {
|
||||
it('emits on subscription changes (i.e. when subscribing/unsubscribing)', async() => {
|
||||
await nextSubEmitPromise;
|
||||
subscriptionSpy.calls.reset();
|
||||
|
||||
|
@ -19,8 +19,6 @@ import {SwTestHarness, SwTestHarnessBuilder} from '@angular/service-worker/worke
|
||||
import {Observable} from 'rxjs';
|
||||
import {take} from 'rxjs/operators';
|
||||
|
||||
import {async_beforeEach, async_fit, async_it} from './async';
|
||||
|
||||
(function() {
|
||||
// Skip environments that don't support the minimum APIs needed to run the SW tests.
|
||||
if (!SwTestHarness.envIsSupported()) {
|
||||
@ -80,7 +78,7 @@ import {async_beforeEach, async_fit, async_it} from './async';
|
||||
let scope: SwTestHarness;
|
||||
let driver: Driver;
|
||||
|
||||
async_beforeEach(async() => {
|
||||
beforeEach(async() => {
|
||||
// Fire up the client.
|
||||
mock = new MockServiceWorkerContainer();
|
||||
comm = new NgswCommChannel(mock as any);
|
||||
@ -100,12 +98,12 @@ import {async_beforeEach, async_fit, async_it} from './async';
|
||||
await driver.initialized;
|
||||
});
|
||||
|
||||
async_it('communicates back and forth via update check', async() => {
|
||||
it('communicates back and forth via update check', async() => {
|
||||
const update = new SwUpdate(comm);
|
||||
await update.checkForUpdate();
|
||||
});
|
||||
|
||||
async_it('detects an actual update', async() => {
|
||||
it('detects an actual update', async() => {
|
||||
const update = new SwUpdate(comm);
|
||||
scope.updateServerState(serverUpdate);
|
||||
|
||||
@ -116,7 +114,7 @@ import {async_beforeEach, async_fit, async_it} from './async';
|
||||
await gotUpdateNotice;
|
||||
});
|
||||
|
||||
async_it('receives push message notifications', async() => {
|
||||
it('receives push message notifications', async() => {
|
||||
const push = new SwPush(comm);
|
||||
scope.updateServerState(serverUpdate);
|
||||
|
||||
@ -133,7 +131,7 @@ import {async_beforeEach, async_fit, async_it} from './async';
|
||||
await gotPushNotice;
|
||||
});
|
||||
|
||||
async_it('receives push message click events', async() => {
|
||||
it('receives push message click events', async() => {
|
||||
const push = new SwPush(comm);
|
||||
scope.updateServerState(serverUpdate);
|
||||
|
||||
@ -147,4 +145,4 @@ import {async_beforeEach, async_fit, async_it} from './async';
|
||||
await gotNotificationClick;
|
||||
});
|
||||
});
|
||||
})();
|
||||
})();
|
||||
|
Reference in New Issue
Block a user