Skip to content
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

--all flag fails to include tested files, sometimes displays no files at all #849

Closed
ralphholzmann opened this issue May 31, 2018 · 6 comments
Labels

Comments

@ralphholzmann
Copy link

Expected Behavior

nyc -a should list all tested and untested files.

Observed Behavior

nyc -a only lists untested files when called against mocha directly. Tested files are not listed.

nyc -a lists no files when called against npm test.

Bonus Points! Code (or Repository) that Reproduces Issue

https://github.com/ralphholzmann/instanbul-bug

Forensic Information

Operating System: the operating system you observed the issue on.
Mac OS

Environment Information:

https://gist.github.com/ralphholzmann/aa66651e742688942556b42c690b5256

@paulsmirnov
Copy link

Cannot reproduce on Windows with nyc 11.8.0:

D:\...\instanbul-bug>npm run test:coverage                       
                                                                                         
> istanbul-bug@1.0.0 test:coverage D:\...\instanbul-bug          
> cross-env NODE_ENV=test nyc -a npm test                                                
                                                                                         
                                                                                         
> istanbul-bug@1.0.0 test D:\...\instanbul-bug                   
> mocha --require @babel/register                                                        
                                                                                         
                                                                                         
                                                                                         
  Tested file                                                                            
    √ adds one                                                                           
                                                                                         
                                                                                         
  1 passing (32ms)                                                                       
                                                                                         
----------------|----------|----------|----------|----------|-------------------|        
File            |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |        
----------------|----------|----------|----------|----------|-------------------|        
All files       |      100 |      100 |      100 |      100 |                   |        
 tested-file.js |      100 |      100 |      100 |      100 |                   |        
----------------|----------|----------|----------|----------|-------------------|        
                                                                                         
D:\...\instanbul-bug>npm run test:coverage2                      
                                                                                         
> istanbul-bug@1.0.0 test:coverage2 D:\...\instanbul-bug         
> cross-env NODE_ENV=test nyc -a mocha --require @babel/register                         
                                                                                         
                                                                                         
                                                                                         
  Tested file                                                                            
    √ adds one                                                                           
                                                                                         
                                                                                         
  1 passing (39ms)                                                                       
                                                                                         
------------------|----------|----------|----------|----------|-------------------|      
File              |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |      
------------------|----------|----------|----------|----------|-------------------|      
All files         |       50 |      100 |       50 |       50 |                   |      
 tested-file.js   |      100 |      100 |      100 |      100 |                   |      
 untested-file.js |        0 |      100 |        0 |        0 |                 1 |      
------------------|----------|----------|----------|----------|-------------------|

@paulsmirnov
Copy link

paulsmirnov commented Jun 7, 2018

However, "nyc": {..., "all": true} option in package.json doesn't work and that is strange to me (as it is documented in README).

UPD: That was 11.8.0, after upgrading to 12.0.2 even -a command-line switch doesn't work:

D:\...\instanbul-bug>npm run test:coverage2

> istanbul-bug@1.0.0 test:coverage2 D:\...\instanbul-bug
> cross-env NODE_ENV=test nyc -a mocha --require @babel/register



  Tested file
    √ adds one


  1 passing (40ms)

----------------|----------|----------|----------|----------|-------------------|
File            |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------------|----------|----------|----------|----------|-------------------|
All files       |      100 |      100 |      100 |      100 |                   |
 tested-file.js |      100 |      100 |      100 |      100 |                   |
----------------|----------|----------|----------|----------|-------------------|

@coreyfarrell
Copy link
Member

Please see https://github.com/istanbuljs/nyc#require-additional-modules.

I am able to see your issue, but I'm able to fix it by moving --register @babel/core. Your current package.json has:

{
  "scripts": {
    "test": "mocha --require @babel/register",
    "test:coverage": "NODE_ENV=test nyc -a npm test",
    "test:coverage2": "NODE_ENV=test nyc -a mocha --require @babel/register"
  }
}

According to the documentation this would be more correct:

{
  "scripts": {
    "test": "mocha --require @babel/register",
    "test2": "mocha",
    "test:coverage": "NODE_ENV=test nyc -a --require @babel/register npm run test2",
    "test:coverage2": "NODE_ENV=test nyc -a mocha --require @babel/register"
  }
}

Important detail is that you have to pass --require @babel/register to nyc, not mocha. It doesn't seem to matter when mocha is the direct subprocess of nyc, but it does seem to matter when working directly (like nyc -> npm -> mocha). I'm not sure if issues might happen from running NODE_ENV=test nyc -a --require @babel/register npm test (where --require @babel/register is passed to nyc and mocha), that is why my exist shows a `test2 script which excludes it.

@coreyfarrell
Copy link
Member

Another unrelated note, babel-plugin-istanbul is currently written against babel 6. Using it in babel 7 doesn't seem to be causing any issues but I still wanted to mention. I have a PR to switch it to use babel 7 but that is not yet merged and will result in a semver-major version bump.

@brunapereira
Copy link

brunapereira commented Jul 9, 2018

Thanks, @coreyfarrell

"test": "mocha --recursive --require babel-core/register",
"test:coverage": "nyc npm test"

I was facing this issue with the scripts above. When I changed it to

"test": "mocha --recursive --require babel-core/register",
"test:coverage": "nyc --require babel-core/register mocha --recursive"

the library didn't show any inconsistency anymore :)

@stale
Copy link

stale bot commented Jan 5, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jan 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants