Comments (7)
Try this @eng-dibo :
`import webpush from 'web-push'
webpush.sendNotification(...)`
from web-push.
I migrated everything to ESM but have one problem with tests namely testSendNotification.js had before each
mocha.beforeEach(function () {
({ sendNotification, setGCMAPIKey, setVapidDetails } = require('../src/index'));
});
and then it deleted cache before each for clean start
mocha.beforeEach(function() {
requestBody = null;
requestDetails = null;
// Delete caches of web push libs to start clean between test runs
delete require.cache[path.join(__dirname, '..', 'src', 'index.js')];
delete require.cache[path.join(__dirname, '..', 'src', 'web-push-lib.js')];
How would you recommend me approaching this if we wnat to get rid of require to make it ESM?
from web-push.
I'm not sure to be honest, I'm not familiar enough with ESM.
from web-push.
What if we simply call setGCMAPIKey
and setVapidDetails
with null
as a way to reset the state?
from web-push.
I'd be happy to accept a PR if anybody wants to help. It sounds relatively easy to move to ESM (see https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-move-my-commonjs-project-to-esm).
from web-push.
Would you be ok with me adding clearCache method to web-push-lib.js and index.js that would clear all state for testing? I don't think there's other way around that
from web-push.
Maybe if #876 is done first, the need to reset state vanishes.
from web-push.
Related Issues (20)
- Add whitelist for valid browser push service hosts HOT 9
- iOS and Apple HOT 5
- Encoding issues while generating VAPID keys HOT 4
- Body not showing in push notification HOT 2
- package.json: change of node >= 6 to node >= 16 should be a minor version upgrade? HOT 1
- Validation error of protocol is never returned
- Is there a changelog somewhere? HOT 3
- Dependency urlsafe-base64 uses Buffer unsafely (via http-ece) HOT 8
- TypeError [ERR_UNKNOWN_ENCODING]: Unknown encoding: base64url HOT 2
- Notifications not always shown in MacOS Chrome HOT 1
- How to define target endpoint for notification HOT 1
- Add support for multiple WebPush instances HOT 2
- Calling fetch function for push notifications in service worker causes CORS error HOT 1
- Can webpush push be configured with images like new notification messages? HOT 1
- Unsubscribed due to error DELIVERY_PERMISSION_DENIED
- FCM legacy api shutdown HOT 1
- Will the code still work when FCM API is removed in Jun-2024? HOT 2
- util.inherits is not a function
- [Feature Request] Add Image Support
- Deno Support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from web-push.