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

@bemedev/app-vitest

v2.0.0

Published

Test helpers for @bemedev/app

Readme

@bemedev/app-vitest

Declarative test sequence generator for @bemedev/app state machines inside Vitest.

@bemedev/app-vitest allows you to write state machine integration tests as a list of sequentially run, declarative test assertions, removing the boilerplate of manual await-tick-assert cycles.

Installation

npm install @bemedev/app-vitest --save-dev
# or
pnpm add @bemedev/app-vitest -D

Requirements: Node.js ≥ 24 · @bemedev/app ≥ 2.0.0 · Vitest ≥ 4.0.0

Quick Start

import { interpret } from '@bemedev/app';
import { constructTests } from '@bemedev/app-vitest';
import { describe, test, vi } from 'vitest';
import { myMachine } from './my.machine';

describe('My Machine Integration', () => {
  const service = interpret(myMachine, { context: { count: 0 } });

  // 1. Initialize the declarative helpers
  const { start, useStateValue, send, stop } = constructTests(service);

  // 2. Define sequence tests by spreading the generated tuples
  test(...start());
  test(...useStateValue('idle'));
  test(...send('INCREMENT'));
  test(...useStateValue('active'));
  test(...stop());
});

API Reference

constructTests( service, helper?, startIndex?)

| Parameter | Type | Description | | ------------ | ------------- | --------------------------------------------------------------------------------------------- | | vi | VitestUtils | The Vitest vi utility object (required for fake timer management). | | service | Interpreter | The interpreter service instance under test (Sync or Async). | | helper | Function | Optional callback to define custom helpers (e.g. context assertions or custom event senders). | | startIndex | number | Optional starting sequence index (defaults to 0). |

Returns an object containing built-in assertions and any custom helpers returned by the helper callback.

Built-in Assertion Helpers

Every function returns a TestArr (tuple of [inviteString, testCallback]) designed to be spread directly into Vitest's test(...) function:

  • start(index?): Starts the service and awaits initial task settlement.
  • stop(index?): Stops the service cleanly.
  • dispose(index?): Alias for stop(index?).
  • pause(index?): Pauses the interpreter service activities and timers.
  • resume(index?): Resumes the interpreter service.
  • send(event, index?): Sends an event to the service and awaits transition settlement.
  • useStateValue(value, index?): Asserts that the current active state value matches value.
  • useTags(...tags): Asserts that the current state carries the specified active tags.
  • useWarnings(...warnings): Asserts that the service has logged the specified warning messages in its warning collector.
  • useErrors(...errors): Asserts that the service has logged the specified error messages in its error collector.
  • changeIndex(fn): Modifies the running test sequence index dynamically.
  • unhandledRejection(testFn, error, timeout?): Asserts that running testFn rejects with the expected error message (setup for unhandledRejection and uncaughtException).

Custom Option Helpers

The third argument helper receives a configuration object exposing helper factories to create customized, type-safe assertions:

const { wait, sendFetch, checkCount } = constructTests(
  vi,
  service,
  ({ waiter, sender, contexts, service }) => ({
    // 1. A custom delay helper (automatically advances fake timers if active)
    wait: waiter(500),

    // 2. A strongly-typed event sender
    sendFetch: sender('FETCH'),

    // 3. A custom context selector assertion
    checkCount: contexts(({ context }) => context.count, 'count'),
  }),
);

Helper Factories:

  • service: The underlying interpreter service instance (Sync or Async) under test.
  • waiter(defaultDelay?): Returns a function to wait for a delay in milliseconds. If Vitest fake timers are active, it automatically advances them using vi.advanceTimersByTimeAsync().
  • sender(eventType): Returns a function to send a specific event type with its payload arguments.
  • contexts(selector?, name?): Returns a function asserting that the resolved value from the selector matches the expected value.

Advanced Example (with Fake Timers)

import { interpret } from '@bemedev/app';
import { constructTests } from '@bemedev/app-vitest';
import { describe, test, vi, afterAll } from 'vitest';
import { timerMachine } from './timer.machine';

vi.useFakeTimers();

describe('Timer Machine tests', () => {
  const service = interpret(timerMachine, { context: { duration: 1000 } });

  const { start, useStateValue, wait, send } = constructTests(
    service,
    ({ waiter }) => ({ waitSecond: waiter(1000) }),
  );

  test(...start());
  test(...useStateValue('idle'));
  test(...send('START'));
  test(...useStateValue('running'));

  // Automatically advances Vitest fake timers by 1000ms
  test(...waitSecond());
  test(...useStateValue('completed'));
});

afterAll(() => vi.useRealTimers());

License

MIT