diff --git a/lib/converter/untested.js b/lib/converter/untested.js index 64168e0..a494b96 100644 --- a/lib/converter/untested.js +++ b/lib/converter/untested.js @@ -146,8 +146,8 @@ const saveUntestedFileSource = async (entryFile, options) => { const getUntestedCoverageData = async (entryList, options, coverageType) => { - // save all empty coverage - const dataId = Util.uid(); + // save all empty coverage, 20 - 5(empty) + const dataId = Util.uid(15, 'empty'); const results = { id: dataId }; @@ -166,15 +166,14 @@ const getUntestedCoverageData = async (entryList, options, coverageType) => { for (const entry of entryList) { // for raw report: source file + // id, url, source, sourceMap await saveUntestedFileSource(entry, options); - const { type, url } = entry; - if (coverageType === 'istanbul') { // =============================================== const item = { - path: fileURLToPath(url), + path: fileURLToPath(entry.url), statementMap: {}, fnMap: {}, branchMap: {}, @@ -189,20 +188,7 @@ const getUntestedCoverageData = async (entryList, options, coverageType) => { } else { // =============================================== - if (type === 'js') { - // empty js - entry.functions = entry.functions || [{ - functionName: '', - ranges: [{ - startOffset: 0, - endOffset: entry.source.length, - count: 0 - }] - }]; - } else { - // empty css - entry.ranges = entry.ranges || []; - } + Util.setEmptyV8Coverage(entry); const item = { ... entry diff --git a/lib/utils/util.js b/lib/utils/util.js index be40d5d..7fa96ff 100644 --- a/lib/utils/util.js +++ b/lib/utils/util.js @@ -272,6 +272,27 @@ const Util = { return handler; }, + setEmptyV8Coverage: (entry) => { + if (entry.type === 'css') { + // empty css + if (!entry.ranges) { + entry.ranges = []; + } + } else { + // empty js + if (!entry.functions) { + entry.functions = [{ + functionName: '', + ranges: [{ + startOffset: 0, + endOffset: entry.source ? entry.source.length : 0, + count: 0 + }] + }]; + } + } + }, + saveSourceCacheFile: async (sourceData, options, fileCache) => { const { cacheName, cachePath } = Util.getCacheFileInfo('source', sourceData.id, options.cacheDir); diff --git a/lib/v8/v8.js b/lib/v8/v8.js index 5b2b843..672063a 100644 --- a/lib/v8/v8.js +++ b/lib/v8/v8.js @@ -109,11 +109,11 @@ const initV8ListAndSourcemap = async (mcr, v8list) => { distFile: entry.distFile }; - // coverage - if (data.type === 'js') { - data.functions = entry.functions; - } else { + // coverage info + if (data.type === 'css') { data.ranges = entry.ranges; + } else { + data.functions = entry.functions; } // resolve source path @@ -213,10 +213,10 @@ const mergeV8Coverage = async (dataList, sourceCache, options) => { for (const id of mergeIds) { const itemList = mergeMap[id]; const item = itemMap[id]; - if (item.type === 'js') { - item.functions = await mergeJsFunctions(itemList); - } else { + if (item.type === 'css') { item.ranges = await mergeCssRanges(itemList); + } else { + item.functions = await mergeJsFunctions(itemList); } } @@ -236,16 +236,21 @@ const mergeV8Coverage = async (dataList, sourceCache, options) => { const mergedList = emptyList.concat(Object.values(itemMap)); // try to load coverage and source by id - for (const item of mergedList) { - const { id } = item; - const json = sourceCache.get(id); + for (const entry of mergedList) { + const json = sourceCache.get(entry.id); if (json) { - item.source = json.source; - item.sourceMap = json.sourceMap; + entry.source = json.source; + entry.sourceMap = json.sourceMap; } else { - Util.logError(`Not found source data: ${Util.relativePath(item.sourcePath)}`); - item.source = ''; + Util.logError(`Not found source data: ${Util.relativePath(entry.sourcePath)}`); + entry.source = ''; + } + + // add empty coverage after source init + if (entry.empty) { + Util.setEmptyV8Coverage(entry); } + } return mergedList; diff --git a/test/test-merge.js b/test/test-merge.js index ed8f7ae..be111b3 100644 --- a/test/test-merge.js +++ b/test/test-merge.js @@ -24,8 +24,6 @@ const coverageOptions = { assetsPath: '../assets', // lcov: true, - // all: ['test/mock/src', 'test/mock/node/lib'], - sourcePath: (filePath) => { const list = ['monocart-coverage-reports/', 'coverage-v8/']; for (const str of list) {