[Bug]: Missing coverage from custom test environment
Version
29.0.3
Steps to reproduce
- Clone my repo at https://github.com/marvasDE/jest-sample
- Install packages via npm i
- Run npm run test:coverage
Expected behavior
100 % Stmts covered in index.js
Actual behavior
83.33 % Stmts covered in index.js
Additional context
We have a global service class, but every line which should be covered with the global service is not covered. The test is running, because there is a console.log.
Uncomment Line 12 of sample.test.ts will fix the behavior, but we would like to use a global service, because in a real project we have multiple tests, which are using a global service to reduce memory usage.
Environment
System:
OS: Linux 5.19 Arch Linux
CPU: (8) x64 AMD Ryzen 7 2700U with Radeon Vega Mobile Gfx
Binaries:
Node: 18.9.0 - /usr/bin/node
Yarn: 1.22.19 - /usr/bin/yarn
npm: 8.19.1 - /usr/bin/npm
npmPackages:
jest: ^29.0.3 => 29.0.3
If your service is instantiated outside of a test (e.g. globalSetup or via a test environment) then that code runs outside of the context jest can pick up the coverage I think...
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.