@code-pushup/coverage-plugin 0.34.0 → 0.39.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/bin.js CHANGED
@@ -579,10 +579,14 @@ function makeArraysComparisonSchema(diffSchema, resultSchema, description) {
579
579
  { description }
580
580
  );
581
581
  }
582
- var scorableMetaSchema = z14.object({ slug: slugSchema, title: titleSchema });
582
+ var scorableMetaSchema = z14.object({
583
+ slug: slugSchema,
584
+ title: titleSchema,
585
+ docsUrl: docsUrlSchema
586
+ });
583
587
  var scorableWithPluginMetaSchema = scorableMetaSchema.merge(
584
588
  z14.object({
585
- plugin: pluginMetaSchema.pick({ slug: true, title: true }).describe("Plugin which defines it")
589
+ plugin: pluginMetaSchema.pick({ slug: true, title: true, docsUrl: true }).describe("Plugin which defines it")
586
590
  })
587
591
  );
588
592
  var scorableDiffSchema = scorableMetaSchema.merge(
@@ -704,7 +708,7 @@ async function ensureDirectoryExists(baseDir) {
704
708
  await mkdir(baseDir, { recursive: true });
705
709
  return;
706
710
  } catch (error) {
707
- ui().logger.error(error.message);
711
+ ui().logger.info(error.message);
708
712
  if (error.code !== "EEXIST") {
709
713
  throw error;
710
714
  }
package/index.js CHANGED
@@ -578,10 +578,14 @@ function makeArraysComparisonSchema(diffSchema, resultSchema, description) {
578
578
  { description }
579
579
  );
580
580
  }
581
- var scorableMetaSchema = z14.object({ slug: slugSchema, title: titleSchema });
581
+ var scorableMetaSchema = z14.object({
582
+ slug: slugSchema,
583
+ title: titleSchema,
584
+ docsUrl: docsUrlSchema
585
+ });
582
586
  var scorableWithPluginMetaSchema = scorableMetaSchema.merge(
583
587
  z14.object({
584
- plugin: pluginMetaSchema.pick({ slug: true, title: true }).describe("Plugin which defines it")
588
+ plugin: pluginMetaSchema.pick({ slug: true, title: true, docsUrl: true }).describe("Plugin which defines it")
585
589
  })
586
590
  );
587
591
  var scorableDiffSchema = scorableMetaSchema.merge(
@@ -692,12 +696,27 @@ async function ensureDirectoryExists(baseDir) {
692
696
  await mkdir(baseDir, { recursive: true });
693
697
  return;
694
698
  } catch (error) {
695
- ui().logger.error(error.message);
699
+ ui().logger.info(error.message);
696
700
  if (error.code !== "EEXIST") {
697
701
  throw error;
698
702
  }
699
703
  }
700
704
  }
705
+ var NoExportError = class extends Error {
706
+ constructor(filepath) {
707
+ super(`No default export found in ${filepath}`);
708
+ }
709
+ };
710
+ async function importEsmModule(options) {
711
+ const { mod } = await bundleRequire({
712
+ format: "esm",
713
+ ...options
714
+ });
715
+ if (!("default" in mod)) {
716
+ throw new NoExportError(options.filepath);
717
+ }
718
+ return mod.default;
719
+ }
701
720
  function pluginWorkDir(slug) {
702
721
  return join("node_modules", ".code-pushup", slug);
703
722
  }
@@ -721,7 +740,7 @@ import chalk4 from "chalk";
721
740
 
722
741
  // packages/plugin-coverage/package.json
723
742
  var name = "@code-pushup/coverage-plugin";
724
- var version = "0.34.0";
743
+ var version = "0.39.0";
725
744
 
726
745
  // packages/plugin-coverage/src/lib/config.ts
727
746
  import { z as z15 } from "zod";
@@ -857,23 +876,31 @@ async function getNxCoveragePaths(targets = ["test"], verbose) {
857
876
  }
858
877
  const { createProjectGraphAsync } = await import("@nx/devkit");
859
878
  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
- });
879
+ const coverageResults = await Promise.all(
880
+ targets.map(async (target) => {
881
+ const relevantNodes = Object.values(nodes).filter(
882
+ (graph) => hasNxTarget(graph, target)
883
+ );
884
+ return await Promise.all(
885
+ relevantNodes.map(async ({ name: name2, data }) => {
886
+ const targetConfig = data.targets?.[target];
887
+ const coveragePath = await getCoveragePathForTarget(
888
+ target,
889
+ targetConfig,
890
+ name2
891
+ );
892
+ const rootToReportsDir = join4(data.root, coveragePath);
893
+ if (verbose) {
894
+ ui().logger.info(`- ${name2}: ${target}`);
895
+ }
896
+ return {
897
+ pathToProject: data.root,
898
+ resultsPath: join4(rootToReportsDir, "lcov.info")
899
+ };
900
+ })
901
+ );
902
+ })
903
+ );
877
904
  if (verbose) {
878
905
  ui().logger.info("\n");
879
906
  }
