diff --git a/lib/report.js b/lib/report.js index d3c8806d..99e56e72 100644 --- a/lib/report.js +++ b/lib/report.js @@ -44,6 +44,7 @@ class Report { excludeNodeModules: excludeNodeModules }) this.excludeAfterRemap = excludeAfterRemap + this.excludeShouldInstrumentCache = new Map() this.omitRelative = omitRelative this.sourceMapCache = {} this.wrapperLength = wrapperLength @@ -96,7 +97,7 @@ class Report { const path = resolve(this.resolve, v8ScriptCov.url) const converter = v8toIstanbul(path, this.wrapperLength, sources, (path) => { if (this.excludeAfterRemap) { - return !this.exclude.shouldInstrument(path) + return !this._shouldInstrument(path) } }) await converter.load() @@ -287,7 +288,7 @@ class Report { } } if ((!this.omitRelative || isAbsolute(v8ScriptCov.url))) { - if (this.excludeAfterRemap || this.exclude.shouldInstrument(v8ScriptCov.url)) { + if (this.excludeAfterRemap || this._shouldInstrument(v8ScriptCov.url)) { result.push(v8ScriptCov) } } @@ -311,6 +312,23 @@ class Report { } return cache } + + /** + * this.exclude.shouldInstrument with cache + * + * @private + * @return {boolean} + */ + _shouldInstrument (filename) { + const cacheResult = this.excludeShouldInstrumentCache.get(filename) + if (cacheResult !== undefined) { + return cacheResult + } + + const result = this.exclude.shouldInstrument(filename) + this.excludeShouldInstrumentCache.set(filename, result) + return result + } } module.exports = function (opts) {