Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a list of tests run with Jest (without running suites)

Is it possible to get a list of suites/specs without running the actual tests w/ Jest.

For example, I have a test that looks like this:

describe('when blah blah blah', function () {
  it('returns foobar', function () { /* test code */ })
})

Ideally, I'd like to be able to just get a list of describe/it statements to quickly look at scenarios covered.

# stdout
when blah blah blah
  returns foobar

I think this is possible with rspec, using a dry-run flag. Is there any such option with Jest?

I took a look at the Jest CLI documentation and have done an issue search at the project's Github page, but could not find anything.

like image 387
dev.kho Avatar asked Dec 08 '17 20:12

dev.kho


People also ask

How do you skip the test suite in Jest?

But we need to skip test 2 due to certain reasons. In jest, we can do this using the test. skip function. Using this function, we can skip specific test cases.

How do you make Jest tests run sequentially?

If you want to run files in sequence as well, run Jest with the --runInBand command line flag. ( -i does the same thing.) Doing this, the scheduler might still run them in a different order from run to run. To prevent this as well, you will need to define your own test sequencer.

How do you filter Jest tests?

It's in the Jest documentation. Another way is to run tests in watch mode, jest --watch , and then press P to filter the tests by typing the test file name or T to run a single test name.

Does Jest run test suites in parallel?

To speed-up your tests, Jest can run them in parallel. By default, Jest will parallelise tests that are in different files. IMPORTANT: Paralellising tests mean using different threads to run test-cases simultaneously.


1 Answers

The switch --listTests returns a JSON array of the test files and then exits (instead of running the tests).

It might not be exactly what you're looking for though since it doesn't parse the describe/it functions, nor is the output very pretty.

https://facebook.github.io/jest/docs/en/cli.html#listtests

like image 101
Oskar Avatar answered Sep 30 '22 19:09

Oskar