pocesar/grunt-mocha-istanbul

Invalid symlinks causes grunt-mocha-istanbul to fail

Closed this issue · 6 comments

I have the following config in my Gruntfile:

mocha_istanbul: {
			server: {
				src: [
					'mocha.hooks/*.spec.js',
					'build/klaus.*/**/test/*.spec.js',
					'mocha.hooks/*.spec.server.js',
					'build/klaus.*/**/test/*.spec.server.js',
				],
				options: {
					reportFormats: ['lcovonly']
				}
			}
		},

All works fine until I create a sym link to a file with extension '.js', which points to a not existing path. It seems not to matter, where I place that broken link.

$ ln -sT src/bar.js src/foo.js
$ ls -la src
$ grunt mocha_istanbul:server --debug
For remote client tests make sure you are connected to VPN.
Testing on 10.8.0.6:9876
Running "mocha_istanbul:server" (mocha_istanbul) task
[D] Task source: /home/mk/work/4.5.1/workspace2/cloud/node_modules/grunt-mocha-istanbul/tasks/index.js
/home/mk/work/4.5.1/workspace2/cloud/node_modules/istanbul/lib/cli.js:42
            throw ex; // turn it into an uncaught exception
            ^

Error: ENOENT: no such file or directory, stat '/home/mk/work/4.5.1/workspace2/cloud/src/foo.js'
    at Error (native)
>> 
Warning: Task "mocha_istanbul:server" failed. Use --force to continue.
Error: Task "mocha_istanbul:server" failed.
    at Task.<anonymous> (/home/mk/work/4.5.1/workspace2/cloud/node_modules/grunt/lib/util/task.js:205:15)
    at Timeout._onTimeout (/home/mk/work/4.5.1/workspace2/cloud/node_modules/grunt/lib/util/task.js:241:33)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)

Aborted due to warnings.

I am unsure, whether the issue comes from grunt-mocha-istanbul, mocha-istanbul or istanbul itself.

I tried it with versions 3.0.1 and 5.0.2.

yeah, from what it seems it's a problem with istanbul. the exception from istanbul cli is being passed to the task through the child_process error event listener.
it seems a problem that should have been fixed by now though gotwarlost/istanbul#206

but anyway, I think it's correct behavior low-level point-of-view. istanbul gets a path, it'll try to instrument the code, but the path doesn't exist, so it should fail like trying to do streams using linux shell

The issue there was reported to be closed in December 2014. My istanbul reports to be version 0.4.5, which is the latest by now, so I guess that issue should be solved.

Also - unlike in that issue, this issue is not, that istanbul does not follow symlinks, but, instead it tries to follow an arbitrary symlink, only, because it has the extension .js.

I would open an issue on istanbul, if we are sure, that grunt-mocha-istanbul does not pass that broken symlink to istanbul as input file somehow. My globbing patterns should not include that file, right? Then istanbul would - for whatever reason - search the whole projects file tree for files (and symlinks) ending with '.js' and try to open without correctly checking for their existence?

I guess the problem would be with grunt then, since it's the one that decides which files should be passed to the task. couldn't find any related issue on there, you might want to report it

I'm not aware of grunt inner workings, on how it determines what is a valid symlink, what isn't. I know it uses globstar / minimatch underneath, so it could also boil down to that. lstat calls are expensive and not portable, that's why I think it's left off, for performance and compatibility reasons

But again: why should it even test src/foo.js given the glob patterns above... Especially as there is no issue with all other grunt modules using similar patterns, I doubt, that it is grunt.

So I will report it against istanbul, maybe someone there has an idea.

it's odd indeed, maybe istanbul is trying to instrument everything it finds in CWD. you could try and use the options.excludes and options.includes to see if you can filter out and istanbul stops complaining about it

you can also execute the task with --verbose --debug flags, as it will show you a list of files it's gathering. if it's the grunt task that is putting the .js symlink in that, then it's a problem with grunt, otherwise it might be istanbul being greedy

Thanks for the pointer. foo.js does not come up in the debug list. Also invoking istanbul directly with an "empty" node command leads to the very same issue. I reported an issue against istanbul: gotwarlost/istanbul#747

I close this ticket for the moment.