You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We should move towards writing tests for it! Unit Tests are fast but only test the business logic (they can't test whether the SQL query written is actually correct, a code passing all the unit tests might fail the code in production!) and Integration tests are slow (can become a headache for developers).
Therefore we can move to E2E Tests. These tests are faster than Integration tests and can be extended to test the action of these services!
So the route is simple:
We need to setup testing instances of all the services, as tests should not contact the real instances. docker compose can be a good idea for this.
We need to replace the the actual services with the testing instances when tests are running, that means Dependency Injection.
But there are some problems:
a) Dependency Injection Design Pattern: As far I know, there is no good library available for this in Nodejs. tsyringe is there, but it also uses a global instance of container, hence second point can't be achieved!
b) Docker might make the CI slow!
Solutions:
a) Traditional way of Dependency Injection (in JAVA) is by using Constructors and decorators on controllers but JS is a functional programming, so either we have to migrate to a new OOPs based framework like Nestjs or we might use a hack by just changing the protocol to GraphQL and using the context variable for Dependency Injection.
b) Caching in DockerFile and multi stage builds can fix this.
I could see three services in this repository:
We should move towards writing tests for it! Unit Tests are fast but only test the business logic (they can't test whether the SQL query written is actually correct, a code passing all the unit tests might fail the code in production!) and Integration tests are slow (can become a headache for developers).
Therefore we can move to E2E Tests. These tests are faster than Integration tests and can be extended to test the action of these services!
So the route is simple:
We need to setup testing instances of all the services, as tests should not contact the real instances.
docker compose
can be a good idea for this.We need to replace the the actual services with the testing instances when tests are running, that means
Dependency Injection
.But there are some problems:
a) Dependency Injection Design Pattern: As far I know, there is no good library available for this in Nodejs.
tsyringe
is there, but it also uses a global instance of container, hence second point can't be achieved!b) Docker might make the CI slow!
Solutions:
a) Traditional way of Dependency Injection (in JAVA) is by using Constructors and decorators on controllers but JS is a functional programming, so either we have to migrate to a new OOPs based framework like
Nestjs
or we might use a hack by just changing the protocol to GraphQL and using thecontext
variable for Dependency Injection.b) Caching in
DockerFile
and multi stage builds can fix this.See this repo: https://github.com/Manik2708/Hi_Server which is implemented in
Nestjs
with E2E Tests anddocker compose
in CI.The text was updated successfully, but these errors were encountered: