Trendyol/jest-testcontainers

Ability to not stop containers in Jest watch mode

ligaz opened this issue ยท 5 comments

ligaz commented

Background: I'm having a container setup that takes a non trivial time to start (~20-30 secs) and if I run Jest in watch mode I have to pay this price on every re-run.

Is there a way to have jest-testcontainers not stop the containers on teardown?

Hey @ligaz,

This is a reasonable feature request. This would also help in the debugging process(whilst running a single test repeatedly and debugging the code).

I think we can pass an optional flag to jest-testcontainers (in config, or env variable, or something else) to enable this.
Currently, jest-testcontainers writes a file including the IP/port info of the started containers. If the mentioned flag is passed, we can re-read from the file, instead of creating new containers. This opens up the question of when and how to stop these containers.

I'm curious about your thoughts on this topic. What kind of implementation could we do? And would you like to contribute this?

ligaz commented

We can pass this option as testEnvironmentOptions Jest config option.

Regarding stopping of containers Jest currently does not support only once semantics during watch mode. In our case we are using testcontainers with ryuk which should automatically cleanup those containers.

Thanks for the pointers. They were helpful. Just published v2.0.0. By default, it will not restart containers in watch mode. Let me know if everything works as expected on your end as well. Thanks!

ligaz commented

๐ŸŽ‰ Just tested it locally and it works flawlessly. Thanks for your work!

Additionally I have opened #21 that adds some info regarding this behavior in the README. Hope you will find it useful.

Merged the update to the documentation. Thanks for all the help. Cheers ๐Ÿป