NYC fails to instrument files that have private class methods (#method(){})
See original GitHub issueExample problem_file.js:
class a {
#method(){}
}
nyc --all --cache=false node ./problem_file.js
Expected Behavior
To have the file show up in the listed output.
Observed Behavior
The file does not show up in the list
Troubleshooting steps
If you look at the node_module/.cache you see the file was not actually instrumented.
Environment Information
System: OS: macOS 11.1 CPU: (8) x64 Intel® Core™ i7-4870HQ CPU @ 2.50GHz Memory: 79.61 MB / 16.00 GB Binaries: Node: 14.15.4 - ~/.nvm/versions/node/v14.15.4/bin/node Yarn: 1.22.10 - ~/.nvm/versions/node/v14.15.4/bin/yarn npm: 6.14.10 - ~/.nvm/versions/node/v14.15.4/bin/npm npmPackages: nyc: ^15.1.0 => 15.1.0
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to mock private method for testing using PowerMock?
I don't see a problem here. With the following code using the Mockito API, I managed to do just that : public class...
Read more >Context | Android Developers
Delete the given private file associated with this Context's application ... Because the service must be an isolated process, it will not have...
Read more >Ruby Private & Protected Methods - RubyGuides
What is a private method in Ruby? It's a type of method that you can ONLY call from inside the class where it's...
Read more >How To Test Private Methods in Typescript
We want to be sure the error method private returns the message. We can't test because it is private, we can't test, but...
Read more >Private Methods in Python - GeeksforGeeks
However, to define a private method prefix the member name with the double ... The above example shows that private methods of the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
nyc uses babel internally and does allow for configuration of the
parserPlugins
that are used. By default this does not includeclassPrivateMethods
as no version of node.js supported that when the latest release was cut. This can be added at https://github.com/istanbuljs/schema/blob/c7747f7a7df8a2b770036834af77dfd0ee445733/index.js#L121-L141 along with any additional babel parser plugins which would be needed to parse code supported directly by any release of node.js. The full list of parser plugins are at https://babeljs.io/docs/en/babel-parser#plugins.For reference the best way in the mean time to support this for your project is to create
nyc.config.cjs
:I’ve created https://github.com/istanbuljs/schema/issues/16 for this since the fix would go in that module.
babel parser plugins are all built-in, babel does not support 3rd party parser plugins so the complete list for the current version of
@babel/parser
is at https://babeljs.io/docs/en/babel-parser#plugins. Normal babel plugins are a different thing from parser plugins.I’ve made a new in-range release of
@istanbuljs/schema
which sets nyc’s default babel parser features to match the capabilities of node.js 15.8.0.