-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
add --all functionality #4
Comments
see also: dtinth/babel-plugin-__coverage__#38 |
@gotwarlost @dtinth, any thoughts as to how we might approach adding blank coverage for all files, without messing with the babel cache? Perhaps we could just walk all the files, and add fake entries in |
Do you think this would be possible todo in the babel-plugin itself? To me it looks more like that nyc should traverse all files and add blank coverage before running the tests. Because on a test-suite without tests, the plugin wouldn't be called at all, but you might still want to get an report telling you 0% right? I would like to give this a shoot over the weekend, so if you have hints were to start let me know please. |
@danez I'm not 100% sure of the best solution; folks might be using different approaches to instrumenting code with babel, etc., so my temptation was to try to do it in the plugin layer -- the other reason being that the plugin knows about my temptation was to think about logic similar to I'm not an expert with babel, so I'm sure your approach might be better, really I'm open to experimentation. |
I had a look, but I couldn't figure out an easy way to do this and spent most of the time understanding how nyc works :) Maybe shipping an instrumenter adapter with this repo for nyc (like the noop.js) that handles and knows how to load stuff that was processed by this plugin. I won't have time to look into to this again in the next weeks. |
Referenced to get nyc/istanbul reporting properly with tests transpiled inline: https://github.com/react-bootstrap/react-prop-types (as of v0.4.0) Note on source maps: Source map support comes with `mocha --compilers js:babel-register`, which seems to enable source maps to work in tests but not in the compiled output. Adding `import 'source-map-support/register'` to the src enables source maps to work in compiled code but break in tests. Including source-map-support in src and requiring source-map-support before babel-register when running mocha (instead of passing the compilers option) appears to get both. Referenced to get source maps working in test and compiled output: evanw/node-source-map-support#121 Notes on coverage: nyc's "--all" option to include reports for files that are not required is currently not working with babel-plugin-istanbul, but they're aware of the matter. Also, including reporter settings in the nyc stanza of package.json appear to trample command line options, so those were moved to the npm test script instead. Related issues: istanbuljs/nyc#333 istanbuljs/babel-plugin-istanbul#4
Referenced to get nyc/istanbul reporting properly with tests transpiled inline: https://github.com/react-bootstrap/react-prop-types (as of v0.4.0) Note on source maps: Source map support comes with `mocha --compilers js:babel-register`, which seems to enable source maps to work in tests but not in the compiled output. Adding `import 'source-map-support/register'` to the src enables source maps to work in compiled code but break in tests. Including source-map-support in src and requiring source-map-support before babel-register when running mocha (instead of passing the compilers option) appears to get both. Referenced to get source maps working in test and compiled output: evanw/node-source-map-support#121 Notes on coverage: nyc's "--all" option to include reports for files that are not required is currently not working with babel-plugin-istanbul, but they're aware of the matter. Also, including reporter settings in the nyc stanza of package.json appear to trample command line options, so those were moved to the npm test script instead. Related issues: istanbuljs/nyc#333 istanbuljs/babel-plugin-istanbul#4
Hi, any news about this enhancement? |
has there been any update on this? |
Any plans on working on this? |
My thoughts so far: The correct representation for "uncovered file" is not some null object but rather a coverage object (with zero hit counts but also a list of statements, branches etc) that has not seen any line executed. IOW it is a byproduct of the instrumentation step. The correct way to get at that data, with the least amount of duplicated work, seems to be to parse the instrumented files and statically evaluate the initial coverage object. |
If anyone wants to save me some digging (@bcoe?) I'd appreciate a quick explanation of how the coverage variable gets named. |
@motiz88 I would definitely love to add the https://github.com/istanbuljs/nyc/blob/master/index.js#L163 I think we might be able to use this as a starting point. |
@motiz88 the coverage variable is generated here for a given file: https://github.com/istanbuljs/istanbul-lib-instrument/blob/master/src/visitor.js#L13 My gut is we can probably use something similar to the approach used in |
@bcoe That does seem to be the shell of a solution. The core then would be extracting this empty report from each already-instrumented file. We could in theory re-parse the original file with a modified version of the instrumenting visitor; but the user's babel pipeline is largely outside our control (as Therefore my approach is to try and statically extract the already-computed "empty coverage" object from each instrumented file. Looking at the code I think we would need to:
If we made it through these 5 steps - we now have the equivalent of |
I'm going to work on this as a PR to |
…rumented file In support of finally fixing istanbuljs/babel-plugin-istanbul#4. Blocked on a babel-traverse release that includes babel/babel#4746
@bcoe With |
@wojtkowiak @lughino @benhunsaker @danez, thanks to the hard work of @motiz88 there is now support for
Your test script will end up looking something like this:
With babel configuration like so: {"babel": {
"presets": [
"es2015"
],
"env": {
"test": {
"plugins": [
"istanbul"
]
}
}
},
"nyc": {
"include": [
"src/**/*.js"
],
"exclude": [
"node_modules"
],
"require": [
"babel-register"
],
"sourceMap": false,
"instrument": false
}} |
I am possibly not doing it right, but the following command & .babelrc do not generate coverage for files that are not imported anywhere (but are included in the source directory): NODE_ENV=test \
nyc --all --include="src/**/*js" --sourceMap=false --instrument=false --reporter=lcov --reporter=text-summary --report-dir=coverage/ \
mocha --compilers js:babel-core/register --require babel-polyfill tests/* (I also tried {
"presets": ["latest", "stage-0"],
"env": {
"test": {
"plugins": [
["istanbul", {"include": ["src/**"]}],
"rewire"
]
}
}
} The { NYC_CACHE: 'disable',
NYC_CONFIG: '{"_":["/Users/david/Projects/scraping/node_modules/abc-environment/node_modules/.bin/mocha"],"silent":false,"s":false,"all":true,"a":true,"cache":false,"c":false,"check-coverage":false,"checkCoverage":false,"source-map":false,"sourceMap":false,"instrument":false,"hook-run-in-context":true,"hookRunInContext":true,"show-process-tree":false,"showProcessTree":false,"help":false,"h":false,"version":false,"include":["src/"],"n":"src/","reporter":["lcov","text-summary"],"r":["lcov","text-summary"],"report-dir":"coverage/","reportDir":"coverage/","exclude":["test/**","test{,-*}.js","**/*.test.js","**/__tests__/**","**/node_modules/**"],"x":["test/**","test{,-*}.js","**/*.test.js","**/__tests__/**","**/node_modules/**"],"require":[],"i":[],"extension":[],"e":[],"branches":0,"functions":0,"lines":90,"statements":0,"cwd":"/Users/david/Projects/scraping","$0":"/Users/david/Projects/scraping/node_modules/abc-environment/node_modules/.bin/nyc","instrumenter":"./lib/instrumenters/noop"}',
NYC_CWD: '/Users/david/Projects/scraping',
NYC_ROOT_ID: '135f9ea6c441b825034943c4b7aeff0f',
BABEL_DISABLE_CACHE: 1,
NYC_INSTRUMENTER: './lib/instrumenters/noop' } |
@queicherius could I get you to push this testing branch somewhere? |
@bcoe Sure, here you go. |
From a quick test of the repo @queicherius put up, if I pass |
I found for amazon-archives/amazon-cognito-identity-js#154 I had to add the following: --- i/package.json
+++ w/package.json
@@ -69,7 +69,12 @@
"timeout": "30s"
},
"nyc": {
+ "all": true,
"cache": true,
+ "include": "src",
+ "require": [
+ "babel-register"
+ ],
"sourceMap": false,
"instrument": false
} This is a pain as
That said, it does work, so 👍 |
Ah, if I also add --- i/.babelrc
+++ w/.babelrc
@@ -2,6 +2,9 @@
"presets": [
"es2015"
],
+ "only": [
+ "src"
+ ],
"env": {
"nyc": {
"sourceMaps": "inline", |
Works flawlessly, thanks @motiz88 ! |
@queicherius from my testing, the problem was that {"nyc": {
"include": ["src/*.js"],
"require": "babel-core/register"
}}
I've added a note that we should add this to our docs: #67 |
There are two things I don't really get, which worries me:
My guess for 2, at least, is that it "works" because If this is what's at work here, then it seems rather brittle: users could move out the Babel cache, not have it populated at the time of running tests, or worse, have it populated with stale data / files they'd already deleted... |
@bcoe so from my testing
|
@queicherius this works for me:
Trying to reproduce your issue: @motiz88 let me try to address your worries: Why would nyc requiring babel-register (aka babel-core/register) make any difference? When you run When
My guess for 2, at least, is that it "works" because nyc is running into the Babel cache folder The babel cache is turned off at the top of |
@bcoe Ohh, that makes sense. I was wondering about that "fake require" stuff. |
Is there some concise guide on how to do this? My coverage takes ages now, but still doesnt deliver correct results. |
I tried to setup this for babel/babylon. I can get it work but with major performance problems and only by using babel-register. Till now the setup looks like this:
{
"nyc": {
"include": [
"src/",
"bin/"
],
"sourceMap": false,
"instrument": false
}
} So far so good, this generates coverage for all tested files and takes 8s to run 2327 tests. Now i changed the config of nyc to {
"nyc": {
"all": true,
"include": [
"src/",
"bin/"
],
"require": [
"babel-register"
],
"sourceMap": false,
"instrument": false
}
} and run nyc with So if I understand correctly there is currently no way to use --all without babel-register? I appreciate the work that has been done on this, but it seems a little bit to opinionated and complicated right now. Maybe we could have an option to tell the noop instrumenter where the instrumented code is in the case it is not generated on demand? |
@danez I know @motiz88 implemented this without the @motiz88 perhaps you could provide some instructions about how you would picture using |
@danez I ran into that too, I fixed it by adding an It looks like you will end up double-transpiling the sources you do load in tests, once for your pre-compile, once for your tests: to make it faster you could not use the transpile output for tests. |
Probably a misconfiguration, but I still don't see all the files being covered with // package.json
"devDependencies": {
"babel-core": "^6.18.2",
"babel-plugin-istanbul": "^3.0.0",
"nyc": "^9.0.1" // nyc@next resolve to 9.0.1-candidate.1; also tried that
},
"babel": {
"presets": ["es2015", "stage-2"],
"comments": false,
"env": {
"test": {
"comments": true,
"sourceMaps": "inline",
"plugins": ["istanbul"]
}
}
},
"nyc": {
"all": true,
"cache": true,
"include": [
"api/src/**/*.js",
"web/src/**/*.js"
],
"reporter": [
"lcov",
"text-summary"
],
"require": [
"babel-register"
],
"sourceMap": false,
"instrument": false
} I see all the files if I take away |
Is there some pull request or other issue which tracks the "release state" of this issue? This issue is closed, but I can't find information if it is released or not and in which version. |
@hoschi @justin-lau @boui if you're continuing have issues with |
@bcoe is it released already? I got no answer to my last question. |
I still can't get this to work. I just installed all things, so they are at their latest version. Can someone please provide feedback on this? I just had 2 hellish days trying to get unit testing with jasmine to work with reporting and coverage.... this would be the last step. |
Any progress on this one? |
I still don't understand how to get this working. Should this issue really be in a closed state? |
Please give a good documentation about this. Still don't know how to get |
@maple-leaf there's a link in the README to a slack channel; this might be a good place to field your question |
we need to figure out a way for
--all
to work with this instrumentation approach, we might be able to work backwards from the--all
functionality in nyc.The text was updated successfully, but these errors were encountered: