Skip to content

Commit b6713a3

Browse files
authored
feat: allow an alternate cache folder to be provided (#443)
1 parent 2828538 commit b6713a3

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function NYC (config) {
5151

5252
this.reporter = arrify(config.reporter || 'text')
5353

54-
this.cacheDirectory = findCacheDir({name: 'nyc', cwd: this.cwd})
54+
this.cacheDirectory = config.cacheDir || findCacheDir({name: 'nyc', cwd: this.cwd})
5555

5656
this.enableCache = Boolean(this.cacheDirectory && (config.enableCache === true || process.env.NYC_CACHE === 'enable'))
5757

test/src/nyc-bin.js

+19
Original file line numberDiff line numberDiff line change
@@ -670,4 +670,23 @@ describe('the nyc cli', function () {
670670
})
671671
})
672672
})
673+
674+
it('allows an alternative cache folder to be specified', function (done) {
675+
var args = [bin, '--cache-dir=./foo-cache', '--cache=true', process.execPath, './half-covered.js']
676+
677+
var proc = spawn(process.execPath, args, {
678+
cwd: fixturesCLI,
679+
env: env
680+
})
681+
proc.on('close', function (code) {
682+
code.should.equal(0)
683+
// we should have created ./foo-cache rather
684+
// than the default ./node_modules/.cache.
685+
fs.readdirSync(path.resolve(
686+
fixturesCLI, './foo-cache'
687+
)).length.should.equal(1)
688+
rimraf.sync(path.resolve(fixturesCLI, 'foo-cache'))
689+
done()
690+
})
691+
})
673692
})

0 commit comments

Comments
 (0)