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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We call
initialize()
within the DataSource provider factory. It doesn't seem to be possible then (that DataSource might not be initialized yet at this point). Can you share a minimum reproduction repository?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes let me try and create something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please give https://github.com/thomasconner/nestjs-typeorm-test a try. I have included a
docker-compose.yml
file to setup Postgres. If you executenpm run test:e2e
you will see the error that I mentioned about. We ran into this with e2e tests we had at work. All the tests would pass but CircleCI would fail because of the error that gets logged.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The argument can be made that we should just remove the line that destroys the datasource in our tests which would definitely solve the problem. But my reasoning for changing it here is that the expectation should be that I could call
datasource.destroy()
without there being an error thrown.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I think that's the valid argument TBH. You're trying to destroy a
DataSource
in your test suite that has been already terminated in theonApplicationShutdown
hook, and we can't really remove it from there as we don't want folks to manually terminate data sources that were auto-created & are maintained within the module.What's the reason for manually calling
destroy
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No specific reason to be honest. We upgraded from TypeORM v2 to v3. Before there was a
connection.close()
so this was replaced, without much thought, withdatasource.destroy()
. This is the only reason it existed.