Skip to content
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
59 changes: 55 additions & 4 deletions packages/jest-test-result/src/__tests__/formatTestResults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import formatTestResults from '../formatTestResults';
import {AggregatedResult} from '../types';
import type {AggregatedResult, AssertionResult} from '../types';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimenB It was unnecessary to add AssertionResult. My mistake, see: #13700 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't hurt


describe('formatTestResults', () => {
const assertion = {
Expand All @@ -15,21 +15,72 @@ describe('formatTestResults', () => {
title: 'returns true',
};

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);
expect(result.testResults[0].assertionResults[0].fullName).toEqual(
assertion.fullName,
);
});

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;

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 = {
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,
);
});
});
21 changes: 20 additions & 1 deletion packages/jest-test-result/src/formatTestResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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: '',
};
};
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-test-result/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion packages/jest-types/src/TestResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down