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

155
Visualizações
nodejs async await inside iterator for loop in mocha test

I'm trying to test the usage of an asynchronous generator using the async and await paradigm.

I have a generator function yielding results from a stream:

async function* getChunkOfData(filepath) {
  try {
    const inputStream = fs.createReadStream(filepath);
    const parser = parse();
    await pipelineAsync(inputStream, parser);
    for await (const line of parser) {
      yield line;
    }
  } catch (err) {
    throw new Error("error while reading csv file: " + err.message);
  }
}

I'm getting line by line in my test and using it as input for an asynchronous function. From the test, I'm getting a timeout error and only the first iteration of the for loop is executed. Here my test code:

describe("My test suite", function () {
  it("My test", async function () {
    try {
      const iterator = getChunkOfData("example.csv");
      for await (const row of iterator) {
        await asyncCall(row);
        // some expect logic using chai
      }
    } catch (err) {
      console.log(await err);
      assert.throw(err);
    }
  });
});

Please note, that I've already tried to increase the test timeout, without any better results also because the asyncCall is executed quite fastly.

about 4 years ago · Juan Pablo Isaza
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