0

I want to set up a CI/CD workflow which includes testing my server as a whole.

Using node I have a couple options such as

  • Jest,
  • Mocha,
  • Chai
  • or a different approach such as Postman/Newman.

I have tried out Jest and found it very difficult to adjust my databases such as Postgres and Redis to the mock environment. In fact, I didn't get it to work at all, presumably because of all the technologies involved.

Is there is a tool, maybe one of the others mentioned, that takes the server as it is, without any additional configuration, calls the endpoints of the Server and gives me results, which I can then use to further take action (push/rollback/discard changes)?

Tobi
  • 363
  • 5
  • 15
  • Please don't add unnecessary formatting, it makes the question less readable. – jonrsharpe May 23 '21 at 20:26
  • @jonrsharpe it's OK if we disagree. Happy to hear your ideas regarding my issue though – Tobi May 23 '21 at 20:37
  • "I have tried out Jest and found it very difficult to adjust my databases such as Postgres and Redis to the mock environment. In fact, I didn't get it to work at all, presumably because of all the technologies involved." Going to have to disagree here Tobi, if anything your code has been written in an untestable way. What patterns are you using? Can you share some code? – Isolated May 23 '21 at 21:53
  • @Isolated I am using Prisma and Ioredis. If you think there would be a solution, I'd happily share some code. – Tobi May 23 '21 at 22:13
  • @Tobi please do! Unit and integration testing can be challenging so if I can provide any tips I will! You may find you'll help get a broader response by sharing an example repo (or actual repo) in your question. – Isolated May 23 '21 at 22:23
  • @Isolated I dont think I can share everything because this is my private project that I want to publish soon and that I have been working on for a year now. But Im happy to share anything related to this issue. I have updated the issue and I included all changes I made – Tobi May 23 '21 at 22:39
  • @Isolated I also included my .test.ts file now. I am trying to achieve integration testing. I want to check the functionality of the server as a whole. I would like to test all endpoints, or, since Im using graphql, all queries and mutations – Tobi May 23 '21 at 22:43
  • @Tobi apologies, my comment was before you added your test file, that makes more sense with that added as context. Is the `main()` method part of Apollo? Or is that a custom function you've added for bootstrapping? Bare with me also whilst I prepare an answer for you – Isolated May 23 '21 at 22:45
  • @Isolated No need to apologize. Youre helping, theres nothing I could blame you for. main() is the function creating all services, setting up pug as a view engine, configuring apollo with express, i18n, cors and all the setup except for app.listen. It returns an instance of ApolloServer and express – Tobi May 23 '21 at 22:48
  • @Tobi Finally, is that called (`main()`) by anything else? Or below, are you calling it? My point here is, the easiest solution would be add the prisma client as an argument (dependency injection) and then from your test file, you can create the mock and inject it in. Providing you inject the required methods, your service will execute as required. Alternatively, have you considered an in-memory/docker solution to avoid mocking entirely? – Isolated May 23 '21 at 22:50
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/232786/discussion-between-isolated-and-tobi). – Isolated May 23 '21 at 22:57
  • @Isolated I have included the essential parts of the main function as well now. Main is only called once by index.ts or by the jest command in the .test.ts file. So it is the same setup function that I would else call for npm run start. I am actually dockerizing everything. On my actual server, node, docker and redis all run in their own container – Tobi May 23 '21 at 22:58

0 Answers0