Remix.run Logo
bluGill 2 days ago

Most side effects are not a problem (or should not be).

Years ago we decided that the data directory would be changeable so we call get data directory - that call is an easy constant in production not worth testing, but in test mode it is a complex call to make temp dir, setup the default contents (which might be real default or a test specific situation), then destroy it when the test is done. So a lot of tests are needed to get it right (everyone uses it)- however because we have this we can use a sqlite in our tests thus saving needing to mock the database: side effects from database manipulation no longer matter.

I do a similar thing for dbus, want to use the systembus - in tests I intercept your open call and launch new server on a different port just for this test. Again a lot of tests.

For time I intercept all the timer and get time calls. When in tests I have an advanceTime function that advances all the timers the intended amount and takes action If you advance 100ms a 10ms timer will fire 9-10 times before the 100ms timer you (9-10 because the last time both timers will fire and which is first depends)

The above is real world things I've done and found very useful for long enough that I'm trying to spread it. I believe that it would help everyone to start doing the same.