@code-pushup/coverage-plugin 0.16.7 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -15
- package/bin.js +875 -0
- package/index.js +134 -214
- package/package.json +10 -1
- package/src/bin.d.ts +1 -0
- package/src/index.d.ts +1 -0
- package/src/lib/config.d.ts +3 -2
- package/src/lib/coverage-plugin.d.ts +1 -2
- package/src/lib/nx/coverage-paths.d.ts +6 -0
- package/src/lib/runner/constants.d.ts +3 -0
- package/src/lib/runner/index.d.ts +4 -0
- package/src/lib/runner/lcov/lcov-runner.d.ts +9 -0
- package/src/lib/utils.d.ts +3 -0
- package/src/lib/runner/lcov/runner.d.ts +0 -9
package/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// packages/plugin-coverage/src/lib/coverage-plugin.ts
|
|
2
|
-
import { join as join3 } from "node:path";
|
|
2
|
+
import { dirname, join as join3 } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
3
4
|
|
|
4
5
|
// packages/models/src/lib/audit.ts
|
|
5
6
|
import { z as z2 } from "zod";
|
|
6
7
|
|
|
7
8
|
// packages/models/src/lib/implementation/schemas.ts
|
|
9
|
+
import { MATERIAL_ICONS } from "vscode-material-icons";
|
|
8
10
|
import { z } from "zod";
|
|
9
|
-
import { MATERIAL_ICONS } from "@code-pushup/portal-client";
|
|
10
11
|
|
|
11
12
|
// packages/models/src/lib/implementation/limits.ts
|
|
12
13
|
var MAX_SLUG_LENGTH = 128;
|
|
@@ -164,10 +165,9 @@ function scorableSchema(description, refSchema, duplicateCheckFn, duplicateMessa
|
|
|
164
165
|
{ description }
|
|
165
166
|
);
|
|
166
167
|
}
|
|
167
|
-
var materialIconSchema = z.enum(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
);
|
|
168
|
+
var materialIconSchema = z.enum(MATERIAL_ICONS, {
|
|
169
|
+
description: "Icon from VSCode Material Icons extension"
|
|
170
|
+
});
|
|
171
171
|
function hasWeightedRefsInCategories(categoryRefs) {
|
|
172
172
|
return categoryRefs.reduce((acc, { weight }) => weight + acc, 0) !== 0;
|
|
173
173
|
}
|
|
@@ -550,11 +550,18 @@ var reportSchema = packageVersionSchema({
|
|
|
550
550
|
// packages/utils/src/lib/file-system.ts
|
|
551
551
|
import { bundleRequire } from "bundle-require";
|
|
552
552
|
import chalk from "chalk";
|
|
553
|
-
import { mkdir, readFile, readdir, stat } from "node:fs/promises";
|
|
553
|
+
import { mkdir, readFile, readdir, rm, stat } from "node:fs/promises";
|
|
554
554
|
import { join } from "node:path";
|
|
555
|
-
async function
|
|
556
|
-
|
|
557
|
-
|
|
555
|
+
async function ensureDirectoryExists(baseDir) {
|
|
556
|
+
try {
|
|
557
|
+
await mkdir(baseDir, { recursive: true });
|
|
558
|
+
return;
|
|
559
|
+
} catch (error) {
|
|
560
|
+
console.error(error.message);
|
|
561
|
+
if (error.code !== "EEXIST") {
|
|
562
|
+
throw error;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
558
565
|
}
|
|
559
566
|
function pluginWorkDir(slug) {
|
|
560
567
|
return join("node_modules", ".code-pushup", slug);
|
|
@@ -574,53 +581,23 @@ import chalk3 from "chalk";
|
|
|
574
581
|
import CliTable3 from "cli-table3";
|
|
575
582
|
|
|
576
583
|
// packages/utils/src/lib/transform.ts
|
|
577
|
-
import { platform } from "node:os";
|
|
578
|
-
function toUnixPath(path, options) {
|
|
579
|
-
const unixPath = path.replace(/\\/g, "/");
|
|
580
|
-
if (options?.toRelative) {
|
|
581
|
-
return unixPath.replace(`${process.cwd().replace(/\\/g, "/")}/`, "");
|
|
582
|
-
}
|
|
583
|
-
return unixPath;
|
|
584
|
-
}
|
|
585
|
-
function toUnixNewlines(text) {
|
|
586
|
-
return platform() === "win32" ? text.replace(/\r\n/g, "\n") : text;
|
|
587
|
-
}
|
|
588
584
|
function capitalize(text) {
|
|
589
585
|
return `${text.charAt(0).toLocaleUpperCase()}${text.slice(
|
|
590
586
|
1
|
|
591
587
|
)}`;
|
|
592
588
|
}
|
|
593
|
-
function toNumberPrecision(value, decimalPlaces) {
|
|
594
|
-
return Number(
|
|
595
|
-
`${Math.round(
|
|
596
|
-
Number.parseFloat(`${value}e${decimalPlaces}`)
|
|
597
|
-
)}e-${decimalPlaces}`
|
|
598
|
-
);
|
|
599
|
-
}
|
|
600
|
-
function toOrdinal(value) {
|
|
601
|
-
if (value % 10 === 1 && value % 100 !== 11) {
|
|
602
|
-
return `${value}st`;
|
|
603
|
-
}
|
|
604
|
-
if (value % 10 === 2 && value % 100 !== 12) {
|
|
605
|
-
return `${value}nd`;
|
|
606
|
-
}
|
|
607
|
-
if (value % 10 === 3 && value % 100 !== 13) {
|
|
608
|
-
return `${value}rd`;
|
|
609
|
-
}
|
|
610
|
-
return `${value}th`;
|
|
611
|
-
}
|
|
612
589
|
|
|
613
590
|
// packages/utils/src/lib/logging.ts
|
|
614
591
|
import chalk4 from "chalk";
|
|
615
592
|
|
|
616
593
|
// packages/plugin-coverage/package.json
|
|
617
594
|
var name = "@code-pushup/coverage-plugin";
|
|
618
|
-
var version = "0.
|
|
595
|
+
var version = "0.17.0";
|
|
619
596
|
|
|
620
597
|
// packages/plugin-coverage/src/lib/config.ts
|
|
621
598
|
import { z as z13 } from "zod";
|
|
622
599
|
var coverageTypeSchema = z13.enum(["function", "branch", "line"]);
|
|
623
|
-
var
|
|
600
|
+
var coverageResultSchema = z13.object({
|
|
624
601
|
resultsPath: z13.string().includes("lcov"),
|
|
625
602
|
pathToProject: z13.string({
|
|
626
603
|
description: "Path from workspace root to project root. Necessary for LCOV reports."
|
|
@@ -636,7 +613,7 @@ var coveragePluginConfigSchema = z13.object({
|
|
|
636
613
|
coverageTypes: z13.array(coverageTypeSchema, {
|
|
637
614
|
description: "Coverage types measured. Defaults to all available types."
|
|
638
615
|
}).min(1).default(["function", "branch", "line"]),
|
|
639
|
-
reports: z13.array(
|
|
616
|
+
reports: z13.array(coverageResultSchema, {
|
|
640
617
|
description: "Path to all code coverage report files. Only LCOV format is supported for now."
|
|
641
618
|
}).min(1),
|
|
642
619
|
perfectScoreThreshold: z13.number({
|
|
@@ -644,193 +621,80 @@ var coveragePluginConfigSchema = z13.object({
|
|
|
644
621
|
}).gt(0).max(1).optional()
|
|
645
622
|
});
|
|
646
623
|
|
|
647
|
-
// packages/plugin-coverage/src/lib/runner/
|
|
624
|
+
// packages/plugin-coverage/src/lib/runner/index.ts
|
|
625
|
+
import chalk5 from "chalk";
|
|
626
|
+
import { writeFile } from "node:fs/promises";
|
|
627
|
+
|
|
628
|
+
// packages/plugin-coverage/src/lib/utils.ts
|
|
629
|
+
var coverageDescription = {
|
|
630
|
+
branch: "Measures how many branches were executed after conditional statements in at least one test.",
|
|
631
|
+
line: "Measures how many lines of code were executed in at least one test.",
|
|
632
|
+
function: "Measures how many functions were called in at least one test."
|
|
633
|
+
};
|
|
634
|
+
function applyMaxScoreAboveThreshold(outputs, threshold) {
|
|
635
|
+
return outputs.map(
|
|
636
|
+
(output) => output.score >= threshold ? { ...output, score: 1 } : output
|
|
637
|
+
);
|
|
638
|
+
}
|
|
639
|
+
var coverageTypeWeightMapper = {
|
|
640
|
+
function: 6,
|
|
641
|
+
branch: 3,
|
|
642
|
+
line: 1
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
// packages/plugin-coverage/src/lib/runner/constants.ts
|
|
648
646
|
import { join as join2 } from "node:path";
|
|
647
|
+
var WORKDIR = pluginWorkDir("coverage");
|
|
648
|
+
var RUNNER_OUTPUT_PATH = join2(WORKDIR, "runner-output.json");
|
|
649
|
+
var PLUGIN_CONFIG_PATH = join2(
|
|
650
|
+
process.cwd(),
|
|
651
|
+
WORKDIR,
|
|
652
|
+
"plugin-config.json"
|
|
653
|
+
);
|
|
649
654
|
|
|
650
655
|
// packages/plugin-coverage/src/lib/runner/lcov/parse-lcov.ts
|
|
651
656
|
import parseLcovExport from "parse-lcov";
|
|
652
657
|
var godKnows = parseLcovExport;
|
|
653
658
|
var parseLcov = "default" in godKnows ? godKnows.default : godKnows;
|
|
654
659
|
|
|
655
|
-
// packages/plugin-coverage/src/lib/runner/
|
|
656
|
-
function
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
return [...numberArr].sort().reduce((acc, currValue) => {
|
|
661
|
-
const prevValue = acc.at(-1);
|
|
662
|
-
if (prevValue != null && (prevValue.start === currValue - 1 || prevValue.end === currValue - 1)) {
|
|
663
|
-
return [...acc.slice(0, -1), { start: prevValue.start, end: currValue }];
|
|
664
|
-
}
|
|
665
|
-
return [...acc, { start: currValue }];
|
|
666
|
-
}, []);
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
// packages/plugin-coverage/src/lib/runner/lcov/transform.ts
|
|
670
|
-
function lcovReportToFunctionStat(record) {
|
|
660
|
+
// packages/plugin-coverage/src/lib/runner/index.ts
|
|
661
|
+
async function createRunnerConfig(scriptPath, config) {
|
|
662
|
+
await ensureDirectoryExists(WORKDIR);
|
|
663
|
+
await writeFile(PLUGIN_CONFIG_PATH, JSON.stringify(config));
|
|
664
|
+
const threshold = config.perfectScoreThreshold;
|
|
671
665
|
return {
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
severity: "error",
|
|
678
|
-
source: {
|
|
679
|
-
file: toUnixPath(record.file),
|
|
680
|
-
position: { startLine: detail.line }
|
|
681
|
-
}
|
|
682
|
-
})
|
|
683
|
-
) : []
|
|
684
|
-
};
|
|
685
|
-
}
|
|
686
|
-
function lcovReportToLineStat(record) {
|
|
687
|
-
const missingCoverage = record.lines.hit < record.lines.found;
|
|
688
|
-
const lines = missingCoverage ? record.lines.details.filter((detail) => !detail.hit).map((detail) => detail.line) : [];
|
|
689
|
-
const linePositions = mergeConsecutiveNumbers(lines);
|
|
690
|
-
return {
|
|
691
|
-
totalFound: record.lines.found,
|
|
692
|
-
totalHit: record.lines.hit,
|
|
693
|
-
issues: missingCoverage ? linePositions.map((linePosition) => {
|
|
694
|
-
const lineReference = linePosition.end == null ? `Line ${linePosition.start} is` : `Lines ${linePosition.start}-${linePosition.end} are`;
|
|
695
|
-
return {
|
|
696
|
-
message: `${lineReference} not covered in any test case.`,
|
|
697
|
-
severity: "warning",
|
|
698
|
-
source: {
|
|
699
|
-
file: toUnixPath(record.file),
|
|
700
|
-
position: {
|
|
701
|
-
startLine: linePosition.start,
|
|
702
|
-
endLine: linePosition.end
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
};
|
|
706
|
-
}) : []
|
|
707
|
-
};
|
|
708
|
-
}
|
|
709
|
-
function lcovReportToBranchStat(record) {
|
|
710
|
-
return {
|
|
711
|
-
totalFound: record.branches.found,
|
|
712
|
-
totalHit: record.branches.hit,
|
|
713
|
-
issues: record.branches.hit < record.branches.found ? record.branches.details.filter((detail) => !detail.taken).map(
|
|
714
|
-
(detail) => ({
|
|
715
|
-
message: `${toOrdinal(
|
|
716
|
-
detail.branch + 1
|
|
717
|
-
)} branch is not taken in any test case.`,
|
|
718
|
-
severity: "error",
|
|
719
|
-
source: {
|
|
720
|
-
file: toUnixPath(record.file),
|
|
721
|
-
position: { startLine: detail.line }
|
|
722
|
-
}
|
|
723
|
-
})
|
|
724
|
-
) : []
|
|
725
|
-
};
|
|
726
|
-
}
|
|
727
|
-
var recordToStatFunctionMapper = {
|
|
728
|
-
branch: lcovReportToBranchStat,
|
|
729
|
-
line: lcovReportToLineStat,
|
|
730
|
-
function: lcovReportToFunctionStat
|
|
731
|
-
};
|
|
732
|
-
function lcovCoverageToAuditOutput(stat2, coverageType) {
|
|
733
|
-
const coverage = calculateCoverage(stat2.totalHit, stat2.totalFound);
|
|
734
|
-
const MAX_DECIMAL_PLACES = 4;
|
|
735
|
-
const roundedIntValue = toNumberPrecision(coverage * 100, 0);
|
|
736
|
-
return {
|
|
737
|
-
slug: `${coverageType}-coverage`,
|
|
738
|
-
score: toNumberPrecision(coverage, MAX_DECIMAL_PLACES),
|
|
739
|
-
value: roundedIntValue,
|
|
740
|
-
displayValue: `${roundedIntValue} %`,
|
|
741
|
-
...stat2.issues.length > 0 && { details: { issues: stat2.issues } }
|
|
742
|
-
};
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
// packages/plugin-coverage/src/lib/runner/lcov/runner.ts
|
|
746
|
-
async function lcovResultsToAuditOutputs(reports, coverageTypes) {
|
|
747
|
-
const parsedReports = await Promise.all(
|
|
748
|
-
reports.map(async (report) => {
|
|
749
|
-
const reportContent = await readTextFile(report.resultsPath);
|
|
750
|
-
const parsedRecords = parseLcov(toUnixNewlines(reportContent));
|
|
751
|
-
return parsedRecords.map((record) => ({
|
|
752
|
-
...record,
|
|
753
|
-
file: report.pathToProject == null ? record.file : join2(report.pathToProject, record.file)
|
|
754
|
-
}));
|
|
755
|
-
})
|
|
756
|
-
);
|
|
757
|
-
if (parsedReports.length !== reports.length) {
|
|
758
|
-
throw new Error("Some provided LCOV reports were not valid.");
|
|
759
|
-
}
|
|
760
|
-
const flatReports = parsedReports.flat();
|
|
761
|
-
if (flatReports.length === 0) {
|
|
762
|
-
throw new Error("All provided reports are empty.");
|
|
763
|
-
}
|
|
764
|
-
const totalCoverageStats = getTotalCoverageFromLcovReports(
|
|
765
|
-
flatReports,
|
|
766
|
-
coverageTypes
|
|
767
|
-
);
|
|
768
|
-
return coverageTypes.map((coverageType) => {
|
|
769
|
-
const stats = totalCoverageStats[coverageType];
|
|
770
|
-
if (!stats) {
|
|
771
|
-
return null;
|
|
666
|
+
command: "node",
|
|
667
|
+
args: [scriptPath],
|
|
668
|
+
outputFile: RUNNER_OUTPUT_PATH,
|
|
669
|
+
...threshold != null && {
|
|
670
|
+
outputTransform: (outputs) => applyMaxScoreAboveThreshold(outputs, threshold)
|
|
772
671
|
}
|
|
773
|
-
|
|
774
|
-
}).filter(exists);
|
|
775
|
-
}
|
|
776
|
-
function getTotalCoverageFromLcovReports(records, coverageTypes) {
|
|
777
|
-
return records.reduce(
|
|
778
|
-
(acc, report) => Object.fromEntries([
|
|
779
|
-
...Object.entries(acc),
|
|
780
|
-
...Object.entries(
|
|
781
|
-
getCoverageStatsFromLcovRecord(report, coverageTypes)
|
|
782
|
-
).map(([type, stats]) => [
|
|
783
|
-
type,
|
|
784
|
-
{
|
|
785
|
-
totalFound: (acc[type]?.totalFound ?? 0) + stats.totalFound,
|
|
786
|
-
totalHit: (acc[type]?.totalHit ?? 0) + stats.totalHit,
|
|
787
|
-
issues: [...acc[type]?.issues ?? [], ...stats.issues]
|
|
788
|
-
}
|
|
789
|
-
])
|
|
790
|
-
]),
|
|
791
|
-
{}
|
|
792
|
-
);
|
|
793
|
-
}
|
|
794
|
-
function getCoverageStatsFromLcovRecord(record, coverageTypes) {
|
|
795
|
-
return Object.fromEntries(
|
|
796
|
-
coverageTypes.map((coverageType) => [
|
|
797
|
-
coverageType,
|
|
798
|
-
recordToStatFunctionMapper[coverageType](record)
|
|
799
|
-
])
|
|
800
|
-
);
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
// packages/plugin-coverage/src/lib/utils.ts
|
|
804
|
-
function applyMaxScoreAboveThreshold(outputs, threshold) {
|
|
805
|
-
return outputs.map(
|
|
806
|
-
(output) => output.score >= threshold ? { ...output, score: 1 } : output
|
|
807
|
-
);
|
|
672
|
+
};
|
|
808
673
|
}
|
|
809
674
|
|
|
810
675
|
// packages/plugin-coverage/src/lib/coverage-plugin.ts
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
);
|
|
815
|
-
function coveragePlugin(config) {
|
|
816
|
-
const { reports, perfectScoreThreshold, coverageTypes, coverageToolCommand } = coveragePluginConfigSchema.parse(config);
|
|
817
|
-
const audits = coverageTypes.map(
|
|
676
|
+
async function coveragePlugin(config) {
|
|
677
|
+
const coverageConfig = coveragePluginConfigSchema.parse(config);
|
|
678
|
+
const audits = coverageConfig.coverageTypes.map(
|
|
818
679
|
(type) => ({
|
|
819
680
|
slug: `${type}-coverage`,
|
|
820
681
|
title: `${capitalize(type)} coverage`,
|
|
821
|
-
description:
|
|
682
|
+
description: coverageDescription[type]
|
|
822
683
|
})
|
|
823
684
|
);
|
|
824
|
-
const
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
outputTransform: getAuditOutputs
|
|
685
|
+
const group = {
|
|
686
|
+
slug: "coverage",
|
|
687
|
+
title: "Code coverage metrics",
|
|
688
|
+
description: "Group containing all defined coverage types as audits.",
|
|
689
|
+
refs: audits.map((audit) => ({
|
|
690
|
+
...audit,
|
|
691
|
+
weight: coverageTypeWeightMapper[audit.slug.slice(0, audit.slug.indexOf("-"))]
|
|
692
|
+
}))
|
|
833
693
|
};
|
|
694
|
+
const runnerScriptPath = join3(
|
|
695
|
+
fileURLToPath(dirname(import.meta.url)),
|
|
696
|
+
"bin.js"
|
|
697
|
+
);
|
|
834
698
|
return {
|
|
835
699
|
slug: "coverage",
|
|
836
700
|
title: "Code coverage",
|
|
@@ -840,12 +704,68 @@ function coveragePlugin(config) {
|
|
|
840
704
|
packageName: name,
|
|
841
705
|
version,
|
|
842
706
|
audits,
|
|
843
|
-
|
|
707
|
+
groups: [group],
|
|
708
|
+
runner: await createRunnerConfig(runnerScriptPath, coverageConfig)
|
|
844
709
|
};
|
|
845
710
|
}
|
|
846
711
|
|
|
712
|
+
// packages/plugin-coverage/src/lib/nx/coverage-paths.ts
|
|
713
|
+
import chalk6 from "chalk";
|
|
714
|
+
import { join as join4 } from "node:path";
|
|
715
|
+
async function getNxCoveragePaths(targets = ["test"]) {
|
|
716
|
+
console.info(
|
|
717
|
+
chalk6.bold("\u{1F4A1} Gathering coverage from the following nx projects:")
|
|
718
|
+
);
|
|
719
|
+
const { createProjectGraphAsync } = await import("@nx/devkit");
|
|
720
|
+
const { nodes } = await createProjectGraphAsync({ exitOnError: false });
|
|
721
|
+
const coverageResults = targets.map((target) => {
|
|
722
|
+
const relevantNodes = Object.values(nodes).filter(
|
|
723
|
+
(graph) => hasNxTarget(graph, target)
|
|
724
|
+
);
|
|
725
|
+
return relevantNodes.map(({ name: name2, data }) => {
|
|
726
|
+
const targetConfig = data.targets?.[target];
|
|
727
|
+
const coveragePath = getCoveragePathForTarget(target, targetConfig, name2);
|
|
728
|
+
const rootToReportsDir = join4(data.root, coveragePath);
|
|
729
|
+
console.info(`- ${name2}: ${target}`);
|
|
730
|
+
return {
|
|
731
|
+
pathToProject: data.root,
|
|
732
|
+
resultsPath: join4(rootToReportsDir, "lcov.info")
|
|
733
|
+
};
|
|
734
|
+
});
|
|
735
|
+
});
|
|
736
|
+
console.info("\n");
|
|
737
|
+
return coverageResults.flat();
|
|
738
|
+
}
|
|
739
|
+
function hasNxTarget(project, target) {
|
|
740
|
+
return project.data.targets != null && target in project.data.targets;
|
|
741
|
+
}
|
|
742
|
+
function getCoveragePathForTarget(target, targetConfig, projectName) {
|
|
743
|
+
if (targetConfig.executor?.includes("@nx/vite")) {
|
|
744
|
+
const { reportsDirectory } = targetConfig.options;
|
|
745
|
+
if (reportsDirectory == null) {
|
|
746
|
+
throw new Error(
|
|
747
|
+
`Coverage configuration not found for target ${target} in ${projectName}. Define your Vitest coverage directory in the reportsDirectory option.`
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
return reportsDirectory;
|
|
751
|
+
}
|
|
752
|
+
if (targetConfig.executor?.includes("@nx/jest")) {
|
|
753
|
+
const { coverageDirectory } = targetConfig.options;
|
|
754
|
+
if (coverageDirectory == null) {
|
|
755
|
+
throw new Error(
|
|
756
|
+
`Coverage configuration not found for target ${target} in ${projectName}. Define your Jest coverage directory in the coverageDirectory option.`
|
|
757
|
+
);
|
|
758
|
+
}
|
|
759
|
+
return coverageDirectory;
|
|
760
|
+
}
|
|
761
|
+
throw new Error(
|
|
762
|
+
`Unsupported executor ${targetConfig.executor}. @nx/vite and @nx/jest are currently supported.`
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
|
|
847
766
|
// packages/plugin-coverage/src/index.ts
|
|
848
767
|
var src_default = coveragePlugin;
|
|
849
768
|
export {
|
|
850
|
-
src_default as default
|
|
769
|
+
src_default as default,
|
|
770
|
+
getNxCoveragePaths
|
|
851
771
|
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-pushup/coverage-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@code-pushup/models": "*",
|
|
6
6
|
"@code-pushup/utils": "*",
|
|
7
7
|
"parse-lcov": "^1.0.4",
|
|
8
|
+
"chalk": "^5.3.0",
|
|
8
9
|
"zod": "^3.22.4"
|
|
9
10
|
},
|
|
11
|
+
"peerDependencies": {
|
|
12
|
+
"@nx/devkit": "^17.0.0"
|
|
13
|
+
},
|
|
14
|
+
"peerDependenciesMeta": {
|
|
15
|
+
"@nx/devkit": {
|
|
16
|
+
"optional": true
|
|
17
|
+
}
|
|
18
|
+
},
|
|
10
19
|
"license": "MIT",
|
|
11
20
|
"homepage": "https://github.com/code-pushup/cli#readme",
|
|
12
21
|
"bugs": {
|
package/src/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/src/index.d.ts
CHANGED
package/src/lib/config.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export declare const coverageTypeSchema: z.ZodEnum<["function", "branch", "line"]>;
|
|
3
3
|
export type CoverageType = z.infer<typeof coverageTypeSchema>;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const coverageResultSchema: z.ZodObject<{
|
|
5
5
|
resultsPath: z.ZodString;
|
|
6
6
|
pathToProject: z.ZodOptional<z.ZodString>;
|
|
7
7
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -11,7 +11,7 @@ export declare const coverageReportSchema: z.ZodObject<{
|
|
|
11
11
|
resultsPath: string;
|
|
12
12
|
pathToProject?: string | undefined;
|
|
13
13
|
}>;
|
|
14
|
-
export type
|
|
14
|
+
export type CoverageResult = z.infer<typeof coverageResultSchema>;
|
|
15
15
|
export declare const coveragePluginConfigSchema: z.ZodObject<{
|
|
16
16
|
coverageToolCommand: z.ZodOptional<z.ZodObject<{
|
|
17
17
|
command: z.ZodString;
|
|
@@ -59,3 +59,4 @@ export declare const coveragePluginConfigSchema: z.ZodObject<{
|
|
|
59
59
|
perfectScoreThreshold?: number | undefined;
|
|
60
60
|
}>;
|
|
61
61
|
export type CoveragePluginConfig = z.input<typeof coveragePluginConfigSchema>;
|
|
62
|
+
export type FinalCoveragePluginConfig = z.infer<typeof coveragePluginConfigSchema>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { PluginConfig } from '@code-pushup/models';
|
|
2
2
|
import { CoveragePluginConfig } from './config';
|
|
3
|
-
export declare const RUNNER_OUTPUT_PATH: string;
|
|
4
3
|
/**
|
|
5
4
|
* Instantiates Code PushUp code coverage plugin for core config.
|
|
6
5
|
*
|
|
@@ -19,4 +18,4 @@ export declare const RUNNER_OUTPUT_PATH: string;
|
|
|
19
18
|
*
|
|
20
19
|
* @returns Plugin configuration.
|
|
21
20
|
*/
|
|
22
|
-
export declare function coveragePlugin(config: CoveragePluginConfig): PluginConfig
|
|
21
|
+
export declare function coveragePlugin(config: CoveragePluginConfig): Promise<PluginConfig>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CoverageResult } from '../config';
|
|
2
|
+
/**
|
|
3
|
+
* @param targets nx targets to be used for measuring coverage, test by default
|
|
4
|
+
* @returns An array of coverage result information for the coverage plugin.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getNxCoveragePaths(targets?: string[]): Promise<CoverageResult[]>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { RunnerConfig } from '@code-pushup/models';
|
|
2
|
+
import { FinalCoveragePluginConfig } from '../config';
|
|
3
|
+
export declare function executeRunner(): Promise<void>;
|
|
4
|
+
export declare function createRunnerConfig(scriptPath: string, config: FinalCoveragePluginConfig): Promise<RunnerConfig>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AuditOutputs } from '@code-pushup/models';
|
|
2
|
+
import { CoverageResult, CoverageType } from '../../config';
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param results Paths to LCOV results
|
|
6
|
+
* @param coverageTypes types of coverage to be considered
|
|
7
|
+
* @returns Audit outputs with complete coverage data.
|
|
8
|
+
*/
|
|
9
|
+
export declare function lcovResultsToAuditOutputs(results: CoverageResult[], coverageTypes: CoverageType[]): Promise<AuditOutputs>;
|
package/src/lib/utils.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { AuditOutputs } from '@code-pushup/models';
|
|
2
|
+
import { CoverageType } from './config';
|
|
3
|
+
export declare const coverageDescription: Record<CoverageType, string>;
|
|
2
4
|
/**
|
|
3
5
|
* Since more code coverage does not necessarily mean better score, this optional override allows for defining custom coverage goals.
|
|
4
6
|
* @param outputs original results
|
|
@@ -6,3 +8,4 @@ import type { AuditOutputs } from '@code-pushup/models';
|
|
|
6
8
|
* @returns Outputs with overriden score (not value) to 1 if it reached a defined threshold.
|
|
7
9
|
*/
|
|
8
10
|
export declare function applyMaxScoreAboveThreshold(outputs: AuditOutputs, threshold: number): AuditOutputs;
|
|
11
|
+
export declare const coverageTypeWeightMapper: Record<CoverageType, number>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { AuditOutputs } from '@code-pushup/models';
|
|
2
|
-
import { CoverageReport, CoverageType } from '../../config';
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param reports report files
|
|
6
|
-
* @param coverageTypes types of coverage to be considered
|
|
7
|
-
* @returns Audit outputs with complete coverage data.
|
|
8
|
-
*/
|
|
9
|
-
export declare function lcovResultsToAuditOutputs(reports: CoverageReport[], coverageTypes: CoverageType[]): Promise<AuditOutputs>;
|