title: Configuring jest for code coverage when code is symlinked in node_modules
body: <p>I am attempting to restructure a Node project using Jest for testing.  Initially, I had all of my <code>.js</code> and <code>.test.js</code> files in the same directory, and all was well in the world— <em>i.e.</em> <code>jest --coverage</code> did what I expected.</p>
  
  <p>I've changed my directory structure now, and testing works, but my coverage reporting does not.</p>
  
  <p>Here is my directory structure, edited to remove <code>node_modules</code> <em>except</em> for a symlink to my <code>lib</code> folder.  I am following <a href="https://github.com/substack/browserify-handbook#avoiding-" rel="nofollow noreferrer">this hint</a> for <code>requiring</code> my module by symlink.</p>
  
  <pre><code>❯ tree
  .
  ├── README.md
  ├── build
  │   └── index.js
  ├── jest.config.js
  ├── lib
  │   ├── path.js
  │   ├── pen.js
  │   ├── section.js
  │   ├── sprite.js
  │   └── utilities.js
  ├── node_modules
  │   ├── itch &lt;= symlink to my `lib` folder
  ├── package-lock.json
  ├── package.json
  └── test
      ├── env
      │   └── foo.html
      ├── path.test.js
      ├── pen.test.js
      ├── section.test.js
      ├── sprite.test.js
      └── utilities.test.js
  </code></pre>
  
  <p>Here is my <code>jest.config.js</code></p>
  
  <pre><code>module.exports = {
    verbose: true,
    collectCoverage: true,
    collectCoverageFrom: ["**/lib/**/*.js", "**/test/**/*.js"]
  };
  </code></pre>
  
  <p>and here is my <code>scripts</code> in <code>package.json</code></p>
  
  <pre><code>"scripts": {
      "test": "jest",
      "build": "mkdir -p ./dist &amp;&amp; browserify index.js --standalone Itch &gt; ./dist/itch.js"
  }
  </code></pre>
  
  <p><code>npm test</code> works, except my code coverage report is all <code>0</code>, as:</p>
  
  <pre><code>Test Suites: 5 passed, 5 total
  Tests:       38 passed, 38 total
  Snapshots:   0 total
  Time:        1.316s
  Ran all test suites.
  --------------|----------|----------|----------|----------|----------------|
  File          |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
  --------------|----------|----------|----------|----------|----------------|
  All files     |        0 |        0 |        0 |        0 |                |
   path.js      |        0 |        0 |        0 |        0 |... 109,111,115 |
   pen.js       |        0 |        0 |        0 |        0 |... 106,107,113 |
   section.js   |        0 |        0 |        0 |        0 |... 89,90,92,95 |
   sprite.js    |        0 |        0 |        0 |        0 |... 200,202,205 |
   utilities.js |        0 |        0 |        0 |        0 |... 55,57,58,62 |
  --------------|----------|----------|----------|----------|----------------|
  </code></pre>
  
  <p>But when I return to the <code>.js</code> and <code>.test.js</code> files being in the same directory, my code coverage is <code>100%</code>.</p>
  
  <p>I assume my issue is either with my <code>collectCoverageFrom</code> variable and/or my use of a symlink to <code>require</code> my modules.</p>
  
  <p>Prompted by <a href="https://github.com/facebook/jest/issues/98" rel="nofollow noreferrer">this issue</a>, I also tried adding a <code>package.json</code> with the same <code>name</code> attribute as my package into my <code>lib</code> directory, to no avail.</p>
  
  <p>In order to test the idea that the issue was with the symlink, I also tried removing the symlink and moving my <code>lib</code> folder directly into my <code>node_modules</code> folder.  Then, when I ran <code>npm test</code>, I received all <code>Unknown</code> test coverage, <em>viz.</em></p>
  
  <pre><code>Test Suites: 5 passed, 5 total
  Tests:       40 passed, 40 total
  Snapshots:   0 total
  Time:        1.576s
  Ran all test suites.
  ----------|----------|----------|----------|----------|----------------|
  File      |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
  ----------|----------|----------|----------|----------|----------------|
  All files |  Unknown |  Unknown |  Unknown |  Unknown |                |
  ----------|----------|----------|----------|----------|----------------|
  </code></pre>
  
  <p>So now, I'm a bit stuck.  Any help would be appreciated.  Thank you!</p>