• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SAP / ui5-tooling-extensions / 16248276690

13 Jul 2025 10:44AM CUT coverage: 100.0%. First build
16248276690

Pull #418

github

web-flow
Merge ecdeccafd into 8452b94f8
Pull Request #418: build(deps-dev): Bump sinon from 20.0.0 to 21.0.0

51 of 51 branches covered (100.0%)

Branch coverage included in aggregate %.

106 of 106 relevant lines covered (100.0%)

6.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/packages/middleware-code-coverage/lib/coverage-reporter.js
1
import libReport from "istanbul-lib-report";
2
import reports from "istanbul-reports";
3
import istanbulLibCoverage from "istanbul-lib-coverage";
4
import path from "node:path";
5

6
/**
7
 * @typedef {object} @ui5/middleware-code-coverage/Coverage
8
 * @property {string[]} coverageMap
9
 * @property {object[]} availableReports
10
 */
11

12
/**
13
 * Reports the coverage
14
 *
15
 * @param {object} coverageData
16
 * @param {*} config
17
 * @param {object} resources Resource collections
18
 * @param {module:@ui5/fs.AbstractReader} resources.all Reader or Collection to read resources of the
19
 *  root project and its dependencies
20
 * @param {module:@ui5/fs.AbstractReader} resources.rootProject Reader or Collection to read resources of
21
 *  the project the server is started in
22
 * @param {module:@ui5/fs.AbstractReader} resources.dependencies Reader or Collection to read resources of
23
 *  the projects dependencies
24
 * @param {@ui5/logger/Logger} log
25
 *  Logger instance of the custom middleware instance
26
 * @returns {@ui5/middleware-code-coverage/Coverage}
27
 */
28
export default async function(coverageData, config, resources, log) {
29
        let {coverage: globalCoverageMap, watermarks} = coverageData;
7✔
30

31
        // For compatibility reasons with the old structure, we need first to check
32
        // whether the "coverage" property is present in coverageData or use the
33
        // whole coverageData object (old structure).
34
        globalCoverageMap = globalCoverageMap || coverageData;
7✔
35

36
        const coverageMap =
37
                istanbulLibCoverage.createCoverageMap(globalCoverageMap);
7✔
38
        const reportConfig = {...config.report};
7✔
39

40
        // Frontend config for watermarks should take precedence if present.
41
        reportConfig.watermarks = {...reportConfig.watermarks, ...watermarks};
7✔
42

43
        // Get & stash code from the resources
44
        // Later this would be needed to create the reports
45
        const coverageSources = await Promise.all(
7✔
46
                Object.keys(coverageMap.data).map(async (key) => {
47
                        let source = "";
7✔
48

49
                        const matchedResource = await resources.all.byPath(key);
7✔
50

51
                        if (matchedResource) {
7✔
52
                                source = await matchedResource.getString();
6✔
53
                        } else {
54
                                log.warn(
1✔
55
                                        `${key} not found! Detailed report can't be generated for that resource!`
56
                                );
57
                        }
58
                        return {key, source};
7✔
59
                })
60
        ).then((sources) =>
61
                sources.reduce(
7✔
62
                        (acc, curElement) => acc.set(curElement.key, curElement.source),
7✔
63
                        new Map()
64
                )
65
        );
66

67
        const reportResults = reportConfig.reporter.reduce((acc, reportType) => {
7✔
68
                // create a context for report generation
69
                const context = libReport.createContext({
7✔
70
                        dir: path.join(config.cwd, reportConfig["report-dir"], reportType),
71
                        watermarks: reportConfig.watermarks,
72
                        coverageMap,
73
                        sourceFinder: (path) => coverageSources.get(path),
7✔
74
                });
75

76
                // create an instance of the relevant report class, passing the
77
                // report name e.g. json/html/html-spa/text
78
                const report = reports.create(reportType);
7✔
79

80
                // call execute to synchronously create and write the report to disk
81
                report.execute(context);
7✔
82

83
                if (report.lcov) {
7✔
84
                        acc.push({report: reportType, destination: [reportType, report.lcov.file].join("/")});
1✔
85
                        acc.push({report: "html", destination: [reportType, report.html.subdir].join("/")});
1✔
86
                } else {
87
                        acc.push({report: reportType, destination: [reportType, report.file].join("/")});
6✔
88
                }
89

90
                return acc;
7✔
91
        }, []);
92

93
        return {
7✔
94
                coverageMap: Object.keys(coverageMap.data),
95
                availableReports: reportResults
96
        };
97
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc