Trendyol / jest-testcontainers

Jest preset for running docker containers with your tests
MIT License
122 stars 16 forks source link

[Question]: Why do you wrote the global vars to a JSON file? #14

Closed luisfermp19 closed 4 years ago

luisfermp19 commented 4 years ago

Hi everyone!

Thank you very much for this utility!

I have a question that I can't answer no matter how hard I try to dive into the code. Why are global variables written to a globals.vars.json file? Couldn't they be directly stored in the global object and then loaded into this.global in the environment?

Thank you very much for the reply! :smile: Best regards!

Yengas commented 4 years ago

Hello darksiderlm18,

We register to the globalSetup to start containers defined in the jest-testcontainers-config.js, so each suite will use the same set of containers. The caveat is that you can't read global variables defined within globalSetup, in your test suites. Please see here for details.

A common pattern(which this library uses as well) is to write to a file and read it from each test suite. You can see another example here.

Hope this answers your question. Feel free to close the issue if it does.

Regards, Yengas

luisfermp19 commented 4 years ago

Hi Yengas,

Thank you very much for the answer, it has finally become clear to me why you store the variables in a file.

Greetings, Best regards! :smile: