@code-pushup/coverage-plugin 0.30.0-alpha → 0.35.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/index.js CHANGED
@@ -698,6 +698,21 @@ async function ensureDirectoryExists(baseDir) {
698
698
  }
699
699
  }
700
700
  }
701
+ var NoExportError = class extends Error {
702
+ constructor(filepath) {
703
+ super(`No default export found in ${filepath}`);
704
+ }
705
+ };
706
+ async function importEsmModule(options) {
707
+ const { mod } = await bundleRequire({
708
+ format: "esm",
709
+ ...options
710
+ });
711
+ if (!("default" in mod)) {
712
+ throw new NoExportError(options.filepath);
713
+ }
714
+ return mod.default;
715
+ }
701
716
  function pluginWorkDir(slug) {
702
717
  return join("node_modules", ".code-pushup", slug);
703
718
  }
@@ -721,7 +736,7 @@ import chalk4 from "chalk";
721
736
 
722
737
  // packages/plugin-coverage/package.json
723
738
  var name = "@code-pushup/coverage-plugin";
724
- var version = "0.29.0";
739
+ var version = "0.35.0";
725
740
 
726
741
  // packages/plugin-coverage/src/lib/config.ts
727
742
  import { z as z15 } from "zod";
@@ -857,23 +872,31 @@ async function getNxCoveragePaths(targets = ["test"], verbose) {
857
872
  }
858
873
  const { createProjectGraphAsync } = await import("@nx/devkit");
859
874
  const { nodes } = await createProjectGraphAsync({ exitOnError: false });
860
- const coverageResults = targets.map((target) => {
861
- const relevantNodes = Object.values(nodes).filter(
862
- (graph) => hasNxTarget(graph, target)
863
- );
864
- return relevantNodes.map(({ name: name2, data }) => {
865
- const targetConfig = data.targets?.[target];
866
- const coveragePath = getCoveragePathForTarget(target, targetConfig, name2);
867
- const rootToReportsDir = join4(data.root, coveragePath);
868
- if (verbose) {
869
- ui().logger.info(`- ${name2}: ${target}`);
870
- }
871
- return {
872
- pathToProject: data.root,
873
- resultsPath: join4(rootToReportsDir, "lcov.info")
874
- };
875
- });
876
- });
875
+ const coverageResults = await Promise.all(
876
+ targets.map(async (target) => {
877
+ const relevantNodes = Object.values(nodes).filter(
878
+ (graph) => hasNxTarget(graph, target)
879
+ );
880
+ return await Promise.all(
881
+ relevantNodes.map(async ({ name: name2, data }) => {
882
+ const targetConfig = data.targets?.[target];
883
+ const coveragePath = await getCoveragePathForTarget(
884
+ target,
885
+ targetConfig,
886
+ name2
887
+ );
888
+ const rootToReportsDir = join4(data.root, coveragePath);
889
+ if (verbose) {
890
+ ui().logger.info(`- ${name2}: ${target}`);
891
+ }
892
+ return {
893
+ pathToProject: data.root,
894
+ resultsPath: join4(rootToReportsDir, "lcov.info")
895
+ };
896
+ })
897
+ );
898
+ })
899
+ );
877
900
  if (verbose) {
878
901
  ui().logger.info("\n");
879
902
  }
@@ -882,21 +905,39 @@ async function getNxCoveragePaths(targets = ["test"], verbose) {
882
905
  function hasNxTarget(project, target) {
883
906
  return project.data.targets != null && target in project.data.targets;
884
907
  }
885
- function getCoveragePathForTarget(target, targetConfig, projectName) {
908
+ async function getCoveragePathForTarget(target, targetConfig, projectName) {
909
+ const { config } = targetConfig.options;
886
910
  if (targetConfig.executor?.includes("@nx/vite")) {
887
- const { reportsDirectory } = targetConfig.options;
911
+ const testConfig = await importEsmModule({
912
+ filepath: config
913
+ });
914
+ const reportsDirectory = testConfig.test.coverage?.reportsDirectory;
915
+ const reporter = testConfig.test.coverage?.reporter;
888
916
  if (reportsDirectory == null) {
889
917
  throw new Error(
890
- `Coverage configuration not found for target ${target} in ${projectName}. Define your Vitest coverage directory in the reportsDirectory option.`
918
+ `Vitest coverage configuration at ${config} does not include coverage path for target ${target} in ${projectName}. Add the path under coverage > reportsDirectory.`
919
+ );
920
+ }
921
+ if (!reporter?.includes("lcov")) {
922
+ throw new Error(
923
+ `Vitest coverage configuration at ${config} does not include LCOV report format for target ${target} in ${projectName}. Add 'lcov' format under coverage > reporter.`
891
924
  );
892
925
  }
893
926
  return reportsDirectory;
894
927
  }
895
928
  if (targetConfig.executor?.includes("@nx/jest")) {
896
- const { coverageDirectory } = targetConfig.options;
929
+ const testConfig = await importEsmModule({
930
+ filepath: config
931
+ });
932
+ const coverageDirectory = testConfig.coverageDirectory;
897
933
  if (coverageDirectory == null) {
898
934
  throw new Error(
899
- `Coverage configuration not found for target ${target} in ${projectName}. Define your Jest coverage directory in the coverageDirectory option.`
935
+ `Jest coverage configuration at ${config} does not include coverage path for target ${target} in ${projectName}. Add the path under coverageDirectory.`
936
+ );
937
+ }
938
+ if (!testConfig.coverageReporters?.includes("lcov")) {
939
+ throw new Error(
940
+ `Jest coverage configuration at ${config} does not include LCOV report format for target ${target} in ${projectName}. Add 'lcov' format under coverageReporters.`
900
941
  );
901
942
  }
902
943
  return coverageDirectory;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@code-pushup/coverage-plugin",
3
- "version": "0.30.0-alpha",
3
+ "version": "0.35.0",
4
4
  "dependencies": {
5
- "@code-pushup/models": "*",
6
- "@code-pushup/utils": "*",
5
+ "@code-pushup/models": "0.35.0",
6
+ "@code-pushup/utils": "0.35.0",
7
7
  "parse-lcov": "^1.0.4",
8
8
  "chalk": "^5.3.0",
9
9
  "zod": "^3.22.4"
@@ -1,6 +1,20 @@
1
+ import type { TargetConfiguration } from '@nx/devkit';
1
2
  import { CoverageResult } from '../config';
2
3
  /**
3
4
  * @param targets nx targets to be used for measuring coverage, test by default
4
5
  * @returns An array of coverage result information for the coverage plugin.
5
6
  */
6
7
  export declare function getNxCoveragePaths(targets?: string[], verbose?: boolean): Promise<CoverageResult[]>;
8
+ export type VitestCoverageConfig = {
9
+ test: {
10
+ coverage?: {
11
+ reporter?: string[];
12
+ reportsDirectory?: string;
13
+ };
14
+ };
15
+ };
16
+ export type JestCoverageConfig = {
17
+ coverageDirectory?: string;
18
+ coverageReporters?: string[];
19
+ };
20
+ export declare function getCoveragePathForTarget(target: string, targetConfig: TargetConfiguration, projectName: string): Promise<string>;