1/* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16const fs = require('fs'); 17const path = require('path'); 18const libCoverage = require('istanbul-lib-coverage'); 19const libReport = require('istanbul-lib-report'); 20const reports = require('istanbul-reports'); 21 22const projectRoot = path.join(__dirname, '..', '..'); 23const coverageDir = path.join(projectRoot, 'coverage'); 24 25const coverageFile = fs.readFileSync(path.join(coverageDir, 'newCoverage.json'), 'utf8'); 26const coverageData = JSON.parse(coverageFile); 27const coverageMap = libCoverage.createCoverageMap(coverageData); 28 29// create summary report 30const summary = libCoverage.createCoverageSummary(); 31coverageMap.files().forEach(file => { 32 const fc = coverageMap.fileCoverageFor(file); 33 const s = fc.toSummary(); 34 summary.merge(s); 35}); 36console.log(summary); 37 38// Watermarks for the report 39const configWatermarks = { 40 statements: [50, 80], 41 branches: [50, 80], 42 functions: [50, 80], 43 lines: [50, 80], 44}; 45const context = libReport.createContext({ 46 dir: path.join(coverageDir, 'report-html'), 47 defaultSummarizer: 'nested', 48 watermarks: configWatermarks, 49 coverageMap, 50}); 51 52const report = reports.create('html', {}); 53report.execute(context); 54 55const report_text = reports.create('text', {}); 56report_text.execute(context);