{"id":13847312,"url":"https://github.com/skovy/cooky-cutter","last_synced_at":"2025-04-06T22:06:36.414Z","repository":{"id":32635923,"uuid":"138500670","full_name":"skovy/cooky-cutter","owner":"skovy","description":"🍪 Object factories for testing in TypeScript","archived":false,"fork":false,"pushed_at":"2022-06-03T02:04:56.000Z","size":605,"stargazers_count":133,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T21:06:23.278Z","etag":null,"topics":["factory","javascript","jest","mocha","testing","typescript"],"latest_commit_sha":null,"homepage":"https://skovy.github.io/cooky-cutter/","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/skovy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-24T17:09:16.000Z","updated_at":"2025-02-28T13:19:45.000Z","dependencies_parsed_at":"2022-09-08T14:22:43.727Z","dependency_job_id":null,"html_url":"https://github.com/skovy/cooky-cutter","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skovy%2Fcooky-cutter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skovy%2Fcooky-cutter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skovy%2Fcooky-cutter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skovy%2Fcooky-cutter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skovy","download_url":"https://codeload.github.com/skovy/cooky-cutter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247557767,"owners_count":20958047,"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":["factory","javascript","jest","mocha","testing","typescript"],"created_at":"2024-08-04T18:01:16.485Z","updated_at":"2025-04-06T22:06:36.389Z","avatar_url":"https://github.com/skovy.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# 🍪 cooky-cutter\n\n**Simple, type safe\\* object factories for JavaScript tests.** (_\\*with TypeScript_)\n\n[![Travis branch](https://img.shields.io/travis/skovy/cooky-cutter/master.svg)](https://travis-ci.org/skovy/cooky-cutter)\n[![Coverage Status](https://coveralls.io/repos/github/skovy/cooky-cutter/badge.svg?branch=master)](https://coveralls.io/github/skovy/cooky-cutter?branch=master)\n[![npm](https://img.shields.io/npm/v/cooky-cutter.svg)](https://www.npmjs.com/package/cooky-cutter)\n[![npm type definitions](https://img.shields.io/npm/types/cooky-cutter.svg)](https://www.npmjs.com/package/cooky-cutter)\n\n**[Read the Release Annoucement](https://skovy.dev/object-factories-for-testing-in-typescript/)**.\n\n## The problem\n\nYou need to write maintainable tests for JavaScript. The code depends on\nspecific entity types defined in the data model. These entities might initially\nget stubbed out in tests (Mocha, Jest, etc) as plain objects. As complexity\ngrows, you move to factory functions (or another package that does this) to\navoid the duplication. A new column gets added, an old one gets removed or maybe\nan entirely new entity is added. The breaking change isn't noticed until the\nentire test suite runs (or maybe never).\n\n## The solution\n\n[`cooky-cutter`](https://www.npmjs.com/package/cooky-cutter) is a light package\nthat leverages TypeScript to define and create factories. Simply pass the type\nas a generic (assuming you already have a type or interface defined for each\nentity type). Whenever the entity type changes, the factories become invalid!\n\n## Installation\n\n```bash\nnpm install --save-dev cooky-cutter\n# or\nyarn add --dev cooky-cutter\n```\n\n## Basic Usage\n\nFor more documentation and examples, read the [full documentation](https://skovy.github.io/cooky-cutter/).\n\n```typescript\nimport { define, random, sequence } from \"cooky-cutter\";\n\n// Define an interface (or type) for the entity\ninterface User {\n  id: number;\n  firstName: string;\n  lastName: string;\n  age: number;\n}\n\n// Define a factory that represents the defined interface\nconst user = define\u003cUser\u003e({\n  id: random,\n  firstName: i =\u003e `Bob #${i}`,\n  lastName: \"Smith\",\n  age: sequence\n});\n\n// Invoke the factory a few times\nconsole.log(user());\n// =\u003e { id: 980711200, firstName: 'Bob #1', lastName: 'Smith', age: 1 }\n\nconsole.log(user());\n// =\u003e { id: 1345667839, firstName: 'Bob #2', lastName: 'Smith', age: 2 }\n\nconsole.log(user());\n// =\u003e { id: 796816401, firstName: 'Bob #3', lastName: 'Smith', age: 3 }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskovy%2Fcooky-cutter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskovy%2Fcooky-cutter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskovy%2Fcooky-cutter/lists"}