From 730de4453cbf4ccb236efea96b61c3c935a9fa99 Mon Sep 17 00:00:00 2001 From: cenfun Date: Wed, 25 Sep 2024 15:43:03 +0800 Subject: [PATCH] whether to remove dir after added --- lib/index.d.ts | 3 ++- lib/index.js | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index 175c382..1e0dafd 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -439,8 +439,9 @@ declare namespace MCR { /** * add V8 coverage from a dir * @param dir node v8 coverage dir + * @param remove whether to remove dir after added */ - addFromDir: (dir: string) => Promise; + addFromDir: (dir: string, remove?: boolean) => Promise; /** generate report */ generate: () => Promise; diff --git a/lib/index.js b/lib/index.js index fcca403..0344fae 100644 --- a/lib/index.js +++ b/lib/index.js @@ -122,11 +122,14 @@ class CoverageReport { } // add coverage from dir - async addFromDir(dir) { + async addFromDir(dir, remove) { const time_start = Date.now(); const results = await readFromDir(this, dir); // remove dir after added - if (!Util.isDebug()) { + if (typeof remove !== 'boolean') { + remove = !Util.isDebug(); + } + if (remove) { Util.rmSync(dir); } Util.logTime(`added from dir: ${dir}`, time_start);