@@ -882,21 +909,39 @@ async function getNxCoveragePaths(targets = ["test"], verbose) {
882
909
  function hasNxTarget(project, target) {
883
910
  return project.data.targets != null && target in project.data.targets;
884
911
  }
885
- function getCoveragePathForTarget(target, targetConfig, projectName) {
912
+ async function getCoveragePathForTarget(target, targetConfig, projectName) {
913
+ const { config } = targetConfig.options;
886
914
  if (targetConfig.executor?.includes("@nx/vite")) {
887
- const { reportsDirectory } = targetConfig.options;
915
+ const testConfig = await importEsmModule({
916
+ filepath: config
917
+ });
918
+ const reportsDirectory = testConfig.test.coverage?.reportsDirectory;
919
+ const reporter = testConfig.test.coverage?.reporter;
888
920
  if (reportsDirectory == null) {
889
921
  throw new Error(
890
- `Coverage configuration not found for target ${target} in ${projectName}. Define your Vitest coverage directory in the reportsDirectory option.`
922
+ `Vitest coverage configuration at ${config} does not include coverage path for target ${target} in ${projectName}. Add the path under coverage > reportsDirectory.`
923
+ );
924
+ }
925
+ if (!reporter?.includes("lcov")) {
926
+ throw new Error(
927
+ `Vitest coverage configuration at ${config} does not include LCOV report format for target ${target} in ${projectName}. Add 'lcov' format under coverage > reporter.`
891
928
  );
892
929
  }
893
930
  return reportsDirectory;
894
931
  }
895
932
  if (targetConfig.executor?.includes("@nx/jest")) {
896
- const { coverageDirectory } = targetConfig.options;
933
+ const testConfig = await importEsmModule({
934
+ filepath: config
935
+ });
936
+ const coverageDirectory = testConfig.coverageDirectory;
897
937
  if (coverageDirectory == null) {
898
938
  throw new Error(
899
- `Coverage configuration not found for target ${target} in ${projectName}. Define your Jest coverage directory in the coverageDirectory option.`
939
+ `Jest coverage configuration at ${config} does not include coverage path for target ${target} in ${projectName}. Add the path under coverageDirectory.`
940
+ );
941
+ }
942
+ if (!testConfig.coverageReporters?.includes("lcov")) {
943
+ throw new Error(
944
+ `Jest coverage configuration at ${config} does not include LCOV report format for target ${target} in ${projectName}. Add 'lcov' format under coverageReporters.`
900
945
  );
901
946
  }
902
947
  return coverageDirectory;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@code-pushup/coverage-plugin",
3
- "version": "0.34.0",
3
+ "version": "0.39.0",
4
4
  "dependencies": {
5
- "@code-pushup/models": "0.34.0",
6
- "@code-pushup/utils": "0.34.0",
5
+ "@code-pushup/models": "0.39.0",
6
+ "@code-pushup/utils": "0.39.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>;