mercredi 25 mars 2020

Jest with Node.js - How to fire tests asynchronously

I am not a Javascript, Node.js or Jest expert. But I've been learning the language for a week now and developed some asynchronous code to create some tests. The functions that do the tests use async-await because I need to pre-populate some data, make an API call and eventually listen into the end system to ensure data was submitted. Long story short, the flow can take time so I had to use async-await to make it synchronous so the test doesn't overtake the pre-requisite steps.

Finally, when I have my test suites built using Jest, I realize that it's taking a lot of time and on printing the logs, I noticed that each of these tests are fired in sequence rather than executing them asynchronously or in parallel. One of the test takes about 60 seconds and he 3 tests when executed took 190 seconds (roughly 3 times).

Is it possible to write the test suite so that the tests that are independent of one another can be fired simultaneously?

test("Test response from loanWoCrmApplicationSubmitted", async () => {
    const responseOk = await huntington.loanWoCrmApplicationSubmitted();
    expect(responseOk).toBeTruthy();
});

test("Test response from loanWoCrmApplicationExported", async () => {
    const responseOk = await huntington.loanWoCrmApplicationExported();
    expect(responseOk).toBeTruthy();
});

test("Test response from loanWoCrmApplicationTridTriggered", async () => {
    const responseOk = await huntington.loanWoCrmApplicationTridTriggered();
    expect(responseOk).toBeTruthy();
});

Aucun commentaire:

Enregistrer un commentaire