Skip to content

Commit

Permalink
fixed untested file coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Sep 16, 2024
1 parent 974d039 commit 1aa5a7e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 64 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
67 changes: 3 additions & 64 deletions lib/converter/untested.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

// ========================================================================================================

Expand Down Expand Up @@ -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') {
Expand All @@ -181,7 +133,6 @@ const getUntestedCoverageData = async (emptyList, options, coverageType) => {
b: {}
};
// object
results.data[item.path] = item;
emptyCoverageList.push(item);

} else {
Expand All @@ -202,25 +153,13 @@ 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);

}

}

// for raw report: coverage file
const { cachePath } = Util.getCacheFileInfo('coverage', dataId, options.cacheDir);
await Util.writeFile(cachePath, JSON.stringify(results));

return emptyCoverageList;
};

Expand Down
2 changes: 2 additions & 0 deletions test/test-merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 1aa5a7e

Please sign in to comment.