Skip to content

Commit

Permalink
Add util to create empty testResult (#8867)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark1626 authored and SimenB committed Aug 22, 2019
1 parent 16f7385 commit 588f93a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@

- `[babel-plugin-jest-hoist]` Show codeframe on static hoisting issues ([#8865](https://github.com/facebook/jest/pull/8865))
- `[jest-config]` [**BREAKING**] Set default display name color based on runner ([#8689](https://github.com/facebook/jest/pull/8689))
- `[@jest/test-result]` Create method to create empty `TestResult` ([#8867](https://github.com/facebook/jest/pull/8867))

### Fixes

Expand Down
Expand Up @@ -7,7 +7,12 @@

import {Circus, Config, Global} from '@jest/types';
import {JestEnvironment} from '@jest/environment';
import {AssertionResult, Status, TestResult} from '@jest/test-result';
import {
AssertionResult,
Status,
TestResult,
createEmptyTestResult,
} from '@jest/test-result';
import {extractExpectedAssertionsErrors, getState, setState} from 'expect';
import {formatExecError, formatResultsErrors} from 'jest-message-util';
import {
Expand Down Expand Up @@ -215,30 +220,14 @@ export const runAndTransformResultsToJestFormat = async ({

dispatch({name: 'teardown'});
return {
...createEmptyTestResult(),
console: undefined,
displayName: config.displayName,
failureMessage,
leaks: false, // That's legacy code, just adding it so Flow is happy.
numFailingTests,
numPassingTests,
numPendingTests,
numTodoTests,
openHandles: [],
perfStats: {
// populated outside
end: 0,
start: 0,
},
skipped: false,
snapshot: {
added: 0,
fileDeleted: false,
matched: 0,
unchecked: 0,
uncheckedKeys: [],
unmatched: 0,
updated: 0,
},
sourceMaps: {},
testExecError,
testFilePath: testPath,
Expand Down
11 changes: 6 additions & 5 deletions packages/jest-jasmine2/src/reporter.ts
Expand Up @@ -6,7 +6,11 @@
*/

import {Config} from '@jest/types';
import {AssertionResult, TestResult} from '@jest/test-result';
import {
AssertionResult,
TestResult,
createEmptyTestResult,
} from '@jest/test-result';
import {formatResultsErrors} from 'jest-message-util';
import {SpecResult} from './jasmine/Spec';
import {SuiteResult} from './jasmine/Suite';
Expand Down Expand Up @@ -78,6 +82,7 @@ export default class Jasmine2Reporter implements Reporter {
});

const testResult = {
...createEmptyTestResult(),
console: null,
failureMessage: formatResultsErrors(
testResults,
Expand All @@ -89,10 +94,6 @@ export default class Jasmine2Reporter implements Reporter {
numPassingTests,
numPendingTests,
numTodoTests,
perfStats: {
end: 0,
start: 0,
},
snapshot: {
added: 0,
fileDeleted: false,
Expand Down
25 changes: 25 additions & 0 deletions packages/jest-test-result/src/helpers.ts
Expand Up @@ -145,3 +145,28 @@ export const addResult = (
testResult.snapshot.unmatched +
testResult.snapshot.updated;
};

export const createEmptyTestResult = (): TestResult => ({
leaks: false, // That's legacy code, just adding it as needed for typing
numFailingTests: 0,
numPassingTests: 0,
numPendingTests: 0,
numTodoTests: 0,
openHandles: [],
perfStats: {
end: 0,
start: 0,
},
skipped: false,
snapshot: {
added: 0,
fileDeleted: false,
matched: 0,
unchecked: 0,
uncheckedKeys: [],
unmatched: 0,
updated: 0,
},
testFilePath: '',
testResults: [],
});
1 change: 1 addition & 0 deletions packages/jest-test-result/src/index.ts
Expand Up @@ -9,6 +9,7 @@ export {default as formatTestResults} from './formatTestResults';
export {
addResult,
buildFailureTestResult,
createEmptyTestResult,
makeEmptyAggregatedTestResult,
} from './helpers';
export {
Expand Down

0 comments on commit 588f93a

Please sign in to comment.