Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

No coverage reports for files that are executed by vm.runInContext. #9349

Closed
JoHuang opened this issue Dec 26, 2019 · 7 comments 路 Fixed by #13974
Closed

No coverage reports for files that are executed by vm.runInContext. #9349

JoHuang opened this issue Dec 26, 2019 · 7 comments 路 Fixed by #13974

Comments

@JoHuang
Copy link

JoHuang commented Dec 26, 2019

馃悰 Bug Report

No coverage reports for files that are executed by vm.runInContext.

To Reproduce

Steps to reproduce the behavior:

  1. create a js file with single line console.log('hello');
  2. create a test file which loads the content of 1. , and run it by vm.runInContext.
  3. jest --coverage, no coverage report of 1. file.

Expected behavior

Show the coverage report.

Link to repl or repo (highly encouraged)

istanbuljs/istanbuljs#85
Not sure if it's related. However istanbul-lib-hooks is removed recently from Jest.

envinfo

System:
OS: macOS Mojave 10.14.6
CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
Binaries:
Node: 12.13.0 - /usr/local/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 6.12.0 - /usr/local/bin/npm
npmPackages:
jest: ^23.6.0 => 23.6.0

System:
OS: macOS Mojave 10.14.6
CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
Binaries:
Node: 12.13.0 - /usr/local/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 6.12.0 - /usr/local/bin/npm
npmPackages:
jest: ^24.9.0 => 24.9.0

Both jest versions are the same.

@SimenB
Copy link
Member

SimenB commented Dec 29, 2019

This should work correctly if using v8 coverage, which will be available in the next version of Jest. I don't think we're going to add support to it for the current babel based approach, as it'd require us to hook into vm.Script and mock it

@JoHuang
Copy link
Author

JoHuang commented May 26, 2020

I checked again with v8 coverage setting, and there's still no coverage reports for vm.
Here is the reproducible repo:
https://github.com/JoHuang/jest-vm-test

thanks

@JoHuang
Copy link
Author

JoHuang commented Jul 10, 2020

Hi,
I found it works with c8.

Please refer to the repo:
https://github.com/JoHuang/jest-vm-test

@JoHuang
Copy link
Author

JoHuang commented Oct 16, 2020

@SimenB
https://github.com/facebook/jest/blob/3641e3cc7309caf4c755add40bebcb77fc18b786/packages/jest-runtime/src/index.ts#L830

I found that it works after commenting this line.
It filters the files which are not required by normal node.js require or import.
However, codes run in VM usually are read as string content, and then put into VM.runincontext ...etc.

V8 coverage is there but Jest filters out the files.

Hope this is helpful.

@JoHuang
Copy link
Author

JoHuang commented Oct 16, 2020

However, this test case e2e/__tests__/v8Coverage.test.ts cannot pass.

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions
Copy link

github-actions bot commented Apr 4, 2023

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.