{"id":17700417,"url":"https://github.com/antman261/tiny-fixtures","last_synced_at":"2026-02-25T22:02:52.312Z","repository":{"id":51241465,"uuid":"364257192","full_name":"Antman261/tiny-fixtures","owner":"Antman261","description":"A very simple javascript package for database fixtures","archived":false,"fork":false,"pushed_at":"2024-10-23T05:30:16.000Z","size":765,"stargazers_count":6,"open_issues_count":3,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-11T20:58:47.585Z","etag":null,"topics":["database","database-fixtures","database-testing","fixture-test","fixtures","nodejs","testing","testing-javascript","testing-tools","typescript"],"latest_commit_sha":null,"homepage":"https://tiny-fixtures.com","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/Antman261.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2021-05-04T13:00:19.000Z","updated_at":"2024-10-23T05:30:20.000Z","dependencies_parsed_at":"2024-06-21T05:42:53.231Z","dependency_job_id":"2977e155-87f5-47a6-9cbe-02677e513acc","html_url":"https://github.com/Antman261/tiny-fixtures","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antman261%2Ftiny-fixtures","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antman261%2Ftiny-fixtures/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antman261%2Ftiny-fixtures/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antman261%2Ftiny-fixtures/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Antman261","download_url":"https://codeload.github.com/Antman261/tiny-fixtures/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253685172,"owners_count":21947301,"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":["database","database-fixtures","database-testing","fixture-test","fixtures","nodejs","testing","testing-javascript","testing-tools","typescript"],"created_at":"2024-10-24T17:42:08.754Z","updated_at":"2026-02-25T22:02:52.282Z","avatar_url":"https://github.com/Antman261.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tiny Fixtures [![tiny-fixtures](https://circleci.com/gh/Antman261/tiny-fixtures.svg?style=svg)](https://app.circleci.com/pipelines/github/Antman261/tiny-fixtures) [![npm monthly downloads](https://img.shields.io/npm/dm/tiny-fixtures.svg?style=flat-square)](https://www.npmjs.com/package/tiny-fixtures) [![current version](https://img.shields.io/npm/v/tiny-fixtures.svg?style=flat-square)](https://www.npmjs.com/package/tiny-fixtures) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n\n## Installation\n\nRun `npm i -D tiny-fixtures` to save to your dev dependencies.\n\n## Compatibility\n\nCurrently, only tested against Postgres flavoured SQL assuming a node-postgres connection pool.\n\n## Usage\n\nInitialise a fixture manager by providing it with a connection pool. \nTinyFixtures will return an object with a `createFixtures` function.\n\n```ts\nimport { tinyFixtures } from 'tiny-fixtures';\nimport { pool } from './db/connection';\nimport { getUsers } from '/db/users';\n\nconst { createFixtures } = tinyFixtures(pool)\n\ndescribe('my test cases', () =\u003e {\n    const [setupUserFixtures, teardownUserFixtures] = createFixtures('users', [\n        {\n            email: 'foo@bar.co',\n            username: 'tinyAnt'\n        }, {\n            email: 'bar@foo.co',\n            username: 'antTiny',\n        }\n    ]);\n    beforeEach(async () =\u003e {\n        await setupUserFixtures();\n    });\n    afterEach(async () =\u003e {\n        await teardownUserFixtures();\n    });\n    it('should have two users in the database', async () =\u003e {\n        expect((await getUsers()).length).to.equal(2);\n    });\n})\n```\n\n`createFixtures` takes \n* a table name\n* an array of objects\n\nEach object in the array is a row to insert. The setup function uses each row object's keys as column names.\n\nIn the example above, tiny-fixtures will insert into columns `email` and `username`.\n\n`createFixtures` returns two functions:\n* setupFixtures,\n* teardownFixtures\n\nCall these functions in your before each and after each hook respectively. Tiny fixtures will then ensure you have clean data for each test. Additionally, it will preserve existing data in the database, improving the local development experience.\n\nTo create fixtures across foreign keys use the third value returned\nby `createFixtures` to populate the next table, being sure to correctly order your\nsetup and teardown steps.\n\n```ts\nimport { tinyFixtures } from 'tiny-fixtures';\nimport { pool } from './db/connection';\nimport { getUsers } from '/db/users';\n\nconst { createFixtures } = tinyFixtures(pool);\n\ndescribe('my test cases', () =\u003e {\n  const [setupUserFixtures, teardownUserFixtures, users] = createFixtures('users', [\n    {\n      email: 'foo@bar.co',\n      username: 'tinyAnt'\n    }, {\n      email: 'bar@foo.co',\n      username: 'antTiny',\n    }\n  ]);\n  const [setupUserMessageFixtures, teardownUserMessageFixtures] = createFixtures(\n    'user_messages',\n    [{\n        user_id: users[0].getRefByKey('id'),\n        message: 'Foobar did the bar foo good',\n      },\n      {\n        user_id: users[0].getRefByKey('id'),\n        message: 'I am a meat popsicle', \n    }]\n  )\n  beforeEach(async () =\u003e {\n    await setupUserFixtures();\n    await setupUserMessageFixtures();\n  });\n  afterEach(async () =\u003e {\n    await teardownUserMessageFixtures();\n    await teardownUserFixtures();\n  });\n  it('should have a user with two messages, and one with none', async () =\u003e {\n    const users = await getUsers();\n    expect(users.length).to.equal(2);\n    expect(users[0].messages.length).to.equal(2);\n    expect(users[1].messages.length).to.equal(0);\n  });\n})\n```\n\nPay attention to the ordering -- following these simple patterns is what keeps tiny-fixtures tiny!\n\n### Explaining `user_id: users[0].getRefByKey('id')`\n\nBecause the fixture hasn't been inserted into the database yet, tiny-fixtures doesn't have any serial/sequence values in the row array returned as the 3rd return value. `getRefByKey` takes the column name of the primary key for the parent object in the foreign key, allowing the value to be resolved when the setup step occurs. \n\nTiny-fixtures resolves the value at setup by inspecting the row objects you provided for functions. When it finds one, it looks up the result for that column in the original object, and populates its value before continuing the insert.\n\nTiny-fixtures is then able to create and destroy fixtures across foreign keys for each test run.\n\n### Docs\n\nFull documentation located at [https://www.tiny-fixtures.com/modules.html](https://www.tiny-fixtures.com/modules.html)\n\n## Changelog\n\nSee [CHANGELOG.md](https://github.com/Antman261/tiny-fixtures/blob/main/CHANGELOG.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantman261%2Ftiny-fixtures","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantman261%2Ftiny-fixtures","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantman261%2Ftiny-fixtures/lists"}