Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow ejecting from coverage reporting in jest_config_template.mjs #294

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions jest/private/jest_config_template.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SKIP_SETTING_COVERAGE_DIR is a custom env var that you set on your jest_test targets?

Perhaps we expose this as a config attribute such as automatic_coverage_reporting which default to True but can be opted out of if you roll your own in a globalTeardown?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes because we source our jest_test from a macro that embeds that in env and then give everyone the same baseline jest.config that we provide which has globalTeardown set. I'm fine with a config attribute, but maybe scope it to be rules_jest_automatic_coverage_reporting so it's not so generic it could have other implications

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) {
Expand Down