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 🙏

© 2024 – Pkg Stats / Ryan Hefner

bun-match-svg

v0.0.8

Published

A custom matcher for Bun tests to compare SVG snapshots.

Downloads

3,937

Readme

bun-match-svg

A custom matcher for Bun tests to compare SVG snapshots.

Quick Start

The fastest way to get started is to use the CLI to initialize your project:

bunx bun-match-svg init

This will:

  1. Create an example test in tests/svg.test.ts
  2. Set up automatic preloading by creating:
    • tests/fixtures/preload.ts
    • bunfig.toml

You can then run the example test:

bun test

Installation

bun add -D bun-match-svg

Usage

Basic Usage

Import the library in your test file:

import "bun-match-svg"

test("your SVG test", () => {
  const svgContent = generateSomeSvg() // Your function to generate SVG
  expect(svgContent).toMatchSvgSnapshot(import.meta.path, "uniqueName")
})

The toMatchSvgSnapshot matcher takes two arguments:

  1. import.meta.path: The path of the current test file.
  2. uniqueName (optional): A unique name for the snapshot. If not provided, it will use the test file name.

Automatically Preload

To make toMatchSvgSnapshot available in all your test files without importing it in each one:

  1. Create a file tests/fixtures/preload.ts with the following content:
import "bun-match-svg"
  1. Define a bunfig.toml file in your project root with:
[test]
preload = ["./tests/fixtures/preload.ts"]

Now toMatchSvgSnapshot will be automatically available in every test file.

How It Works

  • On first run, it creates a snapshot of your SVG.
  • On subsequent runs, it compares the current SVG with the snapshot.
  • If differences are found, it generates a diff image.

Updating Snapshots

To update existing snapshots, run your tests with:

bun test --update-snapshots

Or set the environment variable:

BUN_UPDATE_SNAPSHOTS=1 bun test

Configuration

The matcher uses looks-same for comparison with these default settings:

  • strict: false
  • tolerance: 2

There currently isn't a way to configure this, but PRs welcome!

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is open source and available under the MIT License.