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

@tracegraph/vitest

v0.3.1

Published

TraceGraph reporter for Vitest — captures test structure and results as structured traces

Readme

@tracegraph/vitest

TraceGraph reporter and test utilities for Vitest. Produces per-test .trace.json files (capture level 5), giving full test-lifecycle isolation so every test case has its own trace. Also exports traceTest() for asserting on runtime behaviour directly inside Vitest tests.

What's in this package

| Export | Description | |--------|-------------| | TraceGraphReporter | Vitest reporter class — attaches to Vitest's lifecycle hooks to write one trace per test | | traceTest(name, fn) | Wraps a Vitest test with a trace context and exposes trace.expectBehavior() for behavioural assertions | | makeTraceAssertions(traceId) | Returns a TraceAssertions object for a specific trace ID — useful for custom test helpers | | TraceAssertions | Interface exposing mustCall, mustNotCall, and expectBehavior | | ExpectBehaviorOptions | { mustCall?, mustNotCall? } |

Installation

npm install -D @tracegraph/vitest vitest

Usage

1. Add the reporter to vitest.config.ts

import { defineConfig } from 'vitest/config';
import { TraceGraphReporter } from '@tracegraph/vitest';

export default defineConfig({
  test: {
    reporters: ['verbose', new TraceGraphReporter()],
  },
});

Or let tracegraph run inject it automatically:

tracegraph run -- npx vitest run
# → "@tracegraph/vitest reporter auto-injected"

Each test run produces one .trace.json per test case in .tracegraph/traces/.

2. Behavioural assertions with traceTest

traceTest wraps a standard Vitest test. Inside the callback you get a trace object that lets you assert which functions were called at runtime.

import { describe, expect } from 'vitest';
import { traceTest } from '@tracegraph/vitest';
import { app } from '../src/app';
import request from 'supertest';

describe('InvoiceService', () => {
  traceTest('creates an invoice and validates tax', async (trace) => {
    const res = await request(app).post('/invoices').send({ amount: 100, region: 'US' });
    expect(res.status).toBe(201);

    trace.expectBehavior({
      mustCall:    ['InvoiceService.create', 'TaxService.calculate'],
      mustNotCall: ['InvoiceService.sendEmailDirect'],
    });
  });
});

The test fails if any mustCall function is absent from the trace, or if any mustNotCall function appears.

3. Via the reporter entry point

The default export allows Vitest to load the reporter via the short string form:

npx vitest --reporter=verbose --reporter=@tracegraph/vitest

What the reporter captures

Each test trace includes:

  • test_suite event — the describe block name and file
  • test_run event — the individual test name, pass/fail status, and duration
  • All events emitted by traceFunction / traceMethod / traceExpress during the test body
  • Error events on test failure, including the error type and message

Trace isolation

The reporter creates a fresh trace context for each test case. Events from concurrent tests (when using Vitest's parallel workers) are written to separate .tmp files and finalised independently, so traces never mix between tests.

Requirements

  • Vitest ≥ 1.0.0
  • @tracegraph/trace-js (optional peer — needed if using traceFunction / traceExpress within tests)
  • TRACEGRAPH_ENABLED=1 and TRACEGRAPH_RUN_DIR set in the environment (set automatically by tracegraph run)