-
-
Notifications
You must be signed in to change notification settings - Fork 359
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
Custom cache directory should be resolved to an absolute path #765
Comments
This is easily reproducible by simply changing the working directory of the process in a test: describe('cache directory problem', () => {
it('should put .nyc_cache in different folder', () => {
process.chdir('another_folder')
// require some code that nyc is going to cache
})
}) Naturally, this only happens if the cache operation is triggered after the working directory change...so we're talking code which is loaded dynamically. |
@mojavelinux agreed, this sounds like a bug; any interest in submitting a failing test? |
Already did. Check the PR. #766. |
As a bonus, I added a test for both cases. |
I discovered this bug when my test suite started throwing errors trying to write the nyc cache files. Since the cache folder was moving, it was getting caught up in the clean up script that runs in the beforeEach of my suite. When nyc tried to write to the cache folder, it was gone. |
Thanks for the fix, looks like this released in |
Expected Behavior
I expect nyc to consistently use the same cache directory throughout the process. When a custom cache directory is specified as a relative path, and the working directory of the process changes, this assumption is violated.
The custom cache path needs to be resolved to an absolute path (using
path.resolve()
) before it's used.Observed Behavior
If a custom cache directory is specified as a relative path (such as in package.json), and the working directory of the process is changed by one of the tests, then the cache directory will be recreated in a new location for that portion of the test suite. This puts cache files in an unexpected location and defeats the purpose of having a cache.
If the cache directory is left unspecified, then nyc correctly resolves the value to an absolute path. It's the custom path that isn't being resolved.
See: https://github.com/istanbuljs/nyc/blob/master/index.js#L52
This line needs to be:
Forensic Information
Operating System: Fedora 26 (Linux)
Environment Information:
Node: v8.9.3
npm: 5.5.1
yarn: 1.3.2
nyc: 11.4.1
The text was updated successfully, but these errors were encountered: