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

dbfixtures

v2.1.0

Published

A NodeJS equivalent to DbUnit.

Readme

Build Status

Fixtures Manager

An abstraction layer for handling database fixtures for automated testing purposes, providing a standardized interface across different database systems.

Installation

npm install --save-dev dbfixtures

Features

  • Test runner agnostic
  • No dependencies
  • Written in TypeScript
  • Standardized interface across multiple database systems
  • Easily set your database for each test's needs

NodeJS versions

  • Package version >=2.1.* supports NodeJS v10 or higher.

  • Package version >=2.0.* supports NodeJS v8 or higher.

  • Package version >=1.1.* supports NodeJS v8 or higher.
    NOTE: For versions 8 and 9 the node flag --harmony_promise_finally is required

  • Package version 1.0.* supports NodeJS v7 or higher.

Drivers

This package will use drivers to handle the database operations. Each driver will be dedicated to 1 databse system (ex: MySQL, MongoDb).
You can set as many drivers as needed and the fixtures will be sent to each one.

Driver interface

The drivers are expected to use the following interface

// clears the specified "tables" from any content
truncate: (tableNames: string[]) => Promise<void>

// inserts the supplied "rows" into the specified "table"
insertFixtures: (tableName: string, fixtures: {}[]) => Promise<void>

// terminates the connection to the database
close: () => Promise<void>

Current official drivers

Usage

This package exposes 3 functions

  • setDrivers(...newDrivers: IDriver[]): void: call this function with the array of driver instances to be used when fixtures are inserted.

  • insertFixtures(fixtures: IFixtures): Promise<void>: call this function with the fixtures to be sent to each registered driver.
    Note: the fixtures will be inserted in the order they are provided.

  • closeDrivers(): Promise<void>: call this function to run any necessary cleanup operations on all registered drivers (ex: close DB connections).

The IDriver interface is described in the section Driver interface above.

The IFixtures interface is an object with strings as keys and arrays as values.
The keys are "table" names and for each one provide an array of objects, each representing a "row" to be inserted.

Example

This example uses Mocha as the potential test runner.

const dbfixtures = require('dbfixtures');
const fixturesMysqlDriver = require('dbfixtures-mysql-driver');

const mysqlConnectionInfo = {
  host: 'localhost',
  port: '3306',
  user: 'root',
  password: '',
  database: 'fixtures_test',
};
const fixtures = {
  'roles': [
    { id: 1, name: 'role 1' },
    { id: 2, name: 'role 2' },
  ],
  'users': [
    { id: 1, email: '[email protected]', role_id: 2 },
    { id: 2, email: '[email protected]', role_id: 1 },
    { id: 3, email: '[email protected]', role_id: 1 },
  ],
};

describe('fixtures example', function () {
  before(async function () {
    const mysqlDriver = await fixturesMysqlDriver.create(mysqlConnectionInfo);
    dbfixtures.setDrivers(mysqlDriver);
  });

  after(async function () {
    await dbfixtures.closeDrivers();
  });

  beforeEach(async function () {
    await dbfixtures.insertFixtures(fixtures);
  });

  it('should have the database seeded with the fixtures', function () {
    // ...
  });
});

How It Works

Each registered driver will be called to:

  • clear the "tables" that will be used in the current fixture insertion operation from any content.

  • insert the fixtures in the order they were provided.

  • terminate the connection to their database.

Testing This Package

  • cd into the package's directory

  • run npm install

  • run npm run build

  • for unit tests run npm test -- test/unit/