简体   繁体   中英

How to force a test suite to run first and quit entire Jest execution if it fails?

For my end-to-end testing, I am using Puppeteer with Jest. My codebase is large and I have a lot of tests at the moment. There is one 'preparatory' test suite which checks if there actually is sufficient data on our page for the rest of the tests to proceed. I would like to force this test to run first and then terminate the Jest process if it fails, since there is no need for other tests to run after that.

The --runInBand flag not only has a hard performance hit due to the large number of tsts but also requires manual termination of the Jest process after the failure of the first test, which I have not been able to do.

What is the best way to achieve the above? Could I please get a minimal example of the solution? Thanks!

One of places that precede all tests is globalSetup . It runs in parent process and doesn't obtain Jest environment, so the test needs to be set up manually:

import expect from 'expect';

export default async () => {
    // assertions go here   
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM