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

@hemilabs/anvil-fork-setup

v1.0.1

Published

Vitest globalSetup factory for testing with Anvil forks

Downloads

61

Readme

@hemilabs/anvil-fork-setup

NPM version Package size Follow Hemi on X

A Vitest globalSetup factory that starts an Anvil fork before your tests and stops it after. If Foundry is not installed, it will be installed automatically.

Install

npm add -D @hemilabs/anvil-fork-setup

Setup

1. Create a globalSetup file

// test/e2e/setup.ts
import { anvilFork } from "@hemilabs/anvil-fork-setup";

export default anvilFork({
  chainId: 43111,
  forkUrl: "https://rpc.hemi.network/rpc",
});

2. Add it to your Vitest config

// vitest.config.ts
import { defineConfig } from "vitest/config";

export default defineConfig({
  test: {
    globalSetup: ["test/e2e/setup.ts"],
    testTimeout: 30_000, // RPC calls can be slow
  },
});

3. Enable types for inject

Create a type declaration file and include it in your tsconfig.json:

// test/e2e/env.d.ts
/// <reference types="@hemilabs/anvil-fork-setup" />
// tsconfig.json
{
  "include": ["src/**/*.ts", "test/e2e/env.d.ts"],
}

This makes inject("anvilUrl") type-safe in your test files.

Usage

The Anvil fork URL is available in tests via Vitest's inject:

import { inject } from "vitest";

const anvilUrl = inject("anvilUrl");

Example: E2E tests with viem

Reading from the fork

// test/e2e/public.test.ts
import { createTestClient, erc20Abi, http } from "viem";
import { readContract } from "viem/actions";
import { hemi } from "viem/chains";
import { describe, expect, inject, it } from "vitest";

// ERC-20 token address
const tokenAddress = "0x99e3dE3817F6081B2568208337ef83295b7f591D";

describe("public actions e2e", function () {
  it("should read the token name", async function () {
    const client = createTestClient({
      chain: hemi,
      mode: "anvil",
      transport: http(inject("anvilUrl")),
    });

    const name = await readContract(client, {
      address: tokenAddress,
      abi: erc20Abi,
      functionName: "name",
    });

    expect(typeof name).toBe("string");
  });
});

Writing to the fork

Use inject("anvilUrl") as the transport URL and Anvil's default test mnemonic for accounts:

// test/e2e/wallet.test.ts
import { createTestClient, erc20Abi, http } from "viem";
import { mnemonicToAccount } from "viem/accounts";
import {
  readContract,
  waitForTransactionReceipt,
  writeContract,
} from "viem/actions";
import { hemi } from "viem/chains";
import { describe, expect, inject, it } from "vitest";

const tokenAddress = "0x99e3dE3817F6081B2568208337ef83295b7f591D";
const anvilMnemonic =
  "test test test test test test test test test test test junk";

const account = mnemonicToAccount(anvilMnemonic, { addressIndex: 0 });
const spender = mnemonicToAccount(anvilMnemonic, { addressIndex: 1 });

describe("wallet actions e2e", function () {
  it("should approve and verify allowance", async function () {
    const client = createTestClient({
      account,
      chain: hemi,
      mode: "anvil",
      transport: http(inject("anvilUrl")),
    });

    // Send an approve transaction
    const hash = await writeContract(client, {
      address: tokenAddress,
      abi: erc20Abi,
      functionName: "approve",
      args: [spender.address, 1000n],
    });

    expect(hash).toMatch(/^0x[0-9a-f]{64}$/i);

    // Wait for the receipt and verify
    const receipt = await waitForTransactionReceipt(client, { hash });
    expect(receipt.status).toBe("success");

    // Check the allowance matches the approved amount
    const result = await readContract(client, {
      address: tokenAddress,
      abi: erc20Abi,
      functionName: "allowance",
      args: [account.address, spender.address],
    });
    expect(result).toBe(1000n);
  });
});

Conditional E2E execution

You may want to skip E2E tests locally and only run them in CI. One approach is to gate the globalSetup and test inclusion on an environment variable:

// vitest.config.ts
import { defineConfig } from "vitest/config";

const isCI = process.env.CI === "true";

export default defineConfig({
  test: {
    clearMocks: true,
    ...(isCI
      ? { globalSetup: ["test/e2e/setup.ts"], testTimeout: 30_000 }
      : { exclude: ["test/e2e/**", "node_modules/**"] }),
  },
});

This way npm test runs only unit tests locally, while CI (which sets CI=true) includes E2E tests with the Anvil fork. You can add a convenience script for running E2E locally:

{
  "scripts": {
    "test": "vitest run",
    "test:e2e": "CI=true vitest run"
  }
}

Options

| Option | Type | Required | Default | Description | | --------- | -------- | -------- | ------- | --------------------------- | | chainId | number | Yes | — | Chain ID for the Anvil fork | | forkUrl | string | Yes | — | RPC URL to fork from | | port | number | No | 8545 | Port for the Anvil instance |

License

MIT