From 1aa5a7e3392232e0d3e9f9b0ea4d138187f2ea6c Mon Sep 17 00:00:00 2001 From: cenfun Date: Mon, 16 Sep 2024 15:43:11 +0800 Subject: [PATCH] fixed untested file coverage --- CHANGELOG.md | 3 ++ lib/converter/untested.js | 67 ++------------------------------------- test/test-merge.js | 2 ++ 3 files changed, 8 insertions(+), 64 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c1b81dc..50dd0b6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Changelog +- 2.10.6 + - fixed untested file coverage + - 2.10.5 - added `all.transformer` option to transform untested files - fixed merging issue for statements coverage diff --git a/lib/converter/untested.js b/lib/converter/untested.js index 3a0328a9..f1e746d1 100644 --- a/lib/converter/untested.js +++ b/lib/converter/untested.js @@ -5,7 +5,7 @@ const Util = require('../utils/util.js'); const { pathToFileURL, fileURLToPath } = require('url'); // const EC = require('eight-colors'); -const { minimatch, convertSourceMap } = require('../packages/monocart-coverage-vendor.js'); +const { minimatch } = require('../packages/monocart-coverage-vendor.js'); // ======================================================================================================== @@ -109,63 +109,15 @@ const resolveFileType = (fileType, filePath) => { return 'js'; }; -const saveUntestedFileSource = async (entryFile, options) => { - const { - id, - url, - source, - sourceMap - } = entryFile; - // console.log('-', entry.sourcePath); - - const { cachePath } = Util.getCacheFileInfo('source', id, options.cacheDir); - if (fs.existsSync(cachePath)) { - return; - } - - // save source and sourceMap to separated json file - const sourceData = { - id, - url, - source, - sourceMap - }; - - // remove comments if not debug - if (!Util.isDebug()) { - sourceData.source = convertSourceMap.removeComments(source); - } - - // console.log('save untested file', id, url); - - await Util.saveSourceCacheFile(sourceData, options); - -}; +const getUntestedCoverageData = (emptyList, options, coverageType) => { -const getUntestedCoverageData = async (emptyList, options, coverageType) => { - - // save all empty coverage - const dataId = Util.uid(); - const results = { - id: dataId - }; - - if (coverageType === 'istanbul') { - results.type = 'istanbul'; - results.data = {}; - } else { - results.type = 'v8'; - results.data = []; - } + // NOTE: do not save untested file to raw report const emptyCoverageList = []; // save all empty source and sourcemap for (const entryFile of emptyList) { - // for raw report: source file - await saveUntestedFileSource(entryFile, options); - const { type, url } = entryFile; if (coverageType === 'istanbul') { @@ -181,7 +133,6 @@ const getUntestedCoverageData = async (emptyList, options, coverageType) => { b: {} }; // object - results.data[item.path] = item; emptyCoverageList.push(item); } else { @@ -202,14 +153,6 @@ const getUntestedCoverageData = async (emptyList, options, coverageType) => { entryFile.ranges = entryFile.ranges || []; } - const item = { - ... entryFile - }; - delete item.source; - delete item.sourceMap; - - // array - results.data.push(item); // will be parsed to AST and converted to V8 coverage emptyCoverageList.push(entryFile); @@ -217,10 +160,6 @@ const getUntestedCoverageData = async (emptyList, options, coverageType) => { } - // for raw report: coverage file - const { cachePath } = Util.getCacheFileInfo('coverage', dataId, options.cacheDir); - await Util.writeFile(cachePath, JSON.stringify(results)); - return emptyCoverageList; }; diff --git a/test/test-merge.js b/test/test-merge.js index be111b39..60ac3918 100644 --- a/test/test-merge.js +++ b/test/test-merge.js @@ -24,6 +24,8 @@ 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) {