Jest requires `--no-cache` for proper coverage
See original GitHub issueI have been digging into why many of our well tested components/views are not showing up on coverage reports, and I noticed that if I applied the --no-cache
flag to jest I started getting appropriate coverage numbers. There seems to be an issue with the vue-jest
caching mechanism that may be preventing some from getting appropriate coverage numbers.
We copied our settings from https://github.com/eddyerburgh/vue-test-utils-jest-example
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:28 (13 by maintainers)
Top Results From Across the Web
Jest CLI Options
The jest command line runner has a number of useful options. You can run jest --help to view all available options. Many of...
Read more >How can I clear the Jest cache? - Stack Overflow
As of Jest 22.0.0+, you can use the --clearCache option: Deletes the Jest cache directory and then exits without running tests.
Read more >Jest CLI Options - Robin Pokorny
Whether to use the cache. Defaults to true. Disable the cache using --no-cache . Note: the cache should only be disabled if you...
Read more >Using Visual Studio Code to debug Jest based unit tests
The need. Jest has become the de facto standard for building unit tests. ... no-cache: Disable the cache, Jest caches transformed module files...
Read more >vscode-jest-runner - Visual Studio Marketplace
vscode-jest-runner is focused on running or debugging a specific test ... JST/TSX with CRA you need to have a valid babel and jest...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This issue came out of nowhere for me, took me way too long to recognize that it’s a cache error.
FIX
All tests work again with adding
--no-cache
to the test script:"test:unit": "vue-cli-service test:unit --no-cache"
SETUP
jest.config.js
ERROR
Here is the error from console:
TEST
@eddyerburgh
Even the most simple
isVueInstance
test fails:…but again, other tests fail, too.
This one is a little frustrating for me. Using
--no-cache
fixes the test, but if I’m using it in conjunction with--watch
then changes aren’t picked up as I make them, so the only way to see if I’ve broken something is to manually runjest
. First world problems, but it’d be nice to have my test runner up while building so as to make the flow a bit less tedious.example.spec.ts
example.vue
example.ts
So if I have
jest --watch --no-cache
running, and changemsg
inexample.ts
to'Hey Vue'
the change isn’t picked up andjest
still thinks it’s passing. Not sure if there’s a way around that injest
or if it’s the purview ofvue-jest
but seems relevant to the conversation here.