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

fix: issue with trailing slash in matching coverageThreshold keys #12714

Merged
merged 10 commits into from
Apr 27, 2022
Next Next commit
fix: issue with trailing slash in matching coverageThreshold keys
wespickett committed Apr 22, 2022
commit 4a06da4533c9244a5c43a17e2c09803d51c714cf
5 changes: 4 additions & 1 deletion packages/jest-reporters/src/CoverageReporter.ts
Original file line number Diff line number Diff line change
@@ -269,7 +269,10 @@ export default class CoverageReporter extends BaseReporter {
const pathOrGlobMatches = thresholdGroups.reduce<
Array<[string, string]>
>((agg, thresholdGroup) => {
const absoluteThresholdGroup = path.resolve(thresholdGroup);
// Preserve trailing slash, but not required if root dir
// See https://github.com/facebook/jest/issues/12703
const suffix = thresholdGroup.length > 1 && thresholdGroup.endsWith(path.sep) ? path.sep : '';
const absoluteThresholdGroup = `${path.resolve(thresholdGroup)}${suffix}`;

// The threshold group might be a path:

14 changes: 13 additions & 1 deletion packages/jest-reporters/src/__tests__/CoverageReporter.test.js
Original file line number Diff line number Diff line change
@@ -44,7 +44,9 @@ beforeEach(() => {
'non_covered_file.js': '',
'relative_path_file.js': '',
};

fileTree[`${process.cwd()}/path-test`] = {
'100pc_coverage_file.js': '',
};
mock(fileTree);
});

@@ -79,6 +81,10 @@ describe('onRunComplete', () => {
statements: {covered: 5, pct: 50, skipped: 0, total: 10},
};
const fileCoverage = [
[
'./path-test/100pc_coverage_file.js',
{statements: {covered: 10, pct: 100, total: 10}},
],
['./path-test-files/covered_file_without_threshold.js'],
['./path-test-files/full_path_file.js'],
['./path-test-files/relative_path_file.js'],
@@ -306,6 +312,9 @@ describe('onRunComplete', () => {
{
collectCoverage: true,
coverageThreshold: {
'./path-test/': {
statements: 100,
},
'./path-test-files/': {
statements: 50,
},
@@ -367,6 +376,9 @@ describe('onRunComplete', () => {
{
collectCoverage: true,
coverageThreshold: {
'./path-test/100pc_coverage_file.js': {
statements: 100,
},
'./path-test-files/100pc_coverage_file.js': {
statements: 100,
},