Skip to content

Custom cache directory should be resolved to an absolute path #765

@mojavelinux

Description

@mojavelinux

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:

this.cacheDirectory = path.resolve(config.cacheDir) || findCacheDir({name: 'nyc', cwd: this.cwd})

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions