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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@lynx-js/testing-environment

v0.1.8

Published

A subset of a Lynx environment to be useful for testing

Readme

@lynx-js/testing-environment

@lynx-js/testing-environment is a pure-JavaScript implementation of the Lynx Spec, notably the Element PAPI and Dual-threaded Model for use with Node.js. In general, the goal of the project is to emulate enough of a subset of a Lynx environment to be useful for testing.

The Element PAPI implementation is based on jsdom, for example __CreateElement will return a LynxElement, which extends HTMLElement from jsdom. You can reuse the testing utilities that are commonly used for DOM testing, such as @testing-library/dom (for DOM querying) and @testing-library/jest-dom (custom jest matchers for the DOM), etc.

Usage

import { LynxTestingEnv } from '@lynx-js/testing-environment';
import { JSDOM } from 'jsdom';

const lynxTestingEnv = new LynxTestingEnv(new JSDOM());

To use @lynx-js/testing-environment, you will primarily use the LynxTestingEnv constructor, which is a named export of the package. You will get back a LynxTestingEnv instance, which has a number of methods of useful properties, notably switchToMainThread and switchToBackgroundThread, which allow you to switch between the main thread and background thread.

Use the background thread API:

lynxTestingEnv.switchToBackgroundThread();
// use the background thread global object
globalThis.lynxCoreInject.tt.OnLifecycleEvent(...args);
// or directly use `lynxCoreInject` since it's already injected to `globalThis`
// lynxCoreInject.tt.OnLifecycleEvent(...args);

Use the main thread API:

lynxTestingEnv.switchToMainThread();
// use the main thread Element PAPI
const page = __CreatePage('0', 0);
const view = __CreateView(0);
__AppendElement(page, view);

Note that you can still access the other thread's globals without switching threads:

lynxTestingEnv.switchToMainThread();
// use the `backgroundThread` global object even though we're on the main thread
lynxTestingEnv.backgroundThread.tt.OnLifecycleEvent(...args);

Use in Vitest

It is recommended to configure as Vitest's test environment, for example:

// vitest.config.js
import { defineConfig } from 'vitest/config';

export default defineConfig({
  test: {
    environment: require.resolve(
      '@lynx-js/testing-environment/env/vitest',
    ),
  },
});

After configuration, you can directly access the lynxTestingEnv object globally in the test.

If you want to use @lynx-js/testing-environment for unit testing in ReactLynx, you usually don't need to specify this configuration manually.

Please refer to ReactLynx Testing Library to inherit the configuration from @lynx-js/react/testing-library.

Credits

Thanks to:

  • jsdom for the pure-JavaScript implementation of DOM API.