Skip to content

Commit

Permalink
fix: issue with trailing slash in matching coverageThreshold keys (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
wespickett authored Apr 27, 2022
1 parent f43871e commit 27eb77e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Fixes

- `[@jest/reporters]` Fix trailing slash in matching `coverageThreshold` key ([#12714](https://github.com/facebook/jest/pull/12714))

### Chore & Maintenance

### Performance
Expand Down
11 changes: 10 additions & 1 deletion packages/jest-reporters/src/CoverageReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,16 @@ 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 resolvedThresholdGroup = path.resolve(thresholdGroup);
const suffix =
(thresholdGroup.endsWith(path.sep) ||
(process.platform === 'win32' && thresholdGroup.endsWith('/'))) &&
!resolvedThresholdGroup.endsWith(path.sep)
? path.sep
: '';
const absoluteThresholdGroup = `${resolvedThresholdGroup}${suffix}`;

// The threshold group might be a path:

Expand Down
14 changes: 13 additions & 1 deletion 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 @@ -309,6 +315,9 @@ describe('onRunComplete', () => {
'./path-test-files/': {
statements: 50,
},
'./path-test/': {
statements: 100,
},
global: {
statements: 100,
},
Expand Down Expand Up @@ -370,6 +379,9 @@ describe('onRunComplete', () => {
'./path-test-files/100pc_coverage_file.js': {
statements: 100,
},
'./path-test/100pc_coverage_file.js': {
statements: 100,
},
global: {
statements: 50,
},
Expand Down

0 comments on commit 27eb77e

Please sign in to comment.