UNPKG

danger-plugin-coverage

Version:
53 lines (38 loc) 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCoverageReport = void 0; var _fs = _interopRequireDefault(require("fs")); var _fastGlob = _interopRequireDefault(require("fast-glob")); var _xml2js = require("xml2js"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Get the path to the coverage report. */ const getReportPath = () => { const [filePath] = _fastGlob.default.sync(`${process.cwd()}/*/clover.xml`); return filePath; }; /** * Parse the coverage report. */ const parse = async filePath => { const xmlParser = new _xml2js.Parser(); if (!_fs.default.existsSync(filePath)) { return null; } const data = _fs.default.readFileSync(filePath); const { coverage: coverageXml } = await xmlParser.parseStringPromise(data); return coverageXml; }; /** * Get the coverage report. */ const getCoverageReport = customReportPath => { const filePath = customReportPath || getReportPath(); return parse(filePath); }; exports.getCoverageReport = getCoverageReport;