service-worker-mock
Advanced tools
Comparing version 1.2.4 to 1.3.0
65
index.js
@@ -9,37 +9,46 @@ const url = require('url'); | ||
module.exports = function makeServiceWorkerEnv() { | ||
const env = { | ||
listeners: {}, | ||
location: { origin: '/' }, | ||
skipWaiting: () => Promise.resolve(), | ||
caches: new CacheStorage(), | ||
clients: new Clients(), | ||
registration: new ServiceWorkerRegistration(), | ||
addEventListener: function (name, callback) { | ||
if (!env.listeners[name]) { | ||
env.listeners[name] = []; | ||
class ServiceWorkerGlobalScope { | ||
constructor() { | ||
this.listeners = {}; | ||
this.location = { origin: '/' }; | ||
this.skipWaiting = () => Promise.resolve(); | ||
this.caches = new CacheStorage(); | ||
this.clients = new Clients(); | ||
this.registration = new ServiceWorkerRegistration(); | ||
this.Request = Request; | ||
this.Response = Response; | ||
this.URL = url.URL || url.parse; | ||
this.ServiceWorkerGlobalScope = ServiceWorkerGlobalScope; | ||
// Instance variable to avoid issues with `this` | ||
this.addEventListener = (name, callback) => { | ||
if (!this.listeners[name]) { | ||
this.listeners[name] = []; | ||
} | ||
env.listeners[name].push(callback); | ||
}, | ||
trigger: function (name, args) { | ||
if (env.listeners[name]) { | ||
return handleEvents(name, args, env.listeners[name]); | ||
this.listeners[name].push(callback); | ||
}; | ||
// Instance variable to avoid issues with `this` | ||
this.trigger = (name, args) => { | ||
if (this.listeners[name]) { | ||
return handleEvents(name, args, this.listeners[name]); | ||
} | ||
return Promise.resolve(); | ||
}, | ||
snapshot: function () { | ||
}; | ||
// Instance variable to avoid issues with `this` | ||
this.snapshot = () => { | ||
return { | ||
caches: env.caches.snapshot(), | ||
clients: env.clients.snapshot(), | ||
notifications: env.registration.snapshot() | ||
caches: this.caches.snapshot(), | ||
clients: this.clients.snapshot(), | ||
notifications: this.registration.snapshot() | ||
}; | ||
}, | ||
Request: Request, | ||
Response: Response, | ||
URL: url.URL || url.parse | ||
}; | ||
}; | ||
env.self = env; | ||
this.self = this; | ||
} | ||
} | ||
return env; | ||
module.exports = function makeServiceWorkerEnv() { | ||
return new ServiceWorkerGlobalScope(); | ||
}; |
{ | ||
"name": "service-worker-mock", | ||
"version": "1.2.4", | ||
"version": "1.3.0", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16505
422