From 0facb4d3a0b95bdd11437622bb2d06681284251b Mon Sep 17 00:00:00 2001 From: David Date: Tue, 24 Sep 2024 20:36:28 -0700 Subject: [PATCH] allow ejecting from coverage reporting in jest_config_template.mjs This addresses the ability to let users define their own coverage reporting logic in unique cases. For us, we use monocart-coverage-reporter. In doing so, we needed to write our own `globalTeardown` for jest that uses the split coverage logic, but also manipulates the dat files before they are passed to bazel --- jest/private/jest_config_template.mjs | 34 ++++++++++++++++++--------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/jest/private/jest_config_template.mjs b/jest/private/jest_config_template.mjs index e2d2cc7..a1c90e1 100644 --- a/jest/private/jest_config_template.mjs +++ b/jest/private/jest_config_template.mjs @@ -152,18 +152,30 @@ if (coverageEnabled) { let coverageFile = path.basename(process.env.COVERAGE_OUTPUT_FILE); let coverageDirectory = path.dirname(process.env.COVERAGE_OUTPUT_FILE); - if (process.env.SPLIT_COVERAGE_POST_PROCESSING == "1") { - // in split coverage post processing mode bazel assumes that the COVERAGE_OUTPUT_FILE - // will be created by lcov_merger which runs as a separate action with everything in - // COVERAGE_DIR provided as inputs. so we'll just create the final coverage at - // `COVERAGE_DIR/coverage.dat` which then later moved by merger.sh to final location. - coverageDirectory = process.env.COVERAGE_DIR; - coverageFile = "coverage.dat"; + /** + * Allows the user to disable the jest manifest + * override so that we can pass our own reporters + * and output dir instead. + * + * This is useful in the case of injecting your + * own coverage reporters and then using globalTeardown + * replicate the SPLIT_COVERAGE_POSTPROCESSING logic while + * also manipulating/massaging the `.dat` file before it gets + * passed to Bazel + */ + if (process.env.SKIP_SETTING_COVERAGE_DIR != "1") { + if (process.env.SPLIT_COVERAGE_POST_PROCESSING == "1") { + // in split coverage post processing mode bazel assumes that the COVERAGE_OUTPUT_FILE + // will be created by lcov_merger which runs as a separate action with everything in + // COVERAGE_DIR provided as inputs. so we'll just create the final coverage at + // `COVERAGE_DIR/coverage.dat` which then later moved by merger.sh to final location. + coverageDirectory = process.env.COVERAGE_DIR; + coverageFile = "coverage.dat"; + } + + config.coverageDirectory = coverageDirectory; + config.coverageReporters = ["text", ["lcovonly", { file: coverageFile }]]; } - - config.coverageDirectory = coverageDirectory; - config.coverageReporters = ["text", ["lcovonly", { file: coverageFile }]]; - } if (process.env.JS_BINARY__LOG_DEBUG) {