Skip to content

Commit dd48707

Browse files
mojavelinuxbcoe
authored andcommitted
feat: resolve custom cache directory to absolute path (#766)
1 parent d19fc4f commit dd48707

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function NYC (config) {
4949
this.cwd = config.cwd || process.cwd()
5050
this.reporter = arrify(config.reporter || 'text')
5151

52-
this.cacheDirectory = config.cacheDir || findCacheDir({name: 'nyc', cwd: this.cwd})
52+
this.cacheDirectory = (config.cacheDir && path.resolve(config.cacheDir)) || findCacheDir({name: 'nyc', cwd: this.cwd})
5353
this.cache = Boolean(this.cacheDirectory && config.cache)
5454

5555
this.exclude = testExclude({

test/nyc.js

+18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* global describe, it */
22

33
const NYC = require('../')
4+
const path = require('path')
45

56
require('chai').should()
67

@@ -27,4 +28,21 @@ describe('NYC', function () {
2728
nyc._disableCachingTransform().should.equal(false)
2829
})
2930
})
31+
32+
describe('cacheDirectory', function () {
33+
it('should resolve default cache folder to absolute path', function () {
34+
const nyc = new NYC({
35+
cache: true
36+
})
37+
path.isAbsolute(nyc.cacheDirectory).should.equal(true)
38+
})
39+
40+
it('should resolve custom cache folder to absolute path', function () {
41+
const nyc = new NYC({
42+
cacheDir: '.nyc_cache',
43+
cache: true
44+
})
45+
path.isAbsolute(nyc.cacheDirectory).should.equal(true)
46+
})
47+
})
3048
})

0 commit comments

Comments
 (0)