5 NodeJS tools for fixture management

Lod LAWSON-BETUM
2 min readJan 29, 2020

--

Testing is a very important part of development. When testing a system you will eventually reach the point where the management of test fixtures becomes a requirement. There are no specified standards in NodeJs like in frameworks like Django or Ruby on Rails. In most case, you have to come up with your own solution.

This article covers some tools at your disposal. It discusses when they are relevant and their limitations.

Fixture with static files

A common standard is the use of static files such as JSON files to store mock data. This a pattern used by frameworks such as Ruby on Rails and Django.

Fixtures for MongoDB with node-mongodb-fixtures module (Tool #1)

The node-mongodb-fixtures package is a great package for fixtures management.

Features:

  • JSON files: Create a JSON file with the content to be seeded in the database. A single file is used per collection
  • Javascript files: If JSON files are limiting, javascript files can be used for more flexibility. Same as with JSON a single file is used per collection.
  • Create indexes: Index can be created with fixtures. One index files per collection. This is a great way to keep tests performance.

Another advantage to this package is the ability to create fixtures via CLI or programmatically.

Fixtures for relational databases with sql-fixtures (Tool #2)

The sql-fixture package is similar to the node-mongodb-fixture counterpart, but focuses on Relational databases.

Supported Databases:

  • Postgres
  • Mysql
  • MariaDB
  • sqlite3

Limitations of static fixture files

Static fixture files become cumbersome over time and are difficult to manage, especially when there are complex relationships between entities in your system.

A more flexible fixture API with Superseed (Tool #3)

Superseed takes a different approach to create mock data. There is a more abstract idea of fake data generated (mock data) and data storage (data source). Superseed works with the principle of a seed job. A seed job is required per entity. Each job requires the following

  • A mock data generator
  • A data source

Example usage below.

Event though Superseed solves the problem of managing complex seed generation, it still requires some work to implement the required mock generator and data source per entity. Luckily, Superseed comes with a list mock generator and data sources

Fakingoose (Tool #4)

Fakingoose is not a fixture generator. It a package that can be useful for mock data generation. It can be used with node-mongodb-fixtures. I wrote an article on how to use them together.

Tool #5, create your own fixture

There are times when a package would not solve your specific problem. It might even make the job harder. In those cases, it is best to use your own code. Please share your own implementation in the comment.

Even though there is no defined standard, there are still great tools at your disposal. In some case, you might need to write your own code to suit your specific needs.

Thank You.

--

--

Lod LAWSON-BETUM

In short, I am a Full Stack Developer that is learning every day and is enjoying every moment of it.