Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda