Thanks for your content! It gave me a new approach to integration tests. One of the tradeoffs of putting everything inside test containers is that you cannot mock some dependencies. Maybe you want to test with your database integration but without email integration with the SMTP server. So I prefer to only use the containers for the database or for any dockerizable external dependency that you want to integrate into your testings.
If you want only mysql container you can do so and expose the port and just use the node app by setting env variable. That should work too. In that case you need to change your code by adding host port as well. For example: .withExposedPorts({container: 3306, host: 3306, }), if you get port conflict then change host port to something else.
Thanks for the video! I am trying to setup a bun environment, do you know if there is a problem about it? It says that undefined symbol: node_module_register...
You don't need to use it, but it can be useful in complex testing environments. You can watch this great video for more information: ruclips.net/video/9fzn0j1jbiQ/видео.html
Hi there. I think there are already plenty of good resources about unit testing out there. And using Jest shouldn't make a big difference either. You can take a look at an npm module called "ts-jest" for running Jest with TypeScript.
⭐ Make sure to star the GitHub repository: github.com/flolu/node-integration-testing
amazing straight to the point.
This video should have more views. This is a great content!
Thanks! I was having a hard time finding good implementations for this.
Glad I could help!
Thank you definitely helpful
Glad it was helpful!
This is very neat approach. Not sure if it's better than starting container and running test inside, but still noteworthy 👍
Thanks for your content! It gave me a new approach to integration tests. One of the tradeoffs of putting everything inside test containers is that you cannot mock some dependencies. Maybe you want to test with your database integration but without email integration with the SMTP server. So I prefer to only use the containers for the database or for any dockerizable external dependency that you want to integrate into your testings.
Thanks! And yes, that's completely fine, too. But I can't see why I wouldn't be able to mock an email integration?
If you want only mysql container you can do so and expose the port and just use the node app by setting env variable. That should work too. In that case you need to change your code by adding host port as well. For example: .withExposedPorts({container: 3306, host: 3306, }), if you get port conflict then change host port to something else.
Thanks for the video! I am trying to setup a bun environment, do you know if there is a problem about it? It says that undefined symbol: node_module_register...
Wonderful explained. Thanks for video
I'm glad that I was able to help!
why didn't you use your docker-compos to setup the container?
Depending on your needs you can definitely just use docker-compose. But you have far greater flexibility by using Testcontainers.
In NodeJS testcontainers see DockerComposeEnvironment for sharing compose files with testcontainers
what is the advantage of using testcontainers package instead of just running tests inside app container with docker-compose run?
You don't need to use it, but it can be useful in complex testing environments. You can watch this great video for more information: ruclips.net/video/9fzn0j1jbiQ/видео.html
Hi florian, can you please make similar video using Jest also covering some unit tests as well
Hi there. I think there are already plenty of good resources about unit testing out there.
And using Jest shouldn't make a big difference either. You can take a look at an npm module called "ts-jest" for running Jest with TypeScript.
It was a really helpful video, thanks a lot!
Great to hear that, thanks for the comment!