Skip to content

Commit

Permalink
feat: resolve custom cache directory to absolute path (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux authored and bcoe committed Feb 13, 2018
1 parent d19fc4f commit dd48707
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function NYC (config) {
this.cwd = config.cwd || process.cwd()
this.reporter = arrify(config.reporter || 'text')

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

this.exclude = testExclude({
Expand Down
18 changes: 18 additions & 0 deletions test/nyc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* global describe, it */

const NYC = require('../')
const path = require('path')

require('chai').should()

Expand All @@ -27,4 +28,21 @@ describe('NYC', function () {
nyc._disableCachingTransform().should.equal(false)
})
})

describe('cacheDirectory', function () {
it('should resolve default cache folder to absolute path', function () {
const nyc = new NYC({
cache: true
})
path.isAbsolute(nyc.cacheDirectory).should.equal(true)
})

it('should resolve custom cache folder to absolute path', function () {
const nyc = new NYC({
cacheDir: '.nyc_cache',
cache: true
})
path.isAbsolute(nyc.cacheDirectory).should.equal(true)
})
})
})

0 comments on commit dd48707

Please sign in to comment.