Skip to content

Commit

Permalink
feat: Add util to create empty testResult
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark1626 committed Aug 22, 2019
1 parent 08f109c commit 0833d8e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 23 deletions.
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,
emptyTestResult,
} 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 {
...emptyTestResult(),
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
7 changes: 2 additions & 5 deletions packages/jest-jasmine2/src/reporter.ts
Expand Up @@ -6,7 +6,7 @@
*/

import {Config} from '@jest/types';
import {AssertionResult, TestResult} from '@jest/test-result';
import {AssertionResult, TestResult, emptyTestResult} 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 +78,7 @@ export default class Jasmine2Reporter implements Reporter {
});

const testResult = {
...emptyTestResult(),
console: null,
failureMessage: formatResultsErrors(
testResults,
Expand All @@ -89,10 +90,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 emptyTestResult = (): TestResult => ({
leaks: false, // That's legacy code, just adding it so Flow is happy.
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,
emptyTestResult,
makeEmptyAggregatedTestResult,
} from './helpers';
export {
Expand Down

0 comments on commit 0833d8e

Please sign in to comment.