Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtao25 committed Dec 2, 2024
1 parent 4613c30 commit 1d8ee3b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion plugins/babel-plugin-canyon/package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"license": "MIT",
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion plugins/babel-plugin-canyon/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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代码
Expand Down

0 comments on commit 1d8ee3b

Please sign in to comment.