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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hexatool/fixtures

v1.0.11

Published

Easily create and maintain test fixtures in the file system

Downloads

10

Readme

Installation

npm install --save-dev @hexatool/fixtures

Using yarn

yarn add @hexatool/fixtures -dev

What it does

  • Place fixtures in any parent directory
  • Find them again in your tests by their name
  • Searches up the file system to find a match
  • Makes it easy to move fixtures around and share between tests
  • Copy them into a temporary directory
  • Automatically cleanup any temporary files created

API

import fixtures from '@hexatool/fixtures';

fixtures(dirname, opts)

Create fixture functions for the current file.

const f = fixtures(__dirname);

f.find(basename)

Find and return the path to a fixture by its basename (directory or filename including file extension).

const dirname = f.find('directory');
const filename = f.find('file.txt');
f.find('file'); // Error, not found!

f.copy(basename)

Copy a fixture into a temporary directory by its basename.

const tempDir = f.copy('directory');
const tempFile = f.copy('file.txt');

f.temp()

Create an empty temporary directory.

const tempDir = f.temp();

f.cleanup()

Deletes any temporary files you created. This will automatically be called when the Node process closes.

opts.glob

Which files to match against when searching up the file system.

Default: {fixtures,__fixtures__}/*

const f = fixtures(__dirname, { glob: 'mocks/*.json' });

opts.cleanup

Automatically cleanup temporary files created

Default: true

const f = fixtures(__dirname, { cleanup: false });

opts.root

Set the parent directory to stop searching for fixtures.

Default: "/"

How to use

  1. Giving this workspace
    project
    └───src
        └───fixtures
        │   └───examples/...
        │       samples.txt
        └───nested
            └───fixtures
                    data.json
                index.spec.ts
  2. You can use it with your favourite testing library
    // src/nested/index.spec.ts
      
    import { describe, expect, it, vi } from 'vitest';
    import fixtures from '@hexatool/fixtures';
    const f = fixtures(__dirname);
       
    test('finding a fixture', t => {
         const filePath = f.find('samples.txt');
         // "/project/src/fixtures/samples.txt"
    });
       
    test('copying a file', t => {
         const tmpPath = f.copy('data.json'); //
         // "/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/a9fb0decd08179eb6cf4691568aa2018/data.json"
         // (from /project/src/nested/fixtures/samples.txt)
    });
       
    test('copying a directory', t => {
         const tmpPath = f.copy('examples');
         // "/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd/examples"
         // (from /project/src/fixtures/examples)
    });

Hexatool Code Quality Standards

Publishing this package we are committing ourselves to the following code quality standards:

  • Respect Semantic Versioning: No breaking changes in patch or minor versions
  • No surprises in transitive dependencies: Use the bare minimum dependencies needed to meet the purpose
  • One specific purpose to meet without having to carry a bunch of unnecessary other utilities
  • Tests as documentation and usage examples
  • Well documented ReadMe showing how to install and use
  • License favoring Open Source and collaboration