fixture-riveter is a fixtures replacement library based on thoughtbot's excellent ruby library factory_bot, with some ideas adapted from factory-girl, another javascript library inspired by factory_bot. It's written in Typescript, is fully async, and implements nearly all of factory_bot's features.
It was built for a knex/objection.js codebase and thus the integration with that ORM is the best. It has support for other ORMs through the use of adapters, but some of the features don't work as well or at all with them.
Node.js:
npm install --save-dev fixture-riveter
A complete guide to using fixture-riveter can be found in the guide. For those interested in code first, here is a simple demonstration:
import {fr, ObjectionAdapter} from "fixture-riveter";
fr.setAdapter(new ObjectionAdapter());
fr.fixture(User, (f) => {
f.name(() => "Noah");
f.age(() => 32);
f.sequence("email", (n) => `test${n}@example.com`);
});
const user = await fr.create(User, {name: "Bogart"});
expect(user).to.be.an.instanceof(User);
expect(user.id).to.exist;
expect(user.name).to.equal("Bogart");
expect(user.age).to.equal(32);
expect(user.email).to.equal("[email protected]");
As this is a very young library, there will be plenty of places it could be improved. No PR is too small, no issue is too weird or out of bounds. Please adhere to our Code of Conduct when participating with this project.
Copyright © 2021 Noah Bogart and Batterii, distributed under the license in LICENSE.