From 4a06da4533c9244a5c43a17e2c09803d51c714cf Mon Sep 17 00:00:00 2001 From: Wes Pickett Date: Thu, 21 Apr 2022 16:53:26 -0400 Subject: [PATCH 1/7] fix: issue with trailing slash in matching coverageThreshold keys https://github.com/facebook/jest/issues/12703 --- packages/jest-reporters/src/CoverageReporter.ts | 5 ++++- .../src/__tests__/CoverageReporter.test.js | 14 +++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/jest-reporters/src/CoverageReporter.ts b/packages/jest-reporters/src/CoverageReporter.ts index 203435f08f23..d7bf34d97045 100644 --- a/packages/jest-reporters/src/CoverageReporter.ts +++ b/packages/jest-reporters/src/CoverageReporter.ts @@ -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: diff --git a/packages/jest-reporters/src/__tests__/CoverageReporter.test.js b/packages/jest-reporters/src/__tests__/CoverageReporter.test.js index d3222c158e67..5ff132b9ec47 100644 --- a/packages/jest-reporters/src/__tests__/CoverageReporter.test.js +++ b/packages/jest-reporters/src/__tests__/CoverageReporter.test.js @@ -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, }, From bc46f4941465c51b423510e2d5813f432e787be2 Mon Sep 17 00:00:00 2001 From: Wes Pickett Date: Fri, 22 Apr 2022 16:25:44 -0400 Subject: [PATCH 2/7] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d6ffb16d57e..d0ac5cc645e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Features +- `[jest-reporters]` Fix: trailing slash in matching coverageThreshold key ([#12714](https://github.com/facebook/jest/pull/12714)) - `[babel-jest]` Export `createTransformer` function ([#12399](https://github.com/facebook/jest/pull/12399)) - `[expect]` Expose `AsymmetricMatchers`, `MatcherFunction` and `MatcherFunctionWithState` interfaces ([#12363](https://github.com/facebook/jest/pull/12363), [#12376](https://github.com/facebook/jest/pull/12376)) - `[jest-circus, jest-jasmine2]` Allowed classes and functions as `describe` and `it`/`test` names ([#12484](https://github.com/facebook/jest/pull/12484)) From 70954f880930d2586fcd2addcb70be5a332384c4 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 23 Apr 2022 10:23:19 +0200 Subject: [PATCH 3/7] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0ac5cc645e5..15717b15c27c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,6 @@ ### Features -- `[jest-reporters]` Fix: trailing slash in matching coverageThreshold key ([#12714](https://github.com/facebook/jest/pull/12714)) - `[babel-jest]` Export `createTransformer` function ([#12399](https://github.com/facebook/jest/pull/12399)) - `[expect]` Expose `AsymmetricMatchers`, `MatcherFunction` and `MatcherFunctionWithState` interfaces ([#12363](https://github.com/facebook/jest/pull/12363), [#12376](https://github.com/facebook/jest/pull/12376)) - `[jest-circus, jest-jasmine2]` Allowed classes and functions as `describe` and `it`/`test` names ([#12484](https://github.com/facebook/jest/pull/12484)) @@ -42,6 +41,7 @@ - `[jest-mock]` Add `contexts` member to mock functions ([#12601](https://github.com/facebook/jest/pull/12601)) - `[@jest/reporters]` Add GitHub Actions reporter ([#11320](https://github.com/facebook/jest/pull/11320), [#12658](https://github.com/facebook/jest/pull/12658)) - `[@jest/reporters]` Pass `reporterContext` to custom reporter constructors as third argument ([#12657](https://github.com/facebook/jest/pull/12657)) +- `[@jest/reporters]` Fix trailing slash in matching `coverageThreshold` key ([#12714](https://github.com/facebook/jest/pull/12714)) - `[jest-resolve]` [**BREAKING**] Add support for `package.json` `exports` ([#11961](https://github.com/facebook/jest/pull/11961), [#12373](https://github.com/facebook/jest/pull/12373)) - `[jest-resolve]` Support package self-reference ([#12682](https://github.com/facebook/jest/pull/12682)) - `[jest-resolve, jest-runtime]` Add support for `data:` URI import and mock ([#12392](https://github.com/facebook/jest/pull/12392)) From 30638963ee96a15abe5614a4b3b5f9f07933eac1 Mon Sep 17 00:00:00 2001 From: Wes Pickett Date: Tue, 26 Apr 2022 13:23:18 -0400 Subject: [PATCH 4/7] fix: lint issues. --- packages/jest-reporters/src/CoverageReporter.ts | 9 +++++++-- .../src/__tests__/CoverageReporter.test.js | 10 +++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/jest-reporters/src/CoverageReporter.ts b/packages/jest-reporters/src/CoverageReporter.ts index d7bf34d97045..557781225be2 100644 --- a/packages/jest-reporters/src/CoverageReporter.ts +++ b/packages/jest-reporters/src/CoverageReporter.ts @@ -271,8 +271,13 @@ export default class CoverageReporter extends BaseReporter { >((agg, 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}`; + const suffix = + thresholdGroup.length > 1 && thresholdGroup.endsWith(path.sep) + ? path.sep + : ''; + const absoluteThresholdGroup = `${path.resolve( + thresholdGroup, + )}${suffix}`; // The threshold group might be a path: diff --git a/packages/jest-reporters/src/__tests__/CoverageReporter.test.js b/packages/jest-reporters/src/__tests__/CoverageReporter.test.js index 5ff132b9ec47..1b77144cfcdc 100644 --- a/packages/jest-reporters/src/__tests__/CoverageReporter.test.js +++ b/packages/jest-reporters/src/__tests__/CoverageReporter.test.js @@ -312,12 +312,12 @@ describe('onRunComplete', () => { { collectCoverage: true, coverageThreshold: { - './path-test/': { - statements: 100, - }, './path-test-files/': { statements: 50, }, + './path-test/': { + statements: 100, + }, global: { statements: 100, }, @@ -376,10 +376,10 @@ describe('onRunComplete', () => { { collectCoverage: true, coverageThreshold: { - './path-test/100pc_coverage_file.js': { + './path-test-files/100pc_coverage_file.js': { statements: 100, }, - './path-test-files/100pc_coverage_file.js': { + './path-test/100pc_coverage_file.js': { statements: 100, }, global: { From e581837bcbe99bf4a9eba52384045bd61dd4038f Mon Sep 17 00:00:00 2001 From: Wes Pickett Date: Tue, 26 Apr 2022 14:00:38 -0400 Subject: [PATCH 5/7] fix: cleanup logic. --- packages/jest-reporters/src/CoverageReporter.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/jest-reporters/src/CoverageReporter.ts b/packages/jest-reporters/src/CoverageReporter.ts index 557781225be2..e7e4c6db3d1f 100644 --- a/packages/jest-reporters/src/CoverageReporter.ts +++ b/packages/jest-reporters/src/CoverageReporter.ts @@ -271,13 +271,13 @@ export default class CoverageReporter extends BaseReporter { >((agg, 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.length > 1 && thresholdGroup.endsWith(path.sep) + thresholdGroup.endsWith(path.sep) && + !resolvedThresholdGroup.endsWith(path.sep) ? path.sep : ''; - const absoluteThresholdGroup = `${path.resolve( - thresholdGroup, - )}${suffix}`; + const absoluteThresholdGroup = `${resolvedThresholdGroup}${suffix}`; // The threshold group might be a path: From 95c69b472214f16664aafac2c151e652ae475a24 Mon Sep 17 00:00:00 2001 From: Wes Pickett Date: Tue, 26 Apr 2022 23:43:32 +0400 Subject: [PATCH 6/7] fix: add windows specific case --- packages/jest-reporters/src/CoverageReporter.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/jest-reporters/src/CoverageReporter.ts b/packages/jest-reporters/src/CoverageReporter.ts index e7e4c6db3d1f..b842169a42b5 100644 --- a/packages/jest-reporters/src/CoverageReporter.ts +++ b/packages/jest-reporters/src/CoverageReporter.ts @@ -273,7 +273,8 @@ export default class CoverageReporter extends BaseReporter { // See https://github.com/facebook/jest/issues/12703 const resolvedThresholdGroup = path.resolve(thresholdGroup); const suffix = - thresholdGroup.endsWith(path.sep) && + (thresholdGroup.endsWith(path.sep) || + (process.platform === 'win32' && thresholdGroup.endsWith('/'))) && !resolvedThresholdGroup.endsWith(path.sep) ? path.sep : ''; From 7c352a2d56a11281aecf92cc4f5e85e7c1b56d07 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 27 Apr 2022 08:36:43 +0200 Subject: [PATCH 7/7] move changelog entry --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a74bded3c8db..2975896f5dad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Fixes - `[*]` Lower Node 16 requirement to 16.10 from 16.13 due to a [Node bug](https://github.com/nodejs/node/issues/40014) that causes memory and performance issues ([#12754](https://github.com/facebook/jest/pull/12754)) +- `[@jest/reporters]` Fix trailing slash in matching `coverageThreshold` key ([#12714](https://github.com/facebook/jest/pull/12714)) ### Chore & Maintenance @@ -45,7 +46,7 @@ - `[jest-config]` [**BREAKING**] Rename `moduleLoader` to `runtime` ([#10817](https://github.com/facebook/jest/pull/10817)) - `[jest-config]` [**BREAKING**] Rename `extraGlobals` to `sandboxInjectedGlobals` ([#10817](https://github.com/facebook/jest/pull/10817)) - `[jest-config]` [**BREAKING**] Throw an error instead of showing a warning if multiple configs are used ([#12510](https://github.com/facebook/jest/pull/12510)) -- `[jest-config]` [**BREAKING**] Do not normalize long deprecated configuration options `preprocessorIgnorePatterns`,`scriptPreprocessor`, `setupTestFrameworkScriptFile` and `testPathDirs` ([#1251270110](https://github.com/facebook/jest/pull/12701)) +- `[jest-config]` [**BREAKING**] Do not normalize long deprecated configuration options `preprocessorIgnorePatterns`, `scriptPreprocessor`, `setupTestFrameworkScriptFile` and `testPathDirs` ([#12701](https://github.com/facebook/jest/pull/12701)) - `[jest-cli, jest-core]` Add `--ignoreProjects` CLI argument to ignore test suites by project name ([#12620](https://github.com/facebook/jest/pull/12620)) - `[jest-core]` Pass project config to `globalSetup`/`globalTeardown` function as second argument ([#12440](https://github.com/facebook/jest/pull/12440)) - `[jest-core]` Stabilize test runners with event emitters ([#12641](https://github.com/facebook/jest/pull/12641)) @@ -72,7 +73,6 @@ - `[jest-mock]` Add `contexts` member to mock functions ([#12601](https://github.com/facebook/jest/pull/12601)) - `[@jest/reporters]` Add GitHub Actions reporter ([#11320](https://github.com/facebook/jest/pull/11320), [#12658](https://github.com/facebook/jest/pull/12658)) - `[@jest/reporters]` Pass `reporterContext` to custom reporter constructors as third argument ([#12657](https://github.com/facebook/jest/pull/12657)) -- `[@jest/reporters]` Fix trailing slash in matching `coverageThreshold` key ([#12714](https://github.com/facebook/jest/pull/12714)) - `[jest-resolve]` [**BREAKING**] Add support for `package.json` `exports` ([#11961](https://github.com/facebook/jest/pull/11961), [#12373](https://github.com/facebook/jest/pull/12373)) - `[jest-resolve]` Support package self-reference ([#12682](https://github.com/facebook/jest/pull/12682)) - `[jest-resolve, jest-runtime]` Add support for `data:` URI import and mock ([#12392](https://github.com/facebook/jest/pull/12392))