Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

146
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda