diff --git a/CHANGELOG.md b/CHANGELOG.md index 89d071ccc605..9c4c69ff3817 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/expect-utils]` `toMatchObject` should handle `Symbol` properties ([#13639](https://github.com/facebook/jest/pull/13639)) diff --git a/packages/jest-test-result/src/__tests__/formatTestResults.test.ts b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts index 68936ddc25af..0791d52420e9 100644 --- a/packages/jest-test-result/src/__tests__/formatTestResults.test.ts +++ b/packages/jest-test-result/src/__tests__/formatTestResults.test.ts @@ -6,30 +6,81 @@ */ import formatTestResults from '../formatTestResults'; -import {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', - }; - - const results: AggregatedResult = { - testResults: [ - { - numFailingTests: 0, - perfStats: {end: 2, runtime: 1, slow: false, start: 1}, - // @ts-expect-error - testResults: [assertion], - }, - ], - }; - 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 result = formatTestResults(results, undefined, null); expect(result.testResults[0].assertionResults[0].fullName).toEqual( assertion.fullName, ); }); + + 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 result = formatTestResults(skippedResults, undefined, null); + expect(result.testResults[0].assertionResults[0].status).toEqual( + skippedAssertion.status, + ); + }); + + 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 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..6e43024169e1 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: allTestsPassed + ? allTestsExecuted + ? 'passed' + : 'focused' + : 'failed', 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; 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;