{"id":27774271,"url":"https://github.com/thekeogh/factoryse","last_synced_at":"2026-04-28T12:01:19.832Z","repository":{"id":198688894,"uuid":"700915187","full_name":"thekeogh/factoryse","owner":"thekeogh","description":"Factoryse is a TypeScript-based test factory library that simplifies the creation of test data for your Node.js applications.","archived":false,"fork":false,"pushed_at":"2024-05-29T13:42:48.000Z","size":110,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-30T02:05:09.089Z","etag":null,"topics":["dummy","factory","faker","nodejs","testing","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thekeogh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-05T14:41:02.000Z","updated_at":"2024-05-29T13:41:50.000Z","dependencies_parsed_at":"2024-01-02T11:00:55.361Z","dependency_job_id":"696d07c0-f0e1-4088-8bc5-d175c3698389","html_url":"https://github.com/thekeogh/factoryse","commit_stats":null,"previous_names":["thekeogh/factoryse"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thekeogh%2Ffactoryse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thekeogh%2Ffactoryse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thekeogh%2Ffactoryse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thekeogh%2Ffactoryse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thekeogh","download_url":"https://codeload.github.com/thekeogh/factoryse/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251626895,"owners_count":21617743,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dummy","factory","faker","nodejs","testing","typescript"],"created_at":"2025-04-30T02:05:13.256Z","updated_at":"2026-04-28T12:01:14.793Z","avatar_url":"https://github.com/thekeogh.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Factoryse\n\n[![build](https://github.com/thekeogh/factoryse/actions/workflows/release.yml/badge.svg)](https://github.com/thekeogh/factoryse/actions) [![semantic-release: npm](https://img.shields.io/badge/semantic--release-npm-CB0000?logo=semantic-release)](https://github.com/semantic-release/semantic-release) [![node.js: \u003e=16.20.2](https://img.shields.io/badge/node.js-%3E=16.20.2-036E02?logo=node.js)](https://nodejs.org) \n\nFactoryse is a test factory library built with [TypeScript](https://www.typescriptlang.org/), designed to streamline the creation of test data for your [Node.js](https://nodejs.org/) applications. Craft and manage test objects effortlessly, optimising the efficiency of your testing workflow. This project draws inspiration from Ruby's renowned [Factory Bot](https://github.com/thoughtbot/factory_bot), bringing similar ease and consistency to the world of TypeScript and Node.js testing.\n\nFactoryse is designed to streamline the creation of test data, offering a simple and efficient approach to generate random (or deterministic, if preferred) data, thereby reducing redundancy in your testing setup.\n\nFactoryse is compatible with any modern testing suite, including [Vitest](https://vitest.dev/) and [Jest](https://jestjs.io/), without being tied to any specific one.\n\n## Install\n\n```shell\nnpm install --save-dev factoryse\n```\n\n## How to use\n\n### Defining a factory\n\nFirst, define your factory structure. This involves specifying the data model and creating the factory instance.\n\n```typescript\n// Define the User shape\ninterface User {\n  email: string;\n  createdAt?: Date;\n}\n\n// Create the user factory\nconst user = new Factory\u003cUser\u003e(faker =\u003e ({\n  email: faker.internet.email()\n}));\n```\n\n\u003e It's recommended to use [faker](https://fakerjs.dev/) during factory instantiation for generating diverse random data.\n\n### Generating entries\n\nGenerate a single entry:\n\n```typescript\nconst factory = user.make();\n// Generates: [{ email: \"Jo65@gmail.com\" }]\n```\n\nTo generate multiple entries:\n\n```typescript\nconst factory = user.make(2);\n// Generates: [{ email: \"Jo65@gmail.com\" }, { email: \"Alv38@hotmail.com\" }]\n```\n\n### Retrieving entries\n\nLeverage the `get()` action to access entries created by your Factory. Factoryse offers a variety of query methods to facilitate this retrieval process.\n\n```typescript\n// Retrieve all entries\nusers.get().all(); // User[]\n\n// Retrieve the first entry or the first (`n: number`) entries\nusers.get().first(); // User[]\nusers.get().first(n); // User[]\n\n// Retrieve the last entry or the last (`n: number`) entries\nusers.get().last(); // User[]\nusers.get().last(n); // User[]\n\n// Retrieve a random entry or multiple random (`n: number`) entries\nusers.get().any(); // User[]\nusers.get().any(n); // User[]\n\n// Retrieve a single entry by its index (`n: number`)\nusers.get().at(n); // User\n\n// Retrieve multiple entries by their index (`n: number[]`)\nusers.get().pick(n); // User[]\n\n// Retrieve multiple entries between indexes (`start: number, end: number`)\nusers.get().between(start, end); // User[]\n\n// Retrieve multiple entries by criteria (`c: Partial\u003cUser\u003e`)\nusers.get().by(c); // User[]\n```\n\n### Editing entries\n\nLeverage the `set(source)` action to edit entries in your Factory. Factoryse offers a variety of query methods to facilitate this editing process. Each method used for editing entries will return the modified entries. To retrieve the complete set of entries from the factory after making edits, refer to the `get()` action detailed in the [Retrieving Entries](#retrieving-entries) section.\n\n```typescript\n// Closure to apply modifications to entries\nconst source = faker =\u003e ({ createdAt: faker.date.recent() })\n\n// Update all entries\nusers.set(source).all(); // User[]\n\n// Update the first entry or the first (`n: number`) entries\nusers.set(source).first(); // User[]\nusers.set(source).first(n); // User[]\n\n// Update the last entry or the last (`n: number`) entries\nusers.set(source).last(); // User[]\nusers.set(source).last(n); // User[]\n\n// Update a random entry or multiple random (`n: number`) entries\nusers.set(source).any(); // User[]\nusers.set(source).any(n); // User[]\n\n// Update a single entry by its index (`n: number`)\nusers.set(source).at(n); // User\n\n// Update multiple entries by their index (`n: number[]`)\nusers.set(source).pick(n); // User[]\n\n// Update multiple entries between indexes (`start: number, end: number`)\nusers.set(source).between(start, end); // User[]\n\n// Update multiple entries by criteria (`c: Partial\u003cUser\u003e`)\nusers.set(source).by(c); // User[]\n```\n\n### Deleting entries\n\nLeverage the `delete()` action to delete entries from your Factory. Factoryse offers a variety of query methods to facilitate this deleting process. Each method used for deleting entries will return the deleted entries. To retrieve the complete set of entries from the factory after making deletions, refer to the `get()` action detailed in the [Retrieving Entries](#retrieving-entries) section.\n\n```typescript\n// Delete all entries\nusers.delete().all(); // User[]\n\n// Delete the first entry or the first (`n: number`) entries\nusers.delete().first(); // User[]\nusers.delete().first(n); // User[]\n\n// Delete the last entry or the last (`n: number`) entries\nusers.delete().last(); // User[]\nusers.delete().last(n); // User[]\n\n// Delete a random entry or multiple random (`n: number`) entries\nusers.delete().any(); // User[]\nusers.delete().any(n); // User[]\n\n// Delete a single entry by its index (`n: number`)\nusers.delete().at(n); // User\n\n// Delete multiple entries by their index (`n: number[]`)\nusers.delete().pick(n); // User[]\n\n// Delete multiple entries between indexes (`start: number, end: number`)\nusers.delete().between(start, end); // User[]\n\n// Delete multiple entries by criteria (`c: Partial\u003cUser\u003e`)\nusers.delete().by(c); // User[]\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthekeogh%2Ffactoryse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthekeogh%2Ffactoryse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthekeogh%2Ffactoryse/lists"}