Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integration testing with Sequelize

I've got a Express web api using sequelize that i want to do end to end testing with. I want to be able to do end to end testing with an in memory database so i can run it on whatever machine pleases me.

I use mysql database for development and production, however i was thinking about using an in-memory sqlite database for testing but i'm not sure what the best way is to get test data into it.

There are several modules around like squelize-fixtures but none of them seem to be able to just fill the database with data without the need to write code around it to manipulate and insert it.

Anyone here doing integration tests with sequelize and sqlite that has figured out a good way of doing it without all the boilerplate code?

like image 928
grimurd Avatar asked Sep 28 '22 08:09

grimurd


1 Answers

If you test this way it won't actually be end-to-end testing since you're using a different database.

However, what is wrong with changing your Sequelize dialect to be sqlite and then using sequelize-fixtures to ingest a file of your data? If you feel this is too onerous you could slog your way through it one time and then just save the sqlite db file for future use. You would then instantiate your Sequelize object with

storage: 'path/to/database.sqlite'

No matter what you do or what storage you choose you're going to have to do some work to seed your database.

like image 162
HeadCode Avatar answered Oct 19 '22 05:10

HeadCode