Skip to content

Commit

Permalink
add new option dataDir
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Jul 3, 2024
1 parent 6165dd2 commit 6154e47
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/default/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ module.exports = {
// {string} base dir for normalizing the relative source path, defaults to cwd
baseDir: null,

// {string} coverage data dir, alternative to method `addFromDir()`, defaults to null
dataDir: null,

// (V8 only) {function} A filter function to execute for each element in the V8 list.
// entryFilter: (entry) => {
// if (entry.url.indexOf('googleapis.com') !== -1) {
Expand Down
15 changes: 15 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ declare namespace MCR {
skipPercent?: number;
metrics?: Array<"bytes" | "statements" | "branches" | "functions" | "lines">;
}] |
['markdown-summary'] | ['markdown-summary', {
color: 'unicode' | 'html' | 'tex' | string;
metrics?: Array<"bytes" | "statements" | "branches" | "functions" | "lines">;
outputFile?: string;
}] |
['markdown-details'] | ['markdown-details', {
baseUrl?: string;
color: 'unicode' | 'html' | 'tex' | string;
skipPercent?: number;
metrics?: Array<"bytes" | "statements" | "branches" | "functions" | "lines">;
outputFile?: string;
}] |
['raw'] | ['raw', {
outputDir?: string;
}] |
Expand Down Expand Up @@ -237,6 +249,9 @@ declare namespace MCR {
/** {string} base dir for normalizing the relative source path, defaults to cwd */
baseDir?: string;

/** {string} coverage data dir, alternative to method `addFromDir()`, defaults to null */
dataDir?: string;

/** (V8 only)
*
* {string} `minimatch` pattern for entry url;
Expand Down
5 changes: 5 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ class CoverageReport {

this.initOptions();

const dataDir = this.options.dataDir;
if (dataDir) {
await this.addFromDir(dataDir);
}

const inputData = await getInputData(this);
if (!inputData) {
return;
Expand Down
3 changes: 2 additions & 1 deletion test/generate-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const generate = async () => {
assetsPath: '../assets',
// lcov: true,

dataDir: dir,

entryFilter: {
'**/test/mock/node/**': true
},
Expand All @@ -31,7 +33,6 @@ const generate = async () => {
// clean cache before add coverage data
coverageReport.cleanCache();

await coverageReport.addFromDir(dir);
const coverageResults = await coverageReport.generate();
console.log('test-node-env coverage reportPath', EC.magenta(coverageResults.reportPath));

Expand Down
3 changes: 2 additions & 1 deletion test/test-node-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const coverageOptions = {
assetsPath: '../assets',
// lcov: true,

dataDir: dir,

entryFilter: {
'**/test/mock/node/**': true
},
Expand All @@ -32,7 +34,6 @@ const generate = async () => {
// clean cache before add coverage data
coverageReport.cleanCache();

await coverageReport.addFromDir(dir);
const coverageResults = await coverageReport.generate();
console.log('test-node-api coverage reportPath', EC.magenta(coverageResults.reportPath));

Expand Down

0 comments on commit 6154e47

Please sign in to comment.