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

@brain-bbqs/test-utils

v0.3.0

Published

Test helpers shared by the BBQS companion web apps: Playwright viewport and layout checks, sign-in and archive stubs, the Chromatic per-viewport pattern, and Vitest fixtures for index.html, fetch and storage.

Readme

@brain-bbqs/test-utils

The test scaffolding the BBQS companion apps each carried a copy of. Two entry points, so an app's unit tests never pull Playwright in:

import {
  VIEWPORTS,
  expectNoHorizontalOverflow,
  forEachViewport,
  seedSignedIn,
  seedTheme,
} from "@brain-bbqs/test-utils/playwright";
import { createMainHarness, expectIdContract, readIndexHtml, routeFetch } from "@brain-bbqs/test-utils/vitest";
npm install --save-dev @brain-bbqs/test-utils

Playwright

| Export | Was | | ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ | | VIEWPORTS, expectNoHorizontalOverflow | tests/integration/layout.ts (three identical copies) | | forEachViewport(test, title, body) | the for (const viewport of VIEWPORTS) loop in tests/chromatic/* | | seedSignedIn, stubIncomingDandisets, stubAdminCheck, stubDraftMetadata, stubIdentity | tests/integration/helpers/auth.ts and the archive half of helpers.ts | | seedTheme | tests/integration/helpers/theme.ts |

seedSignedIn takes the app's settings key rather than importing it, so the package does not depend on any app. The Chromatic pattern becomes:

import { test, expect } from "@chromatic-com/playwright";
import { expectNoHorizontalOverflow, forEachViewport } from "@brain-bbqs/test-utils/playwright";

forEachViewport(test, "Main page - default", async ({ page }) => {
  await page.goto("/");
  await expect(page.locator("h1")).toContainText("Clip Extractor");
  await expectNoHorizontalOverflow(page);
});

Vitest

| Export | Was | | ------------------------------------------------------------ | --------------------------------------------------------------------------------------- | | readIndexHtml, bodyOf, mountHtml | the top of every tests/unit/elements.test.ts | | jsonResponse, textResponse, routeFetch, offlineFetch | the jsonResponse/stubFetch helpers, and the "network disabled in tests" fetch stubs | | throwingStorage() | the Storage.prototype spies in settings.test.ts | | createMainHarness, el, fakeFile, pickFiles | bbqs-uploader's and the template's tests/unit/helpers/mainHarness.ts | | readIdContract, expectIdContract | the elements tests, now checked both ways | | installMatchMedia, installDialogPolyfill | the matchMedia stub and <dialog> stand-in in both harnesses | | installObserverStub, stubClipboard, installExecCommand | encoding-helper's fake Resize/IntersectionObservers and clipboard stubs | | installCanvasStub | nothing yet: the 2D context clip-extractor's main.ts needs to boot at all |

Each install*/stub* returns (or carries) a function putting back what was there, and none imports Vitest's vi: hand in a vi.fn where a test asserts on calls.

Booting main.ts

One test file per boot scenario, since a file's module registry runs main.ts's top-level wiring once. The app creates its harness once, in tests/unit/helpers/mainHarness.ts; the import stays in the app's own code so Vitest transforms it and the test file's vi.mock calls apply to it:

// tests/unit/helpers/mainHarness.ts
import { createMainHarness } from "@brain-bbqs/test-utils/vitest";

export const { bootMain } = createMainHarness({ importMain: () => import("../../../src/main") });
export { el } from "@brain-bbqs/test-utils/vitest";
// tests/unit/main.mock-file.test.ts
// @vitest-environment jsdom
beforeAll(async () => {
  await bootMain("?test&mock_file"); // or { url, localStorage, sessionStorage, fetch, matchMedia, beforeImport }
});

Creating the harness empties localStorage and sessionStorage and notes the environment's fetch, both while the test file is still importing, so whatever the file's own setup stores or stubs before bootMain() stays. bootMain then sets the URL, mounts index.html's body without its scripts, seeds the storage it is given, installs a fetch that fails every call (unless the test stubbed its own), a light-theme matchMedia and the <dialog> stand-in, and imports main.ts; it resolves to { module, fetch, canvas, observers }, and a second call throws. An app that draws or observes at boot creates the harness with canvas: true and observers: ["ResizeObserver"] (clip-extractor).

The id contract

// tests/unit/elements.test.ts
// @vitest-environment jsdom
it("index.html and the element lookups agree", () => {
  expectIdContract({ html: readIndexHtml(), lookups: [getShell, getElements] });
});

Every id a lookup requires must be in the page (the error names the lookup's own message), and every id in the page must be registered by a lookup, whether it asks getElementById for it or hands back an element carrying it. Ids the page points at itself (a label's for, aria-*, href="#id", url(#id)) count as registered; pageOnly exempts a styling hook. readIdContract returns the same findings without asserting, including which ids are required and which the lookups tolerate missing (optional).

The Playwright helpers are exercised in a real browser by tests/integration/ here; the Vitest helpers by tests/unit/.