question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NYC fails to instrument files that have private class methods (#method(){})

See original GitHub issue

Example 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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
coreyfarrellcommented, Feb 5, 2021

nyc uses babel internally and does allow for configuration of the parserPlugins that are used. By default this does not include classPrivateMethods 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:

'use strict';

const {parserPlugins} = require('@istanbuljs/schema').defaults.nyc;
module.exports = {
  parserPlugins: [
    ...parserPlugins,
    'classPrivateMethods'
  ]
};

I’ve created https://github.com/istanbuljs/schema/issues/16 for this since the fix would go in that module.

0reactions
coreyfarrellcommented, Feb 13, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found