npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

jest-environment-webgl-node

v0.1.2

Published

Jest environment that provides real headless WebGL 1/2 (ANGLE via @onirenaud/node-webgl) in Node

Readme

jest-environment-webgl-node

Real, headless WebGL 1 and WebGL 2 inside Jest, with no browser. Powered by @onirenaud/node-webgl (Chrome's ANGLE, statically linked).

The environment installs window, document, HTMLCanvasElement, Image, requestAnimationFrame, the WebGL* classes and a file-reading fetch() on the test's sandbox global, and removes them after the test file finishes. document.createElement('canvas').getContext('webgl2') returns a GPU-backed context, so three.js, regl, pixi and plain WebGL code run unchanged.

Install

pnpm add -D jest jest-environment-webgl-node

Usage

// jest.config.mjs
export default {
  testEnvironment: 'jest-environment-webgl-node',
  testEnvironmentOptions: { backend: 'swiftshader', innerWidth: 800, innerHeight: 600 },
};
import * as THREE from 'three';
import { expect, it } from '@jest/globals';

it('renders', () => {
  const canvas = document.createElement('canvas');
  const renderer = new THREE.WebGLRenderer({ canvas });
  renderer.setSize(64, 64, false);
  renderer.render(new THREE.Scene(), new THREE.PerspectiveCamera());

  const gl = renderer.getContext();
  const pixels = new Uint8Array(4);
  gl.readPixels(32, 32, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
  expect(pixels[3]).toBe(255);
});

testEnvironmentOptions are those of node-webgl's init() (backend, api) and installDOM() (baseDir, fetch, devicePixelRatio, innerWidth, innerHeight, frameInterval). Each test file receives a fresh document, DOM event state, viewport values, file-fetch base directory and animation-frame queue. Animation frames use Jest's sandbox timers, so jest.useFakeTimers() and jest.advanceTimersByTime() control them; pending frames are cancelled during environment teardown.

File fetching is enabled by default. Relative paths resolve from that test file's baseDir (default: process.cwd()), while HTTP, data and blob URLs use Node's native fetch. Set fetch: false to use native fetch for every URL. The environment never replaces host globals.

The native WebGL display itself is process-wide and is created by the first context in a worker, so set backend and api consistently across all projects that can share a Jest worker. The environment throws if an explicit backend or api disagrees with the display already initialized in that worker, including one initialized with platform defaults by a project that set no options.

Types for the installed globals: add import 'jest-environment-webgl-node/globals'; to a .d.ts file your tsconfig includes.

This package ships both an ESM and a CommonJS build, so require('jest-environment-webgl-node') works from a plain CommonJS test file. NODE_OPTIONS=--experimental-vm-modules is only needed when a test file itself imports an ESM-only library.

On Linux CI install Mesa (apt-get install libegl1 libgles2 libgl1-mesa-dri) and set LIBGL_ALWAYS_SOFTWARE=1. macOS and Windows use prebuilt binaries.

Using Vitest?

The equivalent package for Vitest is vitest-environment-webgl-node from vitest-gpu.

Author

Created by Ben Houston and sponsored by Land of Assets.

License

MIT