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 does not work with symlinks

See original GitHub issue

I reproduced the issue in this repo: https://github.com/aalexgabi/nyc-symlink-problem/commit/3ce1fe85f2f8bb723a2ede92bf1d9a324655c8e2 When I don’t use a symlink it does work: https://github.com/aalexgabi/nyc-symlink-problem/commit/9da9355e8111233e8efa38f85aef9de2f6fd713c

This was reported many times (not sure all issues here are due to symlinks) but not fixed:

Expected Behavior

I should have symlinked files from node_modules included:

running
working
ran
-----------------------|---------|----------|---------|---------|-------------------
File                   | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
-----------------------|---------|----------|---------|---------|-------------------
All files              |     100 |      100 |     100 |     100 |                   
 src                   |     100 |      100 |     100 |     100 |                   
  test.js              |     100 |      100 |     100 |     100 |                   
 src/node_modules/work |     100 |      100 |     100 |     100 |                   
  index.js             |     100 |      100 |     100 |     100 |                   
-----------------------|---------|----------|---------|---------|-------------------

Observed Behavior

I don’t have symlinked files from node_modules included:

running
working
ran
----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |     100 |      100 |     100 |     100 |                   
 test.js  |     100 |      100 |     100 |     100 |                   
----------|---------|----------|---------|---------|-------------------

Troubleshooting steps

  • still occurring when I put cache: false in my nyc config

Environment Information

% npx envinfo@latest --preset nyc
npx: installed 1 in 0.741s

  System:
    OS: Linux 5.5 Manjaro Linux
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 887.34 MB / 15.52 GB
  Binaries:
    Node: 13.7.0 - ~/.fnm/current/bin/node
    Yarn: 1.22.0 - /usr/bin/yarn
    npm: 6.13.6 - ~/.fnm/current/bin/npm
  npmPackages:
    nyc: ^15.0.1 => 15.0.1 

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
coreyfarrellcommented, Apr 7, 2020

Coverage of files outside the project isn’t supported. It might work for you to tweak your settings as follows:

"cwd": "..",
"include": [
  "project/src/**",
  "lib/**"
]

The cwd says that the project root is the directory above process.cwd(), the include options are modified to be relative to the explicitly set cwd. Note that unlike other options the cwd option has slightly different meaning when provided to CLI vs when provided in config. If you ran nyc --cwd .. then this would prevent nyc from finding project/.nycrc. Thus you have to put the cwd option into project/.nycrc.

2reactions
rwalle61commented, Feb 27, 2021

@coreyfarrell thanks for the cwd suggestion - it worked like a charm! Now I can test coverage across multiple packages in my monorepo (a yarn workspace):

"cwd": "..",
"include": [
  "packageA",
  "packageBRequiresPackageA"
]

Think it would be worth documenting this for people using monorepos

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Complete Guide to Creating Symbolic Links (aka ...
You can create symbolic links using the mklink command in a Command Prompt window as Administrator. To open one, locate the “Command Prompt” ......
Read more >
Creating a symlink directory on a network share to a path ...
#File Not Found UNC paths don't work: 1) navigate to a network share: pushd \\windows2008server\share\ 2) make a symlink:
Read more >
Symbolic link - Wikipedia
In computing, a symbolic link (also symlink or soft link) is a file whose purpose is to point to a file or directory...
Read more >
If circular symlinks are useless, then why are they allowed?
They seem to say conclusively that there is no reason one would ever create such a circular symlink, and therefore it must have...
Read more >
How to Create Symbolic Links: A Comprehensive Guide
What Does a Symbolic Link Do? A symbolic link points to the original file on your system but doesn't contain data in 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