Factories are used to define a blueprint of a data structure and then using that blueprint to generate dummy data. You can create a Factory using our generator with the command bun g
and selecting the factory option. Let’s check out this example.
First, we’ll use the command bun g
, select the factory option and name ContentCreator, and the file will be generated in /app/database/factories/ContentCreatorFactory.ts
. Inside the ContentCreatorFactory file, we’ll set the properties like this.
import { Factory } from "@hefestos/core";
import { ContentCreator } from "..";
export default new Factory().define(ContentCreator, (faker) => {
return {
name: faker.person.fullName(),
biography: faker.lorem.sentence(4),
};
});
The factories uses the @faker-js library. For more references about @faker-js, access the official documentation at https://fakerjs.dev/