From e9131cb8cff3a65887e943fb70c1c1caba1bbfd4 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Mon, 12 Feb 2018 22:01:54 -0700 Subject: [PATCH] feat: resolve custom cache directory to absolute path (#766) --- index.js | 2 +- test/nyc.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f27d0deea..7d0350928 100755 --- a/index.js +++ b/index.js @@ -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({ diff --git a/test/nyc.js b/test/nyc.js index ce8239b46..fe2fc828e 100644 --- a/test/nyc.js +++ b/test/nyc.js @@ -1,6 +1,7 @@ /* global describe, it */ const NYC = require('../') +const path = require('path') require('chai').should() @@ -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) + }) + }) })