You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current coverage reporters are not accurate enough and lead to bad line assignments and incorrect coverage values.
Describe the feature
The current coverage behavior is actually kind of buggy and I've spent a month debugging it so I figured I'd ask for this to be added. On our end, we've patched our way out of the coverage collection because it just doesn't do what we want and it has been cumbersome to get right.
that let's me eject from this so I can set these variables myself. That may not be necessary for this feature. The main thing is not to set coverageReporters if one is provided. I also removed
import fs from 'fs'
import path from 'path'
const outputDir = `${process.env.COVERAGE_DIR}/jest_mcr_temp`
export default async function globalTeardown() {
// If bazel coverage is being run, otherwise don't do this
if (process.env.COVERAGE_DIR) {
/**
* generate the lcov report by merging all the existing
* lcov info files from the coverage dir generated
* by each test
*/
const filePath = path.join(outputDir, 'lcov.info')
/**
* We nest in a dir because otherwise we will gather
* json files that bazel itself generates and we wish to avoid
* gathering.
*/
if (!fs.existsSync(path.dirname(filePath))) {
fs.mkdirSync(path.dirname(filePath), { recursive: true })
}
// If the lcov file doesn't exist, make one otherwise
// coverage fails. This applies to non standard file types like
// html, json, etc.
if (!fs.existsSync(filePath)) {
fs.writeFileSync(filePath, '', {
encoding: 'utf8',
})
}
// Following is taken from https://github.com/aspect-build/rules_jest/blob/940a9fe3c319e1351352e2ffa889e05db790343e/jest/private/jest_config_template.mjs#L151C1-L162
let coverageFile = path.basename(process.env.COVERAGE_OUTPUT_FILE as string)
let coverageDirectory = path.dirname(
process.env.COVERAGE_OUTPUT_FILE as string
)
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/split_coverage.dat` which then later moved by merger.sh to final location.
coverageDirectory = process.env.COVERAGE_DIR as string
coverageFile = 'coverage.dat'
}
// end of rules_js code
// Write coverage data to a file that Bazel knows how to handle
await fs.promises.copyFile(
path.join(outputDir, 'lcov.info'),
path.join(coverageDirectory, coverageFile)
)
}
}
What is the current behavior?
The current coverage reporters are not accurate enough and lead to bad line assignments and incorrect coverage values.
Describe the feature
The current coverage behavior is actually kind of buggy and I've spent a month debugging it so I figured I'd ask for this to be added. On our end, we've patched our way out of the coverage collection because it just doesn't do what we want and it has been cumbersome to get right.
How I fixed this on my end:
rules_jest/jest/private/jest_config_template.mjs
Lines 152 to 165 in 940a9fe
coverageReporters
if one is provided. I also removedrules_jest/jest/private/jest_config_template.mjs
Lines 174 to 179 in 940a9fe
coverageReporters
tocoverageReporters: ['none'],
reporters
globalTeardown
script with the followingThe text was updated successfully, but these errors were encountered: