From ab2ae6d1496e72193d254f91f80ef08d8ba39a7d Mon Sep 17 00:00:00 2001 From: Luca Pizzini Date: Fri, 30 Dec 2022 09:27:46 +0100 Subject: [PATCH 1/9] feature: Added skipped and focused status to FormattedTestResult --- .../src/__tests__/formatTestResults.test.ts | 55 +++++++++++++++++-- .../jest-test-result/src/formatTestResults.ts | 21 ++++++- packages/jest-test-result/src/types.ts | 2 +- 3 files changed, 72 insertions(+), 6 deletions(-) diff --git a/packages/jest-test-result/src/__tests__/formatTestResults.test.ts b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts index 68936ddc25af..e928b57fa73a 100644 --- a/packages/jest-test-result/src/__tests__/formatTestResults.test.ts +++ b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts @@ -26,10 +26,57 @@ describe('formatTestResults', () => { ], }; - it('includes test full name', () => { - const result = formatTestResults(results, undefined, null); - expect(result.testResults[0].assertionResults[0].fullName).toEqual( - assertion.fullName, + const skippedAssertion = { + fullName: 'Pending test', + status: 'pending', + title: 'is still pending', + }; + + const skippedResults: AggregatedResult = { + testResults: [ + { + numFailingTests: 0, + numPassingTests: 0, + numPendingTests: 2, + numTodoTests: 2, + perfStats: {end: 2, runtime: 1, slow: false, start: 1}, + // @ts-expect-error + testResults: [skippedAssertion], + }, + ], + }; + + it('should mark result status to skipped', () => { + const result = formatTestResults(skippedResults, undefined, null); + expect(result.testResults[0].assertionResults[0].status).toEqual( + skippedAssertion.status, + ); + }); + + const focusedAssertion = { + fullName: 'Focused test', + status: 'focused', + title: 'focused test', + }; + + const focusedResults: AggregatedResult = { + testResults: [ + { + numFailingTests: 0, + numPassingTests: 1, + numPendingTests: 1, + numTodoTests: 2, + perfStats: {end: 2, runtime: 1, slow: false, start: 1}, + // @ts-expect-error + testResults: [focusedAssertion], + }, + ], + }; + + it('should mark result status to focused', () => { + const result = formatTestResults(focusedResults, undefined, null); + expect(result.testResults[0].assertionResults[0].status).toEqual( + focusedAssertion.status, ); }); }); diff --git a/packages/jest-test-result/src/formatTestResults.ts b/packages/jest-test-result/src/formatTestResults.ts index 60fb8ab0d039..d943a95ff8c7 100644 --- a/packages/jest-test-result/src/formatTestResults.ts +++ b/packages/jest-test-result/src/formatTestResults.ts @@ -33,6 +33,21 @@ const formatTestResult = ( }; } + if (testResult.skipped) { + const now = Date.now(); + return { + assertionResults: testResult.testResults, + coverage: {}, + endTime: now, + message: testResult.failureMessage ?? '', + name: testResult.testFilePath, + startTime: now, + status: 'skipped', + summary: '', + }; + } + + const allTestsExecuted = testResult.numPendingTests === 0; const allTestsPassed = testResult.numFailingTests === 0; return { assertionResults: testResult.testResults, @@ -44,7 +59,11 @@ const formatTestResult = ( message: testResult.failureMessage ?? '', name: testResult.testFilePath, startTime: testResult.perfStats.start, - status: allTestsPassed ? 'passed' : 'failed', + status: allTestsExecuted + ? allTestsPassed + ? 'passed' + : 'failed' + : 'focused', summary: '', }; }; diff --git a/packages/jest-test-result/src/types.ts b/packages/jest-test-result/src/types.ts index bbc6eeaf5114..aa369fc7175a 100644 --- a/packages/jest-test-result/src/types.ts +++ b/packages/jest-test-result/src/types.ts @@ -125,7 +125,7 @@ export type FormattedTestResult = { message: string; name: string; summary: string; - status: 'failed' | 'passed'; + status: 'failed' | 'passed' | 'skipped' | 'focused'; startTime: number; endTime: number; coverage: unknown; From 86c7a475fca6af23b860745b531b251c0d57f996 Mon Sep 17 00:00:00 2001 From: Luca Pizzini Date: Fri, 30 Dec 2022 09:38:19 +0100 Subject: [PATCH 2/9] fixed test result status evaluation --- packages/jest-test-result/src/formatTestResults.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/jest-test-result/src/formatTestResults.ts b/packages/jest-test-result/src/formatTestResults.ts index d943a95ff8c7..6e43024169e1 100644 --- a/packages/jest-test-result/src/formatTestResults.ts +++ b/packages/jest-test-result/src/formatTestResults.ts @@ -59,11 +59,11 @@ const formatTestResult = ( message: testResult.failureMessage ?? '', name: testResult.testFilePath, startTime: testResult.perfStats.start, - status: allTestsExecuted - ? allTestsPassed + status: allTestsPassed + ? allTestsExecuted ? 'passed' - : 'failed' - : 'focused', + : 'focused' + : 'failed', summary: '', }; }; From fd93b8ccb69501a93c468aa72c6dd077040bd1b1 Mon Sep 17 00:00:00 2001 From: Luca Pizzini Date: Sat, 31 Dec 2022 10:01:29 +0100 Subject: [PATCH 3/9] Added changelog entry and brought back erased test --- CHANGELOG.md | 2 ++ .../src/__tests__/formatTestResults.test.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07f7984aa970..1321a56d0bfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### Features +- `[jest-test-result]` Added `skipped` and `focused` status to `FormattedTestResult` ([#13700](https://github.com/facebook/jest/pull/13700)) + ### Fixes - `[jest-resolve]` add global paths to `require.resolve.paths` ([#13633](https://github.com/facebook/jest/pull/13633)) diff --git a/packages/jest-test-result/src/__tests__/formatTestResults.test.ts b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts index e928b57fa73a..c25565562272 100644 --- a/packages/jest-test-result/src/__tests__/formatTestResults.test.ts +++ b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts @@ -6,7 +6,7 @@ */ import formatTestResults from '../formatTestResults'; -import {AggregatedResult} from '../types'; +import type {AggregatedResult} from '../types'; describe('formatTestResults', () => { const assertion = { @@ -26,6 +26,13 @@ describe('formatTestResults', () => { ], }; + it('includes test full name', () => { + const result = formatTestResults(results, undefined, null); + expect(result.testResults[0].assertionResults[0].fullName).toEqual( + assertion.fullName, + ); + }); + const skippedAssertion = { fullName: 'Pending test', status: 'pending', From c6ccacd0955a63839ba9b95418f9a967d13a534b Mon Sep 17 00:00:00 2001 From: Luca Pizzini Date: Sat, 31 Dec 2022 10:24:02 +0100 Subject: [PATCH 4/9] =?UTF-8?q?Added=20type=20casting=20to=20tests=20and?= =?UTF-8?q?=20missing=20=C2=A0type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/__tests__/formatTestResults.test.ts | 23 ++++++++----------- packages/jest-types/src/TestResult.ts | 9 +++++++- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/jest-test-result/src/__tests__/formatTestResults.test.ts b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts index c25565562272..826cb9cfb5b6 100644 --- a/packages/jest-test-result/src/__tests__/formatTestResults.test.ts +++ b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts @@ -6,25 +6,24 @@ */ import formatTestResults from '../formatTestResults'; -import type {AggregatedResult} from '../types'; +import type {AggregatedResult, AssertionResult} from '../types'; describe('formatTestResults', () => { const assertion = { fullName: 'TestedModule#aMethod when some condition is met returns true', status: 'passed', title: 'returns true', - }; + } as AssertionResult; - const results: AggregatedResult = { + const results = { testResults: [ { numFailingTests: 0, perfStats: {end: 2, runtime: 1, slow: false, start: 1}, - // @ts-expect-error testResults: [assertion], }, ], - }; + } as AggregatedResult; it('includes test full name', () => { const result = formatTestResults(results, undefined, null); @@ -37,9 +36,9 @@ describe('formatTestResults', () => { fullName: 'Pending test', status: 'pending', title: 'is still pending', - }; + } as AssertionResult; - const skippedResults: AggregatedResult = { + const skippedResults = { testResults: [ { numFailingTests: 0, @@ -47,11 +46,10 @@ describe('formatTestResults', () => { numPendingTests: 2, numTodoTests: 2, perfStats: {end: 2, runtime: 1, slow: false, start: 1}, - // @ts-expect-error testResults: [skippedAssertion], }, ], - }; + } as AggregatedResult; it('should mark result status to skipped', () => { const result = formatTestResults(skippedResults, undefined, null); @@ -64,9 +62,9 @@ describe('formatTestResults', () => { fullName: 'Focused test', status: 'focused', title: 'focused test', - }; + } as AssertionResult; - const focusedResults: AggregatedResult = { + const focusedResults = { testResults: [ { numFailingTests: 0, @@ -74,11 +72,10 @@ describe('formatTestResults', () => { numPendingTests: 1, numTodoTests: 2, perfStats: {end: 2, runtime: 1, slow: false, start: 1}, - // @ts-expect-error testResults: [focusedAssertion], }, ], - }; + } as AggregatedResult; it('should mark result status to focused', () => { const result = formatTestResults(focusedResults, undefined, null); diff --git a/packages/jest-types/src/TestResult.ts b/packages/jest-types/src/TestResult.ts index 57981fe9800c..29d6bdf75bc0 100644 --- a/packages/jest-types/src/TestResult.ts +++ b/packages/jest-types/src/TestResult.ts @@ -5,7 +5,14 @@ * LICENSE file in the root directory of this source tree. */ -type Status = 'passed' | 'failed' | 'skipped' | 'pending' | 'todo' | 'disabled'; +type Status = + | 'passed' + | 'failed' + | 'skipped' + | 'pending' + | 'todo' + | 'disabled' + | 'focused'; type Callsite = { column: number; From 0b55335a68a18faa6b4c95a18c1345ac4056b5a4 Mon Sep 17 00:00:00 2001 From: Luca Pizzini Date: Sat, 31 Dec 2022 11:19:42 +0100 Subject: [PATCH 5/9] Removed unecessary typecast to AssertionResult --- .../src/__tests__/formatTestResults.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/jest-test-result/src/__tests__/formatTestResults.test.ts b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts index 826cb9cfb5b6..2e0e6aff6c44 100644 --- a/packages/jest-test-result/src/__tests__/formatTestResults.test.ts +++ b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts @@ -6,14 +6,14 @@ */ import formatTestResults from '../formatTestResults'; -import type {AggregatedResult, AssertionResult} from '../types'; +import type {AggregatedResult} from '../types'; describe('formatTestResults', () => { const assertion = { fullName: 'TestedModule#aMethod when some condition is met returns true', status: 'passed', title: 'returns true', - } as AssertionResult; + }; const results = { testResults: [ @@ -36,7 +36,7 @@ describe('formatTestResults', () => { fullName: 'Pending test', status: 'pending', title: 'is still pending', - } as AssertionResult; + }; const skippedResults = { testResults: [ @@ -62,7 +62,7 @@ describe('formatTestResults', () => { fullName: 'Focused test', status: 'focused', title: 'focused test', - } as AssertionResult; + }; const focusedResults = { testResults: [ From bf6d28f1dc544cdaef7d223e39638248190e4f3a Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 31 Dec 2022 11:21:55 +0100 Subject: [PATCH 6/9] Apply suggestions from code review Co-authored-by: Tom Mrazauskas --- .../jest-test-result/src/__tests__/formatTestResults.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jest-test-result/src/__tests__/formatTestResults.test.ts b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts index 2e0e6aff6c44..36a79cc14afd 100644 --- a/packages/jest-test-result/src/__tests__/formatTestResults.test.ts +++ b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts @@ -6,7 +6,7 @@ */ import formatTestResults from '../formatTestResults'; -import type {AggregatedResult} from '../types'; +import type {AggregatedResult, AssertionResult} from '../types'; describe('formatTestResults', () => { const assertion = { @@ -36,7 +36,7 @@ describe('formatTestResults', () => { fullName: 'Pending test', status: 'pending', title: 'is still pending', - }; + } as AssertionResult; const skippedResults = { testResults: [ From 9e1e23ad8a4f6b01f03f6a48a800c77d92e7a871 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 31 Dec 2022 11:24:15 +0100 Subject: [PATCH 7/9] Revert "Apply suggestions from code review" This reverts commit bf6d28f1dc544cdaef7d223e39638248190e4f3a. --- .../jest-test-result/src/__tests__/formatTestResults.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/jest-test-result/src/__tests__/formatTestResults.test.ts b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts index 36a79cc14afd..2e0e6aff6c44 100644 --- a/packages/jest-test-result/src/__tests__/formatTestResults.test.ts +++ b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts @@ -6,7 +6,7 @@ */ import formatTestResults from '../formatTestResults'; -import type {AggregatedResult, AssertionResult} from '../types'; +import type {AggregatedResult} from '../types'; describe('formatTestResults', () => { const assertion = { @@ -36,7 +36,7 @@ describe('formatTestResults', () => { fullName: 'Pending test', status: 'pending', title: 'is still pending', - } as AssertionResult; + }; const skippedResults = { testResults: [ From 6bf4cfcf86acdf804c9e026972ca8f5511d6cf88 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 31 Dec 2022 11:24:17 +0100 Subject: [PATCH 8/9] Revert "Removed unecessary typecast to AssertionResult" This reverts commit 0b55335a68a18faa6b4c95a18c1345ac4056b5a4. --- .../src/__tests__/formatTestResults.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/jest-test-result/src/__tests__/formatTestResults.test.ts b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts index 2e0e6aff6c44..826cb9cfb5b6 100644 --- a/packages/jest-test-result/src/__tests__/formatTestResults.test.ts +++ b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts @@ -6,14 +6,14 @@ */ import formatTestResults from '../formatTestResults'; -import type {AggregatedResult} from '../types'; +import type {AggregatedResult, AssertionResult} from '../types'; describe('formatTestResults', () => { const assertion = { fullName: 'TestedModule#aMethod when some condition is met returns true', status: 'passed', title: 'returns true', - }; + } as AssertionResult; const results = { testResults: [ @@ -36,7 +36,7 @@ describe('formatTestResults', () => { fullName: 'Pending test', status: 'pending', title: 'is still pending', - }; + } as AssertionResult; const skippedResults = { testResults: [ @@ -62,7 +62,7 @@ describe('formatTestResults', () => { fullName: 'Focused test', status: 'focused', title: 'focused test', - }; + } as AssertionResult; const focusedResults = { testResults: [ From ba610515a2cd544e29c0eeb8567a74ee679f34f8 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 31 Dec 2022 11:26:32 +0100 Subject: [PATCH 9/9] move variables inside test scope --- .../src/__tests__/formatTestResults.test.ts | 102 +++++++++--------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/packages/jest-test-result/src/__tests__/formatTestResults.test.ts b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts index 826cb9cfb5b6..0791d52420e9 100644 --- a/packages/jest-test-result/src/__tests__/formatTestResults.test.ts +++ b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts @@ -9,75 +9,75 @@ import formatTestResults from '../formatTestResults'; import type {AggregatedResult, AssertionResult} from '../types'; describe('formatTestResults', () => { - const assertion = { - fullName: 'TestedModule#aMethod when some condition is met returns true', - status: 'passed', - title: 'returns true', - } as AssertionResult; + it('includes test full name', () => { + const assertion = { + fullName: 'TestedModule#aMethod when some condition is met returns true', + status: 'passed', + title: 'returns true', + } as AssertionResult; - const results = { - testResults: [ - { - numFailingTests: 0, - perfStats: {end: 2, runtime: 1, slow: false, start: 1}, - testResults: [assertion], - }, - ], - } as AggregatedResult; + const results = { + testResults: [ + { + numFailingTests: 0, + perfStats: {end: 2, runtime: 1, slow: false, start: 1}, + testResults: [assertion], + }, + ], + } as AggregatedResult; - it('includes test full name', () => { const result = formatTestResults(results, undefined, null); expect(result.testResults[0].assertionResults[0].fullName).toEqual( assertion.fullName, ); }); - const skippedAssertion = { - fullName: 'Pending test', - status: 'pending', - title: 'is still pending', - } as AssertionResult; + it('should mark result status to skipped', () => { + const skippedAssertion = { + fullName: 'Pending test', + status: 'pending', + title: 'is still pending', + } as AssertionResult; - const skippedResults = { - testResults: [ - { - numFailingTests: 0, - numPassingTests: 0, - numPendingTests: 2, - numTodoTests: 2, - perfStats: {end: 2, runtime: 1, slow: false, start: 1}, - testResults: [skippedAssertion], - }, - ], - } as AggregatedResult; + const skippedResults = { + testResults: [ + { + numFailingTests: 0, + numPassingTests: 0, + numPendingTests: 2, + numTodoTests: 2, + perfStats: {end: 2, runtime: 1, slow: false, start: 1}, + testResults: [skippedAssertion], + }, + ], + } as AggregatedResult; - it('should mark result status to skipped', () => { const result = formatTestResults(skippedResults, undefined, null); expect(result.testResults[0].assertionResults[0].status).toEqual( skippedAssertion.status, ); }); - const focusedAssertion = { - fullName: 'Focused test', - status: 'focused', - title: 'focused test', - } as AssertionResult; + it('should mark result status to focused', () => { + const focusedAssertion = { + fullName: 'Focused test', + status: 'focused', + title: 'focused test', + } as AssertionResult; - const focusedResults = { - testResults: [ - { - numFailingTests: 0, - numPassingTests: 1, - numPendingTests: 1, - numTodoTests: 2, - perfStats: {end: 2, runtime: 1, slow: false, start: 1}, - testResults: [focusedAssertion], - }, - ], - } as AggregatedResult; + const focusedResults = { + testResults: [ + { + numFailingTests: 0, + numPassingTests: 1, + numPendingTests: 1, + numTodoTests: 2, + perfStats: {end: 2, runtime: 1, slow: false, start: 1}, + testResults: [focusedAssertion], + }, + ], + } as AggregatedResult; - it('should mark result status to focused', () => { const result = formatTestResults(focusedResults, undefined, null); expect(result.testResults[0].assertionResults[0].status).toEqual( focusedAssertion.status,