How to Use window.crypto in Node.js
I've been writing a bunch of jest tests recently for libraries that use the underlying window.crypto
methods like getRandomValues()
and window.crypto.subtle
key management methods. One problem I run into is that the window.crypto
object isn't available, so I need to shim it.
To use the window.crypto
methods, you will need Node 15+. You can set the window.crypto
by importing the crypto
package and setting it on the global:
const crypto = require('crypto').webcrypto;
// Shims the crypto property onto global
global.crypto = crypto;
I really loathe creating mock functions for missing libraries in Node because they can lead to faulty positives on tests; I really appreciate webcrypto
being available!
![Responsive Images: The Ultimate Guide]()
Chances are that any Web designers using our Ghostlab browser testing app, which allows seamless testing across all devices simultaneously, will have worked with responsive design in some shape or form. And as today's websites and devices become ever more varied, a plethora of responsive images...
![CSS Animations Between Media Queries]()
CSS animations are right up there with sliced bread. CSS animations are efficient because they can be hardware accelerated, they require no JavaScript overhead, and they are composed of very little CSS code. Quite often we add CSS transforms to elements via CSS during...
![Create a CSS Cube]()
CSS cubes really showcase what CSS has become over the years, evolving from simple color and dimension directives to a language capable of creating deep, creative visuals. Add animation and you've got something really neat. Unfortunately each CSS cube tutorial I've read is a bit...
![CSS Vertical Center with Flexbox]()
I'm 31 years old and feel like I've been in the web development game for centuries. We knew forever that layouts in CSS were a nightmare and we all considered flexbox our savior. Whether it turns out that way remains to be seen but flexbox does easily...