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 21, 2022
1 parent a293b75 commit 4832d23
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/jest-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dependencies": {
"@jest/console": "^28.0.0-alpha.9",
"@jest/reporters": "^28.0.0-alpha.11",
"@jest/reporters": "^28.0.0-alpha.12",
"@jest/test-result": "^28.0.0-alpha.9",
"@jest/transform": "^28.0.0-alpha.11",
"@jest/types": "^28.0.0-alpha.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-reporters/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@jest/reporters",
"description": "Jest's reporters",
"version": "28.0.0-alpha.11",
"version": "28.0.0-alpha.12",

This comment has been minimized.

Copy link
@j3tan

j3tan Apr 21, 2022

probably an error? These are version bumps are handled separate, usually with a lerna command

"main": "./build/index.js",
"types": "./build/index.d.ts",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-reporters/src/CoverageReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export default class CoverageReporter extends BaseReporter {
const pathOrGlobMatches = thresholdGroups.reduce<
Array<[string, string]>
>((agg, thresholdGroup) => {
const absoluteThresholdGroup = path.resolve(thresholdGroup);
const absoluteThresholdGroup = path.resolve(thresholdGroup) + (thresholdGroup.length > 1 && thresholdGroup[thresholdGroup.length - 1] === path.sep ? path.sep : '');

This comment has been minimized.

Copy link
@j3tan

j3tan Apr 21, 2022

A little hard to read, potentially do:

const suffix = thresholdGroup.endsWith(path.sep) ? path.sep : '';
const absoluteThresholdGroup = `${path.resolve(thresholdGroup)}${suffix}`;

Also add a comment explaining why we are re-appending a trailing slash


// 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,

This comment has been minimized.

Copy link
@j3tan

j3tan Apr 21, 2022

shouldn't this not change?

This comment has been minimized.

Copy link
@wespickett

wespickett Apr 22, 2022

Author Owner

The global coverage was 50%, but I added a file with 100% coverage, so it bumped to global coverage a bit

},
},
},
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2544,7 +2544,7 @@ __metadata:
resolution: "@jest/core@workspace:packages/jest-core"
dependencies:
"@jest/console": ^28.0.0-alpha.9
"@jest/reporters": ^28.0.0-alpha.11
"@jest/reporters": ^28.0.0-alpha.12
"@jest/test-result": ^28.0.0-alpha.9
"@jest/test-sequencer": ^28.0.0-alpha.11
"@jest/test-utils": ^28.0.0-alpha.9
Expand Down Expand Up @@ -2748,7 +2748,7 @@ __metadata:
languageName: unknown
linkType: soft

"@jest/reporters@^28.0.0-alpha.11, @jest/reporters@workspace:packages/jest-reporters":
"@jest/reporters@^28.0.0-alpha.12, @jest/reporters@workspace:packages/jest-reporters":
version: 0.0.0-use.local
resolution: "@jest/reporters@workspace:packages/jest-reporters"
dependencies:
Expand Down

0 comments on commit 4832d23

Please sign in to comment.