I am currently using the built-in Jest testing environment that comes with the generated boilerplate by create-react-app. With Jest's integration with Istanbul, one can get the unit test coverage by total number of statements, functions, lines, and branches covered. Aside from these, is there any way to get the total number of assertions used in all the unit test files? Thanks!
I'm not aware if jest has this functionality built in, but we can probably mimic this with grep and wc.
Grep searches files for specific text.
grep [options] PATTERN [FILE...]
-r --recursive
-c --count
-i --ignore-case
--include=PATTERN
Recurse in directories only searching file matching PATTERN.
wc - print newline, word, and byte counts for each file
wc [OPTION]... [FILE]...
-l, --lines
print the newline counts
Print the count of "expect" pattern matches in each file:
grep -r -i -c --include \*.test.js "expect" .
matches
Print the sum of total "expect" pattern matches.
grep -r -i --include \*.test.js "expect" . | wc - l
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With