From 94826616045c984f1b43a9f59273738754502f75 Mon Sep 17 00:00:00 2001 From: Allen Zhang <37892968+zhangtao25@users.noreply.github.com> Date: Tue, 5 Nov 2024 23:50:30 +0800 Subject: [PATCH] feat: update --- plugins/babel-plugin-canyon/package.json | 2 +- .../src/helpers/generate-initial-coverage.js | 26 +++++++++---------- plugins/babel-plugin-canyon/src/index.js | 13 ++-------- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/plugins/babel-plugin-canyon/package.json b/plugins/babel-plugin-canyon/package.json index 3e82c5fc..c316e9a4 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.81", + "version": "1.8.78-beta.22", "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..0a2e57a1 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,20 @@ -// 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'); - // } + 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; } diff --git a/plugins/babel-plugin-canyon/src/index.js b/plugins/babel-plugin-canyon/src/index.js index d3d96b52..2f9b46c5 100644 --- a/plugins/babel-plugin-canyon/src/index.js +++ b/plugins/babel-plugin-canyon/src/index.js @@ -65,14 +65,13 @@ export default declare((api,config) => { // 生成初始覆盖率数据 const initialCoverageDataForTheCurrentFile = generateInitialCoverage(generate(path.node).code) if (generate(path.node).code.includes('coverageData')) { - // console.log(path.node) const t = api.types; // 遍历 Program 中的所有节点 path.traverse({ VariableDeclarator(variablePath) { -// 检查是否是 coverageData + // 检查是否是 coverageData if ( t.isIdentifier(variablePath.node.id, { name: "coverageData" }) && t.isObjectExpression(variablePath.node.init) @@ -85,13 +84,11 @@ export default declare((api,config) => { ); if (hasInstrumentation) { - console.log("发现已插桩的 coverageData 节点,进行进一步修改..."); - // 获取 coverageData 对象的 properties const properties = variablePath.node.init.properties; // 删除 statementMap、fnMap 和 branchMap 属性 - const keysToRemove = ["statementMap", "fnMap", "branchMap"]; + const keysToRemove = ["statementMap", "fnMap", "branchMap","inputSourceMap"]; keysToRemove.forEach(key => { const index = properties.findIndex(prop => @@ -100,17 +97,11 @@ export default declare((api,config) => { if (index !== -1) { properties.splice(index, 1); // 删除属性 - console.log(`已删除 ${key} 属性。`); } }); - - // 打印修改后的代码 - const newCode = generate(variablePath.node).code; - console.log("修改后的代码:", newCode); } } }}) - } // generateCanyon(__canyon__)