incremental-coverage
Advanced tools
Comparing version 2.0.2 to 2.1.0
@@ -1,48 +0,2 @@ | ||
import { FileStreamOpt, StdoutStreamOpt } from '../streams'; | ||
export interface Mapper { | ||
stdio: StdoutStreamOpt; | ||
file: FileStreamOpt; | ||
} | ||
export interface BaseProcessOpts<T extends keyof Mapper> { | ||
since?: string; | ||
cwd?: string; | ||
output?: boolean; | ||
stream: { | ||
name?: T; | ||
opts?: T extends 'stdio' ? StdoutStreamOpt : FileStreamOpt; | ||
}; | ||
} | ||
export interface FormatData { | ||
total: { | ||
increLine: number; | ||
covLine: number; | ||
increRate: string; | ||
}; | ||
files: { | ||
name: string; | ||
increLine?: number; | ||
covLine?: number; | ||
increRate?: string; | ||
detail?: { | ||
number: number; | ||
hits: number; | ||
}[]; | ||
}[]; | ||
} | ||
export declare class BaseProcess<T extends keyof Mapper> { | ||
lcovPath: string; | ||
opts: BaseProcessOpts<T>; | ||
private lcov; | ||
private firstGitMessage; | ||
private diffData; | ||
private formatData; | ||
constructor(lcovPath: string, opts?: BaseProcessOpts<T>); | ||
exec(): Promise<FormatData>; | ||
private getLcov; | ||
private getLog; | ||
private getDiff; | ||
private format; | ||
private output; | ||
} | ||
export * from './async'; | ||
export * from './sync'; | ||
export { getIncrease, getIncreaseSync, FormatData } from './getIncrease'; | ||
export { LcovConcat } from './lcovConcat'; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BaseProcess = void 0; | ||
const os_1 = __importDefault(require("os")); | ||
const dayjs_1 = __importDefault(require("dayjs")); | ||
const parsers_1 = require("../parsers"); | ||
const streams_1 = require("../streams"); | ||
class BaseProcess { | ||
constructor(lcovPath, opts = { stream: {} }) { | ||
this.opts = { | ||
stream: {}, | ||
}; | ||
this.lcov = { detail: {} }; | ||
this.firstGitMessage = {}; | ||
this.diffData = []; | ||
this.formatData = { | ||
total: { increLine: 0, covLine: 0, increRate: '' }, | ||
files: [], | ||
}; | ||
if (typeof lcovPath !== 'string') { | ||
throw new Error('请传递 lcov 文件路径'); | ||
} | ||
this.lcovPath = lcovPath; | ||
const startDay = dayjs_1.default().startOf('month').format('YYYY-MM-DD'); | ||
this.opts.cwd = opts.cwd || process.cwd(); | ||
this.opts.since = opts.since || startDay; | ||
this.opts.stream.name = opts.stream.name || 'file'; | ||
this.opts.stream.opts = opts.stream.opts; | ||
this.opts.output = opts.output; | ||
} | ||
exec() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.getLcov(); | ||
yield this.getLog(); | ||
yield this.getDiff(); | ||
this.format(); | ||
if (this.opts.output) { | ||
this.output(); | ||
} | ||
return this.formatData; | ||
}); | ||
} | ||
getLcov() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.lcov = yield new parsers_1.LcovParser(this.lcovPath).run(); | ||
}); | ||
} | ||
getLog() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const res = yield new parsers_1.LogParser({ | ||
repo: this.opts.cwd, | ||
since: this.opts.since, | ||
}).run(); | ||
this.firstGitMessage = res[res.length - 1]; | ||
}); | ||
} | ||
getDiff() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.diffData = yield new parsers_1.DiffParser(this.firstGitMessage.hash, { | ||
cwd: this.opts.cwd, | ||
}).run(); | ||
if (os_1.default.platform() === 'win32') { | ||
this.diffData = this.diffData.map((item) => { | ||
return Object.assign(Object.assign({}, item), { newPath: item.newPath.replace(/\\/g, '/') }); | ||
}); | ||
} | ||
}); | ||
} | ||
format() { | ||
Object.keys(this.lcov.detail).forEach((lcovItem) => { | ||
this.diffData.forEach((diffItem) => { | ||
if (lcovItem.toLocaleLowerCase().includes(diffItem.newPath.toLocaleLowerCase())) { | ||
const info = this.lcov.detail[lcovItem]; | ||
const temp = { increLine: 0, covLine: 0, increRate: '', detail: [], name: lcovItem }; | ||
const diffLineArr = []; | ||
diffItem.hunks.forEach((hunk) => { | ||
hunk.changes.forEach((change) => { | ||
if (change.type === 'insert' && change.lineNumber) { | ||
diffLineArr.push(change.lineNumber); | ||
} | ||
}); | ||
}); | ||
const lcovLineHit = {}; | ||
const lcovLineArr = []; | ||
const details = info.lines; | ||
details.forEach((detail) => { | ||
const { hits } = detail; | ||
const { number } = detail; | ||
lcovLineHit[number] = hits; | ||
lcovLineArr.push(parseInt(number, 10)); | ||
}); | ||
const diffLineArrSet = new Set(diffLineArr); | ||
const intersectArr = lcovLineArr.filter((x) => diffLineArrSet.has(x)); | ||
intersectArr.forEach((line) => { | ||
this.formatData.total.covLine += lcovLineHit[line] > 0 ? 1 : 0; | ||
temp.covLine += lcovLineHit[line] > 0 ? 1 : 0; | ||
temp.detail.push({ | ||
number: line, | ||
hits: lcovLineHit[line], | ||
}); | ||
}); | ||
this.formatData.total.increLine += intersectArr.length; | ||
temp.increLine += intersectArr.length; | ||
temp.increRate = `${((temp.covLine / temp.increLine) * 100).toFixed(2)}%`; | ||
this.formatData.files.push(temp); | ||
} | ||
}); | ||
}); | ||
this.formatData.total.increRate = `${((this.formatData.total.covLine / this.formatData.total.increLine) * | ||
100).toFixed(2)}%`; | ||
} | ||
output() { | ||
var _a, _b; | ||
let tempStream; | ||
if (((_a = this.opts.stream) === null || _a === void 0 ? void 0 : _a.name) === 'file') { | ||
tempStream = new streams_1.FileStream(this.formatData, this.opts.stream.opts); | ||
} | ||
else if (((_b = this.opts.stream) === null || _b === void 0 ? void 0 : _b.name) === 'stdio') { | ||
tempStream = new streams_1.StdoutStream(this.formatData, this.opts.stream.opts); | ||
} | ||
else { | ||
throw new Error('参数错误'); | ||
} | ||
tempStream.outToStream(); | ||
} | ||
} | ||
exports.BaseProcess = BaseProcess; | ||
__exportStar(require("./async"), exports); | ||
__exportStar(require("./sync"), exports); | ||
var getIncrease_1 = require("./getIncrease"); | ||
Object.defineProperty(exports, "getIncrease", { enumerable: true, get: function () { return getIncrease_1.getIncrease; } }); | ||
Object.defineProperty(exports, "getIncreaseSync", { enumerable: true, get: function () { return getIncrease_1.getIncreaseSync; } }); | ||
var lcovConcat_1 = require("./lcovConcat"); | ||
Object.defineProperty(exports, "LcovConcat", { enumerable: true, get: function () { return lcovConcat_1.LcovConcat; } }); |
@@ -17,3 +17,3 @@ #!/usr/bin/env node | ||
const yargs_1 = __importDefault(require("yargs")); | ||
const apis_1 = require("./apis"); | ||
const getIncrease_1 = require("./apis/getIncrease"); | ||
(() => __awaiter(void 0, void 0, void 0, function* () { | ||
@@ -41,3 +41,3 @@ const res = yargs_1.default | ||
.help().argv; | ||
yield apis_1.getIncrease(res.path, { | ||
yield getIncrease_1.getIncrease(res.path, { | ||
since: res.time, | ||
@@ -44,0 +44,0 @@ output: true, |
@@ -0,3 +1,3 @@ | ||
export * from './apis'; | ||
export { DiffParser, LcovParser, LogParser } from './parsers'; | ||
export { getIncrease, getIncreaseSync, FormatData } from './apis'; | ||
export { Locv, DetailLines, Total } from './types'; | ||
export { Lcov, DetailLines, Total } from './types'; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./apis"), exports); | ||
var parsers_1 = require("./parsers"); | ||
@@ -7,4 +18,1 @@ Object.defineProperty(exports, "DiffParser", { enumerable: true, get: function () { return parsers_1.DiffParser; } }); | ||
Object.defineProperty(exports, "LogParser", { enumerable: true, get: function () { return parsers_1.LogParser; } }); | ||
var apis_1 = require("./apis"); | ||
Object.defineProperty(exports, "getIncrease", { enumerable: true, get: function () { return apis_1.getIncrease; } }); | ||
Object.defineProperty(exports, "getIncreaseSync", { enumerable: true, get: function () { return apis_1.getIncreaseSync; } }); |
import { Parser } from './index'; | ||
import { Locv } from '../types'; | ||
import { Lcov } from '../types'; | ||
export declare class LcovParser implements Parser { | ||
@@ -7,5 +7,5 @@ path: string; | ||
constructor(path: string); | ||
run(): Promise<Locv>; | ||
run(): Promise<Lcov>; | ||
private parserLcov; | ||
private format; | ||
} |
@@ -54,2 +54,4 @@ "use strict"; | ||
const temp = { | ||
linesCovered: item.lines.hit, | ||
linesValid: item.lines.found, | ||
lineRate: item.lines.hit / item.lines.found, | ||
@@ -62,3 +64,2 @@ lines: [], | ||
hits: detail.hit, | ||
branch: '', | ||
}); | ||
@@ -65,0 +66,0 @@ }); |
@@ -6,5 +6,6 @@ export interface Total { | ||
export interface DetailLines { | ||
linesCovered: number; | ||
linesValid: number; | ||
lineRate: number; | ||
lines: { | ||
branch: string; | ||
hits: number; | ||
@@ -14,5 +15,5 @@ number: string; | ||
} | ||
export interface Locv { | ||
export interface Lcov { | ||
detail: Record<string, DetailLines>; | ||
$?: Total; | ||
} |
{ | ||
"name": "incremental-coverage", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -191,3 +191,3 @@ # Incremental Coverage | ||
export interface Locv { | ||
export interface Lcov { | ||
detail: Record<string, DetailLines>; | ||
@@ -194,0 +194,0 @@ $?: Total; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41193
43
888