gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 786 forks source link

Seems Istanbul doesn't follow symlinks with --hook-run-in-context #635

Open vitkarpov opened 8 years ago

vitkarpov commented 8 years ago

Hey, guys!

Seems:

I describe the problem more detailed.

I have the following file stucture:

components
  foo.js

tests
  spec
    foo.js
  node_modules -> ../components

node_modules inside tests is a symlink for components folder which is one level higher. It's done for more convenient require modules.

Important detail is that I run Istanbul from tests folder, not from the root where tests and components are on the same level. It's done 'cause seems Istanbul parses all the files from all the folders in the root and it takes very long time.

So, test/spec/foo.js contains:

// node resolves the path correctly as mocha words fine
var foo = require('foo.js');

describe('foo', function() {
    it('should return foo', function() {
        expect(foo).to.be.equal('foo');
    })
})

I've tried to move foo-module.js right inside tests folder and require with explicit path ../foo-module.js (from tests/spec folder) — it works as expected. Coverage has 2 folders: tests and tests/spec with corresponding files inside.

In the first case, I get only foo.js (from tests/spec) in the coverage.

Seems there're two options:

Does anyone run something similar?

@gotwarlost @davglass If my assumptions are right, give me any hint why it's happening and I'll try to make a pr or work around it somehow.

Thanks!