feat(testing): add serviceWorker tests

This commit is contained in:
Joe Previte
2021-02-18 14:35:41 -07:00
parent ee0973c05a
commit 6b56e6572d
7 changed files with 108 additions and 6 deletions

View File

@@ -0,0 +1,15 @@
--- node_modules/service-worker-mock/fetch.js 2021-02-18 13:47:55.000000000 -0700
+++ patches/service-worker-mock-fixed.js 2021-02-18 15:49:47.000000000 -0700
@@ -1,8 +1,11 @@
module.exports = async (request) => {
+ const Response = require('./models/Response');
const response = new Response('Response from service-worker-mock/fetch.js', {
status: 200,
statusText: 'ok.'
});
- response.url = request.url;
+ if (request && request.url) {
+ response.url = request.url;
+ }
return response;
};

View File

@@ -0,0 +1,9 @@
--- node_modules/service-worker-mock/models/Response.js 2021-02-18 13:47:55.000000000 -0700
+++ patches/service-worker-mock-response.js 2021-02-18 15:57:12.000000000 -0700
@@ -1,5 +1,6 @@
// stubs https://developer.mozilla.org/en-US/docs/Web/API/Response
const Body = require('./Body');
+const Blob = require('./Blob');
const Headers = require('./Headers');
const isSupportedBodyType = (body) =>

View File

@@ -0,0 +1,14 @@
--- node_modules/@types/service-worker-mock/index.d.ts 2021-02-18 13:51:50.000000000 -0700
+++ patches/service-workertypes.d.ts 2021-02-18 16:30:01.000000000 -0700
@@ -3,6 +3,11 @@
// Definitions by: Remco Haszing <https://github.com/remcohaszing>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
+// https://gist.github.com/shqld/32df51a4a4ed429f2c76e4e2cfdf6f96#gistcomment-2793376
+// excludes default libs such as 'dom' conflicting with 'webworker'
+/// <reference no-default-lib="true"/>
+/// <reference lib="esnext" />
+/// <reference lib="webworker" />
export = makeServiceWorkerEnv;
declare function makeServiceWorkerEnv(): WorkerGlobalScope;