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

@cronn/element-snapshot

v0.11.0

Published

Element snapshots for Playwright

Readme

Element Snapshots

Element Snapshots are a custom snapshot implementation inspired by Playwright's ARIA Snapshots and the Accessibility Object Model. They cover additional properties, e.g. validation attributes like required or invalid on form inputs, and are optimized to be serialized as JSON.

Element Snapshots are designed to be used in combination with playwright-file-snapshots for writing Playwright tests.

[!NOTE] Element Snapshots are currently experimental. Not all HTML elements, ARIA roles and attributes are covered. Breaking changes to the snapshot format are possible.

Getting Started

Adding the library to your project

npm install -D @cronn/element-snapshot
yarn add -D @cronn/element-snapshot
pnpm add -D @cronn/element-snapshot

Writing Tests

General-Purpose Snapshots

The function snapshotElement provides a general-purpose snapshot including all supported roles and attributes. It can be used to achieve a high test coverage, but can become hard to read for complex HTML structures.

import { snapshotElement } from "@cronn/element-snapshot";
import { defineValidationFileExpect } from "@cronn/playwright-file-snapshots";

const expect = defineValidationFileExpect();

test("matches element snapshot", async ({ page }) => {
  await expect(snapshotElement(page.getByRole("main"))).toMatchJsonFile();
});

Element Snapshot Example:

{
  "main": [
    {
      "heading": {
        "name": "List",
        "level": 1
      }
    },
    {
      "list": [
        {
          "listitem": "Apple"
        },
        {
          "listitem": "Peach"
        }
      ]
    }
  ]
}

To improve the specificity of certain tests, snapshotElement can be called on certain areas of the page only:

test("matches navigation snapshot", async ({ page }) => {
  await expect(snapshotElement(page.getByRole("navigation"))).toMatchJsonFile({
    name: "navigation",
  });
});

Snapshot Options

Snapshot options can be passed when calling the snapshot function:

await expect(
  snapshotElement(page.getByLabel("My select"), {
    filter: (element) => element.role === "heading",
  }),
).toMatchJsonFile({
  name: "headings",
});

| Option | Default Value | Description | | ------------------------ | ------------- | ------------------------------------------------------------------------------------ | | filter | () => true | Include only elements in the snapshot for which the specified filter returns true. | | includeComboboxOptions | false | Include combobox options in the snapshot. |

Custom Snapshots

The function snapshotElementRaw provides the raw element snapshot in a strictly typed structure. This format is not well suited to be read by humans, but can be utilized to derive custom snapshot formats, e.g. for HTML tables.

import { snapshotElementRaw } from "@cronn/element-snapshot";

test("matches custom snapshot", async ({ page }) => {
  const tableSnapshot = await snapshotElementRaw(page.getByRole("table"));
  const markdownTable = transformToMarkdownTable(tableSnapshot);

  await expect(markdownTable).toMatchTextFile({ fileExtension: "md" });
});

function transformToMarkdownTable(snapshot: Array<NodeSnapshot>): string {
  // transform table snapshot to markdown table
}