Skip to content

Instantly share code, notes, and snippets.

@twolfson
Last active December 24, 2021 11:23
Show Gist options
  • Save twolfson/0e577f814974c26935a023abac50ed7f to your computer and use it in GitHub Desktop.
Save twolfson/0e577f814974c26935a023abac50ed7f to your computer and use it in GitHub Desktop.
Node.js database fixture library evaluation

Last updated: Nov 11, 2016

We are settings up database fixtures in our Node.js project. This is our evaluation of various fixture libraries:

Conclusion:

Going to try out sequelize-fixtures for now as it is less about generating dynamic data and more about fixtures

Our likely usage will be:

  • Define models by key in a JS file (so we can leverage nice integrations like moment-timezone with getters/setters)
  • Use the loadFixtures method with _.pick to retrieve models by key
    • Will prob need to verify that Object.keys of _.pick object is same as keys (so we prevent tests with typos)
  • Also define fixtures.DEFAULT_FIXTURES for easy reference in loader
@uzair004
Copy link

Nice and useful gist, I found associations in sequelize-fixtures bit tricky, have you tried sql-fixtures package ?
Its working fine with relationships b/w gettting error when a field has setters.

@uzair004
Copy link

Also I need to use inserted records in my test, exporting them in array then reading them index wise in test doesn't sound nice way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment