-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ES6 EcmaScript 6 Class coverage is generated for transpiled code #817
Comments
Further information on this issue from my own attempts to get this working... I have a basic demo app that I've put together and I have successfully been able to write test and get code coverage working. Except for one minor problem. All of the code that use the class keyword from ES2015 end up emitting code at the top that looks like this:
It is a very long line, I'll save you the trouble of reading it. There are a couple of problems. First, the /istanbul ignore next/ should be /* istanbul ignore next */ with a space before and after the comment, otherwise istanbul does not properly apply it. Second, even once you fix that, which I tried doing, there are functions in that string that don't get commented at all with the ignore comment. I'm assuming because the set of functions all get added at once so only one comment gets applied at the beginning. My configuration for babel, both in package.json and .babelrc looks like this:
I've also tried adding babel-plugin-transform-runtime as
both before and after the "presets" line but when I do that, I get errors that indicate the auto mocking is unable to read the metadata. It seems that we need some sort of Babel plugin that adds in the comment for all of the transpiled code. |
I finally came up with a solution which you can read about here http://blog.dmbcllc.com/es2015-code-coverage-and-jest-react-js-unit-testing/ |
That's quite ingenious |
I would have submitted a pull request, but I'm not sure this is the BEST way of fixing this issue. |
Well the only thing that's holding me back is the use of transform-runtime |
Why? |
It seems to me like these are things that should be fixed in babel instead of in Jest. |
@DaveMBush It seems I was misinformed about the runtime transforms, as I just read the documentation again and it seems pretty good for my use-case. I do agree with @cpojer that Babel should handle this better. I'll create an issue there and link to this one for reference. Perhaps babel-jest? |
Also happy to help talk to people on the babel side about this. Both issue seem to be simple fixes in Babel, so it should be easy to get them in. |
I'll help where I can. I'm still wrapping my head around React/Jest so I just didn't have time to try to figure out Babel and Syntax trees enough to build a Babel generic fix. I hope my article gives enough information that someone who understands Babel better can apply a generic enough fix. |
Is https://github.com/jmcriffey/babel-istanbul relevant to this discussion? |
Also this seems to be very recent and maybe a good addition? https://github.com/istanbuljs/babel-plugin-istanbul |
I was having a similar issue where multiple files should've had 100% branch coverage but only had 75%. There was a weird behavior in that if I added an extra new line after my imports it would fix the branch coverage. Changing the es6 import statements to require statements also fixed this. Trying to make a repo that recreates the bug so that I can post an issue, I realized that the problem went away when I ran Jest with Can any of you having this problem try this as well and check if it works? 🍺 EDIT: I think it's worth mentioning that I tried deleting the cache and that didn't work either. Only using |
@migueloller Can you have a look at #1214? I had similar issues but with just ES5 code |
I'm assuming this is fixed now. @DmitriiAbramov rewrote Jest's code coverage support. Please try with |
This just made my day! @DmitriiAbramov amazing work!!! 😄 |
nice! |
I've created a test repro, as the latest jest did not make a dent in the percentages for us. |
@a-c-m I've Added a pull request to your repo.
install npm test will no longer work for your repo as the path to the jest executable is hardcoded. Running npm test with scripts test changed to |
@lPadier Many thanks, i've merged and also updated the readme. |
@a-c-m I downloaded your project. After install [email protected] or jest@test I have the message "NO TESTS FOUND". At now jest@test is [email protected]. |
Try jest 15. |
@cpojer I changed jest in my project to 15.1.1 and my tests is running now. But I have old problem with ES6 syntax. What other changes do I need to show the coverage of source files, as in Karma? |
@ola-g86 are you using any custom preprocessors? is your project open sourced? |
It is working now. My settings for this: |
Hi, I am using "jest": "20.1.0-delta.3", and "jest-css-modules": "^1.1.0" . Below is my jest configuration "jest": { My .babelrc is as below { Please help me to resolve my problem so that I can have 100% branching and statements in coverage report. Thanks in advance |
@bankimatglobant i think jest-css-modules is missing You can try to submit a PR to jess-css-modules to use |
I was running into this issue. Adding the transform-runtime and sourceMaps: both in my babelrc fixed it. {
"presets": ["es2015", "react", "stage-1"],
"env": {
"test": {
"plugins": ["transform-runtime"],
"sourceMaps": "both"
}
}
} |
@mikeromano38 I have tried above configuration but it's not working. Just one query that what is "stage-1". My babelrc is as mentioned below: { |
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. |
I am currently re-writing my https://github.com/Skelware/node-file-parser package with ES6, but I'm running into an issue where the test coverage appears to be run on the transpiled code, instead of the source code.
src/NodeFileParser.es6
spec/NodeFileParser.spec.es6:
dist/NodeFileParser.js (generated by Babel):
package.json (excerpt):
Console output:
Lcov html output:
I understand that the ES5 code is different from the ES6 code, and contains some boilerplate when transpiled, but it's really annoying when you're trying to cover all of your code, as you have to scroll through the file in your browser to check for any code that's not covered. I guess it's more accurate like this, but it's annoying.
The text was updated successfully, but these errors were encountered: