Reuse Docker Compose Environment
Closed this issue · 2 comments
Not sure if this is the right platform to ask, please direct me to any other platform if not.
I am utilizing testcontainers to test a large project. I specifically use the compose module to bring the environment up and run a good number of test cases. I would like to create an fresh environment each time, but the time cost of bring the environment up is too high.
Is there anyway to bring up the environment once and reuse it across the different tests?
I tried to use the .withNoRecreate()
option (From #288). But it seems to be not having any effects (It might be that I am using it wrongly or I am downing the env?).
I just wanted to know if there are any best practices to create such a singleton environment, or has anyone already implemented anything similar to this. I have attached code blocks of how I create and stop the env.
// before hook to start env
environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
.withWaitStrategy("service-one", Wait.forHealthCheck())
.withWaitStrategy("service-two", Wait.forLogMessage(/Server started/))
.withNoRecreate()
.up();
// Run Tests
// After hook to bring down the env
await environment.down();
Thanks for maintaining such a valuable project!
Hi, I think this question is more about specific test runner setup. E.g if you are using Jest you can configure a setupFiles which ups the compose env once before all tests. You can inject the env instance into globals if you need access from the tests. Likewise you can stop the env also in the setupFiles.
Thanks for the suggestion @cristianrgreco . I am new to JavaScript ecosystem and I did not know about this possibility with jest. I will try this out.