Kevin Powell - CommunityKP-C
Kevin Powell - Community8mo ago
49 replies
Ganesh

Disable file parallelism for api-DB integration tests

I will be using vitest and supertest with express as my backend framwork to test my REST api.

I have beforeEach blocks in my test files to wipe the db state and fill it with dummy data so each test has same DB state to work with.

Vitest by default runs the tests in different files concurrently. The problem with this is that the different tests might conflict with each other as they might insert same data that invokes validation violation. I can disable file parallelism in vitest just for these database tests so that they are run one after another even if they are in different files.

I have read some posts online and they seem to say that this is not a good idea and that either each of my tests should use a different database or each test should use data that's independent of other tests.

I have no idea how to do the first one, I read about tests containers but that seems overkill for something that's basically just a learning project.

For the second one I'm not sure how to do it without having to keep track of what data is used in which test. I might forget or as tests grow in numbers in might become complicated.

I'd appreciate any input, thank you for your time
Was this page helpful?