Skip to content

Commit

Permalink
fix: issue with trailing slash in matching coverageThreshold keys
Browse files Browse the repository at this point in the history
  • Loading branch information
wespickett committed Apr 22, 2022
1 parent a293b75 commit 2af7081
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/jest-reporters/src/CoverageReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:

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

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

Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -306,6 +312,9 @@ describe('onRunComplete', () => {
{
collectCoverage: true,
coverageThreshold: {
'./path-test/': {
statements: 100,
},
'./path-test-files/': {
statements: 50,
},
Expand Down Expand Up @@ -367,11 +376,14 @@ describe('onRunComplete', () => {
{
collectCoverage: true,
coverageThreshold: {
'./path-test/100pc_coverage_file.js': {
statements: 100,
},
'./path-test-files/100pc_coverage_file.js': {
statements: 100,
},
global: {
statements: 50,
statements: 55.55,
},
},
},
Expand Down

0 comments on commit 2af7081

Please sign in to comment.