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

Add util to create empty testResult #8867

Merged
merged 5 commits into from Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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