lundi 27 avril 2020

Jest - proper way to cancel tests

I have a NodeJS application, and I use Jest for the testing.

My app uses ElasticSearch, and in the beforeAll, I check that ElasticSearch is present indeed. If it's not the case, I want to cancel the tests (because the user probably just forgot to launch it.)

Currently, I'm exiting with a process.exit:

beforeAll(async () => {
    await esClient.ping({
        requestTimeout: Infinity,
        hello: 'elasticsearch!'
    }, function (error) {
        if (error) {
            console.error('Couldn\'t connect to ElasticSearch! Is it launched?');
            process.exit(1);
        }
    });
});

And this works, but jest retries 5 times before giving up. I could change the retries count of jest to 1, but I feel like there's a better way of doing it.

So, is there a clear way to tell jest "Cancel everything now."?

Aucun commentaire:

Enregistrer un commentaire