Skip to content

Commit

Permalink
feat: Added skipped and focused status to FormattedTestResult (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lpizzinidev committed Dec 31, 2022
1 parent fb37bd1 commit f7132ef
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
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/expect-utils]` `toMatchObject` should handle `Symbol` properties ([#13639](https://github.com/facebook/jest/pull/13639))
Expand Down
87 changes: 69 additions & 18 deletions packages/jest-test-result/src/__tests__/formatTestResults.test.ts
Expand Up @@ -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,
);
});
});
21 changes: 20 additions & 1 deletion packages/jest-test-result/src/formatTestResults.ts
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
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
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

0 comments on commit f7132ef

Please sign in to comment.