Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added skipped and focused status to FormattedTestResult #13700

Merged
merged 9 commits into from
Dec 31, 2022
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
87 changes: 69 additions & 18 deletions packages/jest-test-result/src/__tests__/formatTestResults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,81 @@
*/

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 = {
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', () => {
SimenB marked this conversation as resolved.
Show resolved Hide resolved
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,
);
});
});
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