From 1d8ee3b7ee5c15c44bb587c5b7356ba4fbde779b Mon Sep 17 00:00:00 2001 From: zhangtao25 Date: Mon, 2 Dec 2024 16:02:14 +0800 Subject: [PATCH] feat: update --- plugins/babel-plugin-canyon/package.json | 2 +- .../src/helpers/generate-initial-coverage.js | 35 ++++++++++--------- plugins/babel-plugin-canyon/src/index.js | 2 +- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/plugins/babel-plugin-canyon/package.json b/plugins/babel-plugin-canyon/package.json index 047edcb9..b7c079d1 100644 --- a/plugins/babel-plugin-canyon/package.json +++ b/plugins/babel-plugin-canyon/package.json @@ -1,6 +1,6 @@ { "name": "babel-plugin-canyon", - "version": "1.8.86", + "version": "1.8.87", "description": "A Babel plugin cooperates with istanbul to report the coverage", "author": "Allen Zhang ", "license": "MIT", diff --git a/plugins/babel-plugin-canyon/src/helpers/generate-initial-coverage.js b/plugins/babel-plugin-canyon/src/helpers/generate-initial-coverage.js index 03cc13c6..4ed9c4ae 100644 --- a/plugins/babel-plugin-canyon/src/helpers/generate-initial-coverage.js +++ b/plugins/babel-plugin-canyon/src/helpers/generate-initial-coverage.js @@ -1,20 +1,21 @@ -// import fs from 'fs'; -// import path from 'path' +import fs from 'fs'; +import path from 'path' import {extractCoverageData} from "./extract-coverage-data"; - -export const generateInitialCoverage = (paramsPath) => { - const initialCoverageDataForTheCurrentFile = extractCoverageData(paramsPath) - // const filePath = './.canyon_output/coverage-final.json'; - // const dir = path.dirname(filePath); - // if (!fs.existsSync(dir)) { - // fs.mkdirSync(dir, {recursive: true}); - // } - // // 防止返回的数据为空 - // if (initialCoverageDataForTheCurrentFile && initialCoverageDataForTheCurrentFile.path) { - // fs.writeFileSync(`./.canyon_output/coverage-${Math.random()}.json`, JSON.stringify({ - // [initialCoverageDataForTheCurrentFile.path]: initialCoverageDataForTheCurrentFile - // }, null, 2), 'utf-8'); - // } - return initialCoverageDataForTheCurrentFile; +export const generateInitialCoverage = (paramsPath,writeCovLocal) => { + const initialCoverageDataForTheCurrentFile = extractCoverageData(paramsPath) + if (writeCovLocal){ + const filePath = './.canyon_output/coverage-final.json'; + const dir = path.dirname(filePath); + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir, {recursive: true}); + } + // 防止返回的数据为空 + if (initialCoverageDataForTheCurrentFile && initialCoverageDataForTheCurrentFile.path) { + fs.writeFileSync(`./.canyon_output/coverage-map-${Math.random()}.json`, JSON.stringify({ + [initialCoverageDataForTheCurrentFile.path]: initialCoverageDataForTheCurrentFile + }, null, 2), 'utf-8'); + } + } + return initialCoverageDataForTheCurrentFile; } diff --git a/plugins/babel-plugin-canyon/src/index.js b/plugins/babel-plugin-canyon/src/index.js index 6df39be0..80bdad3e 100644 --- a/plugins/babel-plugin-canyon/src/index.js +++ b/plugins/babel-plugin-canyon/src/index.js @@ -72,7 +72,7 @@ export default declare((api,config) => { // 生成初始覆盖率数据 - const initialCoverageDataForTheCurrentFile = generateInitialCoverage(generate(path.node).code) + const initialCoverageDataForTheCurrentFile = generateInitialCoverage(generate(path.node).code,config.writeCovLocal) // generateCanyon(__canyon__) // 生成canyon代码