Comparing version 10.0.0 to 10.1.0
@@ -39,3 +39,4 @@ const { checkCoverages } = require('./check-coverage') | ||
excludeNodeModules: argv.excludeNodeModules, | ||
mergeAsync: argv.mergeAsync | ||
mergeAsync: argv.mergeAsync, | ||
monocartArgv: (argv.experimentalMonocart || process.env.EXPERIMENTAL_MONOCART) ? argv : null | ||
}) | ||
@@ -42,0 +43,0 @@ await report.run() |
@@ -161,2 +161,7 @@ const defaultExclude = require('@istanbuljs/schema/default-exclude') | ||
}) | ||
.option('experimental-monocart', { | ||
default: false, | ||
type: 'boolean', | ||
describe: 'Use Monocart coverage reports' | ||
}) | ||
.pkgConf('c8') | ||
@@ -163,0 +168,0 @@ .demandCommand(1) |
@@ -39,3 +39,4 @@ const Exclude = require('test-exclude') | ||
excludeNodeModules, | ||
mergeAsync | ||
mergeAsync, | ||
monocartArgv | ||
}) { | ||
@@ -64,2 +65,3 @@ this.reporter = reporter | ||
this.mergeAsync = mergeAsync | ||
this.monocartArgv = monocartArgv | ||
} | ||
@@ -78,2 +80,5 @@ | ||
async run () { | ||
if (this.monocartArgv) { | ||
return this.runMonocart() | ||
} | ||
const context = libReport.createContext({ | ||
@@ -95,2 +100,137 @@ dir: this.reportsDirectory, | ||
async importMonocart () { | ||
return import('monocart-coverage-reports') | ||
} | ||
async getMonocart () { | ||
let MCR | ||
try { | ||
MCR = await this.importMonocart() | ||
} catch (e) { | ||
console.error('--experimental-monocart requires the plugin monocart-coverage-reports. Run: "npm i monocart-coverage-reports --save-dev"') | ||
process.exit(1) | ||
} | ||
return MCR | ||
} | ||
async runMonocart () { | ||
const MCR = await this.getMonocart() | ||
if (!MCR) { | ||
return | ||
} | ||
const argv = this.monocartArgv | ||
const exclude = this.exclude | ||
function getEntryFilter () { | ||
return argv.entryFilter || argv.filter || function (entry) { | ||
return exclude.shouldInstrument(fileURLToPath(entry.url)) | ||
} | ||
} | ||
function getSourceFilter () { | ||
return argv.sourceFilter || argv.filter || function (sourcePath) { | ||
if (argv.excludeAfterRemap) { | ||
// console.log(sourcePath) | ||
return exclude.shouldInstrument(sourcePath) | ||
} | ||
return true | ||
} | ||
} | ||
function getReports () { | ||
const reports = Array.isArray(argv.reporter) ? argv.reporter : [argv.reporter] | ||
const reporterOptions = argv.reporterOptions || {} | ||
return reports.map((reportName) => { | ||
const reportOptions = { | ||
...reporterOptions[reportName] | ||
} | ||
if (reportName === 'text') { | ||
reportOptions.skipEmpty = false | ||
reportOptions.skipFull = argv.skipFull | ||
reportOptions.maxCols = process.stdout.columns || 100 | ||
} | ||
return [reportName, reportOptions] | ||
}) | ||
} | ||
// --all: add empty coverage for all files | ||
function getAllOptions () { | ||
if (!argv.all) { | ||
return | ||
} | ||
const src = argv.src | ||
const workingDirs = Array.isArray(src) ? src : (typeof src === 'string' ? [src] : [process.cwd()]) | ||
return { | ||
dir: workingDirs, | ||
filter: (filePath) => { | ||
return exclude.shouldInstrument(filePath) | ||
} | ||
} | ||
} | ||
function initPct (summary) { | ||
Object.keys(summary).forEach(k => { | ||
if (summary[k].pct === '') { | ||
summary[k].pct = 100 | ||
} | ||
}) | ||
return summary | ||
} | ||
// adapt coverage options | ||
const coverageOptions = { | ||
logging: argv.logging, | ||
name: argv.name, | ||
reports: getReports(), | ||
outputDir: argv.reportsDir, | ||
baseDir: argv.baseDir, | ||
entryFilter: getEntryFilter(), | ||
sourceFilter: getSourceFilter(), | ||
inline: argv.inline, | ||
lcov: argv.lcov, | ||
all: getAllOptions(), | ||
clean: argv.clean, | ||
// use default value for istanbul | ||
defaultSummarizer: 'pkg', | ||
onEnd: (coverageResults) => { | ||
// for check coverage | ||
this._allCoverageFiles = { | ||
files: () => { | ||
return coverageResults.files.map(it => it.sourcePath) | ||
}, | ||
fileCoverageFor: (file) => { | ||
const fileCoverage = coverageResults.files.find(it => it.sourcePath === file) | ||
return { | ||
toSummary: () => { | ||
return initPct(fileCoverage.summary) | ||
} | ||
} | ||
}, | ||
getCoverageSummary: () => { | ||
return initPct(coverageResults.summary) | ||
} | ||
} | ||
} | ||
} | ||
const coverageReport = new MCR.CoverageReport(coverageOptions) | ||
coverageReport.cleanCache() | ||
// read v8 coverage data from tempDirectory | ||
await coverageReport.addFromDir(argv.tempDirectory) | ||
// generate report | ||
await coverageReport.generate() | ||
} | ||
async getCoverageMapFromAllCoverageFiles () { | ||
@@ -97,0 +237,0 @@ // the merge process can be very expensive, and it's often the case that |
{ | ||
"name": "c8", | ||
"version": "10.0.0", | ||
"version": "10.1.0", | ||
"description": "output coverage reports using Node.js' built in coverage", | ||
@@ -58,2 +58,5 @@ "main": "./index.js", | ||
}, | ||
"peerDependencies": { | ||
"monocart-coverage-reports": "^2.8.3" | ||
}, | ||
"engines": { | ||
@@ -60,0 +63,0 @@ "node": ">=18" |
@@ -46,2 +46,3 @@ # c8 - native V8 code-coverage | ||
| `--clean` | should temp files be deleted before script execution | `boolean` | `true` | | ||
| `--experimental-monocart` | see [section below](#using-monocart-coverage-reports-experimental) for more info | `boolean` | `false` | | ||
@@ -123,2 +124,19 @@ ## Checking for "full" source coverage using `--all` | ||
## Using Monocart coverage reports (experimental) | ||
Monocart is an alternate library for outputting [v8 code coverage](https://v8.dev/blog/javascript-code-coverage) data as Istanbul reports. | ||
Monocart also provides reporters based directly on v8's byte-offset-based output. Such as, `console-details` and `v8`. This removes a complex transformation step and may be less bug prone for some environments. | ||
**Example usage:** | ||
```sh | ||
c8 --experimental-monocart --reporter=v8 --reporter=console-details node foo.js | ||
``` | ||
NOTE: Monocart requires additional `monocart-coverage-reports` to be installed: | ||
```sh | ||
npm i monocart-coverage-reports --save-dev | ||
``` | ||
## Ignoring Uncovered Lines, Functions, and Blocks | ||
@@ -125,0 +143,0 @@ |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
42187
973
193
12
10