test(service-worker): simplify test helpers (#30977)

PR Close #30977
This commit is contained in:
George Kalpakas 2019-06-24 15:04:08 +03:00 committed by Alex Rickabaugh
parent b6e8d19313
commit 7217525da4
1 changed files with 12 additions and 26 deletions

View File

@ -114,8 +114,6 @@ import {SwTestHarness, SwTestHarnessBuilder} from '../testing/scope';
.withManifest(seqIncreasedManifest) .withManifest(seqIncreasedManifest)
.build(); .build();
const scope = new SwTestHarnessBuilder().withServerState(server).build();
describe('data cache', () => { describe('data cache', () => {
let scope: SwTestHarness; let scope: SwTestHarness;
@ -242,28 +240,16 @@ import {SwTestHarness, SwTestHarnessBuilder} from '../testing/scope';
}); });
})(); })();
async function makeRequest(scope: SwTestHarness, url: string, clientId?: string): function makeRequest(scope: SwTestHarness, url: string, clientId?: string): Promise<string|null> {
Promise<string|null> { const [resTextPromise, done] = makePendingRequest(scope, url, clientId);
const [resPromise, done] = scope.handleFetch(new MockRequest(url), clientId || 'default'); return done.then(() => resTextPromise);
await done; }
const res = await resPromise;
if (res !== undefined) {
return res.text();
}
return null;
}
function makePendingRequest(scope: SwTestHarness, url: string, clientId?: string): function makePendingRequest(
[Promise<string|null>, Promise<void>] { scope: SwTestHarness, url: string, clientId?: string): [Promise<string|null>, Promise<void>] {
const [resPromise, done] = scope.handleFetch(new MockRequest(url), clientId || 'default'); const [resPromise, done] = scope.handleFetch(new MockRequest(url), clientId || 'default');
return [ return [
(async() => { resPromise.then<string|null>(res => res ? res.text() : null),
const res = await resPromise; done,
if (res !== undefined) { ];
return res.text(); }
}
return null;
})(),
done
];
}