Repository navigation
Conversation
withNoRecreate() replaced the project name with the fixed value "testcontainers-node" as a side effect, so a name set earlier with withProjectName() was silently discarded and the result depended on the order of the two calls. Resolve the project name in up() instead: an explicit project name always wins, otherwise the generated name is used, or the fixed name when recreation is disabled. Fixes testcontainers#1524
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DockerComposeEnvironment.withNoRecreate()set the project name to the fixed valuetestcontainers-nodeas a side effect. Combined withwithProjectName, the outcome depended on the call order:In the first form the custom name was silently dropped, and unrelated environments using
withNoRecreate()shared one Compose project.This change stops
withNoRecreate()from touching the project name. The name is resolved once inup(): an explicitwithProjectNamealways wins, otherwise the generatedtestcontainers-<uuid>name is used, or the fixedtestcontainers-nodename when recreation is disabled. The helpers that match containers to the project now readoptions.projectName, which is the resolved value. Since the name is derived from the builder state rather than stored duringwithNoRecreate(), a boolean form of the setter (#1530) will get the generated name back when it is turned off again.The compose docs now mention the fixed project name used by
withNoRecreate().Verification
npx vitest run packages/testcontainers/src/docker-compose-environment/docker-compose-environment.test.ts -t "custom project name"should keep a custom project name when no recreate option is setfails onmainbecause the started container is namedtestcontainers-node-container-1instead ofcustom-<uuid>-container-1.should not recreate the containers when no recreate option is settest still passes, so the fixed project name is still used when no name is set.npm run lint:ci,npm run knip,npm run check-compilesandmkdocs build --strictpass.Not breaking
Environments that only call
withNoRecreate()keep using thetestcontainers-nodeproject, andwithProjectNamefollowed by nothing else behaves as before. Only the combination ofwithProjectNameandwithNoRecreatechanges, and it now honours the explicit name in either order.Closes #1524