Issue
I'd like to be able to programmatically get the number of tests run by the jest command and store that in a variable so I can report metrics on it.
So the output of running the Jest command looks like this
Test Suites: 29 passed, 29 total
Tests: 224 passed, 224 total
Snapshots: 0 total
Time: 287.464 s
Ran all test suites.
How can I store the 224
number (total tests ran)?
I've tried jest --listTests
but that just lists the test files. The reports don't seem to contain the number of tests run, just the number and % of files, functions, and branches covered.
Solution
you can combine the output with awk. to get the total test numbers.
assign the total field to a variable, total:
bash command: total=$(/command/of/jest 2>&1 | awk '/Tests:/{print $(NF-1)}')
Answered By - yi yang Answer Checked By - Marie Seifert (WPSolving Admin)