monocart-coverage-reports
Advanced tools
Comparing version 2.6.0 to 2.6.1
111
lib/cli.js
@@ -7,2 +7,3 @@ #!/usr/bin/env node | ||
const { fileURLToPath, pathToFileURL } = require('url'); | ||
const { | ||
@@ -102,2 +103,67 @@ foregroundChild, | ||
const resolveEntrySource = (entry, sourceMapCache = {}) => { | ||
let source; | ||
const filePath = fileURLToPath(entry.url); | ||
const extname = path.extname(filePath); | ||
if (fs.existsSync(filePath)) { | ||
source = fs.readFileSync(filePath).toString('utf8'); | ||
} | ||
// not for typescript | ||
if (source && !['.ts', '.tsx'].includes(extname)) { | ||
entry.source = source; | ||
return; | ||
} | ||
const sourcemapData = sourceMapCache[entry.url]; | ||
const lineLengths = sourcemapData && sourcemapData.lineLengths; | ||
// for fake source file (can not parse to AST) | ||
if (lineLengths) { | ||
// get runtime code with ts-node | ||
let fakeSource = ''; | ||
sourcemapData.lineLengths.forEach((length) => { | ||
fakeSource += `${''.padEnd(length, '*')}\n`; | ||
}); | ||
entry.fake = true; | ||
entry.source = fakeSource; | ||
} | ||
// Note: no runtime code in source map cache | ||
// This is a problem for typescript | ||
}; | ||
const resolveEntrySourceMap = (entry, sourceMapCache = {}) => { | ||
// sourcemap data | ||
const sourcemapData = sourceMapCache[entry.url]; | ||
if (sourcemapData) { | ||
if (sourcemapData.data) { | ||
entry.sourceMap = resolveSourceMap(sourcemapData.data, entry.url); | ||
} | ||
} | ||
}; | ||
const collectCoverageData = (coverageList, entryFilterHandler, sourceMapCache = {}) => { | ||
if (!Util.isList(coverageList)) { | ||
return; | ||
} | ||
// filter node internal files | ||
coverageList = coverageList.filter((entry) => entry.url && entry.url.startsWith('file:')); | ||
coverageList = coverageList.filter(entryFilterHandler); | ||
if (!Util.isList(coverageList)) { | ||
return; | ||
} | ||
for (const entry of coverageList) { | ||
resolveEntrySource(entry, sourceMapCache); | ||
resolveEntrySourceMap(entry, sourceMapCache); | ||
} | ||
return coverageList; | ||
}; | ||
const executeCommand = async (command, cliOptions) => { | ||
@@ -135,2 +201,4 @@ | ||
const entryFilterHandler = coverageReport.getEntryFilter(); | ||
const files = fs.readdirSync(nodeV8CoverageDir); | ||
@@ -140,41 +208,8 @@ for (const filename of files) { | ||
const json = JSON.parse(content); | ||
let coverageList = json.result; | ||
// for node sourcemap | ||
const sourceMapCache = json['source-map-cache'] || {}; | ||
// filter node internal files | ||
coverageList = coverageList.filter((entry) => entry.url && entry.url.startsWith('file:')); | ||
if (!coverageList.length) { | ||
continue; | ||
const coverageList = json.result; | ||
const sourceMapCache = json['source-map-cache']; | ||
const coverageData = await collectCoverageData(coverageList, entryFilterHandler, sourceMapCache); | ||
if (coverageData) { | ||
await coverageReport.add(coverageData); | ||
} | ||
// attached source content | ||
coverageList.forEach((entry) => { | ||
// source content | ||
const filePath = fileURLToPath(entry.url); | ||
if (fs.existsSync(filePath)) { | ||
entry.source = fs.readFileSync(filePath).toString('utf8'); | ||
} | ||
// sourcemap data | ||
const sourcemapData = sourceMapCache[entry.url]; | ||
if (sourcemapData) { | ||
if (sourcemapData.data) { | ||
entry.sourceMap = resolveSourceMap(sourcemapData.data, entry.url); | ||
} | ||
// sourcemapData.lineLengths just for fake source file (can not parse to AST) | ||
if (!entry.source && sourcemapData.lineLengths) { | ||
// get runtime code with ts-node | ||
let source = ''; | ||
sourcemapData.lineLengths.forEach((length) => { | ||
source += `${''.padEnd(length, '*')}\n`; | ||
}); | ||
entry.fake = true; | ||
entry.source = source; | ||
} | ||
} | ||
}); | ||
await coverageReport.add(coverageList); | ||
} | ||
@@ -181,0 +216,0 @@ |
@@ -138,4 +138,4 @@ const fs = require('fs'); | ||
const sourceData = { | ||
id, | ||
url, | ||
id, | ||
source, | ||
@@ -142,0 +142,0 @@ sourceMap |
@@ -6,3 +6,3 @@ const fs = require('fs'); | ||
const { initV8ListAndSourcemap } = require('./v8/v8.js'); | ||
const { initV8ListAndSourcemap, getEntryFilter } = require('./v8/v8.js'); | ||
const { getInputData, generateCoverageReports } = require('./generate.js'); | ||
@@ -67,4 +67,3 @@ const { getSnapshot, diffSnapshot } = require('./utils/snapshot.js'); | ||
const results = { | ||
id: dataId, | ||
path: dataPath | ||
id: dataId | ||
}; | ||
@@ -74,2 +73,3 @@ | ||
results.type = 'v8'; | ||
// could be empty list after entryFilter | ||
results.data = await initV8ListAndSourcemap(data, this.options); | ||
@@ -176,2 +176,6 @@ } else { | ||
getEntryFilter() { | ||
return getEntryFilter(this.options); | ||
} | ||
} | ||
@@ -178,0 +182,0 @@ |
@@ -398,3 +398,4 @@ const path = require('path'); | ||
mergeV8Coverage, | ||
saveV8Report | ||
saveV8Report, | ||
getEntryFilter | ||
}; |
{ | ||
"name": "monocart-coverage-reports", | ||
"version": "2.6.0", | ||
"version": "2.6.1", | ||
"description": "Monocart coverage reports", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -42,2 +42,3 @@ # Monocart Coverage Reports | ||
- [WebdriverIO](#webdriverio) | ||
- [Storybook Test Runner](#storybook-test-runner) | ||
- [Codecov](#codecov) | ||
@@ -727,2 +728,5 @@ - [Coveralls](#coveralls) | ||
### [Storybook Test Runner](https://github.com/storybookjs/test-runner) | ||
- [storybook-monocart-coverage](https://github.com/cenfun/storybook-monocart-coverage) - Storybook V8 Coverage Example | ||
### [Codecov](https://codecov.com/) | ||
@@ -729,0 +733,0 @@ [![codecov](https://codecov.io/gh/cenfun/monocart-coverage-reports/graph/badge.svg?token=H0LW7UKYU3)](https://codecov.io/gh/cenfun/monocart-coverage-reports) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
756077
7767
792