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

@ilamy/testoise

v0.2.0

Published

Lightweight and fully type-safe lazy test variables for Bun, Vitest, Jest, and Node.js. Inspired by RSpec.

Readme


The Problem

When writing tests with complex setups, we frequently declare let variables and re-assign them in beforeEach. This is repetitive and brittle.

// ❌ The standard (but annoying) way
import { describe, beforeEach, it } from "vitest";

describe("User", () => {
    let firstName: string;
    let fullName: string;

    beforeEach(() => {
        firstName = "John";
        fullName = `${firstName} Doe`;
    });

    describe("when first name changes", () => {
        beforeEach(() => {
            firstName = "Jane";
            fullName = `${firstName} Doe`; // Manual re-evaluation!
        });
        
        it("is updated", () => { /* ... */ });
    });
});

Our Solution: testoise

testoise is a modern, fully type-safe, and lightweight alternative to bdd-lazy-var. It brings the power and elegance of RSpec's let directly into JavaScript!

  1. Evaluates Lazily: Factory is only executed upon get().
  2. Caches Per Test: Return value is cached for the duration of a single it block.
  3. Overrides Cleanly: Nested blocks override parents; dependents react automatically.

Installation

bun add -d @ilamy/testoise # or npm install --save-dev @ilamy/testoise

Basic Usage

Import def, get, and optionally testoise from your test runner's specific adapter path:

  • Bun: import { def, get, testoise } from "@ilamy/testoise/bun"
  • Vitest: import { def, get, testoise } from "@ilamy/testoise/vitest"
  • Jest: import { def, get, testoise } from "@ilamy/testoise/jest"
  • Node.js: import { def, get, testoise } from "@ilamy/testoise/node"
import { describe, it } from "node:test"; 
import { def, get } from "@ilamy/testoise/node"; 

describe("User", () => {
    def("firstName", () => "John");
    def("lastName", () => "Doe");
    
    // 2. Variables can depend on other lazy variables!
    def("fullName", () => `${get("firstName")} ${get("lastName")}`);

    it("uses the default name", () => {
        // Manual type casting for those not using the suite wrapper
        expect(get<string>("fullName")).toBe("John Doe");
    });

    describe("when first name changes", () => {
        // 3. Overrides the "firstName" variable for this describe block only
        def("firstName", () => "Jane");

        it("automatically updates dependent variables", () => {
            expect(get<string>("fullName")).toBe("Jane Doe");
        });
    });
});

Automatic Type Inference

For strong type inference without manual casting, testoise provides a Suite Wrapper. This is the recommended way to use testoise in TypeScript projects.

import { expect, it } from "vitest";
import { testoise } from "@ilamy/testoise/vitest";

// 1. Define your registry
interface MyVars {
  user: { name: string; age: number };
  isAdmin: boolean;
}

// 2. Use the wrapper for automatic inference 🐢
testoise<MyVars>("User Suite", ({ def, get }) => {
  def("user", () => ({ name: "Alice", age: 30 }));
  def("isAdmin", () => get("user").age > 21);

  it("knows Alice is an adult", () => {
    const user = get("user"); // Automatically inferred!
    expect(get("isAdmin")).toBe(true);
  });

  // Now you can use standard describe or simplified testoise!
  describe("when user is underage", () => {
    def("user", () => ({ name: "Bob", age: 15 }));

    it("knows Bob is not an admin", () => {
      expect(get("isAdmin")).toBe(false);
    });
  });
});

[!TIP] The suite wrapper ensures that your variable names and types are always in sync, preventing runtime errors and providing a premium developer experience.


Examples

Explore our examples/ directory for practical, framework-specific setups:


Support Matrix

| Feature | Vitest | Bun | Jest | Node.js | | :--- | :---: | :---: | :---: | :---: | | Lazy Evaluation | ✅ | ✅ | ✅ | ✅ | | Context Nesting | ✅ | ✅ | ✅ | ✅ | | Automatic Inference | ✅ | ✅ | ✅ | ✅ | | Redefinition Protection | ✅ | ✅ | ✅ | ✅ | | React Support | ✅ | ✅ | ✅ | ✅ | | Vue Support | ✅ | ✅ | ✅ | ✅ |


API Reference

def(name: string, factory: () => T): string

Registers a variable.

get<T>(name: string): T

Evaluates and returns the factory result. Caches per test. Supports manual type casting: get<string>("name").

testoise<Registry>(name, suite): void

Suite wrapper for simplified type inference across a suite. Provides a typed api with its own def and get methods. Use standard describe blocks for nesting; type safety will be maintained throughout the scope.


License

MIT © Sujeet KC