Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Jest support #220

Closed
palcu opened this issue Jul 18, 2014 · 5 comments
Closed

Jest support #220

palcu opened this issue Jul 18, 2014 · 5 comments

Comments

@palcu
Copy link

palcu commented Jul 18, 2014

Hello,

I am trying to configure Istanbul to use the https://github.com/facebook/jest framework built on top of Jasmine. When I run istanbul cover jest I get No coverage information was collected, exit without writing coverage information.

Could you please tell me if there is a simple solution for this that I am overlooking, or do I have to implement from scratch Istanbul support in Jest.

Thank you.

@gotwarlost
Copy link
Owner

No idea. I suspect the way jest works by mocking everything by default, it is hooking the require function and not letting istanbul do its thing.

A simple github repo with a lib file, a test file and a build script that uses jest will help me debug this faster.

@palcu
Copy link
Author

palcu commented Jul 19, 2014

I made a repo by using the simple getting started guide. I tried to unmock the istanbul module, but it still does not work.

@gotwarlost
Copy link
Owner

jest uses contextify which runs JS scripts in a V8 context in native code thus bypassing all of istanbul's require and vm.runInThisContext hooks. So istanbul cover will not work since standard hookable node.js functions are not being used and pre-instrumenting files will not help either since every test runs in its own sandbox and there is no global in which to stash the coverage object.

You'll have to talk to the jest team to find a solution assuming they are interested in implementing one.

@palcu
Copy link
Author

palcu commented Jul 20, 2014

Thank you for the answer.

@andrewdeandrade
Copy link

@palcu FWIW the entire approach jest takes with taking over require is extremely bad juju. @Raynos attempted a similar approach a long time ago with the raynos/mock library and determined that you should never overwrite require. My advice is to dump jest and take the same approach substack takes with testing mkdirp using mockfs. The general idea is that if you need mocking for a library, then you should expose that mockability as an option when you require the module. Here it is in use:

https://github.com/substack/node-mkdirp/blob/master/test/opts_fs.js

Like the javascript language, there are some good parts in the react ecosystem (v-dom, flux) and there are some bad parts (jsx, jest). Try to avoid react cargo culting and only use the good parts.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants