Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
Singleton class instance when running tests in parallel with jasmine

I have an automated test setup written in javascript using jasmine and executing tests in parallel. Tests are executed using the following command:

protractor-flake --max-attempts=2 -- ./config/configfile.js --suite $SUITE "$@";

Inside the config file we set up all jasmine reporters, lists of all the test suites but also other prerequisites such as a class providing information about all the different feature flags that are on or off depending on the environment. The feature flags are fetched using an api call which happens in a method in configfile.js just before the tests are executed. I have tried creating a singleton and return the same instance but either i am doing something wrong or every new thread/process will create a new instance even if it's a singleton. Bellow is a simplified version of the singleton class.

class FeatureFlagConfiguration {

 async getFlags() {
     if (FeatureFlagConfiguration.instance === undefined) {
         const client = new Client();
         this.flags = await client.getFlags();
         this.moreInfo = await client.getMoreInfo();
         FeatureFlagConfiguration.instance = this;
         Object.freeze(FeatureFlagConfiguration.instance);
     }
 }

 evaluateFlags() {
     ...
 }


 isFeatureFlagEnabled() {
     ...
 }
}
module.exports = new FeatureFlagConfiguration();
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Try using a global variable instead, as suggested here: https://stackoverflow.com/a/1479341/3482730

So probably something like:

class FeatureFlagConfiguration {

 async getFlags() {
     if (FeatureFlagConfiguration.instance === undefined) { // prob not needed
         const client = new Client();
         this.flags = await client.getFlags();
         this.moreInfo = await client.getMoreInfo();
         FeatureFlagConfiguration.instance = this;  // prob not needed
         Object.freeze(FeatureFlagConfiguration.instance); // prob not needed
     } // prob not needed
 }

 evaluateFlags() {
     ...
 }


 isFeatureFlagEnabled() {
     ...
 }
}

const featureFlagConfigurationInstance = new FeatureFlagConfiguration();

module.exports = featureFlagConfigurationInstance;
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!