How to run Jest tests sequentially?

前端 未结 5 915
抹茶落季
抹茶落季 2020-12-12 15:42

I\'m running Jest tests via npm test. Jest runs tests in parallel by default. Is there any way to make the tests run sequentially?

I have some tests cal

5条回答
  •  旧时难觅i
    2020-12-12 16:45

    It worked for me ensuring sequential running of nicely separated to modules tests:

    1) Keep tests in separated files, but without spec/test in naming.

    |__testsToRunSequentially.test.js
    |__tests
       |__testSuite1.js
       |__testSuite2.js
       |__index.js
    

    2) File with test suite also should look like this (testSuite1.js):

    export const testSuite1 = () => describe(/*your suite inside*/)
    

    3) Import them to testToRunSequentially.test.js and run with --runInBand:

    import { testSuite1, testSuite2 } from './tests'
    
    describe('sequentially run tests', () => {
       testSuite1()
       testSuite2()
    })
    

提交回复
热议问题