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

vitest-temporary-fixture

v1.2.0

Published

Create temporary directories and fixtures on the fly for Vitest tests.

Readme

vitest-temporary-fixture

License: MIT Coverage Status

Utilities for creating temporary directories and fixtures in Vitest tests that are exposed of after the test has finished.

Easily create, use, and clean up temporary files and directories during test runs. Supports both synchronous and asynchronous APIs for flexible test setups.

The temporary directories and fixtures are created in the user's TEMP folder.

Features

  • Create and manage temporary directories for tests
  • Define fixtures for use in Vitest test suites
  • Async and sync APIs for flexibility
  • Simple integration with Vitest

Getting Started

import { FixtureAsync, testDirAsync } from 'vitest-temporary-fixture';

const dir = await testDirAsync({
  // Objects are subdirectories
  packages: {
    pkg: {
      'package.json': '{}',
    },
  },

  // Strings or Buffers are files
  'package-lock.json': '{}',
  'package.json': JSON.stringify({
    private: true,
    workspaces: ['packages/*'],
  }),

  // to create links or symlinks, use the `Fixture` class
  symlink: new FixtureAsync('symlink', 'packages'),
});

NOTE: Relative and Symbolic links are supported but one is not allowed to point to something outside the created directory. This is a security consideration.

Synchronous Example

import fs from 'node:fs';
import path from 'node:path';
import { describe, expect, it } from 'vitest';
import { testDir } from 'vitest-temporary-fixture';

describe('Vitest Temporary Fixture (sync)', () => {
  it('can create a directory with a text file', () => {
    /* ARRANGE */
    const dir = testDir({
      'regular-file.txt': '# content',
    });

    /* ASSERT */
    expect(fs.lstatSync(dir).isDirectory()).toBe(true);
    expect(fs.readFileSync(path.join(dir, 'regular-file.txt'), 'utf8')).toBe(
      '# content',
    );
  });

  it('can create a complete folder structure', () => {
    /*
     * For debugging, one can set 'keepFixture' to `true`.
     * The temporary folder is created in the user's `temp` folder starting with
     * `vitest_<random string>`.
     */
    // testFixtures.keepFixture = true;

    /* ARRANGE */
    const dir = testDir({
      src: {
        'index.ts', 'console.log("Hello World");'
      },
      'package.json': JSON.stringify({
        name: 'my-package',
        version: '0.1.0',
      })
    });

    // console.log(`temp dir path: ${dir}`);

    /* ASSERT */
    expect(fs.lstatSync(dir).isDirectory()).toBe(true);
    expect(fs.lstatSync(path.join(dir, 'src')).isDirectory()).toBe(true);
    expect(fs.readFileSync(path.join(dir, 'src', 'index.ts'), 'utf8')).toBe(
      'console.log("Hello World");',
    );
    expect(fs.readFileSync(path.join(dir, 'package.json'), 'utf8')).toBe(
      {
        name: 'my-package',
        version: '0.1.0',
      }
    );
  });
});

Asynchronous Example

import fsPromises from 'node:fs/promises';
import path from 'node:path';
import { describe, expect, it } from 'vitest';
import { testDirAsync, testFixturesAsync } from 'vitest-temporary-fixture';

describe('Vitest Temporary Fixture (async)', () => {
  it('can create a directory with a text file', async () => {
    /* ARRANGE */
    expect.assertions(2);

    /*
     * For debugging, one can set 'keepFixture' to `true`.
     * The temporary folder is created in the user's `temp` folder starting with
     * `vitest_<random string>`.
     */
    // testFixturesAsync.keepFixture = true;

    const dir = await testDirAsync({
      'regular-file.txt': '# content',
    });

    /* ASSERT */
    await expect(
      fsPromises.lstat(dir).then((result) => result.isDirectory()),
    ).resolves.toBe(true);

    await expect(
      fsPromises.readFile(path.join(dir, 'regular-file.txt'), 'utf8'),
    ).resolves.toBe('# content');
  });
});

API Overview

  • Fixture – Synchronous fixture helper
  • FixtureAsync – Asynchronous fixture helper
  • testDir – Synchronously create and use a temporary directory in a test
  • testDirAsync – Asynchronously create and use a temporary directory in a test
  • testFixtures – Synchronously manage multiple temporary fixtures
  • testFixturesAsync – Asynchronously manage multiple temporary fixtures

See the source files in src/ for detailed API documentation and more examples.

Compatibility

  • Vitest: v1.x or later
  • Node.js: v18 or later recommended

License

MIT License © Johan Meester