0

Question: How can I declare a Nodejs global variable that gets updated multiple times in a session for a process? I am using this global variable in multiple processes. And wants to keep the data of this global variable separated between the processes.

I have currently declared a global variable like global.object1={}; in my cucumber hooks file. And I update its value a few times in my tests. As far as it is 1 test, it works just fine. But when multiple tests run, I am getting race condition. Data from test1 appears in test2. And hence test2 fails. It is visible in logs that test2 is showing data from test1.

In my test, I am trying to keep the data unique between the tests. I have read about a few related blogs and Stackoveflow queries but it's not clear to me what exactly I can do.

My previous approach was to store objects data in a JSON file in separate locations. But this is not how I want to code. I have used Java before and have synchronised my objects to use them between threads. But I am not sure how I can do it here using Nodejs and ES6.

Any leads are welcome.

Xat
  • 67
  • 1
  • 2
  • 9

0 Answers0